source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/PlotUtilsMacro.ipf @ 211

Last change on this file since 211 was 211, checked in by srkline, 15 years ago

Several disjoint changes:

1) Threaded the 1D Cylinder_PolyRadius function
2) in Wrapper, popping the data set list now will auto-pop the function, then the coef to properly update the table of coefficients.
3) tick units in the plots are suppressed (y-axis)
4) Killing data (PlotManager?) now kills the dependent variable so that the rest can be killed
5) Ellipsoid_2D function now has the correct notation of the rotation axis in the parameter names.

File size: 21.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=3.00
3#pragma IgorVersion=6.0
4
5// This is to be used with the Analysis packages ONLY
6// there are a number of utility procedures here for loading
7// data and generating valid lists of data files that are
8// directly copied from the Reduction package
9// -- There WILL be name conflicts if you mix the two...
10//
11// 16 DEC 05 SRK
12// prepended function names with A_ to tag them for the
13// "A"nalysis parckage, though nearly all are duplicate procedures
14// so there will be no overlap with the reduction package
15//
16//
17// these extra procedures are used by:
18// Linearized fits (duplicated in Reduction - will need to handle gently)
19// Invariant (no overlap with reduction)
20//
21// SRK MAR 2005
22
23// create a KW=string; of model=coef correspondence as the models are plotted, rather than
24// some other hard-wired solution
25Function AddModelToStrings(funcStr,coefStr,suffix)
26        String funcStr,coefStr,suffix
27       
28        if(exists("root:coefKWStr")==0)
29                String/G root:coefKWStr=""
30                String/G root:suffixKWStr=""
31        endif
32        SVAR coefKWStr = root:coefKWStr
33        SVAR suffixKWStr = root:suffixKWStr
34        coefKWStr += funcStr+"="+coefStr+";"
35        suffixKWStr += coefStr+"="+suffix+";"
36end
37
38// loads a 1-d (ascii) datafile and plots the data
39// will overwrite existing data if user is OK with this
40// - multiple datasets can be automatically plotted on the same graph
41//
42//substantially easier to write this as a Proc rather than a function...
43
44//
45Proc A_LoadOneDData()
46        A_LoadOneDDataWithName("",1)            //will prompt for file and plot data
47End
48
49// load the data specified by fileStr (a full path:name)
50// and plots if doPlot==1
51// if fileStr is null, a dialog is presented to select the file
52//
53// 3 cases (if)
54// - 3 columns = QIS, no resolution
55// - 6 columns = QSIG, SANS w/resolution
56// - 5 columns = old-style desmeared USANS data (from VAX)
57//
58// This loader replaces the A_LoadOneDData() which was almost completely duplicated code
59//
60//new version, 19JUN07 that loads each data set into a separate data folder
61// the data folder is given the "base name" of the data file as it's loaded
62//
63Proc A_LoadOneDDataWithName(fileStr,doPlot)
64        String fileStr
65        Variable doPlot
66       
67        Variable rr,gg,bb
68        SetDataFolder root:             //build sub-folders for each data set under root
69       
70        //Load the waves, using default waveX names
71        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
72        LoadWave/G/D/A/Q fileStr
73        String fileName = S_fileName
74        Variable numCols = V_flag
75       
76        if(numCols==3)          //simple 3-column data with no resolution information
77                String w0,w1,w2,n0,n1,n2
78               
79                // put the names of the three loaded waves into local names
80                n0 = StringFromList(0, S_waveNames ,";" )
81                n1 = StringFromList(1, S_waveNames ,";" )
82                n2 = StringFromList(2, S_waveNames ,";" )
83               
84                //remove the semicolon AND period from files from the VAX
85                w0 = CleanupName((S_fileName + "_q"),0)
86                w1 = CleanupName((S_fileName + "_i"),0)
87                w2 = CleanupName((S_fileName + "_s"),0)
88               
89                String baseStr=w1[0,strlen(w1)-3]
90                if(DataFolderExists("root:"+baseStr))
91                                DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
92                                if(V_flag==2)   //user selected No, don't load the data
93                                        SetDataFolder root:
94                                        KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
95                                        //if(DataFolderExists("root:myGlobals"))
96                                        //      String/G root:myGlobals:gLastFileName = filename
97                                        //endif
98                                        return          //quits the macro
99                                endif
100                                SetDataFolder $("root:"+baseStr)
101                else
102                        NewDataFolder/S $("root:"+baseStr)
103                endif
104               
105                ////overwrite the existing data, if it exists
106                Duplicate/O $("root:"+n0), $w0
107                Duplicate/O $("root:"+n1), $w1
108                Duplicate/O $("root:"+n2), $w2
109
110                // no resolution matrix to make
111
112                SetScale d,0,0,"1/A",$w0
113                SetScale d,0,0,"1/cm",$w1
114               
115        endif           //3-col data
116       
117        if(numCols == 6)                //6-column SANS or USANS data that has resolution information
118                String w0,w1,w2,n0,n1,n2
119                String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
120               
121                // put the names of the (default named) loaded waves into local names
122                n0 = StringFromList(0, S_waveNames ,";" )
123                n1 = StringFromList(1, S_waveNames ,";" )
124                n2 = StringFromList(2, S_waveNames ,";" )
125                n3 = StringFromList(3, S_waveNames ,";" )
126                n4 = StringFromList(4, S_waveNames ,";" )
127                n5 = StringFromList(5, S_waveNames ,";" )
128               
129                //remove the semicolon AND period from files from the VAX
130                w0 = CleanupName((S_fileName + "_q"),0)
131                w1 = CleanupName((S_fileName + "_i"),0)
132                w2 = CleanupName((S_fileName + "_s"),0)
133                w3 = CleanupName((S_fileName + "sq"),0)
134                w4 = CleanupName((S_fileName + "qb"),0)
135                w5 = CleanupName((S_fileName + "fs"),0)
136               
137                String baseStr=w1[0,strlen(w1)-3]
138                if(DataFolderExists("root:"+baseStr))
139                                DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
140                                if(V_flag==2)   //user selected No, don't load the data
141                                        SetDataFolder root:
142                                        KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
143                                        //if(DataFolderExists("root:myGlobals"))
144                                        //      String/G root:myGlobals:gLastFileName = filename
145                                        //endif         //set the last file loaded to the one NOT loaded
146                                        return          //quits the macro
147                                endif
148                                SetDataFolder $("root:"+baseStr)
149                else
150                        NewDataFolder/S $("root:"+baseStr)
151                endif
152
153////overwrite the existing data, if it exists
154                Duplicate/O $("root:"+n0), $w0
155                Duplicate/O $("root:"+n1), $w1
156                Duplicate/O $("root:"+n2), $w2
157                Duplicate/O $("root:"+n3), $w3
158                Duplicate/O $("root:"+n4), $w4
159                Duplicate/O $("root:"+n5), $w5
160
161                // need to switch based on SANS/USANS
162                if (isSANSResolution($w3[0]))           //checks to see if the first point of the wave is <0]
163                        // make a resolution matrix for SANS data
164                        Variable np=numpnts($w0)
165                        Make/D/O/N=(np,4) $(baseStr+"_res")
166                       
167                        $(baseStr+"_res")[][0] = $w3[p]         //sigQ
168                        $(baseStr+"_res")[][1] = $w4[p]         //qBar
169                        $(baseStr+"_res")[][2] = $w5[p]         //fShad
170                        $(baseStr+"_res")[][3] = $w0[p]         //Qvalues
171                else
172                        //the data is USANS data
173                        // marix calculation here, but for now, just copy the waves
174                        //$(baseStr+"_res")[][0] = $w3[p]               //sigQ
175                        //$(baseStr+"_res")[][1] = $w4[p]               //qBar
176                        //$(baseStr+"_res")[][2] = $w5[p]               //fShad
177                        //$(baseStr+"_res")[][3] = $w0[p]               //Qvalues
178                       
179                        USANS_CalcWeights(baseStr,-$w3[0])
180                       
181                endif
182                Killwaves/Z $w3,$w4,$w5                 //get rid of the resolution waves that are in the matrix
183
184                SetScale d,0,0,"1/A",$w0
185                SetScale d,0,0,"1/cm",$w1
186       
187        endif   //6-col data
188
189        if(numCols==5)          //this is the "old-style" VAX desmeared data format
190                String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
191                Variable rr,gg,bb
192               
193                // put the names of the three loaded waves into local names
194                n0 = StringFromList(0, S_waveNames ,";" )
195                n1 = StringFromList(1, S_waveNames ,";" )
196                n2 = StringFromList(2, S_waveNames ,";" )
197                n3 = StringFromList(3, S_waveNames ,";" )
198                n4 = StringFromList(4, S_waveNames ,";" )
199               
200               
201                //remove the semicolon AND period from files from the VAX
202                w0 = CleanupName((S_fileName+"_q"),0)
203                w1 = CleanupName((S_fileName+"_i"),0)
204                w2 = CleanupName((S_fileName+"_s"),0)
205                w3 = CleanupName((S_fileName+"_ism"),0)
206                w4 = CleanupName((S_fileName+"_fit_ism"),0)
207               
208                String baseStr=w1[0,strlen(w1)-3]
209                if(DataFolderExists("root:"+baseStr))
210                                DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
211                                if(V_flag==2)   //user selected No, don't load the data
212                                        KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
213                                        //if(DataFolderExists("root:myGlobals"))
214                                        //      String/G root:myGlobals:gLastFileName = filename
215                                        //endif         //set the last file loaded to the one NOT loaded
216                                        return          //quits the macro
217                                endif
218                                SetDataFolder $("root:"+baseStr)
219                else
220                        NewDataFolder/S $("root:"+baseStr)
221                endif
222               
223                ////overwrite the existing data, if it exists   
224                Duplicate/O $("root:"+n0), $w0
225                Duplicate/O $("root:"+n1), $w1
226                Duplicate/O $("root:"+n2), $w2
227                Duplicate/O $("root:"+n3), $w3
228                Duplicate/O $("root:"+n4), $w4
229               
230                // no resolution matrix
231        endif           //5-col data
232       
233        //////
234        if(DataFolderExists("root:myGlobals"))
235                String/G root:myGlobals:gLastFileName = filename
236        endif
237       
238        //plot if desired
239        if(doPlot)
240                // assign colors randomly
241                rr = abs(trunc(enoise(65535)))
242                gg = abs(trunc(enoise(65535)))
243                bb = abs(trunc(enoise(65535)))
244               
245                // if target window is a graph, and user wants to append, do so
246           DoWindow/B Plot_Manager
247                if(WinType("") == 1)
248                        DoAlert 1,"Do you want to append this data to the current graph?"
249                        if(V_Flag == 1)
250                                AppendToGraph $w1 vs $w0
251                                ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb)
252                                ErrorBars $w1 Y,wave=($w2,$w2)
253                                ModifyGraph tickUnit(left)=1
254                        else
255                        //new graph
256                                Display $w1 vs $w0
257                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb)
258                                ModifyGraph grid=1,mirror=2,standoff=0
259                                ErrorBars $w1 Y,wave=($w2,$w2)
260                                ModifyGraph tickUnit(left)=1
261                                Legend
262                        endif
263                else
264                // graph window was not target, make new one
265                        Display $w1 vs $w0
266                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb)
267                        ModifyGraph grid=1,mirror=2,standoff=0
268                        ErrorBars $w1 Y,wave=($w2,$w2)
269                        ModifyGraph tickUnit(left)=1
270                        Legend
271                endif
272        endif
273               
274        //go back to the root folder and clean up before leaving
275        SetDataFolder root:
276        KillWaves/Z $n0,$n1,$n2,$n3,$n4,$n5
277End
278
279
280//procedure for loading NSE data in the format (4-columns)
281// qvals - time - I(q,t) - dI(q,t)
282//
283//
284// this does NOT load the data into separate folders...
285//
286Proc A_LoadNSEData()
287        A_LoadNSEDataWithName("",1)
288End
289
290Proc A_LoadNSEDataWithName(fileStr,doPlot)
291
292        //Load the waves, using default waveX names
293        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
294        LoadWave/G/D/A  fileStr
295        String filename = S_fileName
296       
297        String w0,w1,w2,n0,n1,n2,wt,w3,n3
298        Variable rr,gg,bb
299       
300        // put the names of the three loaded waves into local names
301        n0 = StringFromList(0, S_waveNames ,";" )
302        n1 = StringFromList(1, S_waveNames ,";" )
303        n2 = StringFromList(2, S_waveNames ,";" )
304        n3 = StringFromList(3, S_waveNames ,";" )
305       
306       
307        //remove the semicolon AND period from files from the VAX
308        w0 = CleanupName(("qvals_"+S_fileName),0)
309        w1 = CleanupName(("time_"+S_fileName),0)
310        w2 = CleanupName(("iqt_"+S_fileName),0)
311        w3 = CleanupName(("iqterr_"+S_fileName),0)
312       
313        if(exists(w0) !=0)
314                DoAlert 0,"This file has already been loaded. Use Append to Graph..."
315                KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
316                return
317        endif
318       
319        // Rename to give nice names
320        Rename $n0, $w0
321        Rename $n1, $w1
322        Rename $n2, $w2
323        Rename $n3, $w3
324               
325        if(doPlot)
326                // assign colors randomly
327                rr = abs(trunc(enoise(65535)))
328                gg = abs(trunc(enoise(65535)))
329                bb = abs(trunc(enoise(65535)))
330               
331                // if target window is a graph, and user wants to append, do so
332                if(WinType("") == 1)
333                        DoAlert 1,"Do you want to append this data to the current graph?"
334                        if(V_Flag == 1)
335                                AppendToGraph $w2 vs $w1
336                                ModifyGraph mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2) =(rr,gg,bb),grid=1,mirror=2,tickUnit=1
337                                ErrorBars $w2 Y,wave=($w3,$w3)
338                        else
339                        //new graph
340                                Display $w2 vs $w1
341                                ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
342                                ErrorBars $w2 Y,wave=($w3,$w3)
343                                Legend
344                        endif
345                else
346                // graph window was not target, make new one
347                        Display $w2 vs $w1
348                        ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
349                        ErrorBars $w2 Y,wave=($w3,$w3)
350                        Legend
351                endif
352        endif //doPlot         
353
354End
355
356//procedure for loading desmeared USANS data in the format (5-columns)
357// qvals - I(q) - sig I - Ism(q) - fitted Ism(q)
358//no weighting wave is created (not needed in IGOR 4)
359//
360// not really ever used...
361//
362Proc A_LoadUSANSData()
363
364        //Load the waves, using default waveX names
365        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
366        LoadWave/G/D/A
367   String filename = S_fileName
368       
369        String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
370        Variable rr,gg,bb
371       
372        // put the names of the three loaded waves into local names
373        n0 = StringFromList(0, S_waveNames ,";" )
374        n1 = StringFromList(1, S_waveNames ,";" )
375        n2 = StringFromList(2, S_waveNames ,";" )
376        n3 = StringFromList(3, S_waveNames ,";" )
377        n4 = StringFromList(4, S_waveNames ,";" )
378       
379       
380        //remove the semicolon AND period from files from the VAX
381        w0 = CleanupName((S_fileName+"_q"),0)
382        w1 = CleanupName((S_fileName+"_i"),0)
383        w2 = CleanupName((S_fileName+"_s"),0)
384        w3 = CleanupName((S_fileName+"_ism"),0)
385        w4 = CleanupName((S_fileName+"_fit_ism"),0)
386       
387        if(exists(w0) !=0)              //the wave already exists
388                DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
389                if(V_flag==2)   //user selected No
390                        KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
391                        if(DataFolderExists("root:myGlobals"))
392                                String/G root:myGlobals:gLastFileName = filename
393                        endif           //set the last file loaded to the one NOT loaded
394                        return          //quits the macro
395                endif
396        endif
397       
398        ////overwrite the existing data, if it exists
399        Duplicate/O $n0, $w0
400        Duplicate/O $n1, $w1
401        Duplicate/O $n2, $w2
402        Duplicate/O $n3, $w3
403        Duplicate/O $n4, $w4
404        KillWaves $n0,$n1,$n2,$n3,$n4
405       
406        if(DataFolderExists("root:myGlobals"))
407                String/G root:myGlobals:gLastFileName = filename
408        endif
409               
410        // assign colors randomly
411        rr = abs(trunc(enoise(65535)))
412        gg = abs(trunc(enoise(65535)))
413        bb = abs(trunc(enoise(65535)))
414       
415                // if target window is a graph, and user wants to append, do so
416        if(WinType("") == 1)
417                DoAlert 1,"Do you want to append this data to the current graph?"
418                if(V_Flag == 1)
419                        AppendToGraph $w1 vs $w0
420                        ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
421                        ErrorBars $w1 Y,wave=($w2,$w2)
422                else
423                //new graph
424                        Display $w1 vs $w0
425                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
426                        ErrorBars $w1 Y,wave=($w2,$w2)
427                        Legend
428                endif
429        else
430        // graph window was not target, make new one
431                Display $w1 vs $w0
432                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
433                ErrorBars $w1 Y,wave=($w2,$w2)
434                Legend
435        endif
436               
437End
438
439
440//// Extra "Utility Procedures"
441// to pick path, get a list of data files, and make sure that a valid filename
442// is passed to LoadOneDDataWithName()
443//
444
445//prompts user to choose the local folder that contains the SANS Data
446//only one folder can be used, and its path is catPathName (and is a NAME, not a string)
447//this will overwrite the path selection
448//returns 1 if no path selected as error condition
449Function A_PickPath()
450       
451        //set the global string to the selected pathname
452        NewPath/O/M="pick the SANS data folder" catPathName
453        PathInfo/S catPathName
454        String dum = S_path
455        String alertStr = ""
456        alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"
457        //alertStr += "  Please see the manual for details."
458        if (V_flag == 0)
459                //path does not exist - no folder selected
460                String/G root:myGlobals:gCatPathStr = "no folder selected"
461                return(1)
462        else
463                //set the global to the path (as a string)
464                // need 4 \ since it is the escape character
465                if(cmpstr("\\\\",dum[0,1])==0)  //Windoze user going through network neighborhood
466                        DoAlert 0,alertStr
467                        KillPath catPathName
468                        return(1)
469                endif
470                String/G root:myGlobals:gCatPathStr = dum
471                return(0)               //no error
472        endif
473End
474
475//Function attempts to find valid filename from partial name that has been stripped of
476//the VAX version number. The partial name is tried first
477//*** the PATH is hard-wired to catPathName (which is assumed to exist)
478//version numers up to ;10 are tried
479//only the "name;vers" is returned. the path is not prepended, hence the return string
480//is not a complete specification of the file
481//
482// added 11/99 - uppercase and lowercase versions of the file are tried, if necessary
483// since from marquee, the filename field (textread[0]) must be used, and can be a mix of
484// upper/lowercase letters, while the filename on the server (should) be all caps
485// now makes repeated calls to ValidFileString()
486//
487Function/S A_FindValidFilename(partialName)
488        String PartialName
489       
490        String retStr=""
491       
492        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
493        retStr = A_ValidFileString(partialName)
494        if(cmpstr(retStr,"") !=0)
495                //non-null return
496                return(retStr)
497        Endif
498       
499        //if the partial name is derived from the file header, there can be spaces at the beginning
500        //or in the middle of the filename - depending on the prefix and initials used
501        //
502        //remove any leading spaces from the name before starting
503        partialName = A_RemoveAllSpaces(partialName)
504       
505        //try name with no spaces
506        retStr = A_ValidFileString(partialName)
507        if(cmpstr(retStr,"") !=0)
508                //non-null return
509                return(retStr)
510        Endif
511       
512        //try all UPPERCASE
513        partialName = UpperStr(partialName)
514        retStr = A_ValidFileString(partialName)
515        if(cmpstr(retStr,"") !=0)
516                //non-null return
517                return(retStr)
518        Endif
519       
520        //try all lowercase (ret null if failure)
521        partialName = LowerStr(partialName)
522        retStr = A_ValidFileString(partialName)
523        if(cmpstr(retStr,"") !=0)
524                //non-null return
525                return(retStr)
526        else
527                return(retStr)
528        Endif
529End
530
531//function to test a binary file to see if it is a RAW binary SANS file
532//first checks the total bytes in the file (which for raw data is 33316 bytes)
533//**note that the "DIV" file will also show up as a raw file by the run field
534//should be listed in CAT/SHORT and in patch windows
535//
536//Function then checks the file fname (full path:file) for "RAW" run.type field
537//if not found, the data is not raw data and zero is returned
538Function A_CheckIfRawData(fname)
539        String fname
540       
541        Variable refnum,totalBytes
542        String testStr=""
543       
544        Open/R/T="????TEXT" refNum as fname
545        //get the total number of bytes in the file, to avoid moving past EOF
546        FStatus refNum
547        totalBytes = V_logEOF
548        //Print totalBytes
549        if(totalBytes!=33316)
550                //can't possibly be a raw data file
551                Close refnum
552                return(0)               //not a raw SANS file
553        Endif
554        FSetPos refNum,75
555        FReadLine/N=3 refNum,testStr
556        Close refNum
557       
558        if(cmpstr(testStr,"RAW")==0)
559                //true, is raw data file
560                Return(1)
561        else
562                //some other file
563                Return(0)
564        Endif
565End
566
567//list (input) is a list, typically returned from IndexedFile()
568//which is semicolon-delimited, and may contain filesnames from the VAX
569//that contain version numbers, where the version number appears as a separate list item
570//(and also as a non-existent file)
571//these numbers must be purged from the list, especially for display in a popup
572//or list processing of filenames
573//the function returns the list, cleaned of version numbers (up to 11)
574//raw data files will typically never have a version number other than 1.
575Function/S A_RemoveVersNumsFromList(list)
576        String list
577       
578        //get rid of version numbers first (up to 11)
579        Variable ii,num
580        String item
581        num = ItemsInList(list,";")
582        ii=1
583        do
584                item = num2str(ii)
585                list = RemoveFromList(item, list ,";" )
586                ii+=1
587        while(ii<12)
588       
589        return (list)
590End
591
592//Function attempts to find valid filename from partial name that has been stripped of
593//the VAX version number. The partial name is tried first
594//*** the PATH is hard-wired to catPathName (which is assumed to exist)
595//version numers up to ;10 are tried
596//only the "name;vers" is returned. the path is not prepended, hence the return string
597//is not a complete specification of the file
598//
599Function/S A_ValidFileString(partialName)
600        String partialName
601       
602        String tempName = "",msg=""
603        Variable ii,refnum
604       
605        ii=0
606        do
607                if(ii==0)
608                        //first pass, try the partialName
609                        tempName = partialName
610                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag)
611                        if(V_flag == 0)
612                                //file exists
613                                Close refnum            //YES needed,
614                                break
615                        endif
616                else
617                        tempName = partialName + ";" + num2str(ii)
618                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName
619                        if(V_flag == 0)
620                                //file exists
621                                Close refnum
622                                break
623                        endif
624                Endif
625                ii+=1
626                //print "ii=",ii
627        while(ii<11)
628        //go get the selected bits of information, using tempName, which exists
629        if(ii>=11)
630                //msg = partialName + " not found. is version number > 11?"
631                //DoAlert 0, msg
632                //PathInfo catPathName
633                //Print S_Path
634                Return ("")             //use null string as error condition
635        Endif
636       
637        Return (tempName)
638End
639
640//function to remove all spaces from names when searching for filenames
641//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
642//but the text field in the header WILL, if less than 3 characters were used for the
643//user's initials, and can have leading spaces if prefix was less than 5 characters
644//
645//returns a string identical to the original string, except with the interior spaces removed
646//
647Function/S A_RemoveAllSpaces(str)
648        String str
649       
650        String tempstr = str
651        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
652        ii=0
653        do
654                len = strlen(tempStr)
655                spc = strsearch(tempStr," ",0)          //is the last character a space?
656                if (spc == -1)
657                        break           //no more spaces found, get out
658                endif
659                str = tempstr
660                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
661        While(1)        //should never be more than 2 or 3
662       
663        If(strlen(tempStr) < 1)
664                tempStr = ""            //be sure to return a null string if problem found
665        Endif
666       
667        //Print strlen(tempstr)
668       
669        Return(tempStr)
670               
671End
Note: See TracBrowser for help on using the repository browser.