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

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

Modified all procedure files to add to the keyword=value strings to identify the function, coefficients, and suffix once the model is plotted (and the objects will exist)

a one-liner in the Plot and PlotSmeared? macros.

  • necessary for smoother functioning of the wrapper panel.
File size: 20.9 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                        else
254                        //new graph
255                                Display $w1 vs $w0
256                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb)
257                                ModifyGraph grid=1,mirror=2,standoff=0
258                                ErrorBars $w1 Y,wave=($w2,$w2)
259                                Legend
260                        endif
261                else
262                // graph window was not target, make new one
263                        Display $w1 vs $w0
264                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb)
265                        ModifyGraph grid=1,mirror=2,standoff=0
266                        ErrorBars $w1 Y,wave=($w2,$w2)
267                        Legend
268                endif
269        endif
270               
271        //go back to the root folder and clean up before leaving
272        SetDataFolder root:
273        KillWaves/Z $n0,$n1,$n2,$n3,$n4,$n5
274End
275
276
277//procedure for loading NSE data in the format (4-columns)
278// qvals - time - I(q,t) - dI(q,t)
279//
280//
281// this does NOT load the data into separate folders...
282//
283Proc A_LoadNSEData()
284        A_LoadNSEDataWithName("",1)
285End
286
287Proc A_LoadNSEDataWithName(fileStr,doPlot)
288
289        //Load the waves, using default waveX names
290        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
291        LoadWave/G/D/A  fileStr
292        String filename = S_fileName
293       
294        String w0,w1,w2,n0,n1,n2,wt,w3,n3
295        Variable rr,gg,bb
296       
297        // put the names of the three loaded waves into local names
298        n0 = StringFromList(0, S_waveNames ,";" )
299        n1 = StringFromList(1, S_waveNames ,";" )
300        n2 = StringFromList(2, S_waveNames ,";" )
301        n3 = StringFromList(3, S_waveNames ,";" )
302       
303       
304        //remove the semicolon AND period from files from the VAX
305        w0 = CleanupName(("qvals_"+S_fileName),0)
306        w1 = CleanupName(("time_"+S_fileName),0)
307        w2 = CleanupName(("iqt_"+S_fileName),0)
308        w3 = CleanupName(("iqterr_"+S_fileName),0)
309       
310        if(exists(w0) !=0)
311                DoAlert 0,"This file has already been loaded. Use Append to Graph..."
312                KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
313                return
314        endif
315       
316        // Rename to give nice names
317        Rename $n0, $w0
318        Rename $n1, $w1
319        Rename $n2, $w2
320        Rename $n3, $w3
321               
322        if(doPlot)
323                // assign colors randomly
324                rr = abs(trunc(enoise(65535)))
325                gg = abs(trunc(enoise(65535)))
326                bb = abs(trunc(enoise(65535)))
327               
328                // if target window is a graph, and user wants to append, do so
329                if(WinType("") == 1)
330                        DoAlert 1,"Do you want to append this data to the current graph?"
331                        if(V_Flag == 1)
332                                AppendToGraph $w2 vs $w1
333                                ModifyGraph mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2) =(rr,gg,bb),grid=1,mirror=2,tickUnit=1
334                                ErrorBars $w2 Y,wave=($w3,$w3)
335                        else
336                        //new graph
337                                Display $w2 vs $w1
338                                ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
339                                ErrorBars $w2 Y,wave=($w3,$w3)
340                                Legend
341                        endif
342                else
343                // graph window was not target, make new one
344                        Display $w2 vs $w1
345                        ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
346                        ErrorBars $w2 Y,wave=($w3,$w3)
347                        Legend
348                endif
349        endif //doPlot         
350
351End
352
353//procedure for loading desmeared USANS data in the format (5-columns)
354// qvals - I(q) - sig I - Ism(q) - fitted Ism(q)
355//no weighting wave is created (not needed in IGOR 4)
356//
357// not really ever used...
358//
359Proc A_LoadUSANSData()
360
361        //Load the waves, using default waveX names
362        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
363        LoadWave/G/D/A
364   String filename = S_fileName
365       
366        String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
367        Variable rr,gg,bb
368       
369        // put the names of the three loaded waves into local names
370        n0 = StringFromList(0, S_waveNames ,";" )
371        n1 = StringFromList(1, S_waveNames ,";" )
372        n2 = StringFromList(2, S_waveNames ,";" )
373        n3 = StringFromList(3, S_waveNames ,";" )
374        n4 = StringFromList(4, S_waveNames ,";" )
375       
376       
377        //remove the semicolon AND period from files from the VAX
378        w0 = CleanupName((S_fileName+"_q"),0)
379        w1 = CleanupName((S_fileName+"_i"),0)
380        w2 = CleanupName((S_fileName+"_s"),0)
381        w3 = CleanupName((S_fileName+"_ism"),0)
382        w4 = CleanupName((S_fileName+"_fit_ism"),0)
383       
384        if(exists(w0) !=0)              //the wave already exists
385                DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
386                if(V_flag==2)   //user selected No
387                        KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
388                        if(DataFolderExists("root:myGlobals"))
389                                String/G root:myGlobals:gLastFileName = filename
390                        endif           //set the last file loaded to the one NOT loaded
391                        return          //quits the macro
392                endif
393        endif
394       
395        ////overwrite the existing data, if it exists
396        Duplicate/O $n0, $w0
397        Duplicate/O $n1, $w1
398        Duplicate/O $n2, $w2
399        Duplicate/O $n3, $w3
400        Duplicate/O $n4, $w4
401        KillWaves $n0,$n1,$n2,$n3,$n4
402       
403        if(DataFolderExists("root:myGlobals"))
404                String/G root:myGlobals:gLastFileName = filename
405        endif
406               
407        // assign colors randomly
408        rr = abs(trunc(enoise(65535)))
409        gg = abs(trunc(enoise(65535)))
410        bb = abs(trunc(enoise(65535)))
411       
412                // if target window is a graph, and user wants to append, do so
413        if(WinType("") == 1)
414                DoAlert 1,"Do you want to append this data to the current graph?"
415                if(V_Flag == 1)
416                        AppendToGraph $w1 vs $w0
417                        ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
418                        ErrorBars $w1 Y,wave=($w2,$w2)
419                else
420                //new graph
421                        Display $w1 vs $w0
422                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
423                        ErrorBars $w1 Y,wave=($w2,$w2)
424                        Legend
425                endif
426        else
427        // graph window was not target, make new one
428                Display $w1 vs $w0
429                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
430                ErrorBars $w1 Y,wave=($w2,$w2)
431                Legend
432        endif
433               
434End
435
436
437//// Extra "Utility Procedures"
438// to pick path, get a list of data files, and make sure that a valid filename
439// is passed to LoadOneDDataWithName()
440//
441
442//prompts user to choose the local folder that contains the SANS Data
443//only one folder can be used, and its path is catPathName (and is a NAME, not a string)
444//this will overwrite the path selection
445//returns 1 if no path selected as error condition
446Function A_PickPath()
447       
448        //set the global string to the selected pathname
449        NewPath/O/M="pick the SANS data folder" catPathName
450        PathInfo/S catPathName
451        String dum = S_path
452        String alertStr = ""
453        alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"
454        //alertStr += "  Please see the manual for details."
455        if (V_flag == 0)
456                //path does not exist - no folder selected
457                String/G root:myGlobals:gCatPathStr = "no folder selected"
458                return(1)
459        else
460                //set the global to the path (as a string)
461                // need 4 \ since it is the escape character
462                if(cmpstr("\\\\",dum[0,1])==0)  //Windoze user going through network neighborhood
463                        DoAlert 0,alertStr
464                        KillPath catPathName
465                        return(1)
466                endif
467                String/G root:myGlobals:gCatPathStr = dum
468                return(0)               //no error
469        endif
470End
471
472//Function attempts to find valid filename from partial name that has been stripped of
473//the VAX version number. The partial name is tried first
474//*** the PATH is hard-wired to catPathName (which is assumed to exist)
475//version numers up to ;10 are tried
476//only the "name;vers" is returned. the path is not prepended, hence the return string
477//is not a complete specification of the file
478//
479// added 11/99 - uppercase and lowercase versions of the file are tried, if necessary
480// since from marquee, the filename field (textread[0]) must be used, and can be a mix of
481// upper/lowercase letters, while the filename on the server (should) be all caps
482// now makes repeated calls to ValidFileString()
483//
484Function/S A_FindValidFilename(partialName)
485        String PartialName
486       
487        String retStr=""
488       
489        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
490        retStr = A_ValidFileString(partialName)
491        if(cmpstr(retStr,"") !=0)
492                //non-null return
493                return(retStr)
494        Endif
495       
496        //if the partial name is derived from the file header, there can be spaces at the beginning
497        //or in the middle of the filename - depending on the prefix and initials used
498        //
499        //remove any leading spaces from the name before starting
500        partialName = A_RemoveAllSpaces(partialName)
501       
502        //try name with no spaces
503        retStr = A_ValidFileString(partialName)
504        if(cmpstr(retStr,"") !=0)
505                //non-null return
506                return(retStr)
507        Endif
508       
509        //try all UPPERCASE
510        partialName = UpperStr(partialName)
511        retStr = A_ValidFileString(partialName)
512        if(cmpstr(retStr,"") !=0)
513                //non-null return
514                return(retStr)
515        Endif
516       
517        //try all lowercase (ret null if failure)
518        partialName = LowerStr(partialName)
519        retStr = A_ValidFileString(partialName)
520        if(cmpstr(retStr,"") !=0)
521                //non-null return
522                return(retStr)
523        else
524                return(retStr)
525        Endif
526End
527
528//function to test a binary file to see if it is a RAW binary SANS file
529//first checks the total bytes in the file (which for raw data is 33316 bytes)
530//**note that the "DIV" file will also show up as a raw file by the run field
531//should be listed in CAT/SHORT and in patch windows
532//
533//Function then checks the file fname (full path:file) for "RAW" run.type field
534//if not found, the data is not raw data and zero is returned
535Function A_CheckIfRawData(fname)
536        String fname
537       
538        Variable refnum,totalBytes
539        String testStr=""
540       
541        Open/R/T="????TEXT" refNum as fname
542        //get the total number of bytes in the file, to avoid moving past EOF
543        FStatus refNum
544        totalBytes = V_logEOF
545        //Print totalBytes
546        if(totalBytes!=33316)
547                //can't possibly be a raw data file
548                Close refnum
549                return(0)               //not a raw SANS file
550        Endif
551        FSetPos refNum,75
552        FReadLine/N=3 refNum,testStr
553        Close refNum
554       
555        if(cmpstr(testStr,"RAW")==0)
556                //true, is raw data file
557                Return(1)
558        else
559                //some other file
560                Return(0)
561        Endif
562End
563
564//list (input) is a list, typically returned from IndexedFile()
565//which is semicolon-delimited, and may contain filesnames from the VAX
566//that contain version numbers, where the version number appears as a separate list item
567//(and also as a non-existent file)
568//these numbers must be purged from the list, especially for display in a popup
569//or list processing of filenames
570//the function returns the list, cleaned of version numbers (up to 11)
571//raw data files will typically never have a version number other than 1.
572Function/S A_RemoveVersNumsFromList(list)
573        String list
574       
575        //get rid of version numbers first (up to 11)
576        Variable ii,num
577        String item
578        num = ItemsInList(list,";")
579        ii=1
580        do
581                item = num2str(ii)
582                list = RemoveFromList(item, list ,";" )
583                ii+=1
584        while(ii<12)
585       
586        return (list)
587End
588
589//Function attempts to find valid filename from partial name that has been stripped of
590//the VAX version number. The partial name is tried first
591//*** the PATH is hard-wired to catPathName (which is assumed to exist)
592//version numers up to ;10 are tried
593//only the "name;vers" is returned. the path is not prepended, hence the return string
594//is not a complete specification of the file
595//
596Function/S A_ValidFileString(partialName)
597        String partialName
598       
599        String tempName = "",msg=""
600        Variable ii,refnum
601       
602        ii=0
603        do
604                if(ii==0)
605                        //first pass, try the partialName
606                        tempName = partialName
607                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag)
608                        if(V_flag == 0)
609                                //file exists
610                                Close refnum            //YES needed,
611                                break
612                        endif
613                else
614                        tempName = partialName + ";" + num2str(ii)
615                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName
616                        if(V_flag == 0)
617                                //file exists
618                                Close refnum
619                                break
620                        endif
621                Endif
622                ii+=1
623                //print "ii=",ii
624        while(ii<11)
625        //go get the selected bits of information, using tempName, which exists
626        if(ii>=11)
627                //msg = partialName + " not found. is version number > 11?"
628                //DoAlert 0, msg
629                //PathInfo catPathName
630                //Print S_Path
631                Return ("")             //use null string as error condition
632        Endif
633       
634        Return (tempName)
635End
636
637//function to remove all spaces from names when searching for filenames
638//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
639//but the text field in the header WILL, if less than 3 characters were used for the
640//user's initials, and can have leading spaces if prefix was less than 5 characters
641//
642//returns a string identical to the original string, except with the interior spaces removed
643//
644Function/S A_RemoveAllSpaces(str)
645        String str
646       
647        String tempstr = str
648        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
649        ii=0
650        do
651                len = strlen(tempStr)
652                spc = strsearch(tempStr," ",0)          //is the last character a space?
653                if (spc == -1)
654                        break           //no more spaces found, get out
655                endif
656                str = tempstr
657                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
658        While(1)        //should never be more than 2 or 3
659       
660        If(strlen(tempStr) < 1)
661                tempStr = ""            //be sure to return a null string if problem found
662        Endif
663       
664        //Print strlen(tempstr)
665       
666        Return(tempStr)
667               
668End
Note: See TracBrowser for help on using the repository browser.