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

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

Changes to the analysis package to add a few more model functions. Documentation and XOPs are to follow later.

General n-point gaussian quadrature has been added to GaussUtils? by including a Gauss-Laguere point generator from Numerical Recipes. See the Paracrystal models for an example, since they needed more than the 76 point quadrature.

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