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

Last change on this file since 480 was 480, checked in by srkline, 14 years ago

minor bug fixes:
Schematic.ipf: fixed duplicate error, was incorrect folder path
Invariant.ipf: "Can't find dQv" error, now looks in proper data folder

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