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

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

Fixed the USANS sample "cor" data set g50_d2o.cor to be a proper 6-column file. In the previous distribution package it was a 3-column file from way back when on the VAX...

PlotUtilsMacro? updated to display all file types on an open file dialog, rather than just ".txt"

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