source: sans/Analysis/trunk/Put in User Procedures/SANS_Models_v3.00/PlotUtilsMacro.ipf @ 56

Last change on this file since 56 was 42, checked in by srkline, 16 years ago

initial checkin of Analysis v.3.00 files

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