source: sans/Dev/trunk/NCNR_User_Procedures/USANS/PlotUtils_USANS.ipf @ 399

Last change on this file since 399 was 392, checked in by srkline, 15 years ago

Changed NCNR_ raw data reader to get the magnetic field strength (actually the voltage) from byte 348, rather than 190.

Added Jan Ilavsky's fixes to all data loaders to accept 2-column data. A fake error is generated for the data set as read in, so the data can be treated as 3-column data from that point.

  • Property eol-style set to native
  • Property svn:executable set to *
File size: 16.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma Version=2.20
3#pragma IgorVersion=6.0
4
5//loads 3-column or 6-column data into current folder, typically root:
6// 5-column data from average/qsig i loaded  below with U_LoadUSANSData() procedure
7//
8//
9Proc U_LoadOneDData()
10
11        //Load the waves, using default waveX names
12        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
13        LoadWave/G/D/A
14        String filename = S_fileName
15        Variable numCols = V_flag
16       
17        //changes JIL
18        if(numCols==2)          //no errors     
19                n1 = StringFromList(1, S_waveNames ,";" )               
20                Duplicate/O $("root:"+n1), errorTmp
21                 errorTmp = 0.01*(errorTmp)+ 0.03*sqrt(errorTmp)
22                S_waveNames+="errorTmp;"
23                numCols=3
24        endif
25       
26        if(numCols==3)
27                String w0,w1,w2,n0,n1,n2,wt
28                Variable rr,gg,bb
29               
30                // put the names of the three loaded waves into local names
31                n0 = StringFromList(0, S_waveNames ,";" )
32                n1 = StringFromList(1, S_waveNames ,";" )
33                n2 = StringFromList(2, S_waveNames ,";" )
34               
35                //remove the semicolon AND period from files from the VAX
36                w0 = CleanupName((S_fileName + "_q"),0)
37                w1 = CleanupName((S_fileName + "_i"),0)
38                w2 = CleanupName((S_fileName + "_s"),0)
39                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
40               
41                if(exists(w0) !=0)
42                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
43                        if(V_flag==2)   //user selected No
44                                KillWaves/Z $n0,$n1,$n2         // kill the default waveX that were loaded
45                                if(DataFolderExists("root:myGlobals"))
46                                        String/G root:myGlobals:gLastFileName = filename
47                                endif           //set the last file loaded to the one NOT loaded
48                                return          //quits the macro
49                        endif
50                endif
51               
52                ////overwrite the existing data, if it exists
53                Duplicate/O $n0, $w0
54                Duplicate/O $n1, $w1
55                Duplicate/O $n2, $w2
56                KillWaves $n0,$n1,$n2
57               
58                if(DataFolderExists("root:myGlobals"))
59                        String/G root:myGlobals:gLastFileName = filename
60                endif
61               
62                Duplicate/o $w2 $wt
63                $wt = 1/$w2             //assign the weighting wave
64               
65                // set data units for the waves
66//                      if(DataFolderExists("root:myGlobals"))
67//                              String angst = root:myGlobals:gAngstStr
68//                      else
69                        String angst = "A"
70//                      endif
71                SetScale d,0,0,"1/"+angst,$w0
72                SetScale d,0,0,"1/cm",$w1
73               
74                // assign colors randomly
75                rr = abs(trunc(enoise(65535)))
76                gg = abs(trunc(enoise(65535)))
77                bb = abs(trunc(enoise(65535)))
78               
79                // if target window is a graph, and user wants to append, do so
80           DoWindow/B Plot_Manager
81                if(WinType("") == 1)
82                        DoAlert 1,"Do you want to append this data to the current graph?"
83                        if(V_Flag == 1)
84                                AppendToGraph $w1 vs $w0
85                                ModifyGraph mode=3,marker=19,msize=2,rgb ($w1) =(rr,gg,bb)
86                                ModifyGraph tickUnit=1
87                                ErrorBars $w1 Y,wave=($w2,$w2)
88                        else
89                        //new graph
90                                Display $w1 vs $w0
91                                ModifyGraph log=1,mode=3,marker=19,msize=2,rgb=(rr,gg,bb)
92                                ModifyGraph grid=1,mirror=2,standoff=0
93                                ModifyGraph tickUnit=1
94                                ErrorBars $w1 Y,wave=($w2,$w2)
95                                Legend
96                        endif
97                else
98                // graph window was not target, make new one
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                        ModifyGraph tickUnit=1
103                        ErrorBars $w1 Y,wave=($w2,$w2)
104                        Legend
105                endif
106                       
107                // Annotate graph
108                //Textbox/A=LT "XY data loaded from " + S_fileName
109            DoWindow/F Plot_Manager
110        endif
111       
112        if(numCols == 6)
113                String w0,w1,w2,n0,n1,n2,wt
114                String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
115                Variable rr,gg,bb
116               
117               
118                // put the names of the three loaded waves into local names
119                n0 = StringFromList(0, S_waveNames ,";" )
120                n1 = StringFromList(1, S_waveNames ,";" )
121                n2 = StringFromList(2, S_waveNames ,";" )
122                n3 = StringFromList(3, S_waveNames ,";" )
123                n4 = StringFromList(4, S_waveNames ,";" )
124                n5 = StringFromList(5, S_waveNames ,";" )
125               
126                //remove the semicolon AND period from files from the VAX
127                w0 = CleanupName((S_fileName + "_q"),0)
128                w1 = CleanupName((S_fileName + "_i"),0)
129                w2 = CleanupName((S_fileName + "_s"),0)
130                w3 = CleanupName((S_fileName + "sq"),0)
131                w4 = CleanupName((S_fileName + "qb"),0)
132                w5 = CleanupName((S_fileName + "fs"),0)
133                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
134               
135                if(exists(w0) !=0)              //the wave already exists
136                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
137                        if(V_flag==2)   //user selected No
138                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
139                                if(DataFolderExists("root:myGlobals"))
140                                        String/G root:myGlobals:gLastFileName = filename
141                                endif           //set the last file loaded to the one NOT loaded
142                                return          //quits the macro
143                        endif
144                endif
145
146////overwrite the existing data, if it exists
147                Duplicate/O $n0, $w0
148                Duplicate/O $n1, $w1
149                Duplicate/O $n2, $w2
150                Duplicate/O $n3, $w3
151                Duplicate/O $n4, $w4
152                Duplicate/O $n5, $w5
153                KillWaves $n0,$n1,$n2,$n3,$n4,$n5
154               
155                Duplicate/o $w2 $wt
156                $wt = 1/$w2             //assign the weighting wave
157               
158                // copy waves to global strings for use in the smearing calculation
159                if(DataFolderExists("root:myGlobals"))
160                        String/G root:myGlobals:gLastFileName = filename
161                endif
162                String/G gQVals = w0
163                String/G gSig_Q = w3
164                String/G gQ_bar = w4
165                String/G gShadow = w5
166               
167                // set data units for the waves
168//                      if(DataFolderExists("root:myGlobals"))
169//                              String angst = root:myGlobals:gAngstStr
170//                      else
171                        String angst = "A"
172//                      endif
173                SetScale d,0,0,"1/"+angst,$w0
174                SetScale d,0,0,"1/cm",$w1
175               
176                // assign colors randomly
177                rr = abs(trunc(enoise(65535)))
178                gg = abs(trunc(enoise(65535)))
179                bb = abs(trunc(enoise(65535)))
180       
181                // if target window is a graph, and user wants to append, do so
182                DoWindow/B Plot_Manager
183                if(WinType("") == 1)
184                        DoAlert 1,"Do you want to append this data to the current graph?"
185                        if(V_Flag == 1)
186                                AppendToGraph $w1 vs $w0
187                                ModifyGraph mode=3,marker=19,msize=2,rgb ($w1) =(rr,gg,bb)
188                                ModifyGraph tickUnit=1
189                                ErrorBars $w1 Y,wave=($w2,$w2)
190                        else
191                        //new graph
192                                Display $w1 vs $w0
193                                ModifyGraph log=1,mode=3,marker=19,msize=2,rgb=(rr,gg,bb)
194                                ModifyGraph grid=1,mirror=2,standoff=0
195                                ModifyGraph tickUnit=1
196                                ErrorBars $w1 Y,wave=($w2,$w2)
197                                Legend
198                        endif
199                else
200                // graph window was not target, make new one
201                        Display $w1 vs $w0
202                        ModifyGraph log=1,mode=3,marker=19,msize=2,rgb=(rr,gg,bb)
203                        ModifyGraph grid=1,mirror=2,standoff=0
204                        ModifyGraph tickUnit=1
205                        ErrorBars $w1 Y,wave=($w2,$w2)
206                        Legend
207                endif
208                       
209                // Annotate graph
210                //Textbox/A=LT "XY data loaded from " + S_fileName
211            DoWindow/F Plot_Manager
212        endif
213
214        if(numCols==5)
215                String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
216                Variable rr,gg,bb
217               
218                // put the names of the three loaded waves into local names
219                n0 = StringFromList(0, S_waveNames ,";" )
220                n1 = StringFromList(1, S_waveNames ,";" )
221                n2 = StringFromList(2, S_waveNames ,";" )
222                n3 = StringFromList(3, S_waveNames ,";" )
223                n4 = StringFromList(4, S_waveNames ,";" )
224               
225               
226                //remove the semicolon AND period from files from the VAX
227                w0 = CleanupName((S_fileName+"_q"),0)
228                w1 = CleanupName((S_fileName+"_i"),0)
229                w2 = CleanupName((S_fileName+"_s"),0)
230                w3 = CleanupName((S_fileName+"_ism"),0)
231                w4 = CleanupName((S_fileName+"_fit_ism"),0)
232               
233                if(exists(w0) !=0)              //the wave already exists
234                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
235                        if(V_flag==2)   //user selected No
236                                KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
237                                if(DataFolderExists("root:myGlobals"))
238                                        String/G root:myGlobals:gLastFileName = filename
239                                endif           //set the last file loaded to the one NOT loaded
240                                return          //quits the macro
241                        endif
242                endif
243               
244                ////overwrite the existing data, if it exists
245                Duplicate/O $n0, $w0
246                Duplicate/O $n1, $w1
247                Duplicate/O $n2, $w2
248                Duplicate/O $n3, $w3
249                Duplicate/O $n4, $w4
250                KillWaves $n0,$n1,$n2,$n3,$n4
251       
252                if(DataFolderExists("root:myGlobals"))
253                        String/G root:myGlobals:gLastFileName = filename
254                endif
255                // assign colors randomly
256                rr = abs(trunc(enoise(65535)))
257                gg = abs(trunc(enoise(65535)))
258                bb = abs(trunc(enoise(65535)))
259               
260                        // if target window is a graph, and user wants to append, do so
261                if(WinType("") == 1)
262                        DoAlert 1,"Do you want to append this data to the current graph?"
263                        if(V_Flag == 1)
264                                AppendToGraph $w1 vs $w0
265                                ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
266                                ErrorBars $w1 Y,wave=($w2,$w2)
267                        else
268                        //new graph
269                                Display $w1 vs $w0
270                                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
271                                ErrorBars $w1 Y,wave=($w2,$w2)
272                                Legend
273                        endif
274                else
275                // graph window was not target, make new one
276                        Display $w1 vs $w0
277                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
278                        ErrorBars $w1 Y,wave=($w2,$w2)
279                        Legend
280                endif
281       
282        endif
283End
284
285
286//load the data specified by fileStr (a full path:name)
287// Does not graph the data - just loads it
288//
289Proc U_LoadOneDDataWithName(fileStr)
290        String fileStr
291        //Load the waves, using default waveX names
292        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
293        LoadWave/G/D/A/Q fileStr
294        String fileName = S_fileName
295        Variable numCols = V_flag
296       
297        //changes JIL
298        if(numCols==2)          //no errors     
299                n1 = StringFromList(1, S_waveNames ,";" )               
300                Duplicate/O $("root:"+n1), errorTmp
301                 errorTmp = 0.01*(errorTmp)+ 0.03*sqrt(errorTmp)
302                S_waveNames+="errorTmp;"
303                numCols=3
304        endif
305       
306        if(numCols==3)
307                String w0,w1,w2,n0,n1,n2,wt
308               
309                // put the names of the three loaded waves into local names
310                n0 = StringFromList(0, S_waveNames ,";" )
311                n1 = StringFromList(1, S_waveNames ,";" )
312                n2 = StringFromList(2, S_waveNames ,";" )
313               
314                //remove the semicolon AND period from files from the VAX
315                w0 = CleanupName((S_fileName + "_q"),0)
316                w1 = CleanupName((S_fileName + "_i"),0)
317                w2 = CleanupName((S_fileName + "_s"),0)
318                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
319               
320                if(exists(w0) !=0)
321                        DoAlert 1,"The file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
322                        if(V_flag==2)   //user selected No
323                                KillWaves/Z $n0,$n1,$n2         // kill the default waveX that were loaded
324                                if(DataFolderExists("root:myGlobals"))
325                                        String/G root:myGlobals:gLastFileName = filename
326                                endif           //set the last file loaded to the one NOT loaded
327                                return          //quits the macro
328                        endif
329                endif
330               
331                ////overwrite the existing data, if it exists
332                Duplicate/O $n0, $w0
333                Duplicate/O $n1, $w1
334                Duplicate/O $n2, $w2
335                KillWaves $n0,$n1,$n2
336               
337                Duplicate/o $w2 $wt
338                $wt = 1/$w2             //assign the weighting wave
339               
340                if(DataFolderExists("root:myGlobals"))
341                        String/G root:myGlobals:gLastFileName = filename
342                endif
343                String/G gQVals = w0
344                String/G gInten = w1
345                String/G gSigma = w2
346               
347        endif
348       
349        if(numCols == 6)
350                String w0,w1,w2,n0,n1,n2,wt
351                String w3,w4,w5,n3,n4,n5                        //3 extra waves to load
352               
353               
354                // put the names of the three loaded waves into local names
355                n0 = StringFromList(0, S_waveNames ,";" )
356                n1 = StringFromList(1, S_waveNames ,";" )
357                n2 = StringFromList(2, S_waveNames ,";" )
358                n3 = StringFromList(3, S_waveNames ,";" )
359                n4 = StringFromList(4, S_waveNames ,";" )
360                n5 = StringFromList(5, S_waveNames ,";" )
361               
362                //remove the semicolon AND period from files from the VAX
363                w0 = CleanupName((S_fileName + "_q"),0)
364                w1 = CleanupName((S_fileName + "_i"),0)
365                w2 = CleanupName((S_fileName + "_s"),0)
366                w3 = CleanupName((S_fileName + "sq"),0)
367                w4 = CleanupName((S_fileName + "qb"),0)
368                w5 = CleanupName((S_fileName + "fs"),0)
369                wt = CleanupName((S_fileName + "wt"),0)         //create a name for the weighting wave
370               
371                if(exists(w0) !=0)              //the wave already exists
372                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
373                        if(V_flag==2)   //user selected No
374                                KillWaves $n0,$n1,$n2,$n3,$n4,$n5               // kill the default waveX that were loaded
375                                if(DataFolderExists("root:myGlobals"))
376                                        String/G root:myGlobals:gLastFileName = filename
377                                endif           //set the last file loaded to the one NOT loaded
378                                return          //quits the macro
379                        endif
380                endif
381
382////overwrite the existing data, if it exists
383                Duplicate/O $n0, $w0
384                Duplicate/O $n1, $w1
385                Duplicate/O $n2, $w2
386                Duplicate/O $n3, $w3
387                Duplicate/O $n4, $w4
388                Duplicate/O $n5, $w5
389                KillWaves $n0,$n1,$n2,$n3,$n4,$n5
390               
391                Duplicate/o $w2 $wt
392                $wt = 1/$w2             //assign the weighting wave
393               
394                // copy waves to global strings for use in the smearing calculation
395                if(DataFolderExists("root:myGlobals"))
396                        String/G root:myGlobals:gLastFileName = filename
397                endif
398                String/G gQVals = w0
399                String/G gInten = w1
400                String/G gSigma = w2
401                String/G gSig_Q = w3
402                String/G gQ_bar = w4
403                String/G gShadow = w5
404
405        endif
406
407        if(numCols==5)
408                String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
409                Variable rr,gg,bb
410               
411                // put the names of the three loaded waves into local names
412                n0 = StringFromList(0, S_waveNames ,";" )
413                n1 = StringFromList(1, S_waveNames ,";" )
414                n2 = StringFromList(2, S_waveNames ,";" )
415                n3 = StringFromList(3, S_waveNames ,";" )
416                n4 = StringFromList(4, S_waveNames ,";" )
417               
418               
419                //remove the semicolon AND period from files from the VAX
420                w0 = CleanupName((S_fileName+"_q"),0)
421                w1 = CleanupName((S_fileName+"_i"),0)
422                w2 = CleanupName((S_fileName+"_s"),0)
423                w3 = CleanupName((S_fileName+"_ism"),0)
424                w4 = CleanupName((S_fileName+"_fit_ism"),0)
425               
426                if(exists(w0) !=0)              //the wave already exists
427                        DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
428                        if(V_flag==2)   //user selected No
429                                KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
430                                if(DataFolderExists("root:myGlobals"))
431                                        String/G root:myGlobals:gLastFileName = filename
432                                endif           //set the last file loaded to the one NOT loaded
433                                return          //quits the macro
434                        endif
435                endif
436               
437                ////overwrite the existing data, if it exists
438                Duplicate/O $n0, $w0
439                Duplicate/O $n1, $w1
440                Duplicate/O $n2, $w2
441                Duplicate/O $n3, $w3
442                Duplicate/O $n4, $w4
443                KillWaves $n0,$n1,$n2,$n3,$n4
444       
445                if(DataFolderExists("root:myGlobals"))
446                        String/G root:myGlobals:gLastFileName = filename
447                endif
448
449        endif
450End
451
452
453//procedure for loading desmeared USANS data in the format (5-columns)
454// qvals - I(q) - sig I - Ism(q) - fitted Ism(q)
455//no weighting wave is created (not needed in IGOR 4)
456Proc U_LoadUSANSData()
457
458        //Load the waves, using default waveX names
459        //if no path or file is specified for LoadWave, the default Mac open dialog will appear
460        LoadWave/G/D/A
461   String filename = S_fileName
462       
463        String w0,w1,w2,n0,n1,n2,w3,n3,w4,n4
464        Variable rr,gg,bb
465       
466        // put the names of the three loaded waves into local names
467        n0 = StringFromList(0, S_waveNames ,";" )
468        n1 = StringFromList(1, S_waveNames ,";" )
469        n2 = StringFromList(2, S_waveNames ,";" )
470        n3 = StringFromList(3, S_waveNames ,";" )
471        n4 = StringFromList(4, S_waveNames ,";" )
472       
473       
474        //remove the semicolon AND period from files from the VAX
475        w0 = CleanupName((S_fileName+"_q"),0)
476        w1 = CleanupName((S_fileName+"_i"),0)
477        w2 = CleanupName((S_fileName+"_s"),0)
478        w3 = CleanupName((S_fileName+"_ism"),0)
479        w4 = CleanupName((S_fileName+"_fit_ism"),0)
480       
481        if(exists(w0) !=0)              //the wave already exists
482                DoAlert 1,"This file "+S_filename+" has already been loaded. Do you want to load the new data file, overwriting the data in memory?"
483                if(V_flag==2)   //user selected No
484                        KillWaves $n0,$n1,$n2,$n3,$n4           // kill the default waveX that were loaded
485                        if(DataFolderExists("root:myGlobals"))
486                                String/G root:myGlobals:gLastFileName = filename
487                        endif           //set the last file loaded to the one NOT loaded
488                        return          //quits the macro
489                endif
490        endif
491       
492        ////overwrite the existing data, if it exists
493        Duplicate/O $n0, $w0
494        Duplicate/O $n1, $w1
495        Duplicate/O $n2, $w2
496        Duplicate/O $n3, $w3
497        Duplicate/O $n4, $w4
498        KillWaves $n0,$n1,$n2,$n3,$n4
499       
500        if(DataFolderExists("root:myGlobals"))
501                String/G root:myGlobals:gLastFileName = filename
502        endif
503               
504        // assign colors randomly
505        rr = abs(trunc(enoise(65535)))
506        gg = abs(trunc(enoise(65535)))
507        bb = abs(trunc(enoise(65535)))
508       
509                // if target window is a graph, and user wants to append, do so
510        if(WinType("") == 1)
511                DoAlert 1,"Do you want to append this data to the current graph?"
512                if(V_Flag == 1)
513                        AppendToGraph $w1 vs $w0
514                        ModifyGraph mode=3,marker=29,msize=2,rgb ($w1) =(rr,gg,bb),tickUnit=1,grid=1,mirror=2
515                        ErrorBars $w1 Y,wave=($w2,$w2)
516                else
517                //new graph
518                        Display $w1 vs $w0
519                        ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
520                        ErrorBars $w1 Y,wave=($w2,$w2)
521                        Legend
522                endif
523        else
524        // graph window was not target, make new one
525                Display $w1 vs $w0
526                ModifyGraph log=1,mode=3,marker=29,msize=2,rgb=(rr,gg,bb),tickUnit=1,grid=1,mirror=2
527                ErrorBars $w1 Y,wave=($w2,$w2)
528                Legend
529        endif
530               
531End
Note: See TracBrowser for help on using the repository browser.