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

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

bug fixes related to XML changes in the file loader in PlotUtilsMacro?

bug fix in Wrapper, in the error checking of coefficient wave names

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