source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Write_VSANS_QIS.ipf @ 1074

Last change on this file since 1074 was 1073, checked in by srkline, 5 years ago

lots of changes here:
many little fixes to clean up TODO items and marke them DONE

changed the handling of the panel "gap" to split the gap evenly. Q-calculations have been re-verified with this change.

re-named the list of "bin Type" values, and added a few more choices. Streamlined how the averaging and plotting works with this list so that it can be more easily modified as different combinations of binning are envisioned. This resulted in a lot of excess code being cut out and replaced with cleaner logic. This change has also been verified to work as intended.

Attenuation is now always calculated from the table. The table also by (NEW) definition has values for the white beam (one waelength) and graphite (multiple possible wavelengths) where the wavelengths are artificially scaled (*1000) or *1e6) so that the interpolations can be done internally without the need for multiple attenuator tables.

File size: 9.4 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5
6// TODO:
7// -- this is a temporary solution before a real writer is created
8// -- resolution is not generated here (and it shouldn't be) since resolution is not known yet.
9// -- but a real writer will need to be aware of resolution, and there may be different forms
10//
11// this will bypass save dialogs
12// -- AND WILL OVERWITE DATA WITH THE SAME NAME
13//
14Function V_Write1DData(pathStr,folderStr,saveName)
15        String pathStr,folderStr,saveName
16       
17        String formatStr="",fullpath=""
18        Variable refnum,dialog=1
19
20        SetDataFolder $(pathStr+folderStr)
21
22        Wave qw = tmp_q
23        Wave iw = tmp_i
24        Wave sw = tmp_s
25        Wave sigQ = tmp_sq
26        Wave qbar = tmp_qb
27        Wave fs = tmp_fs
28       
29        String dataSetFolderParent,basestr
30       
31        // ParseFilePath to get path without folder name
32//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
33        // ParseFilePath to get basestr
34//      basestr = ParseFilePath(0,folderStr,":",1,0)
35       
36        SVAR gProtoStr = root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
37        Wave/T proto=$("root:Packages:NIST:VSANS:Globals:Protocols:"+gProtoStr)
38       
39       
40        //make sure the waves exist
41       
42        if(WaveExists(qw) == 0)
43                Abort "q is missing"
44        endif
45        if(WaveExists(iw) == 0)
46                Abort "i is missing"
47        endif
48        if(WaveExists(sw) == 0)
49                Abort "s is missing"
50        endif
51        if(WaveExists(sigQ) == 0)
52                Abort "Resolution information is missing."
53        endif
54        if(WaveExists(proto) == 0)
55                Abort "protocol information is missing."
56        endif
57       
58//      Duplicate/O qw qbar,sigQ,fs
59//      if(dimsize(resW,1) > 4)
60//              //it's USANS put -dQv back in the last 3 columns
61//              NVAR/Z dQv = USANS_dQv
62//              if(NVAR_Exists(dQv) == 0)
63//                      SetDataFolder root:
64//                      Abort "It's USANS data, and I don't know what the slit height is."
65//              endif
66//              sigQ = -dQv
67//              qbar = -dQv
68//              fs = -dQv
69//      else
70//              //it's SANS
71//              sigQ = resw[p][0]
72//              qbar = resw[p][1]
73//              fs = resw[p][2]
74//      endif
75//     
76
77// TODO -- not sure if I need to implement this. Update to VSANS specs if I do.
78//      //strings can be too long to print-- must trim to 255 chars
79//      Variable ii,num=8
80//      Make/O/T/N=(num) tempShortProto
81//      for(ii=0;ii<num;ii+=1)
82//              tempShortProto[ii] = (proto[ii])[0,240]
83//      endfor
84
85// if the "default" trimming is used, the proto[] values will be null
86// fill them in with the default values
87        String protoStr7,protoStr8
88        if(strlen(proto[7]) == 0)
89                protoStr7 = "(Default) "+ ksBinTrimBegDefault
90        else
91                protoStr7 = proto[7]
92        endif
93        if(strlen(proto[8]) == 0)
94                protoStr8 = "(Default) "+ ksBinTrimEndDefault
95        else
96                protoStr8 = proto[8]
97        endif   
98
99        PathInfo catPathName
100        fullPath = S_Path + saveName
101
102        Open refnum as fullpath
103
104        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
105
106        //insert protocol information here
107        //-1 list of sample files
108        //0 - bkg
109        //1 - emp
110        //2 - div
111        //3 - mask
112        //4 - abs params c2-c5
113        //5 - average params
114        //6 - DRK (unused in VSANS)
115        //7 - beginning trim points
116        //8 - end trim points
117//      fprintf refnum, "SAM: %s\r\n",samFiles
118        fprintf refnum, "BGD: %s\r\n",proto[0]
119        fprintf refnum, "EMP: %s\r\n",Proto[1]
120        fprintf refnum, "DIV: %s\r\n",Proto[2]
121        fprintf refnum, "MASK: %s\r\n",Proto[3]
122        fprintf refnum, "ABS Parameters (3-6): %s\r\n",Proto[4]
123        fprintf refnum, "Average Choices: %s\r\n",Proto[5]
124        fprintf refnum, "Beginning Trim Points: %s\r\n",ProtoStr7
125        fprintf refnum, "End Trim Points: %s\r\n",ProtoStr8
126
127// TODO
128// x- make this work for 6-columns (or??)
129        formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
130        fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
131        wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
132
133        // three column vresion
134//      formatStr = "%15.4g %15.4g %15.4g\r\n" 
135//      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
136//
137//      wfprintf refnum,formatStr,qw,iw,sw
138
139
140        Close refnum
141       
142//      KillWaves/Z sigQ,qbar,fs
143        Print "Data written to: ",fullpath
144       
145        SetDataFolder root:
146        return(0)
147End
148
149
150
151// TODO:
152// -- this is a temporary solution before a real writer is created
153// -- resolution is not generated here (and it shouldn't be) since resolution is not known yet.
154// -- but a real writer will need to be aware of resolution, and there may be different forms
155//
156// This saves the data in Igor Text format, an ASCII format, but NOT standard SANS columns
157// No concatenation is done. This is meant to be used for input to TRIM, or for general troubleshooting
158//
159//
160// this will bypass save dialogs
161// -- AND WILL OVERWRITE DATA WITH THE SAME NAME
162//
163Function V_Write1DData_ITX(pathStr,folderStr,saveName,binType)
164        String pathStr,folderStr,saveName
165        Variable binType
166       
167        String formatStr="",fullpath=""
168        Variable refnum,dialog=1
169
170        SetDataFolder $(pathStr+folderStr)
171
172
173        //TODO
174        //-- make sure the waves exist
175       
176//      if(WaveExists(qw) == 0)
177//              Abort "q is missing"
178//      endif
179//      if(WaveExists(iw) == 0)
180//              Abort "i is missing"
181//      endif
182//      if(WaveExists(sw) == 0)
183//              Abort "s is missing"
184//      endif
185//      if(WaveExists(resw) == 0)
186//              Abort "Resolution information is missing."
187//      endif
188       
189//      Duplicate/O qw qbar,sigQ,fs
190//      if(dimsize(resW,1) > 4)
191//              //it's USANS put -dQv back in the last 3 columns
192//              NVAR/Z dQv = USANS_dQv
193//              if(NVAR_Exists(dQv) == 0)
194//                      SetDataFolder root:
195//                      Abort "It's USANS data, and I don't know what the slit height is."
196//              endif
197//              sigQ = -dQv
198//              qbar = -dQv
199//              fs = -dQv
200//      else
201//              //it's SANS
202//              sigQ = resw[p][0]
203//              qbar = resw[p][1]
204//              fs = resw[p][2]
205//      endif
206//     
207
208
209
210        // TODO:
211        // -- currently I'm using the Save comand and the /B flag
212        //    to save the data as Igor Text format, since otherwise the command string would be
213        //    too long. Need to come up with an Igor-demo friendly save here
214        //
215        // -- see V_ExportProtocol() for a quick example of how to generate the .ITX format
216        //
217        // -- need a reader/plotter capable of handling this data. The regular data loader won't handle
218        //    all the different number of columns present, or the ITX format. See V_DataPlotting and duplicate these routines
219        //    Most of these routines take "winNameStr" as an argument, so I may be able to use them
220        //
221        // -- do I want to add the /O flag to force an overwrite if there is a name conflict?
222
223        PathInfo catPathName
224        fullPath = S_Path + saveName + ".itx"
225
226//      Open refnum as fullpath
227//      fprintf refnum,"Individual data sets written from folder %s on %s\r\n",folderStr,(date()+" "+time())
228
229        String waveStr=""
230        // can be a multiple number of columns
231               
232        switch(binType)
233                case 1:         // 9 sets = 27 waves!
234                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
235                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
236                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
237                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
238                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
239                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
240                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
241                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
242                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
243                       
244                       
245                        Save/T/M="\r\n"/B waveStr as fullPath
246
247                                               
248//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
249//                     
250//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
251//     
252//                      wfprintf refnum,formatStr,qw,iw,sw
253                        break
254                case 2:         // 5 sets
255
256                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
257                        waveStr += "qBin_qxqy_MLR;iBin_qxqy_MLR;eBin_qxqy_MLR;qBin_qxqy_MTB;iBin_qxqy_MTB;eBin_qxqy_MTB;"
258                        waveStr += "qBin_qxqy_FLR;iBin_qxqy_FLR;eBin_qxqy_FLR;qBin_qxqy_FTB;iBin_qxqy_FTB;eBin_qxqy_FTB;"
259
260                        Save/T/M="\r\n"/B waveStr as fullPath
261                       
262//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
263//                     
264//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
265//     
266//                      wfprintf refnum,formatStr,qw,iw,sw
267                        break
268                case 3:         // 3 sets
269//                      WAVE q1 = qBin_qxqy_B
270//                      WAVE i1 = iBin_qxqy_B
271//                      WAVE s1 = eBin_qxqy_B
272//                      WAVE q2 = qBin_qxqy_MLRTB
273//                      WAVE i2 = iBin_qxqy_MLRTB
274//                      WAVE s2 = eBin_qxqy_MLRTB
275//                      WAVE q3 = qBin_qxqy_FLRTB
276//                      WAVE i3 = iBin_qxqy_FLRTB
277//                      WAVE s3 = eBin_qxqy_FLRTB
278//
279//                             
280//                      Save/T/M="\r\n" q1,i1,s1,q2,i2,s2,q3,i3,s3 as fullPath
281                       
282                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
283                        waveStr += "qBin_qxqy_MLRTB;iBin_qxqy_MLRTB;eBin_qxqy_MLRTB;qBin_qxqy_FLRTB;iBin_qxqy_FLRTB;eBin_qxqy_FLRTB;"
284
285                        Save/T/M="\r\n"/B waveStr as fullPath                   
286                       
287                       
288//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
289//                     
290//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
291//     
292//                      wfprintf refnum,formatStr,qw,iw,sw
293                        break
294                case 4:         // 9 sets
295                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
296                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
297                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
298                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
299                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
300                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
301                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
302                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
303                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
304                       
305                       
306                        Save/T/M="\r\n"/B waveStr as fullPath
307
308//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
309//                     
310//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
311//     
312//                      wfprintf refnum,formatStr,qw,iw,sw
313                        break
314                                       
315                default:
316                // do nothing, just close
317
318        endswitch
319
320//      Close refnum
321
322// TODO
323// -- clean up any waves on exit?        Only if I generate extra waves
324//      KillWaves/Z sigQ,qbar,fs
325       
326        SetDataFolder root:
327        return(0)
328End
329
Note: See TracBrowser for help on using the repository browser.