source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v4.00/PlotUtilsMacro_v40.ipf @ 285

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

Updated version numbers in files (4.0) and corrected a typo in SA_includes_v301

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