source: sans/Dev/trunk/NCNR_User_Procedures/Common/Packages/PlotManager/PlotUtilsMacro_v40.ipf @ 432

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

Bug fixes to USANS procedures to clean up changes with new Packages:NIST: subfolder structure.

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