source: sans/Dev/trunk/NCNR_User_Procedures/SANS/Analysis/Models/PlotUtilsMacro_v40.ipf @ 392

Last change on this file since 392 was 392, checked in by srkline, 14 years ago

Changed NCNR_ raw data reader to get the magnetic field strength (actually the voltage) from byte 348, rather than 190.

Added Jan Ilavsky's fixes to all data loaders to accept 2-column data. A fake error is generated for the data set as read in, so the data can be treated as 3-column data from that point.

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