source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_IQ_Utilities.ipf @ 984

Last change on this file since 984 was 984, checked in by srkline, 7 years ago

lots of changes to 1D averaging and the plotting routines, detector corrections, and basic reads

File size: 7.3 KB
Line 
1#pragma TextEncoding = "MacRoman"               // For details execute DisplayHelpTopic "The TextEncoding Pragma"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5//
6//
7// does no scaling, only the basic (default) trim of the ends, concatenate, sort, and save
8//
9// TODO:
10// -- fill in all of the details...
11//
12Macro V_Combine1DData()
13
14// get the current display type
15        String type = root:Packages:NIST:VSANS:Globals:gCurDispType
16
17// figure out which binning was used
18
19// trim the data if needed
20
21// concatenate the data sets
22        V_1DConcatenate(type)
23       
24// sort the data set
25        V_TmpSort1D(type)
26       
27// write out the data set to a file
28
29
30End
31
32
33
34
35
36// concatentate data in folderStr
37//
38// TODO:
39// -- this currently assumes that all of the waves exist
40// -- need robust error checking for wave existence
41// -- wave names are hard-wired and their name and location may be different in the future
42// -- if different averaging options were chosen (bin type of 2, 4 etc) then
43//    although waves may exist, they may not be the right ones to use. There
44//    will be a somewhat complex selection process
45// -- detector B is currently skipped
46//
47// this seems like a lot of extra work to do something so simple...
48//
49//  root:Packages:NIST:VSANS:RAW:iBin_qxqy_FB
50Function V_1DConcatenate(folderStr)
51        String folderStr
52       
53        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
54       
55        Wave/Z q_fb = qBin_qxqy_FB
56        Wave/Z q_ft = qBin_qxqy_FT
57        Wave/Z q_fl = qBin_qxqy_FL
58        Wave/Z q_fr = qBin_qxqy_FR
59        Wave/Z q_mb = qBin_qxqy_MB
60        Wave/Z q_mt = qBin_qxqy_MT
61        Wave/Z q_ml = qBin_qxqy_ML
62        Wave/Z q_mr = qBin_qxqy_MR
63        Wave/Z q_b = qBin_qxqy_B
64
65        Concatenate/NP {q_fb,q_ft,q_fl,q_fr,q_mb,q_mt,q_ml,q_mr,q_b}, tmp_q
66       
67        Wave/Z i_fb = iBin_qxqy_FB
68        Wave/Z i_ft = iBin_qxqy_FT
69        Wave/Z i_fl = iBin_qxqy_FL
70        Wave/Z i_fr = iBin_qxqy_FR
71        Wave/Z i_mb = iBin_qxqy_MB
72        Wave/Z i_mt = iBin_qxqy_MT
73        Wave/Z i_ml = iBin_qxqy_ML
74        Wave/Z i_mr = iBin_qxqy_MR
75        Wave/Z i_b = iBin_qxqy_B
76       
77        Concatenate/NP {i_fb,i_ft,i_fl,i_fr,i_mb,i_mt,i_ml,i_mr,i_b}, tmp_i
78
79        Wave/Z s_fb = eBin_qxqy_FB
80        Wave/Z s_ft = eBin_qxqy_FT
81        Wave/Z s_fl = eBin_qxqy_FL
82        Wave/Z s_fr = eBin_qxqy_FR
83        Wave/Z s_mb = eBin_qxqy_MB
84        Wave/Z s_mt = eBin_qxqy_MT
85        Wave/Z s_ml = eBin_qxqy_ML
86        Wave/Z s_mr = eBin_qxqy_MR
87        Wave/Z s_b = eBin_qxqy_B
88       
89        Concatenate/NP {s_fb,s_ft,s_fl,s_fr,s_mb,s_mt,s_ml,s_mr,s_b}, tmp_s
90               
91//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_q"),$("root:"+folder2+":"+folder2+"_q")},tmp_q
92//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_i"),$("root:"+folder2+":"+folder2+"_i")},tmp_i
93//      Concatenate/NP {$("root:"+folder1+":"+folder1+"_s"),$("root:"+folder2+":"+folder2+"_s")},tmp_s
94//      Concatenate/NP {$("root:"+folder1+":res0"),$("root:"+folder2+":res0")},tmp_res0
95//      Concatenate/NP {$("root:"+folder1+":res1"),$("root:"+folder2+":res1")},tmp_res1
96//      Concatenate/NP {$("root:"+folder1+":res2"),$("root:"+folder2+":res2")},tmp_res2
97//      Concatenate/NP {$("root:"+folder1+":res3"),$("root:"+folder2+":res3")},tmp_res3
98       
99//// move the concatenated result into the destination folder (killing the old stuff first)
100//      KillWaves/Z $("root:"+folder2+":"+folder2+"_q")
101//      KillWaves/Z $("root:"+folder2+":"+folder2+"_i")
102//      KillWaves/Z $("root:"+folder2+":"+folder2+"_s")
103//      KillWaves/Z $("root:"+folder2+":res0")
104//      KillWaves/Z $("root:"+folder2+":res1")
105//      KillWaves/Z $("root:"+folder2+":res2")
106//      KillWaves/Z $("root:"+folder2+":res3")
107       
108//      Duplicate/O tmp_q $("root:"+folder2+":"+folder2+"_q")
109//      Duplicate/O tmp_i $("root:"+folder2+":"+folder2+"_i")
110//      Duplicate/O tmp_s $("root:"+folder2+":"+folder2+"_s")
111//      Duplicate/O tmp_res0 $("root:"+folder2+":res0")
112//      Duplicate/O tmp_res1 $("root:"+folder2+":res1")
113//      Duplicate/O tmp_res2 $("root:"+folder2+":res2")
114//      Duplicate/O tmp_res3 $("root:"+folder2+":res3")
115
116//      KillWaves/Z tmp_q,tmp_i,tmp_s,tmp_res0,tmp_res1,tmp_res2,tmp_res3       
117       
118        SetDataFolder root:
119       
120        return(0)               
121End
122
123// TODO:
124// see Auto_Sort() in the SANS Automation ipf for the rest of the details of
125// how to combine the resolution waves (they also need to be concatenated, which is currently not done.
126//
127Function V_TmpSort1D(folderStr)
128        String folderStr
129       
130        SetDataFolder $("root:Packages:NIST:VSANS:"+folderStr)
131
132        Wave qw = tmp_q
133        Wave iw = tmp_i
134        Wave sw = tmp_s
135       
136//      Sort qw, qw,iw,sw,res0,res1,res2,res3
137
138        Sort qw, qw,iw,sw
139
140
141        SetDataFolder root:
142        return(0)
143End
144
145
146// trims the beamstop out (based on shadow)
147// trims num from the highQ end
148// splits the res wave into individual waves in anticipation of concatenation
149//
150Function V_Trim1DData(folderStr,nEnd)
151        String folderStr
152        Variable nEnd
153
154        if(DataFolderExists("root:"+folderStr)  == 0)
155                return(0)
156        endif
157               
158        SetDataFolder $("root:"+folderStr)
159       
160        Wave qw = $(folderStr + "_q")
161        Wave iw = $(folderStr + "_i")
162        Wave sw = $(folderStr + "_s")
163        Wave res = $(folderStr + "_res")
164       
165        variable num,ii
166       
167        num=numpnts(qw)
168        //Break out resolution wave into separate waves
169        Make/O/D/N=(num) res0 = res[p][0]               // sigQ
170        Make/O/D/N=(num) res1 = res[p][1]               // qBar
171        Make/O/D/N=(num) res2 = res[p][2]               // fshad
172        Make/O/D/N=(num) res3 = res[p][3]               // qvals
173       
174        // trim off the last nEnd points from everything
175        DeletePoints num-nEnd,nEnd, qw,iw,sw,res0,res1,res2,res3
176       
177        // delete all points where the shadow is < 0.98
178        num=numpnts(qw)
179        for(ii=0;ii<num;ii+=1)
180                if(res2[ii] < 0.98)
181                        DeletePoints ii,1, qw,iw,sw,res0,res1,res2,res3
182                        num -= 1
183                        ii -= 1
184                endif
185        endfor
186       
187////Put resolution contents back???
188//              reswave[][0] = res0[p]
189//              reswave[][1] = res1[p]
190//              reswave[][2] = res2[p]
191//              reswave[][3] = res3[p]
192//             
193                       
194        SetDataFolder root:
195        return(0)
196end
197
198
199// TODO:
200// -- this is a temporary solution before a real writer is created
201// -- resolution is not handled here (and it shouldn't be) since resolution is not known yet.
202//
203//
204// this will bypass save dialogs
205// -- AND WILL OVERWITE DATA WITH THE SAME NAME
206//
207Function V_Write1DData(folderStr,delim,term)
208        String folderStr,delim,term
209       
210        String formatStr="",fullpath=""
211        Variable refnum,dialog=1
212       
213        String dataSetFolderParent,basestr
214       
215        //Abuse ParseFilePath to get path without folder name
216        dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
217        //Abuse ParseFilePath to get basestr
218        basestr = ParseFilePath(0,folderStr,":",1,0)
219       
220        //make sure the waves exist
221        SetDataFolder $(dataSetFolderParent+basestr)
222        WAVE/Z qw = $(baseStr+"_q")
223        WAVE/Z iw = $(baseStr+"_i")
224        WAVE/Z sw = $(baseStr+"_s")
225        WAVE/Z resw = $(baseStr+"_res")
226       
227        if(WaveExists(qw) == 0)
228                Abort "q is missing"
229        endif
230        if(WaveExists(iw) == 0)
231                Abort "i is missing"
232        endif
233        if(WaveExists(sw) == 0)
234                Abort "s is missing"
235        endif
236        if(WaveExists(resw) == 0)
237                Abort "Resolution information is missing."
238        endif
239       
240        Duplicate/O qw qbar,sigQ,fs
241        if(dimsize(resW,1) > 4)
242                //it's USANS put -dQv back in the last 3 columns
243                NVAR/Z dQv = USANS_dQv
244                if(NVAR_Exists(dQv) == 0)
245                        SetDataFolder root:
246                        Abort "It's USANS data, and I don't know what the slit height is."
247                endif
248                sigQ = -dQv
249                qbar = -dQv
250                fs = -dQv
251        else
252                //it's SANS
253                sigQ = resw[p][0]
254                qbar = resw[p][1]
255                fs = resw[p][2]
256        endif
257       
258        PathInfo catPathName
259        fullPath = S_Path + folderStr
260
261        Open refnum as fullpath
262
263        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
264        formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
265        fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
266
267        wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
268        Close refnum
269       
270        KillWaves/Z sigQ,qbar,fs
271       
272        SetDataFolder root:
273        return(0)
274End
Note: See TracBrowser for help on using the repository browser.