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

Last change on this file since 731 was 731, checked in by srkline, 12 years ago

Fixed bug in 1D file loader for the case of 4-column data that is produced from the HFIR reduction (theirs, not ours -- ours produces 6-column data)

File size: 44.9 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//
66
67Proc A_LoadOneDDataWithName(fileStr,doPlot)
68        String fileStr
69        Variable doPlot
70       
71        A_LoadOneDDataToName(fileStr,"",doPlot,0)
72
73End
74
75
76///Function that takes output name as well as input
77Proc A_LoadOneDDataToName(fileStr,outStr,doPlot,forceOverwrite)
78        String fileStr, outstr
79        Variable doPlot,forceOverwrite
80       
81        Variable rr,gg,bb,refnum,dQv
82        String w0,w1,w2,n0,n1,n2
83        String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
84        SetDataFolder root:             //build sub-folders for each data set under root
85
86// I can't see that we need to find dQv here.   
87//      if (exists("root:Packages:NIST:USANS:Globals:MainPanel:gDQv"))
88//              //Running from USANS reduction
89//              Variable dQv = root:Packages:NIST:USANS:Globals:MainPanel:gDQv
90//      endif
91//      if(exists("root:Packages:NIST:USANS_dQv"))
92//              //Running from SANS Analysis
93//              Variable dQv = root:Packages:NIST:USANS_dQv
94//      else
95//              //running from somewhere else, probably SANS Reduction, which uses common loaders
96//              Variable/G root:Packages:NIST:USANS_dQv = 0.117
97//      endif
98               
99        // if no fileStr passed in, display dialog now
100        if (cmpStr(fileStr,"") == 0)
101                fileStr = DoOpenFileDialog("Select a data file to load")
102                if (cmpstr(fileStr,"") == 0)
103                        String/G root:Packages:NIST:gLastFileName = ""
104                        return          //get out if no file selected
105                endif
106        endif
107
108        if (isXML(fileStr) == 1)
109                LoadNISTXMLData(fileStr,outstr,doPlot,forceOverwrite)
110        else           
111                //Load the waves, using default waveX names
112                //if no path or file is specified for LoadWave, the default Mac open dialog will appear
113                LoadWave/G/D/A/Q fileStr
114                String fileNamePath = S_Path+S_fileName
115//              String basestr = ParseFilePath(3,ParseFilePath(5,fileNamePath,":",0,0),":",0,0)
116
117                String basestr
118                if (!cmpstr(outstr, ""))                //Outstr = "", cmpstr returns 0
119//                      enforce a short enough name here to keep Igor objects < 31 chars
120                        baseStr = ShortFileNameString(CleanupName(S_fileName,0))
121                        baseStr = CleanupName(baseStr,0)                //in case the user added odd characters
122                        //baseStr = CleanupName(S_fileName,0)
123                else
124                        baseStr = outstr                        //for output, hopefully correct length as passed in
125                endif
126       
127//              print "basestr :"+basestr
128                String fileName =  ParseFilePath(0,ParseFilePath(5,filestr,":",0,0),":",1,0)
129//              print "filename :"+filename
130                Variable numCols = V_flag
131               
132                //changes JIL to allow 2-column data to be read in, "faking" a 3rd column of errors
133                if(numCols==2) //no errors
134                        n1 = StringFromList(1, S_waveNames ,";" )
135                        Duplicate/O $("root:"+n1), errorTmp
136                        errorTmp = 0.01*(errorTmp)+ 0.03*sqrt(errorTmp)
137                        S_waveNames+="errorTmp;"
138                        numCols=3
139                endif
140               
141                if(numCols==3)          //simple 3-column data with no resolution information
142                       
143                        // put the names of the three loaded waves into local names
144                        n0 = StringFromList(0, S_waveNames ,";" )
145                        n1 = StringFromList(1, S_waveNames ,";" )
146                        n2 = StringFromList(2, S_waveNames ,";" )
147                       
148                        //remove the semicolon AND period from files from the VAX
149                        w0 = CleanupName((basestr + "_q"),0)
150                        w1 = CleanupName((basestr + "_i"),0)
151                        w2 = CleanupName((basestr + "_s"),0)
152                       
153                        //String baseStr=w1[0,strlen(w1)-3]
154                        if(DataFolderExists("root:"+baseStr))
155                                if (!forceOverwrite)
156                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
157                                        if(V_flag==2)   //user selected No, don't load the data
158                                                SetDataFolder root:
159                                                KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
160                                                if(DataFolderExists("root:Packages:NIST"))
161                                                        String/G root:Packages:NIST:gLastFileName = filename
162                                                endif
163                                                return  //quits the macro
164                                        endif
165                                endif
166                                SetDataFolder $("root:"+baseStr)
167                        else
168                                NewDataFolder/S $("root:"+baseStr)
169                        endif
170
171                       
172                        ////overwrite the existing data, if it exists
173                        Duplicate/O $("root:"+n0), $w0
174                        Duplicate/O $("root:"+n1), $w1
175                        Duplicate/O $("root:"+n2), $w2
176       
177                        // no resolution matrix to make
178       
179                        SetScale d,0,0,"1/A",$w0
180                        SetScale d,0,0,"1/cm",$w1
181                       
182                endif           //3-col data
183               
184                if(numCols == 6)                //6-column SANS or USANS data that has resolution information
185                       
186                        // put the names of the (default named) loaded waves into local names
187                        n0 = StringFromList(0, S_waveNames ,";" )
188                        n1 = StringFromList(1, S_waveNames ,";" )
189                        n2 = StringFromList(2, S_waveNames ,";" )
190                        n3 = StringFromList(3, S_waveNames ,";" )
191                        n4 = StringFromList(4, S_waveNames ,";" )
192                        n5 = StringFromList(5, S_waveNames ,";" )
193                       
194                        //remove the semicolon AND period from files from the VAX
195                        w0 = CleanupName((basestr + "_q"),0)
196                        w1 = CleanupName((basestr + "_i"),0)
197                        w2 = CleanupName((basestr + "_s"),0)
198                        w3 = CleanupName((basestr + "sq"),0)
199                        w4 = CleanupName((basestr + "qb"),0)
200                        w5 = CleanupName((basestr + "fs"),0)
201                       
202                        //String baseStr=w1[0,strlen(w1)-3]
203                        if(DataFolderExists("root:"+baseStr))
204                                if(!forceOverwrite)
205                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
206                                        if(V_flag==2)   //user selected No, don't load the data
207                                                SetDataFolder root:
208                                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
209                                                if(DataFolderExists("root:Packages:NIST"))
210                                                        String/G root:Packages:NIST:gLastFileName = filename
211                                                endif
212                                                return          //quits the macro
213                                        endif
214                                endif
215                                SetDataFolder $("root:"+baseStr)
216                        else
217                                NewDataFolder/S $("root:"+baseStr)
218                        endif
219
220
221
222       
223        ////overwrite the existing data, if it exists
224                        Duplicate/O $("root:"+n0), $w0
225                        Duplicate/O $("root:"+n1), $w1
226                        Duplicate/O $("root:"+n2), $w2
227                        Duplicate/O $("root:"+n3), $w3
228                        Duplicate/O $("root:"+n4), $w4
229                        Duplicate/O $("root:"+n5), $w5
230       
231                        // need to switch based on SANS/USANS
232                        if (isSANSResolution($w3[0]))           //checks to see if the first point of the wave is <0]
233                                // make a resolution matrix for SANS data
234                                Variable np=numpnts($w0)
235                                Make/D/O/N=(np,4) $(baseStr+"_res")
236                               
237                                $(baseStr+"_res")[][0] = $w3[p]         //sigQ
238                                $(baseStr+"_res")[][1] = $w4[p]         //qBar
239                                $(baseStr+"_res")[][2] = $w5[p]         //fShad
240                                $(baseStr+"_res")[][3] = $w0[p]         //Qvalues
241                        else
242                                //the data is USANS data
243                                // marix calculation here, but for now, just copy the waves
244                                //$(baseStr+"_res")[][0] = $w3[p]               //sigQ
245                                //$(baseStr+"_res")[][1] = $w4[p]               //qBar
246                                //$(baseStr+"_res")[][2] = $w5[p]               //fShad
247                                //$(baseStr+"_res")[][3] = $w0[p]               //Qvalues
248                                dQv = -$w3[0]
249                               
250                                USANS_CalcWeights(baseStr,dQv)
251                               
252                        endif
253                        Killwaves/Z $w3,$w4,$w5                 //get rid of the resolution waves that are in the matrix
254       
255                        SetScale d,0,0,"1/A",$w0
256                        SetScale d,0,0,"1/cm",$w1
257               
258                endif   //6-col data
259       
260                // Load ORNL data from Heller program
261                if(numCols == 4)                //4-column SANS or USANS data that has resolution information
262                       
263                        // put the names of the (default named) loaded waves into local names
264                        n0 = StringFromList(0, S_waveNames ,";" )
265                        n1 = StringFromList(1, S_waveNames ,";" )
266                        n2 = StringFromList(2, S_waveNames ,";" )
267                        n3 = StringFromList(3, S_waveNames ,";" )
268                       
269                        //remove the semicolon AND period from files from the VAX
270                        w0 = CleanupName((basestr + "_q"),0)
271                        w1 = CleanupName((basestr + "_i"),0)
272                        w2 = CleanupName((basestr + "_s"),0)
273                        w3 = CleanupName((basestr + "sq"),0)
274                        w4 = CleanupName((basestr + "qb"),0)
275                        w5 = CleanupName((basestr + "fs"),0)
276       
277                       
278                        //String baseStr=w1[0,strlen(w1)-3]
279                        if(DataFolderExists("root:"+baseStr))
280                                if(!forceOverwrite)
281                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
282                                        if(V_flag==2)   //user selected No, don't load the data
283                                                SetDataFolder root:
284                                                KillWaves $n0,$n1,$n2,$n3               // kill the default waveX that were loaded
285                                                if(DataFolderExists("root:Packages:NIST"))
286                                                        String/G root:Packages:NIST:gLastFileName = filename
287                                                endif
288                                                return          //quits the macro
289                                        endif
290                                endif
291                                SetDataFolder $("root:"+baseStr)
292                        else
293                                NewDataFolder/S $("root:"+baseStr)
294                        endif
295       
296
297
298       
299        ////overwrite the existing data, if it exists
300                        Duplicate/O $("root:"+n0), $w0
301                        Duplicate/O $("root:"+n1), $w1
302                        Duplicate/O $("root:"+n2), $w2
303                        Duplicate/O $("root:"+n3), $w3
304                        Duplicate/O $("root:"+n0), $w4 // Set qb wave to nominal measured Q values
305                        Duplicate/O $("root:"+n0), $w5 // Make wave of appropriate length
306                        $w4 = $w0
307                        $w5 = 1                                           //  Set all shadowfactor to 1
308       
309                        // need to switch based on SANS/USANS
310                        if (isSANSResolution($w3[0]))           //checks to see if the first point of the wave is <0]
311                                // make a resolution matrix for SANS data
312                                Variable np=numpnts($w0)
313                                Make/D/O/N=(np,4) $(baseStr+"_res")
314                               
315                                $(baseStr+"_res")[][0] = $w3[p]         //sigQ
316                                $(baseStr+"_res")[][1] = $w4[p]         //qBar
317                                $(baseStr+"_res")[][2] = $w5[p]         //fShad
318                                $(baseStr+"_res")[][3] = $w0[p]         //Qvalues
319                        else
320                                //the data is USANS data
321                                // marix calculation here, but for now, just copy the waves
322                                //$(baseStr+"_res")[][0] = $w3[p]               //sigQ
323                                //$(baseStr+"_res")[][1] = $w4[p]               //qBar
324                                //$(baseStr+"_res")[][2] = $w5[p]               //fShad
325                                //$(baseStr+"_res")[][3] = $w0[p]               //Qvalues
326                                dQv = -$w3[0]
327                               
328                                USANS_CalcWeights(baseStr,dQv)
329                               
330                        endif
331                        Killwaves/Z $w3,$w4,$w5                 //get rid of the resolution waves that are in the matrix
332       
333                        SetScale d,0,0,"1/A",$w0
334                        SetScale d,0,0,"1/cm",$w1
335               
336                endif   //4-col data
337       
338       
339                if(numCols==5)          //this is the "old-style" VAX desmeared data format
340                       
341                        // put the names of the three loaded waves into local names
342                        n0 = StringFromList(0, S_waveNames ,";" )
343                        n1 = StringFromList(1, S_waveNames ,";" )
344                        n2 = StringFromList(2, S_waveNames ,";" )
345                        n3 = StringFromList(3, S_waveNames ,";" )
346                        n4 = StringFromList(4, S_waveNames ,";" )
347                       
348                       
349                        //remove the semicolon AND period from files from the VAX
350                        w0 = CleanupName((basestr+"_q"),0)
351                        w1 = CleanupName((basestr+"_i"),0)
352                        w2 = CleanupName((basestr+"_s"),0)
353                        w3 = CleanupName((basestr+"_ism"),0)
354                        w4 = CleanupName((basestr+"_fit_ism"),0)
355                       
356                        //String baseStr=w1[0,strlen(w1)-3]
357                        if(DataFolderExists("root:"+baseStr))
358                                if(!forceOverwrite)
359                                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
360                                        if(V_flag==2)   //user selected No, don't load the data
361                                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
362                                                if(DataFolderExists("root:Packages:NIST"))
363                                                        String/G root:Packages:NIST:gLastFileName = filename
364                                                endif           //set the last file loaded to the one NOT loaded
365                                                return          //quits the macro
366                                        endif
367                                endif
368                                SetDataFolder $("root:"+baseStr)
369                        else
370                                NewDataFolder/S $("root:"+baseStr)
371                        endif
372                       
373                        ////overwrite the existing data, if it exists   
374                        Duplicate/O $("root:"+n0), $w0
375                        Duplicate/O $("root:"+n1), $w1
376                        Duplicate/O $("root:"+n2), $w2
377                        Duplicate/O $("root:"+n3), $w3
378                        Duplicate/O $("root:"+n4), $w4
379                       
380                        // no resolution matrix
381                endif           //5-col data
382
383                //////
384                if(DataFolderExists("root:Packages:NIST"))
385                        String/G root:Packages:NIST:gLastFileName = filename
386                endif
387       
388               
389                //plot if desired
390                if(doPlot)
391                        Print GetDataFolder(1)
392                       
393                        // assign colors randomly
394                        rr = abs(trunc(enoise(65535)))
395                        gg = abs(trunc(enoise(65535)))
396                        bb = abs(trunc(enoise(65535)))
397                       
398                        // if target window is a graph, and user wants to append, do so
399                   DoWindow/B Plot_Manager
400                        if(WinType("") == 1)
401                                DoAlert 1,"Do you want to append this data to the current graph?"
402                               
403                               
404                                if(V_Flag == 1)
405                                        AppendToGraph $w1 vs $w0
406                                        ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1) =(rr,gg,bb),tickUnit=1
407                                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
408                                        ModifyGraph tickUnit(left)=1
409                                else
410                                //new graph
411                                        SetDataFolder $("root:"+baseStr)                //sometimes I end up back in root: here, and I can't figure out why!
412                                        Display $w1 vs $w0
413                                        ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
414                                        ModifyGraph grid=1,mirror=2,standoff=0
415                                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
416                                        ModifyGraph tickUnit(left)=1
417                                        Label left "I(q)"
418                                        Label bottom "q (A\\S-1\\M)"
419                                        Legend
420                                endif
421                        else
422                        // graph window was not target, make new one
423                                Display $w1 vs $w0
424                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
425                                ModifyGraph grid=1,mirror=2,standoff=0
426                                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
427                                ModifyGraph tickUnit(left)=1
428                                Label left "I(q)"
429                                Label bottom "q (A\\S-1\\M)"
430                                Legend
431                        endif
432                endif
433                       
434                //go back to the root folder and clean up before leaving
435                SetDataFolder root:
436                KillWaves/Z $n0,$n1,$n2,$n3,$n4,$n5
437               
438        endif
439End
440
441
442//procedure for loading NSE data in the format (4-columns)
443// qvals - time - I(q,t) - dI(q,t)
444//
445//
446// this does NOT load the data into separate folders...
447//
448Proc A_LoadNSEData()
449        A_LoadNSEDataWithName("",1)
450End
451
452Proc A_LoadNSEDataWithName(fileStr,doPlot)
453
454        //Load the waves, using default waveX names
455        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
456        LoadWave/G/D/A  fileStr
457        String filename = S_fileName
458       
459        String w0,w1,w2,n0,n1,n2,wt,w3,n3
460        Variable rr,gg,bb
461       
462        // put the names of the three loaded waves into local names
463        n0 = StringFromList(0, S_waveNames ,";" )
464        n1 = StringFromList(1, S_waveNames ,";" )
465        n2 = StringFromList(2, S_waveNames ,";" )
466        n3 = StringFromList(3, S_waveNames ,";" )
467       
468       
469        //remove the semicolon AND period from files from the VAX
470        w0 = CleanupName(("qvals_"+S_fileName),0)
471        w1 = CleanupName(("time_"+S_fileName),0)
472        w2 = CleanupName(("iqt_"+S_fileName),0)
473        w3 = CleanupName(("iqterr_"+S_fileName),0)
474       
475        if(exists(w0) !=0)
476                DoAlert 0,"This file has already been loaded. Use Append to Graph..."
477                KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
478                return
479        endif
480       
481        // Rename to give nice names
482        Rename $n0, $w0
483        Rename $n1, $w1
484        Rename $n2, $w2
485        Rename $n3, $w3
486               
487        if(doPlot)
488                // assign colors randomly
489                rr = abs(trunc(enoise(65535)))
490                gg = abs(trunc(enoise(65535)))
491                bb = abs(trunc(enoise(65535)))
492               
493                // if target window is a graph, and user wants to append, do so
494                if(WinType("") == 1)
495                        DoAlert 1,"Do you want to append this data to the current graph?"
496                        if(V_Flag == 1)
497                                AppendToGraph $w2 vs $w1
498                                ModifyGraph mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2) =(rr,gg,bb),grid=1,mirror=2,tickUnit=1
499                                ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
500                        else
501                        //new graph
502                                Display $w2 vs $w1
503                                ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
504                                ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
505                                Legend
506                        endif
507                else
508                // graph window was not target, make new one
509                        Display $w2 vs $w1
510                        ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
511                        ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
512                        Legend
513                endif
514        endif //doPlot         
515
516End
517
518//procedure for loading desmeared USANS data in the format (5-columns)
519// qvals - I(q) - sig I - Ism(q) - fitted Ism(q)
520//no weighting wave is created (not needed in IGOR 4)
521//
522// not really ever used...
523//
524Proc A_LoadUSANSData()
525
526        //Load the waves, using default waveX names
527        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
528        LoadWave/G/D/A
529   String filename = S_fileName
530       
531        String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
532        Variable rr,gg,bb
533       
534        // put the names of the three loaded waves into local names
535        n0 = StringFromList(0, S_waveNames ,";" )
536        n1 = StringFromList(1, S_waveNames ,";" )
537        n2 = StringFromList(2, S_waveNames ,";" )
538        n3 = StringFromList(3, S_waveNames ,";" )
539        n4 = StringFromList(4, S_waveNames ,";" )
540       
541       
542        //remove the semicolon AND period from files from the VAX
543        w0 = CleanupName((S_fileName+"_q"),0)
544        w1 = CleanupName((S_fileName+"_i"),0)
545        w2 = CleanupName((S_fileName+"_s"),0)
546        w3 = CleanupName((S_fileName+"_ism"),0)
547        w4 = CleanupName((S_fileName+"_fit_ism"),0)
548       
549        if(exists(w0) !=0)              //the wave already exists
550                DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
551                if(V_flag==2)   //user selected No
552                        KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
553                        if(DataFolderExists("root:Packages:NIST"))
554                                String/G root:Packages:NIST:gLastFileName = filename
555                        endif           //set the last file loaded to the one NOT loaded
556                        return          //quits the macro
557                endif
558        endif
559       
560        ////overwrite the existing data, if it exists
561        Duplicate/O $n0, $w0
562        Duplicate/O $n1, $w1
563        Duplicate/O $n2, $w2
564        Duplicate/O $n3, $w3
565        Duplicate/O $n4, $w4
566        KillWaves $n0,$n1,$n2,$n3,$n4
567       
568        if(DataFolderExists("root:Packages:NIST"))
569                String/G root:Packages:NIST:gLastFileName = filename
570        endif
571               
572        // assign colors randomly
573        rr = abs(trunc(enoise(65535)))
574        gg = abs(trunc(enoise(65535)))
575        bb = abs(trunc(enoise(65535)))
576       
577                // if target window is a graph, and user wants to append, do so
578        if(WinType("") == 1)
579                DoAlert 1,"Do you want to append this data to the current graph?"
580                if(V_Flag == 1)
581                        AppendToGraph $w1 vs $w0
582                        ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
583                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
584                else
585                //new graph
586                        Display $w1 vs $w0
587                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
588                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
589                        Legend
590                endif
591        else
592        // graph window was not target, make new one
593                Display $w1 vs $w0
594                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
595                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
596                Legend
597        endif
598               
599End
600
601
602//// Extra "Utility Procedures"
603// to pick path, get a list of data files, and make sure that a valid filename
604// is passed to LoadOneDDataWithName()
605//
606
607//prompts user to choose the local folder that contains the SANS Data
608//only one folder can be used, and its path is catPathName (and is a NAME, not a string)
609//this will overwrite the path selection
610//returns 1 if no path selected as error condition
611Function A_PickPath()
612       
613        //set the global string to the selected pathname
614        NewPath/O/M="pick the SANS data folder" catPathName
615        PathInfo/S catPathName
616        String dum = S_path
617        String alertStr = ""
618        alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"
619        //alertStr += "  Please see the manual for details."
620        if (V_flag == 0)
621                //path does not exist - no folder selected
622                String/G root:Packages:NIST:gCatPathStr = "no folder selected"
623                return(1)
624        else
625                //set the global to the path (as a string)
626                // need 4 \ since it is the escape character
627                if(cmpstr("\\\\",dum[0,1])==0)  //Windoze user going through network neighborhood
628                        DoAlert 0,alertStr
629                        KillPath catPathName
630                        return(1)
631                endif
632                String/G root:Packages:NIST:gCatPathStr = dum
633                return(0)               //no error
634        endif
635End
636
637//Function attempts to find valid filename from partial name that has been stripped of
638//the VAX version number. The partial name is tried first
639//*** the PATH is hard-wired to catPathName (which is assumed to exist)
640//version numers up to ;10 are tried
641//only the "name;vers" is returned. the path is not prepended, hence the return string
642//is not a complete specification of the file
643//
644// added 11/99 - uppercase and lowercase versions of the file are tried, if necessary
645// since from marquee, the filename field (textread[0]) must be used, and can be a mix of
646// upper/lowercase letters, while the filename on the server (should) be all caps
647// now makes repeated calls to ValidFileString()
648//
649Function/S A_FindValidFilename(partialName)
650        String PartialName
651       
652        String retStr=""
653       
654        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
655        retStr = A_ValidFileString(partialName)
656        if(cmpstr(retStr,"") !=0)
657                //non-null return
658                return(retStr)
659        Endif
660       
661        //if the partial name is derived from the file header, there can be spaces at the beginning
662        //or in the middle of the filename - depending on the prefix and initials used
663        //
664        //remove any leading spaces from the name before starting
665        partialName = A_RemoveAllSpaces(partialName)
666       
667        //try name with no spaces
668        retStr = A_ValidFileString(partialName)
669        if(cmpstr(retStr,"") !=0)
670                //non-null return
671                return(retStr)
672        Endif
673       
674        //try all UPPERCASE
675        partialName = UpperStr(partialName)
676        retStr = A_ValidFileString(partialName)
677        if(cmpstr(retStr,"") !=0)
678                //non-null return
679                return(retStr)
680        Endif
681       
682        //try all lowercase (ret null if failure)
683        partialName = LowerStr(partialName)
684        retStr = A_ValidFileString(partialName)
685        if(cmpstr(retStr,"") !=0)
686                //non-null return
687                return(retStr)
688        else
689                return(retStr)
690        Endif
691End
692
693//function to test a binary file to see if it is a RAW binary SANS file
694//first checks the total bytes in the file (which for raw data is 33316 bytes)
695//**note that the "DIV" file will also show up as a raw file by the run field
696//should be listed in CAT/SHORT and in patch windows
697//
698//Function then checks the file fname (full path:file) for "RAW" run.type field
699//if not found, the data is not raw data and zero is returned
700Function A_CheckIfRawData(fname)
701        String fname
702       
703        Variable refnum,totalBytes
704        String testStr=""
705       
706        Open/R/T="????TEXT" refNum as fname
707        //get the total number of bytes in the file, to avoid moving past EOF
708        FStatus refNum
709        totalBytes = V_logEOF
710        //Print totalBytes
711        if(totalBytes!=33316)
712                //can't possibly be a raw data file
713                Close refnum
714                return(0)               //not a raw SANS file
715        Endif
716        FSetPos refNum,75
717        FReadLine/N=3 refNum,testStr
718        Close refNum
719       
720        if(cmpstr(testStr,"RAW")==0)
721                //true, is raw data file
722                Return(1)
723        else
724                //some other file
725                Return(0)
726        Endif
727End
728
729//list (input) is a list, typically returned from IndexedFile()
730//which is semicolon-delimited, and may contain filesnames from the VAX
731//that contain version numbers, where the version number appears as a separate list item
732//(and also as a non-existent file)
733//these numbers must be purged from the list, especially for display in a popup
734//or list processing of filenames
735//the function returns the list, cleaned of version numbers (up to 11)
736//raw data files will typically never have a version number other than 1.
737Function/S A_RemoveVersNumsFromList(list)
738        String list
739       
740        //get rid of version numbers first (up to 11)
741        Variable ii,num
742        String item
743        num = ItemsInList(list,";")
744        ii=1
745        do
746                item = num2str(ii)
747                list = RemoveFromList(item, list ,";" )
748                ii+=1
749        while(ii<12)
750       
751        return (list)
752End
753
754//Function attempts to find valid filename from partial name that has been stripped of
755//the VAX version number. The partial name is tried first
756//*** the PATH is hard-wired to catPathName (which is assumed to exist)
757//version numers up to ;10 are tried
758//only the "name;vers" is returned. the path is not prepended, hence the return string
759//is not a complete specification of the file
760//
761Function/S A_ValidFileString(partialName)
762        String partialName
763       
764        String tempName = "",msg=""
765        Variable ii,refnum
766       
767        ii=0
768        do
769                if(ii==0)
770                        //first pass, try the partialName
771                        tempName = partialName
772                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag)
773                        if(V_flag == 0)
774                                //file exists
775                                Close refnum            //YES needed,
776                                break
777                        endif
778                else
779                        tempName = partialName + ";" + num2str(ii)
780                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName
781                        if(V_flag == 0)
782                                //file exists
783                                Close refnum
784                                break
785                        endif
786                Endif
787                ii+=1
788                //print "ii=",ii
789        while(ii<11)
790        //go get the selected bits of information, using tempName, which exists
791        if(ii>=11)
792                //msg = partialName + " not found. is version number > 11?"
793                //DoAlert 0, msg
794                //PathInfo catPathName
795                //Print S_Path
796                Return ("")             //use null string as error condition
797        Endif
798       
799        Return (tempName)
800End
801
802//function to remove all spaces from names when searching for filenames
803//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
804//but the text field in the header WILL, if less than 3 characters were used for the
805//user's initials, and can have leading spaces if prefix was less than 5 characters
806//
807//returns a string identical to the original string, except with the interior spaces removed
808//
809Function/S A_RemoveAllSpaces(str)
810        String str
811       
812        String tempstr = str
813        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
814        ii=0
815        do
816                len = strlen(tempStr)
817                spc = strsearch(tempStr," ",0)          //is the last character a space?
818                if (spc == -1)
819                        break           //no more spaces found, get out
820                endif
821                str = tempstr
822                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
823        While(1)        //should never be more than 2 or 3
824       
825        If(strlen(tempStr) < 1)
826                tempStr = ""            //be sure to return a null string if problem found
827        Endif
828       
829        //Print strlen(tempstr)
830       
831        Return(tempStr)
832               
833End
834
835//AJJ Oct 2008
836//Moved from GaussUtils - makes more sense to have it here
837
838// utility used in the "PlotSmeared...() macros to get a list of data folders
839//
840//1:    Waves.
841//2:    Numeric variables.
842//3:    String variables.
843//4:    Data folders.
844Function/S GetAList(type)
845        Variable type
846       
847        SetDataFolder root:
848       
849        String objName,str=""
850        Variable index = 0
851        do
852                objName = GetIndexedObjName(":", type, index)
853                if (strlen(objName) == 0)
854                        break
855                endif
856                //Print objName
857                str += objName + ";"
858                index += 1
859        while(1)
860       
861        // remove myGlobals, Packages, etc. from the folder list
862        if(type==4)
863                str = RemoveFromList("myGlobals", str , ";" )
864                str = RemoveFromList("Packages", str, ";")
865                str = RemoveFromList("AutoFit", str, ";")
866                str = RemoveFromList("TISANE", str, ";")
867                str = RemoveFromList("HayPenMSA", str, ";")
868                str = RemoveFromList("SAS", str, ";")                   //from Irena
869                str = RemoveFromList("USAXS", str, ";")
870                str = RemoveFromList("RAW;SAM;EMP;BGD;DIV;MSK;ABS;CAL;COR;STO;SUB;DRK;SAS;", str  ,";")                 //root level folders present in old reduction experiments
871        endif
872       
873        return(str)
874End
875
876
877//returns the path to the file, or null if cancel
878//
879// either the T="????" or the /F flags work to set the filter to "all files"
880// but the T is essentially obsolete, /F is new for Igor 6.1 and recommended
881Function/S DoOpenFileDialog(msg)
882        String msg
883       
884        Variable refNum
885//      String message = "Select a file"
886        String outputPath
887       
888        String fileFilters = "All Files:.*;"
889               
890//      Open/D/R/T="????"/M=msg refNum
891        Open/D/R/F=fileFilters/M=msg refNum
892        outputPath = S_fileName
893       
894        return outputPath
895End
896
897// returns the path to the file, or null if the user cancelled
898// fancy use of optional parameters
899//
900// enforce short file names (25 characters)
901Function/S DoSaveFileDialog(msg,[fname,suffix])
902        String msg,fname,suffix
903        Variable refNum
904//      String message = "Save the file as"
905
906        if(ParamIsDefault(fname))
907//              Print "fname not supplied"
908                fname = ""
909        endif
910        if(ParamIsDefault(suffix))
911//              Print "suffix not supplied"
912                suffix = ""
913        endif
914       
915        String outputPath,tmpName,testStr
916        Variable badLength=0,maxLength=25,l1,l2
917       
918       
919        tmpName = fname + suffix
920       
921        do
922                badLength=0
923                Open/D/M=msg/T="????" refNum as tmpName         //OS will allow 255 characters, but then I can't read it back in!
924                outputPath = S_fileName
925               
926                testStr = ParseFilePath(0, outputPath, ":", 1, 0)               //just the filename
927                if(strlen(testStr)==0)
928                        break           //cancel, allow exit
929                endif
930                if(strlen(testStr) > maxLength)
931                        badlength = 1
932                        DoAlert 2,"File name is too long. Is\r"+testStr[0,maxLength-1]+"\rOK?"
933                        if(V_flag==3)
934                                outputPath = ""
935                                break
936                        endif
937                        if(V_flag==1)                   //my suggested name is OK, so trim the output
938                                badlength=0
939                                l1 = strlen(testStr)            //too long length
940                                l1 = l1-maxLength               //number to trim
941                                //Print outputPath
942                                l2=strlen(outputPath)
943                                outputPath = outputPath[0,l2-1-l1]
944                                //Print "modified  ",outputPath
945                        endif
946                        //if(V_flag==2)  do nothing, let it go around again
947                endif
948               
949        while(badLength)
950       
951        return outputPath
952End
953
954// returns a shortened file name (26 characters max) so that the loader
955// won't try to create Igor objects that have names that are longer than 31
956//
957Function/S ShortFileNameString(inStr)
958        String inStr
959
960        String outStr=""
961        Variable maxLength=25
962        Variable nameTooLong=0
963        String/G root:Packages:NIST:gShortNameStr = inStr[0,maxLength-1]
964        SVAR newStr = root:Packages:NIST:gShortNameStr
965
966        if(strlen(inStr) <= maxLength)
967                return (inStr)          //length OK
968        else
969                do
970                        nameTooLong = 0
971                       
972                        DoAlert 1,"File name is too long. Is\r"+inStr[0,maxLength-1]+"\rOK?"
973                        if(V_flag==1)                   //my suggested name is OK, so trim the output
974                                outStr = inStr[0,maxLength-1]
975                                //Print "modified  ",outStr
976                                return(outStr)
977                        endif
978       
979       
980                        if(V_flag == 2)         //not OK, do something about it
981                               
982                                DoWindow/F ShorterNameInput             //it really shouldn't exist...
983                                if(V_flag==0)
984                               
985                                        NewPanel /W=(166,90,666,230) as "Enter a Shorter Name"
986                                        DoWindow/C ShorterNameInput
987                                        SetDrawLayer UserBack
988                                        TitleBox title0,pos={35,8},size={261,20},title=" Enter a shorter file name. It must be 25 characters or less "
989                                        TitleBox title0,fSize=12,fStyle=1
990                                        SetVariable setvar0,pos={21,52},size={300,15},title="New name",value= _STR:newStr
991                                        SetVariable setvar0,proc=ShorterNameSetVarProc,fsize=12
992                                        SetVariable setvar0 valueBackColor=(65535,49151,49151)
993                                        Button button0,pos={259,87},size={60,20},title="Done"
994                                        Button button0,proc=ShorterNameDoneButtonProc
995                               
996                                endif
997                               
998                                PauseForUser ShorterNameInput
999                               
1000                                // this really should force a good name, but there could be errors that I'm not catching
1001//                              Print newStr, strlen(newStr)
1002                                nameTooLong = 0
1003                        endif
1004               
1005                while (nameTooLong)
1006               
1007                return(newStr)
1008               
1009        endif
1010               
1011End
1012
1013
1014// for the ShortFileNameString() - PauseForUser to get a shorter file name
1015Function ShorterNameSetVarProc(sva) : SetVariableControl
1016        STRUCT WMSetVariableAction &sva
1017               
1018        switch( sva.eventCode )
1019                case 1: // mouse up
1020                case 2: // Enter key
1021                case 3: // Live update
1022                                String sv = sva.sval
1023                                if( strlen(sv) > 25 )
1024                                        sv= sv[0,24]
1025                                        SetVariable  $(sva.ctrlName),win=$(sva.win),value=_STR:sv
1026                                        SetVariable setvar0 valueBackColor=(65535,49151,49151)
1027                                        Beep
1028                                else
1029                                        SetVariable setvar0 valueBackColor=(65535,65535,65535)
1030                                endif
1031                                break
1032                endswitch
1033        return 0
1034End
1035
1036// for the ShortFileNameString() - PauseForUser to get a shorter file name
1037Function ShorterNameDoneButtonProc(ba) : ButtonControl
1038        STRUCT WMButtonAction &ba
1039       
1040        String win = ba.win
1041
1042        switch (ba.eventCode)
1043                case 2:
1044                        SVAR newStr = root:Packages:NIST:gShortNameStr
1045                        ControlInfo setvar0
1046                        newStr = S_value
1047                        DoWindow/K ShorterNameInput
1048                       
1049                        break
1050        endswitch
1051
1052        return 0
1053End
1054
1055
1056// a function common to many panels, so put the basic version here that simply
1057// returns null string if no functions are present. Calling procedures can
1058// add to the list to customize as needed.
1059// show the available models
1060// not the f*(cw,xw) point calculations
1061// not the *X(cw,xw) XOPS
1062//
1063// KIND:10 should show only user-defined curve fitting functions
1064// - not XOPs
1065// - not other user-defined functions
1066Function/S User_FunctionPopupList()
1067        String list,tmp
1068        list = FunctionList("*",";","KIND:10")          //get every user defined curve fit function
1069
1070        //now start to remove everything the user doesn't need to see...
1071
1072        tmp = FunctionList("*_proto",";","KIND:10")             //prototypes
1073        list = RemoveFromList(tmp, list  ,";")
1074       
1075        //prototypes that show up if GF is loaded
1076        list = RemoveFromList("GFFitFuncTemplate", list)
1077        list = RemoveFromList("GFFitAllAtOnceTemplate", list)
1078        list = RemoveFromList("NewGlblFitFunc", list)
1079        list = RemoveFromList("NewGlblFitFuncAllAtOnce", list)
1080        list = RemoveFromList("GlobalFitFunc", list)
1081        list = RemoveFromList("GlobalFitAllAtOnce", list)
1082        list = RemoveFromList("GFFitAAOStructTemplate", list)
1083        list = RemoveFromList("NewGF_SetXWaveInList", list)
1084        list = RemoveFromList("NewGlblFitFuncAAOStruct", list)
1085       
1086        // more to remove as a result of 2D/Gizmo
1087        list = RemoveFromList("A_WMRunLessThanDelta", list)
1088        list = RemoveFromList("WMFindNaNValue", list)
1089        list = RemoveFromList("WM_Make3DBarChartParametricWave", list)
1090        list = RemoveFromList("UpdateQxQy2Mat", list)
1091        list = RemoveFromList("MakeBSMask", list)
1092       
1093        // MOTOFIT/GenFit bits
1094        tmp = "GEN_allatoncefitfunc;GEN_fitfunc;GetCheckBoxesState;MOTO_GFFitAllAtOnceTemplate;MOTO_GFFitFuncTemplate;MOTO_NewGF_SetXWaveInList;MOTO_NewGlblFitFunc;MOTO_NewGlblFitFuncAllAtOnce;GeneticFit_UnSmearedModel;GeneticFit_SmearedModel;"
1095        list = RemoveFromList(tmp, list  ,";")
1096
1097        // SANS Reduction bits
1098        tmp = "ASStandardFunction;Ann_1D_Graph;Avg_1D_Graph;BStandardFunction;CStandardFunction;Draw_Plot1D;MyMat2XYZ;"
1099        list = RemoveFromList(tmp, list  ,";")
1100        tmp = "NewDirection;SANSModelAAO_MCproto;Monte_SANS_Threaded;Monte_SANS_NotThreaded;Monte_SANS_W1;Monte_SANS_W2;Monte_SANS_W3;Monte_SANS_W4;Monte_SANS;FractionReachingDetector;TwoLevel_EC;SmearedTwoLevel_EC;"
1101        list = RemoveFromList(tmp, list  ,";")
1102
1103
1104        // USANS Reduction bits
1105        tmp = "DSM_Guinier_Fit;RemoveMaskedPoints;"
1106        list = RemoveFromList(tmp, list  ,";")
1107
1108        //more functions from analysis models (2008)
1109        tmp = "Barbell_Inner;Barbell_Outer;Barbell_integrand;BCC_Integrand;Integrand_BCC_Inner;Integrand_BCC_Outer;"
1110        list = RemoveFromList(tmp, list  ,";")
1111        tmp = "CapCyl;CapCyl_Inner;CapCyl_Outer;ConvLens;ConvLens_Inner;ConvLens_Outer;"
1112        list = RemoveFromList(tmp, list  ,";")
1113        tmp = "Dumb;Dumb_Inner;Dumb_Outer;FCC_Integrand;Integrand_FCC_Inner;Integrand_FCC_Outer;"
1114        list = RemoveFromList(tmp, list  ,";")
1115        tmp = "Integrand_SC_Inner;Integrand_SC_Outer;SC_Integrand;SphCyl;SphCyl_Inner;SphCyl_Outer;"
1116        list = RemoveFromList(tmp, list  ,";")
1117        tmp = "CSPP_Outer;CSPP_Inner;PP_Outer;PP_Inner;"
1118        list = RemoveFromList(tmp, list  ,";")
1119        tmp = "Guinier_Fit;"
1120        list = RemoveFromList(tmp, list  ,";")
1121
1122        tmp = FunctionList("f*",";","NPARAMS:2")                //point calculations
1123        list = RemoveFromList(tmp, list  ,";")
1124       
1125        tmp = FunctionList("fSmear*",";","NPARAMS:3")           //smeared dependency calculations
1126        list = RemoveFromList(tmp, list  ,";")
1127       
1128        // anything that might be included in Irena
1129        tmp = FunctionList("GEN_*",";","KIND:10")
1130        list = RemoveFromList(tmp, list  ,";")
1131        tmp = FunctionList("IN2G_*",";","KIND:10")
1132        list = RemoveFromList(tmp, list  ,";")
1133        tmp = FunctionList("IR1A_*",";","KIND:10")
1134        list = RemoveFromList(tmp, list  ,";")
1135        tmp = FunctionList("IR1B_*",";","KIND:10")
1136        list = RemoveFromList(tmp, list  ,";")
1137        tmp = FunctionList("IR1U_*",";","KIND:10")
1138        list = RemoveFromList(tmp, list  ,";")
1139        tmp = FunctionList("IR1V_*",";","KIND:10")
1140        list = RemoveFromList(tmp, list  ,";")
1141        tmp = FunctionList("IR1_*",";","KIND:10")
1142        list = RemoveFromList(tmp, list  ,";")
1143        tmp = FunctionList("IR2D_*",";","KIND:10")
1144        list = RemoveFromList(tmp, list  ,";")
1145
1146        tmp = FunctionList("IR2D_*",";","KIND:10")
1147        list = RemoveFromList(tmp, list  ,";")
1148        tmp = FunctionList("IR2H_*",";","KIND:10")
1149        list = RemoveFromList(tmp, list  ,";") 
1150        tmp = FunctionList("IR2L_*",";","KIND:10")
1151        list = RemoveFromList(tmp, list  ,";")
1152        tmp = FunctionList("IR2Pr_*",";","KIND:10")
1153        list = RemoveFromList(tmp, list  ,";")
1154        tmp = FunctionList("IR2R_*",";","KIND:10")
1155        list = RemoveFromList(tmp, list  ,";")
1156        tmp = FunctionList("IR2S_*",";","KIND:10")
1157        list = RemoveFromList(tmp, list  ,";")
1158        tmp = FunctionList("IR2_*",";","KIND:10")
1159        list = RemoveFromList(tmp, list  ,";")
1160        tmp = FunctionList("*LogLog",";","KIND:10")
1161        list = RemoveFromList(tmp, list  ,";")
1162       
1163        //functions included in Nika
1164        tmp = FunctionList("NI1*",";","KIND:10")
1165        list = RemoveFromList(tmp, list  ,";")
1166        tmp = FunctionList("TransAx_*",";","KIND:10")
1167        list = RemoveFromList(tmp, list  ,";")
1168        tmp = FunctionList("TransformAxis*",";","KIND:10")
1169        list = RemoveFromList(tmp, list  ,";")
1170        tmp = FunctionList("erfForNormal*",";","KIND:10")
1171        list = RemoveFromList(tmp, list  ,";")
1172
1173        // functions in Indra (USAXS)
1174        tmp = FunctionList("IN2Q_*",";","KIND:10")
1175        list = RemoveFromList(tmp, list  ,";")
1176        tmp = FunctionList("IN3_*",";","KIND:10")
1177        list = RemoveFromList(tmp, list  ,";")
1178       
1179//      tmp = FunctionList("*X",";","KIND:4")           //XOPs, but these shouldn't show up if KIND:10 is used initially
1180//      Print "X* = ",tmp
1181//      print " "
1182//      list = RemoveFromList(tmp, list  ,";")
1183       
1184        //non-fit functions that I can't seem to filter out
1185        list = RemoveFromList("BinaryHS_PSF11;BinaryHS_PSF12;BinaryHS_PSF22;EllipCyl_Integrand;PP_Inner;PP_Outer;Phi_EC;TaE_Inner;TaE_Outer;",list,";")
1186
1187        list = SortList(list)
1188        return(list)
1189End
1190
1191
1192///////////////////////////////////////////////////
1193// old SANSPreferences have been moved here to a common place and renamed to "NCNR Preferences" so that they
1194// are common to all of the packages (and will appear on all of the menus)
1195//
1196// globals moved to root:Packages:NIST: since this is generated by all packages.
1197//
1198///////////////////////////
1199// user preferences
1200//
1201// globals are created in initialize.ipf
1202//
1203// this panel allows for user modification
1204///////////////////////////
1205Proc Show_Preferences_Panel()
1206
1207        DoWindow/F Pref_Panel
1208        if(V_flag==0)
1209                Initialize_Preferences()
1210                Pref_Panel()
1211        Endif
1212//      Print "Preferences Panel stub"
1213End
1214
1215Proc Initialize_Preferences()
1216        // create the globals here if they are not already present
1217       
1218        // each package initialization should call this to repeat the initialization
1219        // without overwriting what was already set
1220       
1221        Variable val
1222       
1223        ///// items for SANS reduction
1224        val = NumVarOrDefault("root:Packages:NIST:gLogScalingAsDefault", 1 )
1225        Variable/G root:Packages:NIST:gLogScalingAsDefault=val
1226       
1227        val = NumVarOrDefault("root:Packages:NIST:gAllowDRK", 0 )
1228        Variable/G root:Packages:NIST:gAllowDRK=val                     //don't show DRK as default
1229       
1230        val = NumVarOrDefault("root:Packages:NIST:gDoTransCheck", 1 )
1231        Variable/G root:Packages:NIST:gDoTransCheck=val
1232       
1233        val = NumVarOrDefault("root:Packages:NIST:gBinWidth", 1 )
1234        Variable/G root:Packages:NIST:gBinWidth=val
1235       
1236        val = NumVarOrDefault("root:Packages:NIST:gNPhiSteps", 72 )
1237        Variable/G root:Packages:NIST:gNPhiSteps=val
1238       
1239        // flags to turn detector corrections on/off for testing (you should leave these ON)
1240        val = NumVarOrDefault("root:Packages:NIST:gDoDetectorEffCorr", 1 )
1241        Variable/G root:Packages:NIST:gDoDetectorEffCorr = 1
1242       
1243        val = NumVarOrDefault("root:Packages:NIST:gDoTransmissionCorr", 1 )
1244        Variable/G root:Packages:NIST:gDoTransmissionCorr = 1
1245       
1246       
1247        /// items for SANS Analysis
1248       
1249       
1250        /// items for USANS Reduction
1251       
1252       
1253        /// items for everyone
1254        val = NumVarOrDefault("root:Packages:NIST:gXML_Write", 0 )
1255        Variable/G root:Packages:NIST:gXML_Write = val
1256       
1257       
1258end
1259
1260Function LogScalePrefCheck(ctrlName,checked) : CheckBoxControl
1261        String ctrlName
1262        Variable checked
1263       
1264        NVAR gLog = root:Packages:NIST:gLogScalingAsDefault
1265        glog=checked
1266        //print "log pref checked = ",checked
1267End
1268
1269Function DRKProtocolPref(ctrlName,checked) : CheckBoxControl
1270        String ctrlName
1271        Variable checked
1272       
1273        NVAR gDRK = root:Packages:NIST:gAllowDRK
1274        gDRK = checked
1275        //Print "DRK preference = ",checked
1276End
1277
1278Function UnityTransPref(ctrlName,checked) : CheckBoxControl
1279        String ctrlName
1280        Variable checked
1281       
1282        NVAR gVal = root:Packages:NIST:gDoTransCheck
1283        gVal = checked
1284End
1285
1286Function XMLWritePref(ctrlName,checked) : CheckBoxControl
1287        String ctrlName
1288        Variable checked
1289       
1290        NVAR gVal = root:Packages:NIST:gXML_Write
1291        gVal = checked
1292End
1293
1294Function PrefDoneButtonProc(ctrlName) : ButtonControl
1295        String ctrlName
1296       
1297        DoWindow/K pref_panel
1298End
1299
1300Proc Pref_Panel()
1301        PauseUpdate; Silent 1           // building window...
1302        NewPanel /W=(646,208,1070,468)/K=2 as "NCNR Preference Panel"
1303        DoWindow/C pref_panel
1304        ModifyPanel cbRGB=(49694,61514,27679)
1305        SetDrawLayer UserBack
1306        ModifyPanel fixedSize=1
1307//////
1308//on main portion of panel, always visible
1309        Button PrefPanelButtonA,pos={354,12},size={50,20},proc=PrefDoneButtonProc,title="Done"
1310
1311        TabControl PrefTab,pos={7,49},size={410,202},tabLabel(0)="General",proc=PrefTabProc
1312        TabControl PrefTab,tabLabel(1)="SANS",tabLabel(2)="USANS",tabLabel(3)="Analysis"
1313        TabControl PrefTab,value=0
1314        TabControl PrefTab labelBack=(49694,61514,27679)
1315       
1316//on tab(0) - General - initially visible
1317        CheckBox PrefCtrl_0a,pos={21,96},size={124,14},proc=XMLWritePref,title="Use canSAS XML Output"
1318        CheckBox PrefCtrl_0a,help={"Checking this will set the default output format to be canSAS XML rather than NIST 6 column"}
1319        CheckBox PrefCtrl_0a,value= root:Packages:NIST:gXML_Write
1320
1321//on tab(1) - SANS
1322        CheckBox PrefCtrl_1a,pos={21,100},size={171,14},proc=LogScalePrefCheck,title="Use Log scaling for 2D data display"
1323        CheckBox PrefCtrl_1a,help={"Checking this will display 2D SANS data with a logarithmic color scale of neutron counts. If not checked, the color mapping will be linear."}
1324        CheckBox PrefCtrl_1a,value= root:Packages:NIST:gLogScalingAsDefault
1325        CheckBox PrefCtrl_1b,pos={21,120},size={163,14},proc=DRKProtocolPref,title="Allow DRK correction in protocols"
1326        CheckBox PrefCtrl_1b,help={"Checking this will allow DRK correction to be used in reduction protocols. You will need to re-draw the protocol panel for this change to be visible."}
1327        CheckBox PrefCtrl_1b,value= root:Packages:NIST:gAllowDRK
1328        CheckBox PrefCtrl_1c,pos={21,140},size={137,14},proc=UnityTransPref,title="Check for Transmission = 1"
1329        CheckBox PrefCtrl_1c,help={"Checking this will check for SAM or EMP Trans = 1 during data correction"}
1330        CheckBox PrefCtrl_1c,value= root:Packages:NIST:gDoTransCheck
1331        SetVariable PrefCtrl_1d,pos={21,170},size={200,15},title="Averaging Bin Width (pixels)"
1332        SetVariable PrefCtrl_1d,limits={1,100,1},value= root:Packages:NIST:gBinWidth
1333        SetVariable PrefCtrl_1e,pos={21,195},size={200,15},title="# Phi Steps (annular avg)"
1334        SetVariable PrefCtrl_1e,limits={1,360,1},value= root:Packages:NIST:gNPhiSteps
1335        CheckBox PrefCtrl_1f title="Do Transmssion Correction?",size={140,14},value=1
1336        CheckBox PrefCtrl_1f pos={255,100},help={"TURN OFF ONLY FOR DEBUGGING. This corrects the data for angle dependent transmssion."}
1337        CheckBox PrefCtrl_1g title="Do Efficiency Correction?",size={140,14}
1338        CheckBox PrefCtrl_1g value=1,pos={255,120},help={"TURN OFF ONLY FOR DEBUGGING. This corrects the data for angle dependent detector efficiency."}
1339
1340
1341        CheckBox PrefCtrl_1a,disable=1
1342        CheckBox PrefCtrl_1b,disable=1
1343        CheckBox PrefCtrl_1c,disable=1
1344        SetVariable PrefCtrl_1d,disable=1
1345        SetVariable PrefCtrl_1e,disable=1
1346        CheckBox PrefCtrl_1f,disable=1
1347        CheckBox PrefCtrl_1g,disable=1
1348
1349//on tab(2) - USANS
1350        GroupBox PrefCtrl_2a pos={21,100},size={1,1},title="nothing to set",fSize=12
1351
1352        GroupBox PrefCtrl_2a,disable=1
1353
1354
1355//on tab(3) - Analysis
1356        GroupBox PrefCtrl_3a pos={21,100},size={1,1},title="nothing to set",fSize=12
1357       
1358        GroupBox PrefCtrl_3a,disable=1
1359
1360EndMacro
1361
1362// function to control the drawing of controls in the TabControl on the main panel
1363// Naming scheme for the controls MUST be strictly adhered to... else controls will
1364// appear in odd places...
1365// all controls are named PrefCtrl_NA where N is the tab number and A is the letter denoting
1366// the controls position on that particular tab.
1367// in this way, they will always be drawn correctly..
1368//
1369Function PrefTabProc(name,tab)
1370        String name
1371        Variable tab
1372       
1373//      Print "name,number",name,tab
1374        String ctrlList = ControlNameList("",";"),item="",nameStr=""
1375        Variable num = ItemsinList(ctrlList,";"),ii,onTab
1376        for(ii=0;ii<num;ii+=1)
1377                //items all start w/"PrefCtrl_", 9 characters
1378                item=StringFromList(ii, ctrlList ,";")
1379                nameStr=item[0,8]
1380                if(cmpstr(nameStr,"PrefCtrl_")==0)
1381                        onTab = str2num(item[9])                        //[9] is a number
1382                        ControlInfo $item
1383                        switch(abs(V_flag))     
1384                                case 1:
1385                                        Button $item,disable=(tab!=onTab)
1386                                        break
1387                                case 2:
1388                                        CheckBox $item,disable=(tab!=onTab)
1389                                        break
1390                                case 5:
1391                                        SetVariable $item,disable=(tab!=onTab)
1392                                        break
1393                                case 10:       
1394                                        TitleBox $item,disable=(tab!=onTab)
1395                                        break
1396                                case 4:
1397                                        ValDisplay $item,disable=(tab!=onTab)
1398                                        break
1399                                case 9:
1400                                        GroupBox $item,disable=(tab!=onTab)
1401                                        break
1402                                // add more items to the switch if different control types are used
1403                        endswitch
1404                endif
1405        endfor
1406        return(0)
1407End
1408
Note: See TracBrowser for help on using the repository browser.