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

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

A variety of fixes to make some procedures compatible with the new Packages:NIST subfolder structure

Also, some additional changes to include the proper procedures when loading overall packages

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