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

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

added procedures to compare files to see if they are from the same configuration, same wavelength, etc. so they can be properly chosen for transmission files, scattering files, and properly identified for the different resolution conditions.

Re-worked the logic of dispatching averaging, plotting, and saving in Execute_Protocol. Hopefully this will alow for easier dispatching for future conditions, including getting the correct resolution calculation.

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