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

Last change on this file since 668 was 668, checked in by srkline, 13 years ago

Made the preference panel fancier, with a tab control. this makes it much easier to add more things in the future. Added two more SANS items to turn off some detector corrections. good for testing, but maybe a bit dangerous.

removed the SANSPreferences procedure file from the general includes list for reduction. kept it in the very old versions of the includes (510 and older) for backwards comaptibility. new experiments start with 520 or higher.

File size: 44.4 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        endif
870       
871        return(str)
872End
873
874
875//returns the path to the file, or null if cancel
876//
877// either the T="????" or the /F flags work to set the filter to "all files"
878// but the T is essentially obsolete, /F is new for Igor 6.1 and recommended
879Function/S DoOpenFileDialog(msg)
880        String msg
881       
882        Variable refNum
883//      String message = "Select a file"
884        String outputPath
885       
886        String fileFilters = "All Files:.*;"
887               
888//      Open/D/R/T="????"/M=msg refNum
889        Open/D/R/F=fileFilters/M=msg refNum
890        outputPath = S_fileName
891       
892        return outputPath
893End
894
895// returns the path to the file, or null if the user cancelled
896// fancy use of optional parameters
897//
898// enforce short file names (25 characters)
899Function/S DoSaveFileDialog(msg,[fname,suffix])
900        String msg,fname,suffix
901        Variable refNum
902//      String message = "Save the file as"
903
904        if(ParamIsDefault(fname))
905//              Print "fname not supplied"
906                fname = ""
907        endif
908        if(ParamIsDefault(suffix))
909//              Print "suffix not supplied"
910                suffix = ""
911        endif
912       
913        String outputPath,tmpName,testStr
914        Variable badLength=0,maxLength=25,l1,l2
915       
916       
917        tmpName = fname + suffix
918       
919        do
920                badLength=0
921                Open/D/M=msg/T="????" refNum as tmpName         //OS will allow 255 characters, but then I can't read it back in!
922                outputPath = S_fileName
923               
924                testStr = ParseFilePath(0, outputPath, ":", 1, 0)               //just the filename
925                if(strlen(testStr)==0)
926                        break           //cancel, allow exit
927                endif
928                if(strlen(testStr) > maxLength)
929                        badlength = 1
930                        DoAlert 2,"File name is too long. Is\r"+testStr[0,maxLength-1]+"\rOK?"
931                        if(V_flag==3)
932                                outputPath = ""
933                                break
934                        endif
935                        if(V_flag==1)                   //my suggested name is OK, so trim the output
936                                badlength=0
937                                l1 = strlen(testStr)            //too long length
938                                l1 = l1-maxLength               //number to trim
939                                //Print outputPath
940                                l2=strlen(outputPath)
941                                outputPath = outputPath[0,l2-1-l1]
942                                //Print "modified  ",outputPath
943                        endif
944                        //if(V_flag==2)  do nothing, let it go around again
945                endif
946               
947        while(badLength)
948       
949        return outputPath
950End
951
952// returns a shortened file name (26 characters max) so that the loader
953// won't try to create Igor objects that have names that are longer than 31
954//
955Function/S ShortFileNameString(inStr)
956        String inStr
957
958        String outStr=""
959        Variable maxLength=25
960        Variable nameTooLong=0
961        String/G root:Packages:NIST:gShortNameStr = inStr[0,maxLength-1]
962        SVAR newStr = root:Packages:NIST:gShortNameStr
963
964        if(strlen(inStr) <= maxLength)
965                return (inStr)          //length OK
966        else
967                do
968                        nameTooLong = 0
969                       
970                        DoAlert 1,"File name is too long. Is\r"+inStr[0,maxLength-1]+"\rOK?"
971                        if(V_flag==1)                   //my suggested name is OK, so trim the output
972                                outStr = inStr[0,maxLength-1]
973                                //Print "modified  ",outStr
974                                return(outStr)
975                        endif
976       
977       
978                        if(V_flag == 2)         //not OK, do something about it
979                               
980                                DoWindow/F ShorterNameInput             //it really shouldn't exist...
981                                if(V_flag==0)
982                               
983                                        NewPanel /W=(166,90,666,230) as "Enter a Shorter Name"
984                                        DoWindow/C ShorterNameInput
985                                        SetDrawLayer UserBack
986                                        TitleBox title0,pos={35,8},size={261,20},title=" Enter a shorter file name. It must be 25 characters or less "
987                                        TitleBox title0,fSize=12,fStyle=1
988                                        SetVariable setvar0,pos={21,52},size={300,15},title="New name",value= _STR:newStr
989                                        SetVariable setvar0,proc=ShorterNameSetVarProc,fsize=12
990                                        SetVariable setvar0 valueBackColor=(65535,49151,49151)
991                                        Button button0,pos={259,87},size={60,20},title="Done"
992                                        Button button0,proc=ShorterNameDoneButtonProc
993                               
994                                endif
995                               
996                                PauseForUser ShorterNameInput
997                               
998                                // this really should force a good name, but there could be errors that I'm not catching
999//                              Print newStr, strlen(newStr)
1000                                nameTooLong = 0
1001                        endif
1002               
1003                while (nameTooLong)
1004               
1005                return(newStr)
1006               
1007        endif
1008               
1009End
1010
1011
1012// for the ShortFileNameString() - PauseForUser to get a shorter file name
1013Function ShorterNameSetVarProc(sva) : SetVariableControl
1014        STRUCT WMSetVariableAction &sva
1015               
1016        switch( sva.eventCode )
1017                case 1: // mouse up
1018                case 2: // Enter key
1019                case 3: // Live update
1020                                String sv = sva.sval
1021                                if( strlen(sv) > 25 )
1022                                        sv= sv[0,24]
1023                                        SetVariable  $(sva.ctrlName),win=$(sva.win),value=_STR:sv
1024                                        SetVariable setvar0 valueBackColor=(65535,49151,49151)
1025                                        Beep
1026                                else
1027                                        SetVariable setvar0 valueBackColor=(65535,65535,65535)
1028                                endif
1029                                break
1030                endswitch
1031        return 0
1032End
1033
1034// for the ShortFileNameString() - PauseForUser to get a shorter file name
1035Function ShorterNameDoneButtonProc(ba) : ButtonControl
1036        STRUCT WMButtonAction &ba
1037       
1038        String win = ba.win
1039
1040        switch (ba.eventCode)
1041                case 2:
1042                        SVAR newStr = root:Packages:NIST:gShortNameStr
1043                        ControlInfo setvar0
1044                        newStr = S_value
1045                        DoWindow/K ShorterNameInput
1046                       
1047                        break
1048        endswitch
1049
1050        return 0
1051End
1052
1053
1054// a function common to many panels, so put the basic version here that simply
1055// returns null string if no functions are present. Calling procedures can
1056// add to the list to customize as needed.
1057// show the available models
1058// not the f*(cw,xw) point calculations
1059// not the *X(cw,xw) XOPS
1060//
1061// KIND:10 should show only user-defined curve fitting functions
1062// - not XOPs
1063// - not other user-defined functions
1064Function/S User_FunctionPopupList()
1065        String list,tmp
1066        list = FunctionList("*",";","KIND:10")          //get every user defined curve fit function
1067
1068        //now start to remove everything the user doesn't need to see...
1069
1070        tmp = FunctionList("*_proto",";","KIND:10")             //prototypes
1071        list = RemoveFromList(tmp, list  ,";")
1072       
1073        //prototypes that show up if GF is loaded
1074        list = RemoveFromList("GFFitFuncTemplate", list)
1075        list = RemoveFromList("GFFitAllAtOnceTemplate", list)
1076        list = RemoveFromList("NewGlblFitFunc", list)
1077        list = RemoveFromList("NewGlblFitFuncAllAtOnce", list)
1078        list = RemoveFromList("GlobalFitFunc", list)
1079        list = RemoveFromList("GlobalFitAllAtOnce", list)
1080        list = RemoveFromList("GFFitAAOStructTemplate", list)
1081        list = RemoveFromList("NewGF_SetXWaveInList", list)
1082        list = RemoveFromList("NewGlblFitFuncAAOStruct", list)
1083       
1084        // more to remove as a result of 2D/Gizmo
1085        list = RemoveFromList("A_WMRunLessThanDelta", list)
1086        list = RemoveFromList("WMFindNaNValue", list)
1087        list = RemoveFromList("WM_Make3DBarChartParametricWave", list)
1088        list = RemoveFromList("UpdateQxQy2Mat", list)
1089        list = RemoveFromList("MakeBSMask", list)
1090       
1091        // MOTOFIT/GenFit bits
1092        tmp = "GEN_allatoncefitfunc;GEN_fitfunc;GetCheckBoxesState;MOTO_GFFitAllAtOnceTemplate;MOTO_GFFitFuncTemplate;MOTO_NewGF_SetXWaveInList;MOTO_NewGlblFitFunc;MOTO_NewGlblFitFuncAllAtOnce;GeneticFit_UnSmearedModel;GeneticFit_SmearedModel;"
1093        list = RemoveFromList(tmp, list  ,";")
1094
1095        // SANS Reduction bits
1096        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;"
1097        list = RemoveFromList(tmp, list  ,";")
1098
1099        // USANS Reduction bits
1100        tmp = "DSM_Guinier_Fit;RemoveMaskedPoints;"
1101        list = RemoveFromList(tmp, list  ,";")
1102
1103        //more functions from analysis models (2008)
1104        tmp = "Barbell_Inner;Barbell_Outer;Barbell_integrand;BCC_Integrand;Integrand_BCC_Inner;Integrand_BCC_Outer;"
1105        list = RemoveFromList(tmp, list  ,";")
1106        tmp = "CapCyl;CapCyl_Inner;CapCyl_Outer;ConvLens;ConvLens_Inner;ConvLens_Outer;"
1107        list = RemoveFromList(tmp, list  ,";")
1108        tmp = "Dumb;Dumb_Inner;Dumb_Outer;FCC_Integrand;Integrand_FCC_Inner;Integrand_FCC_Outer;"
1109        list = RemoveFromList(tmp, list  ,";")
1110        tmp = "Integrand_SC_Inner;Integrand_SC_Outer;SC_Integrand;SphCyl;SphCyl_Inner;SphCyl_Outer;"
1111        list = RemoveFromList(tmp, list  ,";")
1112        tmp = "CSPP_Outer;CSPP_Inner;PP_Outer;PP_Inner;"
1113        list = RemoveFromList(tmp, list  ,";")
1114        tmp = "Guinier_Fit;"
1115        list = RemoveFromList(tmp, list  ,";")
1116
1117        tmp = FunctionList("f*",";","NPARAMS:2")                //point calculations
1118        list = RemoveFromList(tmp, list  ,";")
1119       
1120        tmp = FunctionList("fSmear*",";","NPARAMS:3")           //smeared dependency calculations
1121        list = RemoveFromList(tmp, list  ,";")
1122       
1123        // anything that might be included in Irena
1124        tmp = FunctionList("GEN_*",";","KIND:10")
1125        list = RemoveFromList(tmp, list  ,";")
1126        tmp = FunctionList("IN2G_*",";","KIND:10")
1127        list = RemoveFromList(tmp, list  ,";")
1128        tmp = FunctionList("IR1A_*",";","KIND:10")
1129        list = RemoveFromList(tmp, list  ,";")
1130        tmp = FunctionList("IR1B_*",";","KIND:10")
1131        list = RemoveFromList(tmp, list  ,";")
1132        tmp = FunctionList("IR1U_*",";","KIND:10")
1133        list = RemoveFromList(tmp, list  ,";")
1134        tmp = FunctionList("IR1V_*",";","KIND:10")
1135        list = RemoveFromList(tmp, list  ,";")
1136        tmp = FunctionList("IR1_*",";","KIND:10")
1137        list = RemoveFromList(tmp, list  ,";")
1138        tmp = FunctionList("IR2D_*",";","KIND:10")
1139        list = RemoveFromList(tmp, list  ,";")
1140
1141        tmp = FunctionList("IR2D_*",";","KIND:10")
1142        list = RemoveFromList(tmp, list  ,";")
1143        tmp = FunctionList("IR2H_*",";","KIND:10")
1144        list = RemoveFromList(tmp, list  ,";") 
1145        tmp = FunctionList("IR2L_*",";","KIND:10")
1146        list = RemoveFromList(tmp, list  ,";")
1147        tmp = FunctionList("IR2Pr_*",";","KIND:10")
1148        list = RemoveFromList(tmp, list  ,";")
1149        tmp = FunctionList("IR2R_*",";","KIND:10")
1150        list = RemoveFromList(tmp, list  ,";")
1151        tmp = FunctionList("IR2S_*",";","KIND:10")
1152        list = RemoveFromList(tmp, list  ,";")
1153        tmp = FunctionList("IR2_*",";","KIND:10")
1154        list = RemoveFromList(tmp, list  ,";")
1155        tmp = FunctionList("*LogLog",";","KIND:10")
1156        list = RemoveFromList(tmp, list  ,";")
1157       
1158        //functions included in Nika
1159        tmp = FunctionList("NI1*",";","KIND:10")
1160        list = RemoveFromList(tmp, list  ,";")
1161        tmp = FunctionList("TransAx_*",";","KIND:10")
1162        list = RemoveFromList(tmp, list  ,";")
1163        tmp = FunctionList("TransformAxis*",";","KIND:10")
1164        list = RemoveFromList(tmp, list  ,";")
1165        tmp = FunctionList("erfForNormal*",";","KIND:10")
1166        list = RemoveFromList(tmp, list  ,";")
1167
1168        // functions in Indra (USAXS)
1169        tmp = FunctionList("IN2Q_*",";","KIND:10")
1170        list = RemoveFromList(tmp, list  ,";")
1171        tmp = FunctionList("IN3_*",";","KIND:10")
1172        list = RemoveFromList(tmp, list  ,";")
1173       
1174//      tmp = FunctionList("*X",";","KIND:4")           //XOPs, but these shouldn't show up if KIND:10 is used initially
1175//      Print "X* = ",tmp
1176//      print " "
1177//      list = RemoveFromList(tmp, list  ,";")
1178       
1179        //non-fit functions that I can't seem to filter out
1180        list = RemoveFromList("BinaryHS_PSF11;BinaryHS_PSF12;BinaryHS_PSF22;EllipCyl_Integrand;PP_Inner;PP_Outer;Phi_EC;TaE_Inner;TaE_Outer;",list,";")
1181
1182        list = SortList(list)
1183        return(list)
1184End
1185
1186
1187///////////////////////////////////////////////////
1188// old SANSPreferences have been moved here to a common place and renamed to "NCNR Preferences" so that they
1189// are common to all of the packages (and will appear on all of the menus)
1190//
1191// globals moved to root:Packages:NIST: since this is generated by all packages.
1192//
1193///////////////////////////
1194// user preferences
1195//
1196// globals are created in initialize.ipf
1197//
1198// this panel allows for user modification
1199///////////////////////////
1200Proc Show_Preferences_Panel()
1201
1202        DoWindow/F Pref_Panel
1203        if(V_flag==0)
1204                Initialize_Preferences()
1205                Pref_Panel()
1206        Endif
1207//      Print "Preferences Panel stub"
1208End
1209
1210Proc Initialize_Preferences()
1211        // create the globals here if they are not already present
1212       
1213        // each package initialization should call this to repeat the initialization
1214        // without overwriting what was already set
1215       
1216        Variable val
1217       
1218        ///// items for SANS reduction
1219        val = NumVarOrDefault("root:Packages:NIST:gLogScalingAsDefault", 1 )
1220        Variable/G root:Packages:NIST:gLogScalingAsDefault=val
1221       
1222        val = NumVarOrDefault("root:Packages:NIST:gAllowDRK", 0 )
1223        Variable/G root:Packages:NIST:gAllowDRK=val                     //don't show DRK as default
1224       
1225        val = NumVarOrDefault("root:Packages:NIST:gDoTransCheck", 1 )
1226        Variable/G root:Packages:NIST:gDoTransCheck=val
1227       
1228        val = NumVarOrDefault("root:Packages:NIST:gBinWidth", 1 )
1229        Variable/G root:Packages:NIST:gBinWidth=val
1230       
1231        val = NumVarOrDefault("root:Packages:NIST:gNPhiSteps", 72 )
1232        Variable/G root:Packages:NIST:gNPhiSteps=val
1233       
1234        // flags to turn detector corrections on/off for testing (you should leave these ON)
1235        val = NumVarOrDefault("root:Packages:NIST:gDoDetectorEffCorr", 1 )
1236        Variable/G root:Packages:NIST:gDoDetectorEffCorr = 1
1237       
1238        val = NumVarOrDefault("root:Packages:NIST:gDoTransmissionCorr", 1 )
1239        Variable/G root:Packages:NIST:gDoTransmissionCorr = 1
1240       
1241       
1242        /// items for SANS Analysis
1243       
1244       
1245        /// items for USANS Reduction
1246       
1247       
1248        /// items for everyone
1249        val = NumVarOrDefault("root:Packages:NIST:gXML_Write", 1 )
1250        Variable/G root:Packages:NIST:gXML_Write = val
1251       
1252       
1253end
1254
1255Function LogScalePrefCheck(ctrlName,checked) : CheckBoxControl
1256        String ctrlName
1257        Variable checked
1258       
1259        NVAR gLog = root:Packages:NIST:gLogScalingAsDefault
1260        glog=checked
1261        //print "log pref checked = ",checked
1262End
1263
1264Function DRKProtocolPref(ctrlName,checked) : CheckBoxControl
1265        String ctrlName
1266        Variable checked
1267       
1268        NVAR gDRK = root:Packages:NIST:gAllowDRK
1269        gDRK = checked
1270        //Print "DRK preference = ",checked
1271End
1272
1273Function UnityTransPref(ctrlName,checked) : CheckBoxControl
1274        String ctrlName
1275        Variable checked
1276       
1277        NVAR gVal = root:Packages:NIST:gDoTransCheck
1278        gVal = checked
1279End
1280
1281Function XMLWritePref(ctrlName,checked) : CheckBoxControl
1282        String ctrlName
1283        Variable checked
1284       
1285        NVAR gVal = root:Packages:NIST:gXML_Write
1286        gVal = checked
1287End
1288
1289Function PrefDoneButtonProc(ctrlName) : ButtonControl
1290        String ctrlName
1291       
1292        DoWindow/K pref_panel
1293End
1294
1295Proc Pref_Panel()
1296        PauseUpdate; Silent 1           // building window...
1297        NewPanel /W=(646,208,1070,468)/K=2 as "NCNR Preference Panel"
1298        DoWindow/C pref_panel
1299        ModifyPanel cbRGB=(49694,61514,27679)
1300        SetDrawLayer UserBack
1301        ModifyPanel fixedSize=1
1302//////
1303//on main portion of panel, always visible
1304        Button PrefPanelButtA,pos={354,12},size={50,20},proc=PrefDoneButtonProc,title="Done"
1305
1306        TabControl PrefTab,pos={7,49},size={410,202},tabLabel(0)="General",proc=PrefTabProc
1307        TabControl PrefTab,tabLabel(1)="SANS",tabLabel(2)="USANS",tabLabel(3)="Analysis"
1308        TabControl PrefTab,value=0
1309        TabControl PrefTab labelBack=(49694,61514,27679)
1310       
1311//on tab(0) - General - initially visible
1312        CheckBox PrefChec_0a,pos={21,96},size={124,14},proc=XMLWritePref,title="Use canSAS XML Output"
1313        CheckBox PrefChec_0a,help={"Checking this will set the default output format to be canSAS XML rather than NIST 6 column"}
1314        CheckBox PrefChec_0a,value= root:Packages:NIST:gXML_Write
1315
1316//on tab(1) - SANS
1317        CheckBox PrefChec_1a,pos={21,100},size={171,14},proc=LogScalePrefCheck,title="Use Log scaling for 2D data display"
1318        CheckBox PrefChec_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."}
1319        CheckBox PrefChec_1a,value= root:Packages:NIST:gLogScalingAsDefault
1320        CheckBox PrefChec_1b,pos={21,120},size={163,14},proc=DRKProtocolPref,title="Allow DRK correction in protocols"
1321        CheckBox PrefChec_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."}
1322        CheckBox PrefChec_1b,value= root:Packages:NIST:gAllowDRK
1323        CheckBox PrefChec_1c,pos={21,140},size={137,14},proc=UnityTransPref,title="Check for Transmission = 1"
1324        CheckBox PrefChec_1c,help={"Checking this will check for SAM or EMP Trans = 1 during data correction"}
1325        CheckBox PrefChec_1c,value= root:Packages:NIST:gDoTransCheck
1326        SetVariable PrefSetV_1d,pos={21,170},size={200,15},title="Averaging Bin Width (pixels)"
1327        SetVariable PrefSetV_1d,limits={1,100,1},value= root:Packages:NIST:gBinWidth
1328        SetVariable PrefSetV_1e,pos={21,195},size={200,15},title="# Phi Steps (annular avg)"
1329        SetVariable PrefSetV_1e,limits={1,360,1},value= root:Packages:NIST:gNPhiSteps
1330        CheckBox PrefChec_1f title="Do Transmssion Correction?",size={140,14},value=1
1331        CheckBox PrefChec_1f pos={255,100},help={"TURN OFF ONLY FOR DEBUGGING. This corrects the data for angle dependent transmssion."}
1332        CheckBox PrefChec_1g title="Do Efficiency Correction?",size={140,14}
1333        CheckBox PrefChec_1g value=1,pos={255,120},help={"TURN OFF ONLY FOR DEBUGGING. This corrects the data for angle dependent detector efficiency."}
1334
1335
1336        CheckBox PrefChec_1a,disable=1
1337        CheckBox PrefChec_1b,disable=1
1338        CheckBox PrefChec_1c,disable=1
1339        SetVariable PrefSetV_1d,disable=1
1340        SetVariable PrefSetV_1e,disable=1
1341        CheckBox PrefChec_1f,disable=1
1342        CheckBox PrefChec_1g,disable=1
1343
1344//on tab(2) - USANS
1345        GroupBox PrefGrou_2a pos={21,100},size={1,1},title="nothing to set",fSize=12
1346
1347        GroupBox PrefGrou_2a,disable=1
1348
1349
1350//on tab(3) - Analysis
1351        GroupBox PrefGrou_3a pos={21,100},size={1,1},title="nothing to set",fSize=12
1352       
1353        GroupBox PrefGrou_3a,disable=1
1354
1355EndMacro
1356
1357// function to control the drawing of controls in the TabControl on the main panel
1358// Naming scheme for the controls MUST be strictly adhered to... else controls will
1359// appear in odd places...
1360// all controls are named PrefCtrl_NA where N is the tab number and A is the letter denoting
1361// the controls position on that particular tab.
1362// in this way, they will always be drawn correctly..
1363//
1364Function PrefTabProc(name,tab)
1365        String name
1366        Variable tab
1367       
1368//      Print "name,number",name,tab
1369        String ctrlList = ControlNameList("",";"),item="",nameStr=""
1370        Variable num = ItemsinList(ctrlList,";"),ii,onTab
1371        for(ii=0;ii<num;ii+=1)
1372                //items all start w/"PrefCtrl_"
1373                item=StringFromList(ii, ctrlList ,";")
1374                nameStr=item[0,10]
1375                strswitch(item[0,7])   
1376                        case "PrefChec":               
1377                                onTab = str2num(item[9])
1378                                CheckBox $item,disable=(tab!=onTab)
1379                                break                                           // exit from switch
1380                        case "PrefSetV":               
1381                                onTab = str2num(item[9])
1382                                SetVariable $item,disable=(tab!=onTab)
1383                                break
1384                        case "PrefGrou":               
1385                                onTab = str2num(item[9])
1386                                GroupBox $item,disable=(tab!=onTab)
1387                                break
1388                        default:
1389                                        //do nothing for no match
1390                endswitch
1391       
1392        endfor
1393End
1394
Note: See TracBrowser for help on using the repository browser.