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

Last change on this file since 838 was 838, checked in by srkline, 10 years ago

adding two new help files for real space modeling and description of the 2D resolution function

cleaning up the FFT routines for addition as a beta operation

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