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

Last change on this file since 398 was 398, checked in by ajj, 14 years ago

Added reader for 4 column data from ORNL as produced by W Heller's reduction. Currently assumes Heller is using the same gaussian approximation for resolution function as we are.

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