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

Last change on this file since 563 was 563, checked in by ajj, 13 years ago

Updating XML reader to match output of non-xml loader. Now creates sq,qb and fs waves as well as res wave.

File size: 31.4 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,paramStr,suffix)
26        String funcStr,coefStr,paramStr,suffix
27       
28        if(exists("root:Packages:NIST:paramKWStr")==0)
29//              String/G root:Packages:NIST:coefKWStr=""
30                String/G root:Packages:NIST:paramKWStr=""
31//              String/G root:Packages:NIST:suffixKWStr=""
32        endif
33        SVAR coefKWStr = root:Packages:NIST:coefKWStr
34        SVAR paramKWStr = root:Packages:NIST:paramKWStr
35        SVAR suffixKWStr = root:Packages:NIST:suffixKWStr
36        coefKWStr += funcStr+"="+coefStr+";"
37        paramKWStr += funcStr+"="+paramStr+";"
38        suffixKWStr += funcStr+"="+suffix+";"
39end
40
41// loads a 1-d (ascii) datafile and plots the data
42// will overwrite existing data if user is OK with this
43// - multiple datasets can be automatically plotted on the same graph
44//
45//substantially easier to write this as a Proc rather than a function...
46
47//
48Proc A_LoadOneDData()
49        A_LoadOneDDataWithName("",1)            //will prompt for file and plot data
50End
51
52// load the data specified by fileStr (a full path:name)
53// and plots if doPlot==1
54// if fileStr is null, a dialog is presented to select the file
55//
56// 3 cases (if)
57// - 3 columns = QIS, no resolution
58// - 6 columns = QSIG, SANS w/resolution
59// - 5 columns = old-style desmeared USANS data (from VAX)
60//
61// This loader replaces the A_LoadOneDData() which was almost completely duplicated code
62//
63//new version, 19JUN07 that loads each data set into a separate data folder
64// the data folder is given the "base name" of the data file as it's loaded
65//
66Proc A_LoadOneDDataWithName(fileStr,doPlot)
67        String fileStr
68        Variable doPlot
69       
70        Variable rr,gg,bb,refnum,dQv
71        String w0,w1,w2,n0,n1,n2
72        String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
73        SetDataFolder root:             //build sub-folders for each data set under root
74
75// I can't see that we need to find dQv here.   
76//      if (exists("root:Packages:NIST:USANS:Globals:MainPanel:gDQv"))
77//              //Running from USANS reduction
78//              Variable dQv = root:Packages:NIST:USANS:Globals:MainPanel:gDQv
79//      endif
80//      if(exists("root:Packages:NIST:USANS_dQv"))
81//              //Running from SANS Analysis
82//              Variable dQv = root:Packages:NIST:USANS_dQv
83//      else
84//              //running from somewhere else, probably SANS Reduction, which uses common loaders
85//              Variable/G root:Packages:NIST:USANS_dQv = 0.117
86//      endif
87               
88        if (cmpStr(fileStr,"") == 0)
89                //No filename given, open dialog
90                Open/D/R  refnum
91                if (cmpstr(S_filename,"") == 0)
92                        return
93                else
94                        fileStr = S_filename
95                endif
96        endif
97
98        if (isXML(fileStr) == 1)
99                LoadNISTXMLData(fileStr,doPlot)
100        else           
101                //Load the waves, using default waveX names
102                //if no path or file is specified for LoadWave, the default Mac open dialog will appear
103                LoadWave/G/D/A/Q fileStr
104                String fileNamePath = S_Path+S_fileName
105//              String basestr = ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0)
106                String baseStr = CleanupName(S_fileName,0)
107//              print "basestr :"+basestr
108                String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
109//              print "filename :"+filename
110                Variable numCols = V_flag
111               
112                //changes JIL to allow 2-column data to be read in, "faking" a 3rd column of errors
113                if(numCols==2) //no errors
114                        n1 = StringFromList(1, S_waveNames ,";" )
115                        Duplicate/O $("root:"+n1), errorTmp
116                        errorTmp = 0.01*(errorTmp)+ 0.03*sqrt(errorTmp)
117                        S_waveNames+="errorTmp;"
118                        numCols=3
119                endif
120               
121                if(numCols==3)          //simple 3-column data with no resolution information
122                       
123                        // put the names of the three loaded waves into local names
124                        n0 = StringFromList(0, S_waveNames ,";" )
125                        n1 = StringFromList(1, S_waveNames ,";" )
126                        n2 = StringFromList(2, S_waveNames ,";" )
127                       
128                        //remove the semicolon AND period from files from the VAX
129                        w0 = CleanupName((basestr + "_q"),0)
130                        w1 = CleanupName((basestr + "_i"),0)
131                        w2 = CleanupName((basestr + "_s"),0)
132                       
133                        //String baseStr=w1[0,strlen(w1)-3]
134                        if(DataFolderExists("root:"+baseStr))
135                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
136                                        if(V_flag==2)   //user selected No, don't load the data
137                                                SetDataFolder root:
138                                                KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
139                                                //if(DataFolderExists("root:Packages:NIST"))
140                                                //      String/G root:Packages:NIST:gLastFileName = filename
141                                                //endif
142                                                return  //quits the macro
143                                        endif
144                                        SetDataFolder $("root:"+baseStr)
145                        else
146                                NewDataFolder/S $("root:"+baseStr)
147                        endif
148                       
149                        ////overwrite the existing data, if it exists
150                        Duplicate/O $("root:"+n0), $w0
151                        Duplicate/O $("root:"+n1), $w1
152                        Duplicate/O $("root:"+n2), $w2
153       
154                        // no resolution matrix to make
155       
156                        SetScale d,0,0,"1/A",$w0
157                        SetScale d,0,0,"1/cm",$w1
158                       
159                endif           //3-col data
160               
161                if(numCols == 6)                //6-column SANS or USANS data that has resolution information
162                       
163                        // put the names of the (default named) loaded waves into local names
164                        n0 = StringFromList(0, S_waveNames ,";" )
165                        n1 = StringFromList(1, S_waveNames ,";" )
166                        n2 = StringFromList(2, S_waveNames ,";" )
167                        n3 = StringFromList(3, S_waveNames ,";" )
168                        n4 = StringFromList(4, S_waveNames ,";" )
169                        n5 = StringFromList(5, S_waveNames ,";" )
170                       
171                        //remove the semicolon AND period from files from the VAX
172                        w0 = CleanupName((basestr + "_q"),0)
173                        w1 = CleanupName((basestr + "_i"),0)
174                        w2 = CleanupName((basestr + "_s"),0)
175                        w3 = CleanupName((basestr + "sq"),0)
176                        w4 = CleanupName((basestr + "qb"),0)
177                        w5 = CleanupName((basestr + "fs"),0)
178                       
179                        //String baseStr=w1[0,strlen(w1)-3]
180                        if(DataFolderExists("root:"+baseStr))
181                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
182                                        if(V_flag==2)   //user selected No, don't load the data
183                                                SetDataFolder root:
184                                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
185                                                if(DataFolderExists("root:Packages:NIST"))
186                                                        String/G root:Packages:NIST:gLastFileName = filename
187                                                endif           //set the last file loaded to the one NOT loaded
188                                                return          //quits the macro
189                                        endif
190                                        SetDataFolder $("root:"+baseStr)
191                        else
192                                NewDataFolder/S $("root:"+baseStr)
193                        endif
194       
195        ////overwrite the existing data, if it exists
196                        Duplicate/O $("root:"+n0), $w0
197                        Duplicate/O $("root:"+n1), $w1
198                        Duplicate/O $("root:"+n2), $w2
199                        Duplicate/O $("root:"+n3), $w3
200                        Duplicate/O $("root:"+n4), $w4
201                        Duplicate/O $("root:"+n5), $w5
202       
203                        // need to switch based on SANS/USANS
204                        if (isSANSResolution($w3[0]))           //checks to see if the first point of the wave is <0]
205                                // make a resolution matrix for SANS data
206                                Variable np=numpnts($w0)
207                                Make/D/O/N=(np,4) $(baseStr+"_res")
208                               
209                                $(baseStr+"_res")[][0] = $w3[p]         //sigQ
210                                $(baseStr+"_res")[][1] = $w4[p]         //qBar
211                                $(baseStr+"_res")[][2] = $w5[p]         //fShad
212                                $(baseStr+"_res")[][3] = $w0[p]         //Qvalues
213                        else
214                                //the data is USANS data
215                                // marix calculation here, but for now, just copy the waves
216                                //$(baseStr+"_res")[][0] = $w3[p]               //sigQ
217                                //$(baseStr+"_res")[][1] = $w4[p]               //qBar
218                                //$(baseStr+"_res")[][2] = $w5[p]               //fShad
219                                //$(baseStr+"_res")[][3] = $w0[p]               //Qvalues
220                                dQv = -$w3[0]
221                               
222                                USANS_CalcWeights(baseStr,dQv)
223                               
224                        endif
225                        Killwaves/Z $w3,$w4,$w5                 //get rid of the resolution waves that are in the matrix
226       
227                        SetScale d,0,0,"1/A",$w0
228                        SetScale d,0,0,"1/cm",$w1
229               
230                endif   //6-col data
231       
232                // Load ORNL data from Heller program
233                if(numCols == 4)                //4-column SANS or USANS data that has resolution information
234                       
235                        // put the names of the (default named) loaded waves into local names
236                        n0 = StringFromList(0, S_waveNames ,";" )
237                        n1 = StringFromList(1, S_waveNames ,";" )
238                        n2 = StringFromList(2, S_waveNames ,";" )
239                        n3 = StringFromList(3, S_waveNames ,";" )
240                       
241                        //remove the semicolon AND period from files from the VAX
242                        w0 = CleanupName((basestr + "_q"),0)
243                        w1 = CleanupName((basestr + "_i"),0)
244                        w2 = CleanupName((basestr + "_s"),0)
245                        w3 = CleanupName((basestr + "sq"),0)
246                        w4 = CleanupName((basestr + "qb"),0)
247                        w5 = CleanupName((basestr + "fs"),0)
248       
249                       
250                        //String baseStr=w1[0,strlen(w1)-3]
251                        if(DataFolderExists("root:"+baseStr))
252                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
253                                        if(V_flag==2)   //user selected No, don't load the data
254                                                SetDataFolder root:
255                                                KillWaves $n0,$n1,$n2,$n3               // kill the default waveX that were loaded
256                                                if(DataFolderExists("root:Packages:NIST"))
257                                                        String/G root:Packages:NIST:gLastFileName = filename
258                                                endif           //set the last file loaded to the one NOT loaded
259                                                return          //quits the macro
260                                        endif
261                                        SetDataFolder $("root:"+baseStr)
262                        else
263                                NewDataFolder/S $("root:"+baseStr)
264                        endif
265       
266        ////overwrite the existing data, if it exists
267                        Duplicate/O $("root:"+n0), $w0
268                        Duplicate/O $("root:"+n1), $w1
269                        Duplicate/O $("root:"+n2), $w2
270                        Duplicate/O $("root:"+n3), $w3
271                        Duplicate/O $("root:"+n0), $w4 // Set qb wave to nominal measured Q values
272                        Duplicate/O $("root:"+n0), $w5 // Make wave of appropriate length
273                        $w5 = 1                                           //  Set all shadowfactor to 1
274       
275                        // need to switch based on SANS/USANS
276                        if (isSANSResolution($w3[0]))           //checks to see if the first point of the wave is <0]
277                                // make a resolution matrix for SANS data
278                                Variable np=numpnts($w0)
279                                Make/D/O/N=(np,4) $(baseStr+"_res")
280                               
281                                $(baseStr+"_res")[][0] = $w3[p]         //sigQ
282                                $(baseStr+"_res")[][1] = $w4[p]         //qBar
283                                $(baseStr+"_res")[][2] = $w5[p]         //fShad
284                                $(baseStr+"_res")[][3] = $w0[p]         //Qvalues
285                        else
286                                //the data is USANS data
287                                // marix calculation here, but for now, just copy the waves
288                                //$(baseStr+"_res")[][0] = $w3[p]               //sigQ
289                                //$(baseStr+"_res")[][1] = $w4[p]               //qBar
290                                //$(baseStr+"_res")[][2] = $w5[p]               //fShad
291                                //$(baseStr+"_res")[][3] = $w0[p]               //Qvalues
292                                dQv = -$w3[0]
293                               
294                                USANS_CalcWeights(baseStr,dQv)
295                               
296                        endif
297                        Killwaves/Z $w3,$w4,$w5                 //get rid of the resolution waves that are in the matrix
298       
299                        SetScale d,0,0,"1/A",$w0
300                        SetScale d,0,0,"1/cm",$w1
301               
302                endif   //4-col data
303       
304       
305                if(numCols==5)          //this is the "old-style" VAX desmeared data format
306                       
307                        // put the names of the three loaded waves into local names
308                        n0 = StringFromList(0, S_waveNames ,";" )
309                        n1 = StringFromList(1, S_waveNames ,";" )
310                        n2 = StringFromList(2, S_waveNames ,";" )
311                        n3 = StringFromList(3, S_waveNames ,";" )
312                        n4 = StringFromList(4, S_waveNames ,";" )
313                       
314                       
315                        //remove the semicolon AND period from files from the VAX
316                        w0 = CleanupName((basestr+"_q"),0)
317                        w1 = CleanupName((basestr+"_i"),0)
318                        w2 = CleanupName((basestr+"_s"),0)
319                        w3 = CleanupName((basestr+"_ism"),0)
320                        w4 = CleanupName((basestr+"_fit_ism"),0)
321                       
322                        //String baseStr=w1[0,strlen(w1)-3]
323                        if(DataFolderExists("root:"+baseStr))
324                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
325                                        if(V_flag==2)   //user selected No, don't load the data
326                                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
327                                                //if(DataFolderExists("root:Packages:NIST"))
328                                                //      String/G root:Packages:NIST:gLastFileName = filename
329                                                //endif         //set the last file loaded to the one NOT loaded
330                                                return          //quits the macro
331                                        endif
332                                        SetDataFolder $("root:"+baseStr)
333                        else
334                                NewDataFolder/S $("root:"+baseStr)
335                        endif
336                       
337                        ////overwrite the existing data, if it exists   
338                        Duplicate/O $("root:"+n0), $w0
339                        Duplicate/O $("root:"+n1), $w1
340                        Duplicate/O $("root:"+n2), $w2
341                        Duplicate/O $("root:"+n3), $w3
342                        Duplicate/O $("root:"+n4), $w4
343                       
344                        // no resolution matrix
345                endif           //5-col data
346
347                //////
348                if(DataFolderExists("root:Packages:NIST"))
349                        String/G root:Packages:NIST:gLastFileName = filename
350                endif
351       
352               
353                //plot if desired
354                if(doPlot)
355                        Print GetDataFolder(1)
356                       
357                        // assign colors randomly
358                        rr = abs(trunc(enoise(65535)))
359                        gg = abs(trunc(enoise(65535)))
360                        bb = abs(trunc(enoise(65535)))
361                       
362                        // if target window is a graph, and user wants to append, do so
363                   DoWindow/B Plot_Manager
364                        if(WinType("") == 1)
365                                DoAlert 1,"Do you want to append this data to the current graph?"
366                               
367                               
368                                if(V_Flag == 1)
369                                        AppendToGraph $w1 vs $w0
370                                        ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1
371                                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
372                                        ModifyGraph tickUnit(left)=1
373                                else
374                                //new graph
375                                        SetDataFolder $("root:"+baseStr)                //sometimes I end up back in root: here, and I can't figure out why!
376                                        Display $w1 vs $w0
377                                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
378                                        ModifyGraph grid=1,mirror=2,standoff=0
379                                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
380                                        ModifyGraph tickUnit(left)=1
381                                        Legend
382                                endif
383                        else
384                        // graph window was not target, make new one
385                                Display $w1 vs $w0
386                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
387                                ModifyGraph grid=1,mirror=2,standoff=0
388                                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
389                                ModifyGraph tickUnit(left)=1
390                                Legend
391                        endif
392                endif
393                       
394                //go back to the root folder and clean up before leaving
395                SetDataFolder root:
396                KillWaves/Z $n0,$n1,$n2,$n3,$n4,$n5
397               
398        endif
399End
400
401
402//procedure for loading NSE data in the format (4-columns)
403// qvals - time - I(q,t) - dI(q,t)
404//
405//
406// this does NOT load the data into separate folders...
407//
408Proc A_LoadNSEData()
409        A_LoadNSEDataWithName("",1)
410End
411
412Proc A_LoadNSEDataWithName(fileStr,doPlot)
413
414        //Load the waves, using default waveX names
415        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
416        LoadWave/G/D/A  fileStr
417        String filename = S_fileName
418       
419        String w0,w1,w2,n0,n1,n2,wt,w3,n3
420        Variable rr,gg,bb
421       
422        // put the names of the three loaded waves into local names
423        n0 = StringFromList(0, S_waveNames ,";" )
424        n1 = StringFromList(1, S_waveNames ,";" )
425        n2 = StringFromList(2, S_waveNames ,";" )
426        n3 = StringFromList(3, S_waveNames ,";" )
427       
428       
429        //remove the semicolon AND period from files from the VAX
430        w0 = CleanupName(("qvals_"+S_fileName),0)
431        w1 = CleanupName(("time_"+S_fileName),0)
432        w2 = CleanupName(("iqt_"+S_fileName),0)
433        w3 = CleanupName(("iqterr_"+S_fileName),0)
434       
435        if(exists(w0) !=0)
436                DoAlert 0,"This file has already been loaded. Use Append to Graph..."
437                KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
438                return
439        endif
440       
441        // Rename to give nice names
442        Rename $n0, $w0
443        Rename $n1, $w1
444        Rename $n2, $w2
445        Rename $n3, $w3
446               
447        if(doPlot)
448                // assign colors randomly
449                rr = abs(trunc(enoise(65535)))
450                gg = abs(trunc(enoise(65535)))
451                bb = abs(trunc(enoise(65535)))
452               
453                // if target window is a graph, and user wants to append, do so
454                if(WinType("") == 1)
455                        DoAlert 1,"Do you want to append this data to the current graph?"
456                        if(V_Flag == 1)
457                                AppendToGraph $w2 vs $w1
458                                ModifyGraph mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2) =(rr,gg,bb),grid=1,mirror=2,tickUnit=1
459                                ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
460                        else
461                        //new graph
462                                Display $w2 vs $w1
463                                ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
464                                ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
465                                Legend
466                        endif
467                else
468                // graph window was not target, make new one
469                        Display $w2 vs $w1
470                        ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
471                        ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
472                        Legend
473                endif
474        endif //doPlot         
475
476End
477
478//procedure for loading desmeared USANS data in the format (5-columns)
479// qvals - I(q) - sig I - Ism(q) - fitted Ism(q)
480//no weighting wave is created (not needed in IGOR 4)
481//
482// not really ever used...
483//
484Proc A_LoadUSANSData()
485
486        //Load the waves, using default waveX names
487        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
488        LoadWave/G/D/A
489   String filename = S_fileName
490       
491        String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
492        Variable rr,gg,bb
493       
494        // put the names of the three loaded waves into local names
495        n0 = StringFromList(0, S_waveNames ,";" )
496        n1 = StringFromList(1, S_waveNames ,";" )
497        n2 = StringFromList(2, S_waveNames ,";" )
498        n3 = StringFromList(3, S_waveNames ,";" )
499        n4 = StringFromList(4, S_waveNames ,";" )
500       
501       
502        //remove the semicolon AND period from files from the VAX
503        w0 = CleanupName((S_fileName+"_q"),0)
504        w1 = CleanupName((S_fileName+"_i"),0)
505        w2 = CleanupName((S_fileName+"_s"),0)
506        w3 = CleanupName((S_fileName+"_ism"),0)
507        w4 = CleanupName((S_fileName+"_fit_ism"),0)
508       
509        if(exists(w0) !=0)              //the wave already exists
510                DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
511                if(V_flag==2)   //user selected No
512                        KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
513                        if(DataFolderExists("root:Packages:NIST"))
514                                String/G root:Packages:NIST:gLastFileName = filename
515                        endif           //set the last file loaded to the one NOT loaded
516                        return          //quits the macro
517                endif
518        endif
519       
520        ////overwrite the existing data, if it exists
521        Duplicate/O $n0, $w0
522        Duplicate/O $n1, $w1
523        Duplicate/O $n2, $w2
524        Duplicate/O $n3, $w3
525        Duplicate/O $n4, $w4
526        KillWaves $n0,$n1,$n2,$n3,$n4
527       
528        if(DataFolderExists("root:Packages:NIST"))
529                String/G root:Packages:NIST:gLastFileName = filename
530        endif
531               
532        // assign colors randomly
533        rr = abs(trunc(enoise(65535)))
534        gg = abs(trunc(enoise(65535)))
535        bb = abs(trunc(enoise(65535)))
536       
537                // if target window is a graph, and user wants to append, do so
538        if(WinType("") == 1)
539                DoAlert 1,"Do you want to append this data to the current graph?"
540                if(V_Flag == 1)
541                        AppendToGraph $w1 vs $w0
542                        ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
543                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
544                else
545                //new graph
546                        Display $w1 vs $w0
547                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
548                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
549                        Legend
550                endif
551        else
552        // graph window was not target, make new one
553                Display $w1 vs $w0
554                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
555                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
556                Legend
557        endif
558               
559End
560
561
562//// Extra "Utility Procedures"
563// to pick path, get a list of data files, and make sure that a valid filename
564// is passed to LoadOneDDataWithName()
565//
566
567//prompts user to choose the local folder that contains the SANS Data
568//only one folder can be used, and its path is catPathName (and is a NAME, not a string)
569//this will overwrite the path selection
570//returns 1 if no path selected as error condition
571Function A_PickPath()
572       
573        //set the global string to the selected pathname
574        NewPath/O/M="pick the SANS data folder" catPathName
575        PathInfo/S catPathName
576        String dum = S_path
577        String alertStr = ""
578        alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"
579        //alertStr += "  Please see the manual for details."
580        if (V_flag == 0)
581                //path does not exist - no folder selected
582                String/G root:Packages:NIST:gCatPathStr = "no folder selected"
583                return(1)
584        else
585                //set the global to the path (as a string)
586                // need 4 \ since it is the escape character
587                if(cmpstr("\\\\",dum[0,1])==0)  //Windoze user going through network neighborhood
588                        DoAlert 0,alertStr
589                        KillPath catPathName
590                        return(1)
591                endif
592                String/G root:Packages:NIST:gCatPathStr = dum
593                return(0)               //no error
594        endif
595End
596
597//Function attempts to find valid filename from partial name that has been stripped of
598//the VAX version number. The partial name is tried first
599//*** the PATH is hard-wired to catPathName (which is assumed to exist)
600//version numers up to ;10 are tried
601//only the "name;vers" is returned. the path is not prepended, hence the return string
602//is not a complete specification of the file
603//
604// added 11/99 - uppercase and lowercase versions of the file are tried, if necessary
605// since from marquee, the filename field (textread[0]) must be used, and can be a mix of
606// upper/lowercase letters, while the filename on the server (should) be all caps
607// now makes repeated calls to ValidFileString()
608//
609Function/S A_FindValidFilename(partialName)
610        String PartialName
611       
612        String retStr=""
613       
614        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
615        retStr = A_ValidFileString(partialName)
616        if(cmpstr(retStr,"") !=0)
617                //non-null return
618                return(retStr)
619        Endif
620       
621        //if the partial name is derived from the file header, there can be spaces at the beginning
622        //or in the middle of the filename - depending on the prefix and initials used
623        //
624        //remove any leading spaces from the name before starting
625        partialName = A_RemoveAllSpaces(partialName)
626       
627        //try name with no spaces
628        retStr = A_ValidFileString(partialName)
629        if(cmpstr(retStr,"") !=0)
630                //non-null return
631                return(retStr)
632        Endif
633       
634        //try all UPPERCASE
635        partialName = UpperStr(partialName)
636        retStr = A_ValidFileString(partialName)
637        if(cmpstr(retStr,"") !=0)
638                //non-null return
639                return(retStr)
640        Endif
641       
642        //try all lowercase (ret null if failure)
643        partialName = LowerStr(partialName)
644        retStr = A_ValidFileString(partialName)
645        if(cmpstr(retStr,"") !=0)
646                //non-null return
647                return(retStr)
648        else
649                return(retStr)
650        Endif
651End
652
653//function to test a binary file to see if it is a RAW binary SANS file
654//first checks the total bytes in the file (which for raw data is 33316 bytes)
655//**note that the "DIV" file will also show up as a raw file by the run field
656//should be listed in CAT/SHORT and in patch windows
657//
658//Function then checks the file fname (full path:file) for "RAW" run.type field
659//if not found, the data is not raw data and zero is returned
660Function A_CheckIfRawData(fname)
661        String fname
662       
663        Variable refnum,totalBytes
664        String testStr=""
665       
666        Open/R/T="????TEXT" refNum as fname
667        //get the total number of bytes in the file, to avoid moving past EOF
668        FStatus refNum
669        totalBytes = V_logEOF
670        //Print totalBytes
671        if(totalBytes!=33316)
672                //can't possibly be a raw data file
673                Close refnum
674                return(0)               //not a raw SANS file
675        Endif
676        FSetPos refNum,75
677        FReadLine/N=3 refNum,testStr
678        Close refNum
679       
680        if(cmpstr(testStr,"RAW")==0)
681                //true, is raw data file
682                Return(1)
683        else
684                //some other file
685                Return(0)
686        Endif
687End
688
689//list (input) is a list, typically returned from IndexedFile()
690//which is semicolon-delimited, and may contain filesnames from the VAX
691//that contain version numbers, where the version number appears as a separate list item
692//(and also as a non-existent file)
693//these numbers must be purged from the list, especially for display in a popup
694//or list processing of filenames
695//the function returns the list, cleaned of version numbers (up to 11)
696//raw data files will typically never have a version number other than 1.
697Function/S A_RemoveVersNumsFromList(list)
698        String list
699       
700        //get rid of version numbers first (up to 11)
701        Variable ii,num
702        String item
703        num = ItemsInList(list,";")
704        ii=1
705        do
706                item = num2str(ii)
707                list = RemoveFromList(item, list ,";" )
708                ii+=1
709        while(ii<12)
710       
711        return (list)
712End
713
714//Function attempts to find valid filename from partial name that has been stripped of
715//the VAX version number. The partial name is tried first
716//*** the PATH is hard-wired to catPathName (which is assumed to exist)
717//version numers up to ;10 are tried
718//only the "name;vers" is returned. the path is not prepended, hence the return string
719//is not a complete specification of the file
720//
721Function/S A_ValidFileString(partialName)
722        String partialName
723       
724        String tempName = "",msg=""
725        Variable ii,refnum
726       
727        ii=0
728        do
729                if(ii==0)
730                        //first pass, try the partialName
731                        tempName = partialName
732                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag)
733                        if(V_flag == 0)
734                                //file exists
735                                Close refnum            //YES needed,
736                                break
737                        endif
738                else
739                        tempName = partialName + ";" + num2str(ii)
740                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName
741                        if(V_flag == 0)
742                                //file exists
743                                Close refnum
744                                break
745                        endif
746                Endif
747                ii+=1
748                //print "ii=",ii
749        while(ii<11)
750        //go get the selected bits of information, using tempName, which exists
751        if(ii>=11)
752                //msg = partialName + " not found. is version number > 11?"
753                //DoAlert 0, msg
754                //PathInfo catPathName
755                //Print S_Path
756                Return ("")             //use null string as error condition
757        Endif
758       
759        Return (tempName)
760End
761
762//function to remove all spaces from names when searching for filenames
763//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
764//but the text field in the header WILL, if less than 3 characters were used for the
765//user's initials, and can have leading spaces if prefix was less than 5 characters
766//
767//returns a string identical to the original string, except with the interior spaces removed
768//
769Function/S A_RemoveAllSpaces(str)
770        String str
771       
772        String tempstr = str
773        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
774        ii=0
775        do
776                len = strlen(tempStr)
777                spc = strsearch(tempStr," ",0)          //is the last character a space?
778                if (spc == -1)
779                        break           //no more spaces found, get out
780                endif
781                str = tempstr
782                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
783        While(1)        //should never be more than 2 or 3
784       
785        If(strlen(tempStr) < 1)
786                tempStr = ""            //be sure to return a null string if problem found
787        Endif
788       
789        //Print strlen(tempstr)
790       
791        Return(tempStr)
792               
793End
794
795//AJJ Oct 2008
796//Moved from GaussUtils - makes more sense to have it here
797
798// utility used in the "PlotSmeared...() macros to get a list of data folders
799//
800//1:    Waves.
801//2:    Numeric variables.
802//3:    String variables.
803//4:    Data folders.
804Function/S GetAList(type)
805        Variable type
806       
807        SetDataFolder root:
808       
809        String objName,str=""
810        Variable index = 0
811        do
812                objName = GetIndexedObjName(":", type, index)
813                if (strlen(objName) == 0)
814                        break
815                endif
816                //Print objName
817                str += objName + ";"
818                index += 1
819        while(1)
820       
821        // remove myGlobals, Packages, etc. from the folder list
822        if(type==4)
823                str = RemoveFromList("myGlobals", str , ";" )
824                str = RemoveFromList("Packages", str, ";")
825                str = RemoveFromList("AutoFit", str, ";")
826                str = RemoveFromList("TISANE", str, ";")
827                str = RemoveFromList("HayPenMSA", str, ";")
828        endif
829       
830        return(str)
831End
832
833
834//returns the path to the file, or null if cancel
835Function/S DoOpenFileDialog(msg)
836        String msg
837       
838        Variable refNum
839//      String message = "Select a file"
840        String outputPath
841       
842        Open/D/R/T="????"/M=msg refNum
843        outputPath = S_fileName
844       
845        return outputPath
846End
847
848// returns the path to the file, or null if the user cancelled
849// fancy use of optional parameters
850//
851// enforce short file names (26 characters)
852Function/S DoSaveFileDialog(msg,[fname,suffix])
853        String msg,fname,suffix
854        Variable refNum
855//      String message = "Save the file as"
856
857        if(ParamIsDefault(fname))
858//              Print "fname not supplied"
859                fname = ""
860        endif
861        if(ParamIsDefault(suffix))
862//              Print "suffix not supplied"
863                suffix = ""
864        endif
865       
866        String outputPath,tmpName,testStr
867        Variable badLength=0,maxLength=26,l1,l2
868       
869       
870        tmpName = fname + suffix
871       
872        do
873                badLength=0
874                Open/D/M=msg/T="????" refNum as tmpName
875                outputPath = S_fileName
876               
877                testStr = ParseFilePath(0, outputPath, ":", 1, 0)               //just the filename
878                if(strlen(testStr)==0)
879                        break           //cancel, allow exit
880                endif
881                if(strlen(testStr) > maxLength)
882                        badlength = 1
883                        DoAlert 2,"File name is too long. Is\r"+testStr[0,25]+"\rOK?"
884                        if(V_flag==3)
885                                outputPath = ""
886                                break
887                        endif
888                        if(V_flag==1)                   //my suggested name is OK, so trim the output
889                                badlength=0
890                                l1 = strlen(testStr)            //too long length
891                                l1 = l1-maxLength               //number to trim
892                                //Print outputPath
893                                l2=strlen(outputPath)
894                                outputPath = outputPath[0,l2-1-l1]
895                                //Print "modified  ",outputPath
896                        endif
897                        //if(V_flag==2)  do nothing, let it go around again
898                endif
899               
900        while(badLength)
901       
902        return outputPath
903End
904
905// a function common to many panels, so put the basic version here that simply
906// returns null string if no functions are present. Calling procedures can
907// add to the list to customize as needed.
908// show the available models
909// not the f*(cw,xw) point calculations
910// not the *X(cw,xw) XOPS
911//
912// KIND:10 should show only user-defined curve fitting functions
913// - not XOPs
914// - not other user-defined functions
915Function/S User_FunctionPopupList()
916        String list,tmp
917        list = FunctionList("*",";","KIND:10")          //get every user defined curve fit function
918
919        //now start to remove everything the user doesn't need to see...
920
921        tmp = FunctionList("*_proto",";","KIND:10")             //prototypes
922        list = RemoveFromList(tmp, list  ,";")
923       
924        //prototypes that show up if GF is loaded
925        list = RemoveFromList("GFFitFuncTemplate", list)
926        list = RemoveFromList("GFFitAllAtOnceTemplate", list)
927        list = RemoveFromList("NewGlblFitFunc", list)
928        list = RemoveFromList("NewGlblFitFuncAllAtOnce", list)
929        list = RemoveFromList("GlobalFitFunc", list)
930        list = RemoveFromList("GlobalFitAllAtOnce", list)
931        list = RemoveFromList("GFFitAAOStructTemplate", list)
932        list = RemoveFromList("NewGF_SetXWaveInList", list)
933        list = RemoveFromList("NewGlblFitFuncAAOStruct", list)
934       
935        // more to remove as a result of 2D/Gizmo
936        list = RemoveFromList("A_WMRunLessThanDelta", list)
937        list = RemoveFromList("WMFindNaNValue", list)
938        list = RemoveFromList("WM_Make3DBarChartParametricWave", list)
939        list = RemoveFromList("UpdateQxQy2Mat", list)
940        list = RemoveFromList("MakeBSMask", list)
941       
942        // MOTOFIT/GenFit bits
943        tmp = "GEN_allatoncefitfunc;GEN_fitfunc;GetCheckBoxesState;MOTO_GFFitAllAtOnceTemplate;MOTO_GFFitFuncTemplate;MOTO_NewGF_SetXWaveInList;MOTO_NewGlblFitFunc;MOTO_NewGlblFitFuncAllAtOnce;GeneticFit_UnSmearedModel;GeneticFit_SmearedModel;"
944        list = RemoveFromList(tmp, list  ,";")
945
946        // SANS Reduction bits
947        tmp = "ASStandardFunction;Ann_1D_Graph;Avg_1D_Graph;BStandardFunction;CStandardFunction;Draw_Plot1D;MyMat2XYZ;NewDirection;SANSModelAAO_MCproto;Monte_SANS_Threaded;Monte_SANS_NotThreaded;Monte_SANS_W1;Monte_SANS_W2;Monte_SANS;FractionReachingDetector;"
948        list = RemoveFromList(tmp, list  ,";")
949
950        // USANS Reduction bits
951        tmp = "DSM_Guinier_Fit;RemoveMaskedPoints;"
952        list = RemoveFromList(tmp, list  ,";")
953
954        //more functions from analysis models (2008)
955        tmp = "Barbell_Inner;Barbell_Outer;Barbell_integrand;BCC_Integrand;Integrand_BCC_Inner;Integrand_BCC_Outer;"
956        list = RemoveFromList(tmp, list  ,";")
957        tmp = "CapCyl;CapCyl_Inner;CapCyl_Outer;ConvLens;ConvLens_Inner;ConvLens_Outer;"
958        list = RemoveFromList(tmp, list  ,";")
959        tmp = "Dumb;Dumb_Inner;Dumb_Outer;FCC_Integrand;Integrand_FCC_Inner;Integrand_FCC_Outer;"
960        list = RemoveFromList(tmp, list  ,";")
961        tmp = "Integrand_SC_Inner;Integrand_SC_Outer;SC_Integrand;SphCyl;SphCyl_Inner;SphCyl_Outer;"
962        list = RemoveFromList(tmp, list  ,";")
963
964
965        tmp = FunctionList("f*",";","NPARAMS:2")                //point calculations
966        list = RemoveFromList(tmp, list  ,";")
967       
968        tmp = FunctionList("fSmear*",";","NPARAMS:3")           //smeared dependency calculations
969        list = RemoveFromList(tmp, list  ,";")
970       
971//      tmp = FunctionList("*X",";","KIND:4")           //XOPs, but these shouldn't show up if KIND:10 is used initially
972//      Print "X* = ",tmp
973//      print " "
974//      list = RemoveFromList(tmp, list  ,";")
975       
976        //non-fit functions that I can't seem to filter out
977        list = RemoveFromList("BinaryHS_PSF11;BinaryHS_PSF12;BinaryHS_PSF22;EllipCyl_Integrand;PP_Inner;PP_Outer;Phi_EC;TaE_Inner;TaE_Outer;",list,";")
978
979        list = SortList(list)
980        return(list)
981End
Note: See TracBrowser for help on using the repository browser.