source: sans/Dev/trunk/NCNR_User_Procedures/Common/PlotUtilsMacro_v40.ipf @ 418

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

Moving data folders into root:Packages:NIST

This could be hairy.

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