source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/PlotUtils.ipf @ 83

Last change on this file since 83 was 78, checked in by srkline, 16 years ago

In PlotUtils? (plot manager) now checks for the existence of a graph to append the data rather than generate an error.

File size: 21.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
4
5//**************************
6// Vers. 1.2 092101
7//
8//must be using IGOR Pro v. 3.14 or higher for StringFromList()
9//loads 3-column or 6-column data into the experiment with appropriate extensions
10// added to the cleaned-up filenames
11//
12// 2 versions - one to always present dialog, and a second if the filename
13// is already known
14//
15//*****************************
16
17
18// loads a 1-d (ascii) datafile and plots the data
19// will not overwrite existing data (old data must be deleted first)
20// - multiple datasets can be automatically plotted on the same graph
21//
22//substantially easier to write this as a Proc rather than a function...
23//
24Proc LoadOneDData()
25
26        //Load the waves, using default waveX names
27        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
28        LoadWave/G/D/A
29        String filename = S_fileName
30         
31        if(V_flag==3)
32                String w0,w1,w2,n0,n1,n2,wt
33                Variable rr,gg,bb
34               
35                // put the names of the three loaded waves into local names
36                n0 = StringFromList(0, S_waveNames ,";" )
37                n1 = StringFromList(1, S_waveNames ,";" )
38                n2 = StringFromList(2, S_waveNames ,";" )
39               
40                //remove the semicolon AND period from files from the VAX
41                w0 = CleanupName((S_fileName + "_q"),0)
42                w1 = CleanupName((S_fileName + "_i"),0)
43                w2 = CleanupName((S_fileName + "_s"),0)
44                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
45               
46                if(exists(w0) !=0)
47                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
48                        if(V_flag==2)   //user selected No
49                                KillWaves/Z $n0,$n1,$n2         // kill the default waveX that were loaded
50                                String/G root:myGlobals:gLastFileName = filename                //set the last file loaded to the one NOT loaded
51                                return          //quits the macro
52                        endif
53                endif
54               
55                ////overwrite the existing data, if it exists
56                Duplicate/O $n0, $w0
57                Duplicate/O $n1, $w1
58                Duplicate/O $n2, $w2
59                KillWaves $n0,$n1,$n2
60               
61                String/G root:myGlobals:gLastFileName = filename
62                Duplicate/o $w2 $wt
63                $wt = 1/$w2             //assign the weighting wave
64               
65                // set data units for the waves
66                String angst = root:myGlobals:gAngstStr
67                SetScale d,0,0,"1/"+angst,$w0
68                SetScale d,0,0,"1/cm",$w1
69               
70                // assign colors randomly
71                rr = abs(trunc(enoise(65535)))
72                gg = abs(trunc(enoise(65535)))
73                bb = abs(trunc(enoise(65535)))
74               
75                // if target window is a graph, and user wants to append, do so
76            DoWindow/B Plot_Manager
77                if(WinType("") == 1)
78                        DoAlert 1,"Do you want to append this data to the current graph?"
79                        if(V_Flag == 1)
80                                AppendToGraph $w1 vs $w0
81                                ModifyGraph mode=3,marker=19,msize=2,rgb ($w1) =(rr,gg,bb)
82                                ErrorBars $w1 Y,wave=($w2,$w2)
83                        else
84                        //new graph
85                                Display $w1 vs $w0
86                                ModifyGraph log=1,mode=3,marker=19,msize=2,rgb=(rr,gg,bb)
87                                ModifyGraph grid=1,mirror=2,standoff=0
88                                ErrorBars $w1 Y,wave=($w2,$w2)
89                                Legend
90                        endif
91                else
92                // graph window was not target, make new one
93                        Display $w1 vs $w0
94                        ModifyGraph log=1,mode=3,marker=19,msize=2,rgb=(rr,gg,bb)
95                        ModifyGraph grid=1,mirror=2,standoff=0
96                        ErrorBars $w1 Y,wave=($w2,$w2)
97                        Legend
98                endif
99                       
100                // Annotate graph
101                //Textbox/A=LT "XY data loaded from " + S_fileName
102               DoWindow/F Plot_Manager
103                return
104        endif
105       
106        if(V_flag == 6)
107                String w0,w1,w2,n0,n1,n2,wt
108                String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
109                Variable rr,gg,bb
110               
111               
112                // put the names of the three loaded waves into local names
113                n0 = StringFromList(0, S_waveNames ,";" )
114                n1 = StringFromList(1, S_waveNames ,";" )
115                n2 = StringFromList(2, S_waveNames ,";" )
116                n3 = StringFromList(3, S_waveNames ,";" )
117                n4 = StringFromList(4, S_waveNames ,";" )
118                n5 = StringFromList(5, S_waveNames ,";" )
119               
120                //remove the semicolon AND period from files from the VAX
121                w0 = CleanupName((S_fileName + "_q"),0)
122                w1 = CleanupName((S_fileName + "_i"),0)
123                w2 = CleanupName((S_fileName + "_s"),0)
124                w3 = CleanupName((S_fileName + "sq"),0)
125                w4 = CleanupName((S_fileName + "qb"),0)
126                w5 = CleanupName((S_fileName + "fs"),0)
127                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
128               
129                if(exists(w0) !=0)              //the wave already exists
130                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
131                        if(V_flag==2)   //user selected No
132                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
133                                String/G root:myGlobals:gLastFileName = filename                //set the last file loaded to the one NOT loaded
134                                return          //quits the macro
135                        endif
136                endif
137
138////overwrite the existing data, if it exists
139                Duplicate/O $n0, $w0
140                Duplicate/O $n1, $w1
141                Duplicate/O $n2, $w2
142                Duplicate/O $n3, $w3
143                Duplicate/O $n4, $w4
144                Duplicate/O $n5, $w5
145                KillWaves $n0,$n1,$n2,$n3,$n4,$n5
146               
147                Duplicate/o $w2 $wt
148                $wt = 1/$w2             //assign the weighting wave
149               
150                // copy waves to global strings for use in the smearing calculation
151                String/G root:myGlobals:gLastFileName = filename
152                String/G gQVals = w0
153                String/G gSig_Q = w3
154                String/G gQ_bar = w4
155                String/G gShadow = w5
156               
157                // set data units for the waves
158                String angst = root:myGlobals:gAngstStr
159                SetScale d,0,0,"1/"+angst,$w0
160                SetScale d,0,0,"1/cm",$w1
161               
162                // assign colors randomly
163                rr = abs(trunc(enoise(65535)))
164                gg = abs(trunc(enoise(65535)))
165                bb = abs(trunc(enoise(65535)))
166       
167                // if target window is a graph, and user wants to append, do so
168                DoWindow/B Plot_Manager
169                if(WinType("") == 1)
170                        DoAlert 1,"Do you want to append this data to the current graph?"
171                        if(V_Flag == 1)
172                                AppendToGraph $w1 vs $w0
173                                ModifyGraph mode=3,marker=19,msize=2,rgb ($w1) =(rr,gg,bb)
174                                ErrorBars $w1 Y,wave=($w2,$w2)
175                        else
176                        //new graph
177                                Display $w1 vs $w0
178                                ModifyGraph log=1,mode=3,marker=19,msize=2,rgb=(rr,gg,bb)
179                                ModifyGraph grid=1,mirror=2,standoff=0
180                                ErrorBars $w1 Y,wave=($w2,$w2)
181                                Legend
182                        endif
183                else
184                // graph window was not target, make new one
185                        Display $w1 vs $w0
186                        ModifyGraph log=1,mode=3,marker=19,msize=2,rgb=(rr,gg,bb)
187                        ModifyGraph grid=1,mirror=2,standoff=0
188                        ErrorBars $w1 Y,wave=($w2,$w2)
189                        Legend
190                endif
191                       
192                // Annotate graph
193                //Textbox/A=LT "XY data loaded from " + S_fileName
194               DoWindow/F Plot_Manager
195                return
196        endif
197       
198        if(V_flag==5)                   //old USANS desmeared data
199                String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
200                Variable rr,gg,bb
201               
202                // put the names of the three loaded waves into local names
203                n0 = StringFromList(0, S_waveNames ,";" )
204                n1 = StringFromList(1, S_waveNames ,";" )
205                n2 = StringFromList(2, S_waveNames ,";" )
206                n3 = StringFromList(3, S_waveNames ,";" )
207                n4 = StringFromList(4, S_waveNames ,";" )
208               
209               
210                //remove the semicolon AND period from files from the VAX
211                w0 = CleanupName((S_fileName+"_q"),0)
212                w1 = CleanupName((S_fileName+"_i"),0)
213                w2 = CleanupName((S_fileName+"_s"),0)
214                w3 = CleanupName((S_fileName+"_ism"),0)
215                w4 = CleanupName((S_fileName+"_fit_ism"),0)
216               
217                if(exists(w0) !=0)              //the wave already exists
218                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
219                        if(V_flag==2)   //user selected No
220                                KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
221                                String/G root:myGlobals:gLastFileName = filename                //set the last file loaded to the one NOT loaded
222                                return          //quits the macro
223                        endif
224                endif
225               
226////overwrite the existing data, if it exists
227                Duplicate/O $n0, $w0
228                Duplicate/O $n1, $w1
229                Duplicate/O $n2, $w2
230                Duplicate/O $n3, $w3
231                Duplicate/O $n4, $w4
232                KillWaves $n0,$n1,$n2,$n3,$n4
233               
234                String/G root:myGlobals:gLastFileName = filename
235               
236                // assign colors randomly
237                rr = abs(trunc(enoise(65535)))
238                gg = abs(trunc(enoise(65535)))
239                bb = abs(trunc(enoise(65535)))
240               
241                        // if target window is a graph, and user wants to append, do so
242                if(WinType("") == 1)
243                        DoAlert 1,"Do you want to append this data to the current graph?"
244                        if(V_Flag == 1)
245                                AppendToGraph $w1 vs $w0
246                                ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
247                                ErrorBars $w1 Y,wave=($w2,$w2)
248                        else
249                        //new graph
250                                Display $w1 vs $w0
251                                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
252                                ErrorBars $w1 Y,wave=($w2,$w2)
253                                Legend
254                        endif
255                else
256                // graph window was not target, make new one
257                        Display $w1 vs $w0
258                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
259                        ErrorBars $w1 Y,wave=($w2,$w2)
260                        Legend
261                endif
262       
263                return
264        endif
265       
266End
267
268//load the data specified by fileStr (a full path:name)
269// Does not graph the data - just loads it
270//
271Proc LoadOneDDataWithName(fileStr)
272        String fileStr
273        //Load the waves, using default waveX names
274        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
275        LoadWave/G/D/A/Q fileStr
276        String fileName = S_fileName
277
278        if(V_flag==3)
279                String w0,w1,w2,n0,n1,n2,wt
280               
281                // put the names of the three loaded waves into local names
282                n0 = StringFromList(0, S_waveNames ,";" )
283                n1 = StringFromList(1, S_waveNames ,";" )
284                n2 = StringFromList(2, S_waveNames ,";" )
285               
286                //remove the semicolon AND period from files from the VAX
287                w0 = CleanupName((S_fileName + "_q"),0)
288                w1 = CleanupName((S_fileName + "_i"),0)
289                w2 = CleanupName((S_fileName + "_s"),0)
290                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
291               
292                if(exists(w0) !=0)
293//                              DoAlert 0,"This file has already been loaded. Use Append to Graph..."
294//                              KillWaves $n0,$n1,$n2           // kill the default waveX that were loaded
295//                              return
296                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
297                        if(V_flag==2)   //user selected No
298                                KillWaves/Z $n0,$n1,$n2         // kill the default waveX that were loaded
299                                String/G root:myGlobals:gLastFileName = filename                //set the last file loaded to the one NOT loaded
300                                return          //quits the macro
301                        endif
302                endif
303               
304                ////overwrite the existing data, if it exists
305                Duplicate/O $n0, $w0
306                Duplicate/O $n1, $w1
307                Duplicate/O $n2, $w2
308                KillWaves $n0,$n1,$n2
309               
310                Duplicate/o $w2 $wt
311                $wt = 1/$w2             //assign the weighting wave
312               
313                String/G root:myGlobals:gLastFileName = filename
314                String/G gQVals = w0
315                String/G gInten = w1
316                String/G gSigma = w2
317       
318        endif
319       
320        if(V_flag == 6)
321                String w0,w1,w2,n0,n1,n2,wt
322                String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
323               
324               
325                // put the names of the three loaded waves into local names
326                n0 = StringFromList(0, S_waveNames ,";" )
327                n1 = StringFromList(1, S_waveNames ,";" )
328                n2 = StringFromList(2, S_waveNames ,";" )
329                n3 = StringFromList(3, S_waveNames ,";" )
330                n4 = StringFromList(4, S_waveNames ,";" )
331                n5 = StringFromList(5, S_waveNames ,";" )
332               
333                //remove the semicolon AND period from files from the VAX
334                w0 = CleanupName((S_fileName + "_q"),0)
335                w1 = CleanupName((S_fileName + "_i"),0)
336                w2 = CleanupName((S_fileName + "_s"),0)
337                w3 = CleanupName((S_fileName + "sq"),0)
338                w4 = CleanupName((S_fileName + "qb"),0)
339                w5 = CleanupName((S_fileName + "fs"),0)
340                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
341               
342                if(exists(w0) !=0)              //the wave already exists
343//                              DoAlert 0,"This file has already been loaded."
344//                              KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
345//                              return          //quits the macro
346                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
347                        if(V_flag==2)   //user selected No
348                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
349                                String/G root:myGlobals:gLastFileName = filename                //set the last file loaded to the one NOT loaded
350                                return          //quits the macro
351                        endif
352                endif
353
354////overwrite the existing data, if it exists
355                Duplicate/O $n0, $w0
356                Duplicate/O $n1, $w1
357                Duplicate/O $n2, $w2
358                Duplicate/O $n3, $w3
359                Duplicate/O $n4, $w4
360                Duplicate/O $n5, $w5
361                KillWaves $n0,$n1,$n2,$n3,$n4,$n5
362               
363                Duplicate/o $w2 $wt
364                $wt = 1/$w2             //assign the weighting wave
365               
366                // copy waves to global strings for use in the smearing calculation
367                String/G root:myGlobals:gLastFileName = filename
368                String/G gQVals = w0
369                String/G gInten = w1
370                String/G gSigma = w2
371                String/G gSig_Q = w3
372                String/G gQ_bar = w4
373                String/G gShadow = w5
374               
375        endif
376
377        if(V_flag==5)
378                String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
379                Variable rr,gg,bb
380               
381                // put the names of the three loaded waves into local names
382                n0 = StringFromList(0, S_waveNames ,";" )
383                n1 = StringFromList(1, S_waveNames ,";" )
384                n2 = StringFromList(2, S_waveNames ,";" )
385                n3 = StringFromList(3, S_waveNames ,";" )
386                n4 = StringFromList(4, S_waveNames ,";" )
387               
388               
389                //remove the semicolon AND period from files from the VAX
390                w0 = CleanupName((S_fileName+"_q"),0)
391                w1 = CleanupName((S_fileName+"_i"),0)
392                w2 = CleanupName((S_fileName+"_s"),0)
393                w3 = CleanupName((S_fileName+"_ism"),0)
394                w4 = CleanupName((S_fileName+"_fit_ism"),0)
395               
396                if(exists(w0) !=0)              //the wave already exists
397                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
398                        if(V_flag==2)   //user selected No
399                                KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
400                                if(DataFolderExists("root:myGlobals"))
401                                        String/G root:myGlobals:gLastFileName = filename
402                                endif           //set the last file loaded to the one NOT loaded
403                                return          //quits the macro
404                        endif
405                endif
406               
407                ////overwrite the existing data, if it exists
408                Duplicate/O $n0, $w0
409                Duplicate/O $n1, $w1
410                Duplicate/O $n2, $w2
411                Duplicate/O $n3, $w3
412                Duplicate/O $n4, $w4
413                KillWaves $n0,$n1,$n2,$n3,$n4
414       
415                if(DataFolderExists("root:myGlobals"))
416                        String/G root:myGlobals:gLastFileName = filename
417                endif
418
419        endif
420End
421
422
423
424//////////////////////////////////////////
425Proc Show_Plot_Manager()
426        DoWindow/F Plot_Manager
427        if(V_flag==0)
428                Plot_Manager()
429        endif
430End
431
432Proc Plot_Manager()
433        PauseUpdate; Silent 1           // building window...
434        NewPanel /W=(658,347,920,562)/K=1
435        DoWindow/C Plot_Manager
436        ModifyPanel cbRGB=(37265,65535,32896),fixedSize=1
437        Button button0,pos={161,178},size={50,20},proc=PlotManager_Done,title="Done"
438        PopupMenu popup0,pos={11,50},size={211,20},title="Data in Memory"
439        PopupMenu popup0,mode=1,value= #"OneDDataInMemory()"
440        Button button1,pos={60,14},size={140,20},proc=PlotManger_Load,title="Load Data From File"
441        Button button2,pos={118,84},size={100,20},proc=PlotManager_Append,title="Append Data"
442        Button button3,pos={11,84},size={80,20},proc=PlotManager_newGraph,title="New Graph"
443        Button button4,pos={11,118},size={220,20},proc=PlotManager_Kill,title="Remove Selection From Memory"
444        Button button5,pos={11,148},size={220,20},proc=PlotManager_KillAll,title="Remove All Data From Memory"
445EndMacro
446
447//lists the intensity waves in the current data folder
448// only looks for data ending in "i"
449//
450Function/S OneDDataInMemory()
451        //SetDataFolder root:
452        String list = WaveList("*i", ";", "" )
453        list = SortList(list,";",0)                     //re-alphabetize the list
454        return(list)
455end
456
457
458Function PlotManager_Done(ctrlName) : ButtonControl
459        String ctrlName
460        DoWindow/K Plot_Manager
461End
462
463Proc PlotManger_Load(ctrlName) : ButtonControl
464        String ctrlName
465       
466        OneDLoader_Panel()
467        //LoadOneDData()
468        ControlUpdate/W=Plot_Manager popup0
469End
470
471Function PlotManager_Append(ctrlName) : ButtonControl
472        String ctrlName
473        //appends data set from memory
474        String iStr,qStr,eStr
475        Variable rr,gg,bb
476       
477        //get the current selection
478        ControlInfo popup0
479        if(strlen(S_Value)==0)
480                Abort "You must load data from a file into memory before appending the data"
481        Endif
482       
483        PM_doAppend(S_Value)
484       
485        DoWindow/F Plot_Manager
486End
487
488//actually does the appending
489//pass it the name of the wave, find the q-i-s waves
490Function PM_doAppend(iStr)
491        String iStr
492        //appends data set from memory
493        String qStr,eStr
494        Variable rr,gg,bb
495       
496        if(cmpstr(WinList("*", ";","WIN:1"),"") == 0 )
497                DoAlert 0,"There are no open graphs. Please use the New Graph button"
498                return(0)
499        endif
500       
501        //this assumes that iStr IS the i-wave, and the name ends in "i"
502        qStr=iStr[0,strlen(iStr)-2]+"q"
503        eStr=iStr[0,strlen(iStr)-2]+"s"
504       
505        rr = abs(trunc(enoise(65535)))
506        gg = abs(trunc(enoise(65535)))
507        bb = abs(trunc(enoise(65535)))
508       
509        // append to whatever is top-most graph
510        AppendToGraph $iStr vs $qStr
511        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb($iStr)=(rr,gg,bb)
512        ErrorBars $iStr Y,wave=($eStr,$eStr)
513End
514
515Proc PlotManager_newGraph(ctrlName) : ButtonControl
516        String ctrlName
517
518        String iStr,qStr,eStr
519        Variable rr,gg,bb
520       
521        //get the current selection
522        ControlInfo popup0
523        if(strlen(S_Value)==0)
524                Abort "You must load data from a file into memory before plotting the data"
525        Endif
526        PM_doNewGraph(S_Value)
527        DoWindow/F Plot_Manager
528End
529
530Function PM_doNewGraph(iStr)
531        String iStr
532
533        String qStr,eStr
534        Variable rr,gg,bb
535       
536        //iStr will end in "i"
537        qStr=iStr[0,strlen(iStr)-2]+"q"
538        eStr=iStr[0,strlen(iStr)-2]+"s"
539       
540        rr = abs(trunc(enoise(65535)))
541        gg = abs(trunc(enoise(65535)))
542        bb = abs(trunc(enoise(65535)))
543       
544        // always make a new graph
545        Display $iStr vs $qStr
546        ModifyGraph log=1,mode($istr)=3,marker($iStr)=19,msize($iStr)=2,rgb=(rr,gg,bb)
547        ModifyGraph grid=1,mirror=2,standoff=0
548        ErrorBars $iStr Y,wave=($eStr,$eStr)
549       
550        Label left "I(q)"
551        SVAR angst = root:myGlobals:gAngstStr
552        Label bottom "q ("+angst+"\\S-1\\M)"
553       
554        Legend
555End
556
557//kill the specified wave (if possible)
558Proc PlotManager_Kill(ctrlName) : ButtonControl
559        String ctrlName
560       
561        String iStr,qStr,eStr,sqStr,qbStr,fsStr,wtStr
562
563        ControlInfo popup0
564        iStr=S_Value            //this will end in "i"
565        qStr=iStr[0,strlen(iStr)-2]+"q"
566        eStr=iStr[0,strlen(iStr)-2]+"s"
567        sqStr=iStr[0,strlen(iStr)-3]+"sq"                       //remove the underscore from these names
568        qbStr=iStr[0,strlen(iStr)-3]+"qb"
569        fsStr=iStr[0,strlen(iStr)-3]+"fs"
570        wtStr=iStr[0,strlen(iStr)-3]+"wt"
571       
572        CheckDisplayed/A $iStr                  //is the intensity data in use?
573        if(V_flag==0)
574                Killwaves/Z $iStr,$qStr,$eStr,$sqStr,$qbStr,$fsStr,$wtStr
575        endif
576        ControlUpdate popup0            //refresh the popup, very important if last item removed
577End
578
579//kill the specified wave (if possible)
580Proc PlotManager_KillAll(ctrlName) : ButtonControl
581        String ctrlName
582       
583        String iStr,qStr,eStr,sqStr,qbStr,fsStr,wtStr
584
585        String list =  OneDDataInMemory()
586        Variable num=ItemsInList(list),ii
587       
588        ii=0
589        do     
590                iStr=StringFromList(ii, list  ,";")
591                qStr=iStr[0,strlen(iStr)-2]+"q"
592                eStr=iStr[0,strlen(iStr)-2]+"s"
593                sqStr=iStr[0,strlen(iStr)-3]+"sq"               //remove the underscore from these names
594                qbStr=iStr[0,strlen(iStr)-3]+"qb"
595                fsStr=iStr[0,strlen(iStr)-3]+"fs"
596                wtStr=iStr[0,strlen(iStr)-3]+"wt"
597               
598                CheckDisplayed/A $iStr                  //is the intensity data in use?
599                if(V_flag==0)
600                        Killwaves/Z $iStr,$qStr,$eStr,$sqStr,$qbStr,$fsStr,$wtStr
601                endif
602                ii+=1
603        while(ii<num)
604        ControlUpdate popup0            //refresh the popup, very important if all items are removed
605End
606
607Proc Init_OneDLoader()
608        //create the data folder
609        NewDataFolder/O/S root:myGlobals:OneDLoader
610        //create the waves
611        Make/O/T/N=1 fileWave=""
612        Make/O/N=1 selWave=0
613        Variable/G ind=0
614        SetDataFolder root:
615End
616
617// main procedure for invoking the raw to ascii panel
618// initializes each time to make sure
619Proc OneDLoader_Panel()
620        Init_OneDLoader()
621        DoWindow/F OneDLoader
622        if(V_Flag==0)
623                OneDLoader()
624        endif
625         OneDLoader_GetListButton("")
626End
627
628//procedure for drawing the simple panel to export raw->ascii
629//
630Proc OneDLoader()
631        PauseUpdate; Silent 1           // building window...
632        NewPanel /W=(501,97,885,282) /K=2
633        DoWindow/C OneDLoader
634        SetDrawLayer UserBack
635        DrawText 237,38,"Shift-click to load"
636        DrawText 254,58,"multiple files"
637        ListBox fileList,pos={4,3},size={206,179}
638        ListBox fileList,listWave=root:myGlobals:OneDLoader:fileWave
639        ListBox fileList,selWave=root:myGlobals:OneDLoader:selWave,mode= 4
640        Button button0,pos={239,78},size={110,20},proc=OneDLoader_LoadButton,title="Load File(s)"
641        Button button0,help={"Loads the selected files into memory and will graph them if that option is checked"}
642        Button button1,pos={260,150},size={70,20},proc=OneDLoader_CancelButton,title="Cancel"
643        Button button1,help={"Closes the panel without loading any data"}
644        CheckBox check0,pos={242,112},size={113,14},title="All in a new graph?",value= 1
645        CheckBox check0,help={"Makes a new graph with all of the selected data. Otherwise, you will be prompted to append data"}
646//      Button button3,pos={230,16},size={60,20},proc=OneDLoader_GetListButton,title="Get List"
647//      Button button3,help={"Refreshes the file listing"}
648EndMacro
649
650//closes the panel if user cancels
651Function OneDLoader_CancelButton(ctrlName) : ButtonControl
652        String ctrlName
653
654        //kill the panel
655        DoWindow/K OneDLoader
656        return(0)
657End
658
659//filters to remove only the files that are named like a raw data file, i.e. "*.SAn"
660//does not check to see if they really are RAW files though...(too tedious)
661Function OneDLoader_GetListButton(ctrlName) : ButtonControl
662        String ctrlName
663       
664        //make sure that path exists
665        PathInfo catPathName
666        if (V_flag == 0)
667                Abort "Folder path does not exist - use Pick Path button on Main Panel"
668        Endif
669       
670        String newList = ReducedDataFileList("")
671        Variable num
672       
673        num=ItemsInList(newlist,";")
674        WAVE/T fileWave=$"root:myGlobals:OneDLoader:fileWave"
675        WAVE selWave=$"root:myGlobals:OneDLoader:selWave"
676        Redimension/N=(num) fileWave
677        Redimension/N=(num) selWave
678        fileWave = StringFromList(p,newlist,";")
679        Sort filewave,filewave
680End
681
682Function OneDLoader_LoadButton(ctrlName) : ButtonControl
683        String ctrlName
684       
685        //loop through the selected files in the list...
686        Wave/T fileWave=$"root:myGlobals:OneDLoader:fileWave"
687        Wave sel=$"root:myGlobals:OneDLoader:selWave"
688        Variable num=numpnts(sel),ii=0
689        String fname="",pathStr="",fullPath="",newFileName=""
690       
691        PathInfo catPathName                    //this is where the files are
692        pathStr=S_path
693       
694        Variable doGraph,cnt
695
696        ControlInfo check0
697        doGraph=V_Value
698        cnt=0
699        // get the current state
700        do
701                if(sel[ii] == 1)
702                        fname=pathStr + FindValidFilename(fileWave[ii])         //in case of VAX version numbers
703                        Execute "LoadOneDDataWithName(\""+fname+"\")"
704                        cnt += 1        //a file was loaded
705                        if(doGraph==1)
706                                SVAR  fileName = root:myGlobals:gLastFileName           //last file loaded
707                                if(cnt==1)
708                                        PM_doNewGraph(  CleanupName((fileName + "_i"),0) )              //create the name of the intensity wave loaded
709                                else
710                                        PM_doAppend(  CleanupName((fileName + "_i"),0) )       
711                                endif
712                        endif
713                endif
714                ii+=1
715        while(ii<num)
716        //kill the panel
717        DoWindow/K OneDLoader
718        return(0)
719End
Note: See TracBrowser for help on using the repository browser.