source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Utilities_General.ipf @ 987

Last change on this file since 987 was 987, checked in by srkline, 7 years ago

lots of changes to how VCALC simulations can be written to Nexus files to effectively make test data with different callues before the virtual machine is ready. many changes for visualization to effectively handle zeros in log scaled images

File size: 5.3 KB
Line 
1#pragma TextEncoding = "MacRoman"               // For details execute DisplayHelpTopic "The TextEncoding Pragma"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4//
5//              general utilities
6//
7// for use by multiple panels and packages
8
9
10//prompts user to choose the local folder that contains the SANS Data
11//only one folder can be used, and its path is catPathName (and is a NAME, not a string)
12//this will overwrite the path selection
13//returns 1 if no path selected as error condition, or if user cancelled
14Function V_PickPath()
15       
16        //set the global string to the selected pathname
17        NewPath/O/M="pick the SANS data folder" catPathName
18        if(V_Flag != 0)
19                return(1)               //user cancelled
20        endif
21       
22        PathInfo/S catPathName
23        String dum = S_path
24        String alertStr = ""
25        alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"
26        //alertStr += "  Please see the manual for details."
27        if (V_flag == 0)
28                //path does not exist - no folder selected
29                String/G root:Packges:NIST:VSANS:Globals:gCatPathStr = "no folder selected"
30                return(1)
31        else
32                //set the global to the path (as a string)
33                // need 4 \ since it is the escape character
34                if(cmpstr("\\\\",dum[0,1])==0)  //Windows user going through network neighborhood
35                        DoAlert 0,alertStr
36                        KillPath catPathName
37                        return(1)
38                endif
39                String/G root:Packges:NIST:VSANS:Globals:gCatPathStr = dum
40                return(0)               //no error
41        endif
42End
43
44//
45// entry from the Main Panel
46//
47Proc V_ChangeDisplay(type)
48        String type
49        Prompt type,"WORK data type to display",popup,"RAW;SAM;EMP;BGD;ADJ;"
50
51        UpdateDisplayInformation(type)
52End
53
54//
55// tests if two values are close enough to each other
56// very useful since ICE came to be
57//
58// tol is an absolute value (since input v1 or v2 may be zero, can't reliably
59// use a percentage
60Function CloseEnough(v1,v2,tol)
61        Variable v1, v2, tol
62
63        if(abs(v1-v2) < tol)
64                return(1)
65        else
66                return(0)
67        endif
68End
69
70
71
72// TODO:
73// -- this must be called as needed to force a re-read of the data from disk
74//    "as needed" means that when an operation is done that needs to ensure
75//     a fresh read from disk, it must take care of the kill.
76// -- the ksBaseDFPath needs to be removed. It's currently pointing to RawVSANS, which is
77//    really not used as intended anymore.
78//
79Function V_KillNamedDataFolder(fname)
80        String fname
81       
82        Variable err=0
83       
84        String folderStr = V_GetFileNameFromPathNoSemi(fname)
85        folderStr = V_RemoveDotExtension(folderStr)
86       
87        KillDataFolder/Z $(ksBaseDFPath+folderStr)
88        err = V_flag
89       
90        return(err)
91end
92
93//given a filename of a SANS data filename of the form
94// name.anything
95//returns the name as a string without the ".fbdfasga" extension
96//
97// returns the input string if a "." can't be found (maybe it wasn't there)
98Function/S V_RemoveDotExtension(item)
99        String item
100        String invalid = item   //
101        Variable num=-1
102       
103        //find the "dot"
104        String runStr=""
105        Variable pos = strsearch(item,".",0)
106        if(pos == -1)
107                //"dot" not found
108                return (invalid)
109        else
110                //found, get all of the characters preceeding it
111                runStr = item[0,pos-1]
112                return (runStr)
113        Endif
114End
115
116//returns a string containing filename (WITHOUT the ;vers)
117//the input string is a full path to the file (Mac-style, still works on Win in IGOR)
118//with the folders separated by colons
119//
120// called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf
121//
122Function/S V_GetFileNameFromPathNoSemi(fullPath)
123        String fullPath
124       
125        Variable offset1,offset2
126        String filename=""
127        //String PartialPath
128        offset1 = 0
129        do
130                offset2 = StrSearch(fullPath, ":", offset1)
131                if (offset2 == -1)                              // no more colons ?
132                        fileName = FullPath[offset1,strlen(FullPath) ]
133                        //PartialPath = FullPath[0, offset1-1]
134                        break
135                endif
136                offset1 = offset2+1
137        while (1)
138       
139        //remove version number from name, if it's there - format should be: filename;N
140        filename =  StringFromList(0,filename,";")              //returns null if error
141       
142        Return filename
143End
144
145//
146// -- this was copied directly, no changes , from PlotUtils_Macro_v40
147//
148// returns the path to the file, or null if the user cancelled
149// fancy use of optional parameters
150//
151// enforce short file names (25 characters)
152Function/S V_DoSaveFileDialog(msg,[fname,suffix])
153        String msg,fname,suffix
154        Variable refNum
155//      String message = "Save the file as"
156
157        if(ParamIsDefault(fname))
158//              Print "fname not supplied"
159                fname = ""
160        endif
161        if(ParamIsDefault(suffix))
162//              Print "suffix not supplied"
163                suffix = ""
164        endif
165       
166        String outputPath,tmpName,testStr
167        Variable badLength=0,maxLength=25,l1,l2
168       
169       
170        tmpName = fname + suffix
171       
172        do
173                badLength=0
174                Open/D/M=msg/T="????" refNum as tmpName         //OS will allow 255 characters, but then I can't read it back in!
175                outputPath = S_fileName
176               
177                testStr = ParseFilePath(0, outputPath, ":", 1, 0)               //just the filename
178                if(strlen(testStr)==0)
179                        break           //cancel, allow exit
180                endif
181                if(strlen(testStr) > maxLength)
182                        badlength = 1
183                        DoAlert 2,"File name is too long. Is\r"+testStr[0,maxLength-1]+"\rOK?"
184                        if(V_flag==3)
185                                outputPath = ""
186                                break
187                        endif
188                        if(V_flag==1)                   //my suggested name is OK, so trim the output
189                                badlength=0
190                                l1 = strlen(testStr)            //too long length
191                                l1 = l1-maxLength               //number to trim
192                                //Print outputPath
193                                l2=strlen(outputPath)
194                                outputPath = outputPath[0,l2-1-l1]
195                                //Print "modified  ",outputPath
196                        endif
197                        //if(V_flag==2)  do nothing, let it go around again
198                endif
199               
200        while(badLength)
201       
202        return outputPath
203End
204
205
Note: See TracBrowser for help on using the repository browser.