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

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

Start of a data management panel. Functions are defined but need guts filling in.

This will replace the subtract_1d panel.

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