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

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

removing work folder names from the popup list of data folders when an old experiment is loaded - improves back-compatibility.

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