source: sans/Dev/trunk/NCNR_User_Procedures/SANS_Analysis/Models/PlotUtilsMacro_v40.ipf @ 325

Last change on this file since 325 was 325, checked in by ajj, 15 years ago

Adding SANS Analysis Models to new Dev tree

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