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

Last change on this file since 625 was 625, checked in by ajj, 13 years ago

Modifications to NSORT to use data folder methods for dataset handling

  • XML input supported
  • No XML output yet, but preparation work done.
File size: 31.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=4.00
3#pragma IgorVersion=6.1
4
5// This is to be used with the Analysis packages ONLY
6// there are a number of utility procedures here for loading
7// data and generating valid lists of data files that are
8// directly copied from the Reduction package
9// -- There WILL be name conflicts if you mix the two...
10//
11// 16 DEC 05 SRK
12// prepended function names with A_ to tag them for the
13// "A"nalysis parckage, though nearly all are duplicate procedures
14// so there will be no overlap with the reduction package
15//
16//
17// these extra procedures are used by:
18// Linearized fits (duplicated in Reduction - will need to handle gently)
19// Invariant (no overlap with reduction)
20//
21// SRK MAR 2005
22
23// create a KW=string; of model=coef correspondence as the models are plotted, rather than
24// some other hard-wired solution
25Function AddModelToStrings(funcStr,coefStr,paramStr,suffix)
26        String funcStr,coefStr,paramStr,suffix
27       
28        if(exists("root:Packages:NIST:paramKWStr")==0)
29//              String/G root:Packages:NIST:coefKWStr=""
30                String/G root:Packages:NIST:paramKWStr=""
31//              String/G root:Packages:NIST:suffixKWStr=""
32        endif
33        SVAR coefKWStr = root:Packages:NIST:coefKWStr
34        SVAR paramKWStr = root:Packages:NIST:paramKWStr
35        SVAR suffixKWStr = root:Packages:NIST:suffixKWStr
36        coefKWStr += funcStr+"="+coefStr+";"
37        paramKWStr += funcStr+"="+paramStr+";"
38        suffixKWStr += funcStr+"="+suffix+";"
39end
40
41// loads a 1-d (ascii) datafile and plots the data
42// will overwrite existing data if user is OK with this
43// - multiple datasets can be automatically plotted on the same graph
44//
45//substantially easier to write this as a Proc rather than a function...
46
47//
48Proc A_LoadOneDData()
49        A_LoadOneDDataWithName("",1)            //will prompt for file and plot data
50End
51
52// load the data specified by fileStr (a full path:name)
53// and plots if doPlot==1
54// if fileStr is null, a dialog is presented to select the file
55//
56// 3 cases (if)
57// - 3 columns = QIS, no resolution
58// - 6 columns = QSIG, SANS w/resolution
59// - 5 columns = old-style desmeared USANS data (from VAX)
60//
61// This loader replaces the A_LoadOneDData() which was almost completely duplicated code
62//
63//new version, 19JUN07 that loads each data set into a separate data folder
64// the data folder is given the "base name" of the data file as it's loaded
65//
66
67Proc A_LoadOneDDataWithName(fileStr,doPlot)
68        String fileStr
69        Variable doPlot
70       
71        A_LoadOneDDataToName(fileStr,"",doPlot,0)
72
73End
74
75
76///Function that takes output name as well as input
77Proc A_LoadOneDDataToName(fileStr,outStr,doPlot,forceOverwrite)
78        String fileStr, outstr
79        Variable doPlot,forceOverwrite
80       
81        Variable rr,gg,bb,refnum,dQv
82        String w0,w1,w2,n0,n1,n2
83        String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
84        SetDataFolder root:             //build sub-folders for each data set under root
85
86// I can't see that we need to find dQv here.   
87//      if (exists("root:Packages:NIST:USANS:Globals:MainPanel:gDQv"))
88//              //Running from USANS reduction
89//              Variable dQv = root:Packages:NIST:USANS:Globals:MainPanel:gDQv
90//      endif
91//      if(exists("root:Packages:NIST:USANS_dQv"))
92//              //Running from SANS Analysis
93//              Variable dQv = root:Packages:NIST:USANS_dQv
94//      else
95//              //running from somewhere else, probably SANS Reduction, which uses common loaders
96//              Variable/G root:Packages:NIST:USANS_dQv = 0.117
97//      endif
98               
99        // if no fileStr passed in, display dialog now
100        if (cmpStr(fileStr,"") == 0)
101                fileStr = DoOpenFileDialog("Select a data file to load")
102                if (cmpstr(fileStr,"") == 0)
103                        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                                        Legend
414                                endif
415                        else
416                        // graph window was not target, make new one
417                                Display $w1 vs $w0
418                                ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1
419                                ModifyGraph grid=1,mirror=2,standoff=0
420                                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
421                                ModifyGraph tickUnit(left)=1
422                                Legend
423                        endif
424                endif
425                       
426                //go back to the root folder and clean up before leaving
427                SetDataFolder root:
428                KillWaves/Z $n0,$n1,$n2,$n3,$n4,$n5
429               
430        endif
431End
432
433
434//procedure for loading NSE data in the format (4-columns)
435// qvals - time - I(q,t) - dI(q,t)
436//
437//
438// this does NOT load the data into separate folders...
439//
440Proc A_LoadNSEData()
441        A_LoadNSEDataWithName("",1)
442End
443
444Proc A_LoadNSEDataWithName(fileStr,doPlot)
445
446        //Load the waves, using default waveX names
447        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
448        LoadWave/G/D/A  fileStr
449        String filename = S_fileName
450       
451        String w0,w1,w2,n0,n1,n2,wt,w3,n3
452        Variable rr,gg,bb
453       
454        // put the names of the three loaded waves into local names
455        n0 = StringFromList(0, S_waveNames ,";" )
456        n1 = StringFromList(1, S_waveNames ,";" )
457        n2 = StringFromList(2, S_waveNames ,";" )
458        n3 = StringFromList(3, S_waveNames ,";" )
459       
460       
461        //remove the semicolon AND period from files from the VAX
462        w0 = CleanupName(("qvals_"+S_fileName),0)
463        w1 = CleanupName(("time_"+S_fileName),0)
464        w2 = CleanupName(("iqt_"+S_fileName),0)
465        w3 = CleanupName(("iqterr_"+S_fileName),0)
466       
467        if(exists(w0) !=0)
468                DoAlert 0,"This file has already been loaded. Use Append to Graph..."
469                KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
470                return
471        endif
472       
473        // Rename to give nice names
474        Rename $n0, $w0
475        Rename $n1, $w1
476        Rename $n2, $w2
477        Rename $n3, $w3
478               
479        if(doPlot)
480                // assign colors randomly
481                rr = abs(trunc(enoise(65535)))
482                gg = abs(trunc(enoise(65535)))
483                bb = abs(trunc(enoise(65535)))
484               
485                // if target window is a graph, and user wants to append, do so
486                if(WinType("") == 1)
487                        DoAlert 1,"Do you want to append this data to the current graph?"
488                        if(V_Flag == 1)
489                                AppendToGraph $w2 vs $w1
490                                ModifyGraph mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2) =(rr,gg,bb),grid=1,mirror=2,tickUnit=1
491                                ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
492                        else
493                        //new graph
494                                Display $w2 vs $w1
495                                ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
496                                ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
497                                Legend
498                        endif
499                else
500                // graph window was not target, make new one
501                        Display $w2 vs $w1
502                        ModifyGraph standoff=0,mode($w2)=3,marker($w2)=29,msize($w2)=2,rgb($w2)=(rr,gg,bb),grid=1,mirror=2,tickUnit=1
503                        ErrorBars/T=0 $w2 Y,wave=($w3,$w3)
504                        Legend
505                endif
506        endif //doPlot         
507
508End
509
510//procedure for loading desmeared USANS data in the format (5-columns)
511// qvals - I(q) - sig I - Ism(q) - fitted Ism(q)
512//no weighting wave is created (not needed in IGOR 4)
513//
514// not really ever used...
515//
516Proc A_LoadUSANSData()
517
518        //Load the waves, using default waveX names
519        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
520        LoadWave/G/D/A
521   String filename = S_fileName
522       
523        String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
524        Variable rr,gg,bb
525       
526        // put the names of the three loaded waves into local names
527        n0 = StringFromList(0, S_waveNames ,";" )
528        n1 = StringFromList(1, S_waveNames ,";" )
529        n2 = StringFromList(2, S_waveNames ,";" )
530        n3 = StringFromList(3, S_waveNames ,";" )
531        n4 = StringFromList(4, S_waveNames ,";" )
532       
533       
534        //remove the semicolon AND period from files from the VAX
535        w0 = CleanupName((S_fileName+"_q"),0)
536        w1 = CleanupName((S_fileName+"_i"),0)
537        w2 = CleanupName((S_fileName+"_s"),0)
538        w3 = CleanupName((S_fileName+"_ism"),0)
539        w4 = CleanupName((S_fileName+"_fit_ism"),0)
540       
541        if(exists(w0) !=0)              //the wave already exists
542                DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
543                if(V_flag==2)   //user selected No
544                        KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
545                        if(DataFolderExists("root:Packages:NIST"))
546                                String/G root:Packages:NIST:gLastFileName = filename
547                        endif           //set the last file loaded to the one NOT loaded
548                        return          //quits the macro
549                endif
550        endif
551       
552        ////overwrite the existing data, if it exists
553        Duplicate/O $n0, $w0
554        Duplicate/O $n1, $w1
555        Duplicate/O $n2, $w2
556        Duplicate/O $n3, $w3
557        Duplicate/O $n4, $w4
558        KillWaves $n0,$n1,$n2,$n3,$n4
559       
560        if(DataFolderExists("root:Packages:NIST"))
561                String/G root:Packages:NIST:gLastFileName = filename
562        endif
563               
564        // assign colors randomly
565        rr = abs(trunc(enoise(65535)))
566        gg = abs(trunc(enoise(65535)))
567        bb = abs(trunc(enoise(65535)))
568       
569                // if target window is a graph, and user wants to append, do so
570        if(WinType("") == 1)
571                DoAlert 1,"Do you want to append this data to the current graph?"
572                if(V_Flag == 1)
573                        AppendToGraph $w1 vs $w0
574                        ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
575                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
576                else
577                //new graph
578                        Display $w1 vs $w0
579                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
580                        ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
581                        Legend
582                endif
583        else
584        // graph window was not target, make new one
585                Display $w1 vs $w0
586                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
587                ErrorBars/T=0 $w1 Y,wave=($w2,$w2)
588                Legend
589        endif
590               
591End
592
593
594//// Extra "Utility Procedures"
595// to pick path, get a list of data files, and make sure that a valid filename
596// is passed to LoadOneDDataWithName()
597//
598
599//prompts user to choose the local folder that contains the SANS Data
600//only one folder can be used, and its path is catPathName (and is a NAME, not a string)
601//this will overwrite the path selection
602//returns 1 if no path selected as error condition
603Function A_PickPath()
604       
605        //set the global string to the selected pathname
606        NewPath/O/M="pick the SANS data folder" catPathName
607        PathInfo/S catPathName
608        String dum = S_path
609        String alertStr = ""
610        alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"
611        //alertStr += "  Please see the manual for details."
612        if (V_flag == 0)
613                //path does not exist - no folder selected
614                String/G root:Packages:NIST:gCatPathStr = "no folder selected"
615                return(1)
616        else
617                //set the global to the path (as a string)
618                // need 4 \ since it is the escape character
619                if(cmpstr("\\\\",dum[0,1])==0)  //Windoze user going through network neighborhood
620                        DoAlert 0,alertStr
621                        KillPath catPathName
622                        return(1)
623                endif
624                String/G root:Packages:NIST:gCatPathStr = dum
625                return(0)               //no error
626        endif
627End
628
629//Function attempts to find valid filename from partial name that has been stripped of
630//the VAX version number. The partial name is tried first
631//*** the PATH is hard-wired to catPathName (which is assumed to exist)
632//version numers up to ;10 are tried
633//only the "name;vers" is returned. the path is not prepended, hence the return string
634//is not a complete specification of the file
635//
636// added 11/99 - uppercase and lowercase versions of the file are tried, if necessary
637// since from marquee, the filename field (textread[0]) must be used, and can be a mix of
638// upper/lowercase letters, while the filename on the server (should) be all caps
639// now makes repeated calls to ValidFileString()
640//
641Function/S A_FindValidFilename(partialName)
642        String PartialName
643       
644        String retStr=""
645       
646        //try name with no changes - to allow for ABS files that have spaces in the names 12APR04
647        retStr = A_ValidFileString(partialName)
648        if(cmpstr(retStr,"") !=0)
649                //non-null return
650                return(retStr)
651        Endif
652       
653        //if the partial name is derived from the file header, there can be spaces at the beginning
654        //or in the middle of the filename - depending on the prefix and initials used
655        //
656        //remove any leading spaces from the name before starting
657        partialName = A_RemoveAllSpaces(partialName)
658       
659        //try name with no spaces
660        retStr = A_ValidFileString(partialName)
661        if(cmpstr(retStr,"") !=0)
662                //non-null return
663                return(retStr)
664        Endif
665       
666        //try all UPPERCASE
667        partialName = UpperStr(partialName)
668        retStr = A_ValidFileString(partialName)
669        if(cmpstr(retStr,"") !=0)
670                //non-null return
671                return(retStr)
672        Endif
673       
674        //try all lowercase (ret null if failure)
675        partialName = LowerStr(partialName)
676        retStr = A_ValidFileString(partialName)
677        if(cmpstr(retStr,"") !=0)
678                //non-null return
679                return(retStr)
680        else
681                return(retStr)
682        Endif
683End
684
685//function to test a binary file to see if it is a RAW binary SANS file
686//first checks the total bytes in the file (which for raw data is 33316 bytes)
687//**note that the "DIV" file will also show up as a raw file by the run field
688//should be listed in CAT/SHORT and in patch windows
689//
690//Function then checks the file fname (full path:file) for "RAW" run.type field
691//if not found, the data is not raw data and zero is returned
692Function A_CheckIfRawData(fname)
693        String fname
694       
695        Variable refnum,totalBytes
696        String testStr=""
697       
698        Open/R/T="????TEXT" refNum as fname
699        //get the total number of bytes in the file, to avoid moving past EOF
700        FStatus refNum
701        totalBytes = V_logEOF
702        //Print totalBytes
703        if(totalBytes!=33316)
704                //can't possibly be a raw data file
705                Close refnum
706                return(0)               //not a raw SANS file
707        Endif
708        FSetPos refNum,75
709        FReadLine/N=3 refNum,testStr
710        Close refNum
711       
712        if(cmpstr(testStr,"RAW")==0)
713                //true, is raw data file
714                Return(1)
715        else
716                //some other file
717                Return(0)
718        Endif
719End
720
721//list (input) is a list, typically returned from IndexedFile()
722//which is semicolon-delimited, and may contain filesnames from the VAX
723//that contain version numbers, where the version number appears as a separate list item
724//(and also as a non-existent file)
725//these numbers must be purged from the list, especially for display in a popup
726//or list processing of filenames
727//the function returns the list, cleaned of version numbers (up to 11)
728//raw data files will typically never have a version number other than 1.
729Function/S A_RemoveVersNumsFromList(list)
730        String list
731       
732        //get rid of version numbers first (up to 11)
733        Variable ii,num
734        String item
735        num = ItemsInList(list,";")
736        ii=1
737        do
738                item = num2str(ii)
739                list = RemoveFromList(item, list ,";" )
740                ii+=1
741        while(ii<12)
742       
743        return (list)
744End
745
746//Function attempts to find valid filename from partial name that has been stripped of
747//the VAX version number. The partial name is tried first
748//*** the PATH is hard-wired to catPathName (which is assumed to exist)
749//version numers up to ;10 are tried
750//only the "name;vers" is returned. the path is not prepended, hence the return string
751//is not a complete specification of the file
752//
753Function/S A_ValidFileString(partialName)
754        String partialName
755       
756        String tempName = "",msg=""
757        Variable ii,refnum
758       
759        ii=0
760        do
761                if(ii==0)
762                        //first pass, try the partialName
763                        tempName = partialName
764                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag)
765                        if(V_flag == 0)
766                                //file exists
767                                Close refnum            //YES needed,
768                                break
769                        endif
770                else
771                        tempName = partialName + ";" + num2str(ii)
772                        Open/Z/R/T="????TEXT"/P=catPathName refnum tempName
773                        if(V_flag == 0)
774                                //file exists
775                                Close refnum
776                                break
777                        endif
778                Endif
779                ii+=1
780                //print "ii=",ii
781        while(ii<11)
782        //go get the selected bits of information, using tempName, which exists
783        if(ii>=11)
784                //msg = partialName + " not found. is version number > 11?"
785                //DoAlert 0, msg
786                //PathInfo catPathName
787                //Print S_Path
788                Return ("")             //use null string as error condition
789        Endif
790       
791        Return (tempName)
792End
793
794//function to remove all spaces from names when searching for filenames
795//the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)
796//but the text field in the header WILL, if less than 3 characters were used for the
797//user's initials, and can have leading spaces if prefix was less than 5 characters
798//
799//returns a string identical to the original string, except with the interior spaces removed
800//
801Function/S A_RemoveAllSpaces(str)
802        String str
803       
804        String tempstr = str
805        Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename
806        ii=0
807        do
808                len = strlen(tempStr)
809                spc = strsearch(tempStr," ",0)          //is the last character a space?
810                if (spc == -1)
811                        break           //no more spaces found, get out
812                endif
813                str = tempstr
814                tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string
815        While(1)        //should never be more than 2 or 3
816       
817        If(strlen(tempStr) < 1)
818                tempStr = ""            //be sure to return a null string if problem found
819        Endif
820       
821        //Print strlen(tempstr)
822       
823        Return(tempStr)
824               
825End
826
827//AJJ Oct 2008
828//Moved from GaussUtils - makes more sense to have it here
829
830// utility used in the "PlotSmeared...() macros to get a list of data folders
831//
832//1:    Waves.
833//2:    Numeric variables.
834//3:    String variables.
835//4:    Data folders.
836Function/S GetAList(type)
837        Variable type
838       
839        SetDataFolder root:
840       
841        String objName,str=""
842        Variable index = 0
843        do
844                objName = GetIndexedObjName(":", type, index)
845                if (strlen(objName) == 0)
846                        break
847                endif
848                //Print objName
849                str += objName + ";"
850                index += 1
851        while(1)
852       
853        // remove myGlobals, Packages, etc. from the folder list
854        if(type==4)
855                str = RemoveFromList("myGlobals", str , ";" )
856                str = RemoveFromList("Packages", str, ";")
857                str = RemoveFromList("AutoFit", str, ";")
858                str = RemoveFromList("TISANE", str, ";")
859                str = RemoveFromList("HayPenMSA", str, ";")
860        endif
861       
862        return(str)
863End
864
865
866//returns the path to the file, or null if cancel
867Function/S DoOpenFileDialog(msg)
868        String msg
869       
870        Variable refNum
871//      String message = "Select a file"
872        String outputPath
873       
874        Open/D/R/T="????"/M=msg refNum
875        outputPath = S_fileName
876       
877        return outputPath
878End
879
880// returns the path to the file, or null if the user cancelled
881// fancy use of optional parameters
882//
883// enforce short file names (26 characters)
884Function/S DoSaveFileDialog(msg,[fname,suffix])
885        String msg,fname,suffix
886        Variable refNum
887//      String message = "Save the file as"
888
889        if(ParamIsDefault(fname))
890//              Print "fname not supplied"
891                fname = ""
892        endif
893        if(ParamIsDefault(suffix))
894//              Print "suffix not supplied"
895                suffix = ""
896        endif
897       
898        String outputPath,tmpName,testStr
899        Variable badLength=0,maxLength=26,l1,l2
900       
901       
902        tmpName = fname + suffix
903       
904        do
905                badLength=0
906                Open/D/M=msg/T="????" refNum as tmpName
907                outputPath = S_fileName
908               
909                testStr = ParseFilePath(0, outputPath, ":", 1, 0)               //just the filename
910                if(strlen(testStr)==0)
911                        break           //cancel, allow exit
912                endif
913                if(strlen(testStr) > maxLength)
914                        badlength = 1
915                        DoAlert 2,"File name is too long. Is\r"+testStr[0,25]+"\rOK?"
916                        if(V_flag==3)
917                                outputPath = ""
918                                break
919                        endif
920                        if(V_flag==1)                   //my suggested name is OK, so trim the output
921                                badlength=0
922                                l1 = strlen(testStr)            //too long length
923                                l1 = l1-maxLength               //number to trim
924                                //Print outputPath
925                                l2=strlen(outputPath)
926                                outputPath = outputPath[0,l2-1-l1]
927                                //Print "modified  ",outputPath
928                        endif
929                        //if(V_flag==2)  do nothing, let it go around again
930                endif
931               
932        while(badLength)
933       
934        return outputPath
935End
936
937// a function common to many panels, so put the basic version here that simply
938// returns null string if no functions are present. Calling procedures can
939// add to the list to customize as needed.
940// show the available models
941// not the f*(cw,xw) point calculations
942// not the *X(cw,xw) XOPS
943//
944// KIND:10 should show only user-defined curve fitting functions
945// - not XOPs
946// - not other user-defined functions
947Function/S User_FunctionPopupList()
948        String list,tmp
949        list = FunctionList("*",";","KIND:10")          //get every user defined curve fit function
950
951        //now start to remove everything the user doesn't need to see...
952
953        tmp = FunctionList("*_proto",";","KIND:10")             //prototypes
954        list = RemoveFromList(tmp, list  ,";")
955       
956        //prototypes that show up if GF is loaded
957        list = RemoveFromList("GFFitFuncTemplate", list)
958        list = RemoveFromList("GFFitAllAtOnceTemplate", list)
959        list = RemoveFromList("NewGlblFitFunc", list)
960        list = RemoveFromList("NewGlblFitFuncAllAtOnce", list)
961        list = RemoveFromList("GlobalFitFunc", list)
962        list = RemoveFromList("GlobalFitAllAtOnce", list)
963        list = RemoveFromList("GFFitAAOStructTemplate", list)
964        list = RemoveFromList("NewGF_SetXWaveInList", list)
965        list = RemoveFromList("NewGlblFitFuncAAOStruct", list)
966       
967        // more to remove as a result of 2D/Gizmo
968        list = RemoveFromList("A_WMRunLessThanDelta", list)
969        list = RemoveFromList("WMFindNaNValue", list)
970        list = RemoveFromList("WM_Make3DBarChartParametricWave", list)
971        list = RemoveFromList("UpdateQxQy2Mat", list)
972        list = RemoveFromList("MakeBSMask", list)
973       
974        // MOTOFIT/GenFit bits
975        tmp = "GEN_allatoncefitfunc;GEN_fitfunc;GetCheckBoxesState;MOTO_GFFitAllAtOnceTemplate;MOTO_GFFitFuncTemplate;MOTO_NewGF_SetXWaveInList;MOTO_NewGlblFitFunc;MOTO_NewGlblFitFuncAllAtOnce;GeneticFit_UnSmearedModel;GeneticFit_SmearedModel;"
976        list = RemoveFromList(tmp, list  ,";")
977
978        // SANS Reduction bits
979        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;"
980        list = RemoveFromList(tmp, list  ,";")
981
982        // USANS Reduction bits
983        tmp = "DSM_Guinier_Fit;RemoveMaskedPoints;"
984        list = RemoveFromList(tmp, list  ,";")
985
986        //more functions from analysis models (2008)
987        tmp = "Barbell_Inner;Barbell_Outer;Barbell_integrand;BCC_Integrand;Integrand_BCC_Inner;Integrand_BCC_Outer;"
988        list = RemoveFromList(tmp, list  ,";")
989        tmp = "CapCyl;CapCyl_Inner;CapCyl_Outer;ConvLens;ConvLens_Inner;ConvLens_Outer;"
990        list = RemoveFromList(tmp, list  ,";")
991        tmp = "Dumb;Dumb_Inner;Dumb_Outer;FCC_Integrand;Integrand_FCC_Inner;Integrand_FCC_Outer;"
992        list = RemoveFromList(tmp, list  ,";")
993        tmp = "Integrand_SC_Inner;Integrand_SC_Outer;SC_Integrand;SphCyl;SphCyl_Inner;SphCyl_Outer;"
994        list = RemoveFromList(tmp, list  ,";")
995        tmp = "CSPP_Outer;CSPP_Inner;PP_Outer;PP_Inner;"
996        list = RemoveFromList(tmp, list  ,";")
997
998        tmp = FunctionList("f*",";","NPARAMS:2")                //point calculations
999        list = RemoveFromList(tmp, list  ,";")
1000       
1001        tmp = FunctionList("fSmear*",";","NPARAMS:3")           //smeared dependency calculations
1002        list = RemoveFromList(tmp, list  ,";")
1003       
1004//      tmp = FunctionList("*X",";","KIND:4")           //XOPs, but these shouldn't show up if KIND:10 is used initially
1005//      Print "X* = ",tmp
1006//      print " "
1007//      list = RemoveFromList(tmp, list  ,";")
1008       
1009        //non-fit functions that I can't seem to filter out
1010        list = RemoveFromList("BinaryHS_PSF11;BinaryHS_PSF12;BinaryHS_PSF22;EllipCyl_Integrand;PP_Inner;PP_Outer;Phi_EC;TaE_Inner;TaE_Outer;",list,";")
1011
1012        list = SortList(list)
1013        return(list)
1014End
Note: See TracBrowser for help on using the repository browser.