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

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

Changes to the installer:

Templates are obsolete now. Packages are all loaded from the macros menu. Templates have been deleted from SVN.

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