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

Last change on this file since 1239 was 1239, checked in by srkline, 3 years ago

adding downstream window transmission correction -- added function to detector corrections, and added item to preference panel. Transmission value is currently set as a global since the value is not part of the VSANS header. Global value defaults to T=1= no correction.

Other changes are cleanup of TODO items that were already done and tested. inline commnents have been updated.

File size: 24.6 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5//
6// this is the general writer for output of 1D averaged I(q) datasets
7//
8Function V_Write1DData(pathStr,folderStr,saveName)
9        String pathStr,folderStr,saveName
10       
11        String formatStr="",fullpath=""
12        Variable refnum,dialog=1
13
14        SetDataFolder $(pathStr+folderStr)
15
16        Wave qw = tmp_q
17        Wave iw = tmp_i
18        Wave sw = tmp_s
19        Wave sigQ = tmp_sq
20        Wave qbar = tmp_qb
21        Wave fs = tmp_fs
22       
23        String dataSetFolderParent,basestr
24       
25        // ParseFilePath to get path without folder name
26//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
27        // ParseFilePath to get basestr
28//      basestr = ParseFilePath(0,folderStr,":",1,0)
29       
30        SVAR gProtoStr = root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
31        Wave/T proto=$("root:Packages:NIST:VSANS:Globals:Protocols:"+gProtoStr)
32       
33        SVAR samFiles = root:Packages:NIST:VSANS:Globals:Protocols:gSAM
34       
35        //make sure the waves exist
36       
37        if(WaveExists(qw) == 0)
38                Abort "q is missing"
39        endif
40        if(WaveExists(iw) == 0)
41                Abort "i is missing"
42        endif
43        if(WaveExists(sw) == 0)
44                Abort "s is missing"
45        endif
46        if(WaveExists(sigQ) == 0)
47                Abort "Resolution information is missing."
48        endif
49        if(WaveExists(proto) == 0)
50                Abort "protocol information is missing."
51        endif
52       
53//      Duplicate/O qw qbar,sigQ,fs
54//      if(dimsize(resW,1) > 4)
55//              //it's USANS put -dQv back in the last 3 columns
56//              NVAR/Z dQv = USANS_dQv
57//              if(NVAR_Exists(dQv) == 0)
58//                      SetDataFolder root:
59//                      Abort "It's USANS data, and I don't know what the slit height is."
60//              endif
61//              sigQ = -dQv
62//              qbar = -dQv
63//              fs = -dQv
64//      else
65//              //it's SANS
66//              sigQ = resw[p][0]
67//              qbar = resw[p][1]
68//              fs = resw[p][2]
69//      endif
70//     
71
72// TODO -- not sure if I need to implement this. Update to VSANS specs if I do.
73//      //strings can be too long to print-- must trim to 255 chars
74//      Variable ii,num=8
75//      Make/O/T/N=(num) tempShortProto
76//      for(ii=0;ii<num;ii+=1)
77//              tempShortProto[ii] = (proto[ii])[0,240]
78//      endfor
79
80// if the "default" trimming is used, the proto[] values will be null
81// fill them in with the default values
82        String protoStr7,protoStr8
83        if(strlen(proto[7]) == 0)
84                protoStr7 = "(Default) "+ ksBinTrimBegDefault
85        else
86                protoStr7 = proto[7]
87        endif
88        if(strlen(proto[8]) == 0)
89                protoStr8 = "(Default) "+ ksBinTrimEndDefault
90        else
91                protoStr8 = proto[8]
92        endif   
93
94        PathInfo catPathName
95        fullPath = S_Path + saveName
96
97        Open refnum as fullpath
98
99        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
100
101        //insert protocol information here
102        //-1 list of sample files
103        //0 - bkg
104        //1 - emp
105        //2 - div
106        //3 - mask
107        //4 - abs params c2-c5
108        //5 - average params
109        //6 - DRK (unused in VSANS)
110        //7 - beginning trim points
111        //8 - end trim points
112        fprintf refnum, "SAM: %s\r\n",samFiles
113        fprintf refnum, "BGD: %s\r\n",proto[0]
114        fprintf refnum, "EMP: %s\r\n",Proto[1]
115        fprintf refnum, "DIV: %s\r\n",Proto[2]
116        fprintf refnum, "MASK: %s\r\n",Proto[3]
117        fprintf refnum, "ABS Parameters (3-6): %s\r\n",Proto[4]
118        fprintf refnum, "Average Choices: %s\r\n",Proto[5]
119        fprintf refnum, "Beginning Trim Points: %s\r\n",ProtoStr7
120        fprintf refnum, "End Trim Points: %s\r\n",ProtoStr8
121        fprintf refnum, "COLLIMATION=%s\r\n",proto[9]
122
123// DONE
124// x- make this work for 6-columns (or??)
125        formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"     
126        fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"       
127        wfprintf refnum,formatStr,qw,iw,sw,sigQ,qbar,fs
128
129        // three column vresion
130//      formatStr = "%15.4g %15.4g %15.4g\r\n" 
131//      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
132//
133//      wfprintf refnum,formatStr,qw,iw,sw
134
135
136        Close refnum
137       
138//      KillWaves/Z sigQ,qbar,fs
139        Print "Data written to: ",fullpath
140       
141        SetDataFolder root:
142        return(0)
143End
144
145
146//
147// this is the general writer for output of 1D averaged I(q) datasets
148// this version is limited to three column data where there is no
149// resolution information present
150//
151Function V_Write1DData_3Col(pathStr,folderStr,saveName)
152        String pathStr,folderStr,saveName
153       
154        String formatStr="",fullpath=""
155        Variable refnum,dialog=1
156
157        SetDataFolder $(pathStr+folderStr)
158
159        Wave qw = tmp_q
160        Wave iw = tmp_i
161        Wave sw = tmp_s
162//      Wave sigQ = tmp_sq
163//      Wave qbar = tmp_qb
164//      Wave fs = tmp_fs
165       
166        String dataSetFolderParent,basestr
167       
168        // ParseFilePath to get path without folder name
169//      dataSetFolderParent = ParseFilePath(1,folderStr,":",1,0)
170        // ParseFilePath to get basestr
171//      basestr = ParseFilePath(0,folderStr,":",1,0)
172       
173        SVAR gProtoStr = root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
174        Wave/T proto=$("root:Packages:NIST:VSANS:Globals:Protocols:"+gProtoStr)
175       
176        SVAR samFiles = root:Packages:NIST:VSANS:Globals:Protocols:gSAM
177       
178        //make sure the waves exist
179       
180        if(WaveExists(qw) == 0)
181                Abort "q is missing"
182        endif
183        if(WaveExists(iw) == 0)
184                Abort "i is missing"
185        endif
186        if(WaveExists(sw) == 0)
187                Abort "s is missing"
188        endif
189//      if(WaveExists(sigQ) == 0)
190//              Abort "Resolution information is missing."
191//      endif
192        if(WaveExists(proto) == 0)
193                Abort "protocol information is missing."
194        endif
195
196
197// if the "default" trimming is used, the proto[] values will be null
198// fill them in with the default values
199        String protoStr7,protoStr8
200        if(strlen(proto[7]) == 0)
201                protoStr7 = "(Default) "+ ksBinTrimBegDefault
202        else
203                protoStr7 = proto[7]
204        endif
205        if(strlen(proto[8]) == 0)
206                protoStr8 = "(Default) "+ ksBinTrimEndDefault
207        else
208                protoStr8 = proto[8]
209        endif   
210
211        PathInfo catPathName
212        fullPath = S_Path + saveName
213
214        Open refnum as fullpath
215
216        fprintf refnum,"Combined data written from folder %s on %s\r\n",folderStr,(date()+" "+time())
217
218        //insert protocol information here
219        //-1 list of sample files
220        //0 - bkg
221        //1 - emp
222        //2 - div
223        //3 - mask
224        //4 - abs params c2-c5
225        //5 - average params
226        //6 - DRK (unused in VSANS)
227        //7 - beginning trim points
228        //8 - end trim points
229        fprintf refnum, "SAM: %s\r\n",samFiles
230        fprintf refnum, "BGD: %s\r\n",proto[0]
231        fprintf refnum, "EMP: %s\r\n",Proto[1]
232        fprintf refnum, "DIV: %s\r\n",Proto[2]
233        fprintf refnum, "MASK: %s\r\n",Proto[3]
234        fprintf refnum, "ABS Parameters (3-6): %s\r\n",Proto[4]
235        fprintf refnum, "Average Choices: %s\r\n",Proto[5]
236        fprintf refnum, "Beginning Trim Points: %s\r\n",ProtoStr7
237        fprintf refnum, "End Trim Points: %s\r\n",ProtoStr8
238        fprintf refnum, "COLLIMATION=%s\r\n",proto[9]
239
240
241        // three column version
242        formatStr = "%15.4g %15.4g %15.4g\r\n" 
243        fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
244//
245        wfprintf refnum,formatStr,qw,iw,sw
246
247        Close refnum
248       
249//      KillWaves/Z sigQ,qbar,fs
250        Print "Data written to: ",fullpath
251       
252        SetDataFolder root:
253        return(0)
254End
255
256
257//
258// This saves the data in individual files for each detector panel. They are meant only for
259// troubleshooting, but the files are in the general ascii format (without resolution)
260// so only three columns are written out
261//
262// this will bypass save dialogs
263// -- AND WILL OVERWRITE DATA WITH THE SAME NAME
264//
265Function V_Write1DData_Individual(pathStr,folderStr,saveName,exten,binType)
266        String pathStr,folderStr,saveName,exten
267        Variable binType
268       
269        String formatStr="",fullpath="",item,fileName,detList
270        Variable refnum,num,ii
271
272        SetDataFolder $(pathStr+folderStr)
273
274        NVAR gIgnoreB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
275
276        // while in the proper data folder, loop through the detector files
277        // and write out each individual panel (or sets of panels) as specified
278        // by the binning type.
279        //
280        // copy the desired files over to tmp_q, tmp_i, and tmp_s, then
281        // pass to a worker Function
282        //
283       
284        //
285        //  ksBinType1 = "FT;FB;FL;FR;MT;MB;ML;MR;B;"           //these are the "active" extensions
286        //  ksBinType2 = "FTB;FLR;MTB;MLR;B;"
287        //  ksBinType3 = "FLRTB;MLRTB;B;"
288        //  ksBinType4 = "FL;FR;ML;MR;B;"               //in SLIT mode, disregard the T/B panels
289       
290       
291        switch(binType)
292                case 1:         // 9 sets
293                        detList = ksBinType1
294                        break
295                case 2:         // 5 sets
296                        detList = ksBinType2
297                        break
298                case 3:         // 3 sets
299                        detList = ksBinType3
300                        break
301                case 4:         // 5 sets
302                        detList = ksBinType4
303                        break
304                case 5:         // 4 sets
305                        detList = ksBinType5
306                        break
307                case 6:         // 3 sets
308                        detList = ksBinType6
309                        break
310                case 7:         // 4 sets
311                        detList = ksBinType7
312                        break
313                                                               
314                default:
315                // do nothing, just close
316
317        endswitch
318
319        num=ItemsInList(detList)
320        for(ii=0;ii<num;ii+=1)
321                SetDataFolder $(pathStr+folderStr)
322
323                item=StringFromList(ii, detList)
324               
325                if(gIgnoreB && cmpstr(item,"B") == 0)
326                        //do nothing
327                else
328                        fileName = saveName + "_"+item+"."+exten
329                        Wave qWave = $("qBin_qxqy_"+item)
330                        Wave iWave = $("iBin_qxqy_"+item)
331                        Wave eWave = $("eBin_qxqy_"+item)
332                        KillWaves/Z tmp_q, tmp_i, tmp_s
333                        Duplicate/O qWave tmp_q
334                        Duplicate/O iWave tmp_i
335                        Duplicate/O eWave tmp_s
336                        V_Write1DData_3Col(pathStr,folderStr,fileName)
337                endif
338               
339        endfor
340       
341        SetDataFolder root:
342        return(0)
343End
344
345
346
347
348
349// DONE:
350// - this is a temporary solution before a real writer is created
351// -- it has been replaced with V_Write1DData_Individual
352// - resolution is not generated here (and it shouldn't be) since resolution is not known yet.
353// - but a real writer will need to be aware of resolution, and there may be different forms
354//
355// This saves the data in Igor Text format, an ASCII format, but NOT standard SANS columns
356// No concatenation is done. This is meant to be used for input to TRIM, or for general troubleshooting
357//
358//
359// this will bypass save dialogs
360// -- AND WILL OVERWRITE DATA WITH THE SAME NAME
361//
362Function V_Write1DData_ITX(pathStr,folderStr,saveName,binType)
363        String pathStr,folderStr,saveName
364        Variable binType
365       
366        String formatStr="",fullpath=""
367        Variable refnum,dialog=1
368
369        SetDataFolder $(pathStr+folderStr)
370
371
372        //TODO
373        //-- make sure the waves exist
374       
375//      if(WaveExists(qw) == 0)
376//              Abort "q is missing"
377//      endif
378//      if(WaveExists(iw) == 0)
379//              Abort "i is missing"
380//      endif
381//      if(WaveExists(sw) == 0)
382//              Abort "s is missing"
383//      endif
384//      if(WaveExists(resw) == 0)
385//              Abort "Resolution information is missing."
386//      endif
387       
388//      Duplicate/O qw qbar,sigQ,fs
389//      if(dimsize(resW,1) > 4)
390//              //it's USANS put -dQv back in the last 3 columns
391//              NVAR/Z dQv = USANS_dQv
392//              if(NVAR_Exists(dQv) == 0)
393//                      SetDataFolder root:
394//                      Abort "It's USANS data, and I don't know what the slit height is."
395//              endif
396//              sigQ = -dQv
397//              qbar = -dQv
398//              fs = -dQv
399//      else
400//              //it's SANS
401//              sigQ = resw[p][0]
402//              qbar = resw[p][1]
403//              fs = resw[p][2]
404//      endif
405//     
406
407
408
409        // TODO:
410        // -- currently I'm using the Save comand and the /B flag
411        //    to save the data as Igor Text format, since otherwise the command string would be
412        //    too long. Need to come up with an Igor-demo friendly save here
413        //
414        // -- see V_ExportProtocol() for a quick example of how to generate the .ITX format
415        //
416        // -- need a reader/plotter capable of handling this data. The regular data loader won't handle
417        //    all the different number of columns present, or the ITX format. See V_DataPlotting and duplicate these routines
418        //    Most of these routines take "winNameStr" as an argument, so I may be able to use them
419        //
420        // -- do I want to add the /O flag to force an overwrite if there is a name conflict?
421
422        PathInfo catPathName
423        fullPath = S_Path + saveName + ".itx"
424
425//      Open refnum as fullpath
426//      fprintf refnum,"Individual data sets written from folder %s on %s\r\n",folderStr,(date()+" "+time())
427
428        String waveStr=""
429        // can be a multiple number of columns
430               
431        switch(binType)
432                case 1:         // 9 sets = 27 waves!
433                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
434                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
435                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
436                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
437                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
438                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
439                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
440                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
441                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
442                       
443                       
444                        Save/T/M="\r\n"/B waveStr as fullPath
445
446                                               
447//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
448//                     
449//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
450//     
451//                      wfprintf refnum,formatStr,qw,iw,sw
452                        break
453                case 2:         // 5 sets
454
455                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
456                        waveStr += "qBin_qxqy_MLR;iBin_qxqy_MLR;eBin_qxqy_MLR;qBin_qxqy_MTB;iBin_qxqy_MTB;eBin_qxqy_MTB;"
457                        waveStr += "qBin_qxqy_FLR;iBin_qxqy_FLR;eBin_qxqy_FLR;qBin_qxqy_FTB;iBin_qxqy_FTB;eBin_qxqy_FTB;"
458
459                        Save/T/M="\r\n"/B waveStr as fullPath
460                       
461//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
462//                     
463//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
464//     
465//                      wfprintf refnum,formatStr,qw,iw,sw
466                        break
467                case 3:         // 3 sets
468//                      WAVE q1 = qBin_qxqy_B
469//                      WAVE i1 = iBin_qxqy_B
470//                      WAVE s1 = eBin_qxqy_B
471//                      WAVE q2 = qBin_qxqy_MLRTB
472//                      WAVE i2 = iBin_qxqy_MLRTB
473//                      WAVE s2 = eBin_qxqy_MLRTB
474//                      WAVE q3 = qBin_qxqy_FLRTB
475//                      WAVE i3 = iBin_qxqy_FLRTB
476//                      WAVE s3 = eBin_qxqy_FLRTB
477//
478//                             
479//                      Save/T/M="\r\n" q1,i1,s1,q2,i2,s2,q3,i3,s3 as fullPath
480                       
481                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
482                        waveStr += "qBin_qxqy_MLRTB;iBin_qxqy_MLRTB;eBin_qxqy_MLRTB;qBin_qxqy_FLRTB;iBin_qxqy_FLRTB;eBin_qxqy_FLRTB;"
483
484                        Save/T/M="\r\n"/B waveStr as fullPath                   
485                       
486                       
487//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
488//                     
489//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
490//     
491//                      wfprintf refnum,formatStr,qw,iw,sw
492                        break
493                case 4:         // 9 sets
494                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
495                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
496                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
497                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
498                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
499                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
500                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
501                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
502                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
503                       
504                       
505                        Save/T/M="\r\n"/B waveStr as fullPath
506
507//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
508//                     
509//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
510//     
511//                      wfprintf refnum,formatStr,qw,iw,sw
512                        break
513                                       
514                default:
515                // do nothing, just close
516
517        endswitch
518
519//      Close refnum
520
521// TODO
522// -- clean up any waves on exit?        Only if I generate extra waves
523//      KillWaves/Z sigQ,qbar,fs
524       
525        SetDataFolder root:
526        return(0)
527End
528
529// awkward, but can't call STRUCT from Proc
530Proc Vm_Write1DData_ITX()
531        Vf_FakeSaveIQITXClick()
532End
533
534Function Vf_FakeSaveIQITXClick()
535        STRUCT WMButtonAction ba
536        ba.eventCode=2
537        V_SaveIQ_ButtonProc(ba)
538end
539
540
541///////// QxQy Export  //////////
542//
543// (see the similar-named SANS routine for additonal steps - like resolution, etc.)
544//ASCII export of data as 8-columns qx-qy-Intensity-err-qz-sigmaQ_parall-sigmaQ_perp-fShad
545// + limited header information
546//
547//      Jan 2019 -- first version, simply exports the basic matrix of data with no resolution information
548//
549//
550Function V_QxQy_Export(type,fullpath,newFileName,dialog)
551        String type,fullpath,newFileName
552        Variable dialog         //=1 will present dialog for name
553       
554        String typeStr=""
555        Variable refnum
556        String detStr="",detSavePath
557
558        SVAR gProtoStr = root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
559       
560        // declare, or make a fake protocol if needed (if the export type is RAW)
561        String rawTag=""
562        if(cmpstr(type,"RAW")==0)
563                Make/O/T/N=(kNumProtocolSteps) proto
564                RawTag = "RAW Data File: "     
565        else
566                Wave/T proto=$("root:Packages:NIST:VSANS:Globals:Protocols:"+gProtoStr)
567        endif
568       
569        SVAR samFiles = $("root:Packages:NIST:VSANS:"+type+":gFileList")
570       
571        //check each wave - MUST exist, or will cause a crash
572//      If(!(WaveExists(data)))
573//              Abort "data DNExist QxQy_Export()"
574//      Endif
575
576        if(dialog)
577                PathInfo/S catPathName
578                fullPath = DoSaveFileDialog("Save data as")
579                If(cmpstr(fullPath,"")==0)
580                        //user cancel, don't write out a file
581                        Close/A
582                        Abort "no data file was written"
583                Endif
584                //Print "dialog fullpath = ",fullpath
585        Endif
586
587        // data values to populate the file header
588        String fileName,fileDate,fileLabel
589        Variable monCt,lambda,offset,dist,trans,thick
590        Variable bCentX,bCentY,a2,a1a2_dist,deltaLam,bstop
591        String a1Str
592        Variable pixX,pixY
593        Variable numTextLines,ii,jj,kk
594        Variable pixSizeX,pixSizeY
595        Variable duration
596
597        numTextLines = 30
598        Make/O/T/N=(numTextLines) labelWave
599
600        //
601       
602        //loop over all of the detector panels
603        NVAR gIgnoreDetB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
604
605        String detList
606        if(gIgnoreDetB)
607                detList = ksDetectorListNoB
608        else
609                detList = ksDetectorListAll
610        endif
611       
612        for(kk=0;kk<ItemsInList(detList);kk+=1)
613
614                detStr = StringFromList(kk, detList, ";")
615                detSavePath = fullPath + "_" + detStr + ".DAT"
616               
617                pixX = V_getDet_pixel_num_x(type,detStr)
618                pixY = V_getDet_pixel_num_y(type,detStr)
619               
620                fileName = newFileName
621                fileDate = V_getDataStartTime(type)             // already a string
622                fileLabel = V_getSampleDescription(type)
623               
624                monCt = V_getBeamMonNormData(type)
625                lambda = V_getWavelength(type)
626       
627        // TODO - switch based on panel type
628        //      V_getDet_LateralOffset(fname,detStr)
629        //      V_getDet_VerticalOffset(fname,detStr)
630                offset = V_getDet_LateralOffset(type,detStr)
631       
632                dist = V_getDet_ActualDistance(type,detStr)
633                trans = V_getSampleTransmission(type)
634                thick = V_getSampleThickness(type)
635               
636                bCentX = V_getDet_beam_center_x(type,detStr)
637                bCentY = V_getDet_beam_center_y(type,detStr)
638                a1Str = V_getSourceAp_size(type)                //already a string
639                a2 = V_getSampleAp2_size(type)
640                a1a2_dist = V_getSourceAp_distance(type)
641                deltaLam = V_getWavelength_spread(type)
642                // TODO -- decipher which beamstop, if any is actually in place
643        // or -- V_getBeamStopC3_size(type)
644                bstop = V_getBeamStopC2_size(type)
645
646                pixSizeX = V_getDet_x_pixel_size(type,detStr)
647                pixSizeY = V_getDet_y_pixel_size(type,detStr)
648               
649                duration = V_getCount_time(type)
650               
651        /////////
652                labelWave[0] = "FILE: "+fileName+"   CREATED: "+fileDate
653                labelWave[1] = "LABEL: "+fileLabel
654                labelWave[2] = "MON CNT   LAMBDA (A)  DET_OFF(cm)   DET_DIST(cm)   TRANS   THICK(cm)"
655                labelWave[3] = num2str(monCt)+"  "+num2str(lambda)+"       "+num2str(offset)+"     "+num2str(dist)
656                labelWave[3] += "     "+num2str(trans)+"     "+num2str(thick)
657                labelWave[4] = "BCENT(X,Y)(cm)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)"
658                labelWave[5] = num2str(bCentX)+"  "+num2str(bCentY)+"  "+a1Str+"    "+num2str(a2)+"    "
659                labelWave[5] += num2str(a1a2_dist)+"    "+num2str(deltaLam)+"    "+num2str(bstop)
660                labelWave[6] =  "SAM: "+rawTag+samFiles
661                labelWave[7] =  "BGD: "+proto[0]
662                labelWave[8] =  "EMP: "+proto[1]
663                labelWave[9] =  "DIV: "+proto[2]
664                labelWave[10] =  "MASK: "+proto[3]
665                labelWave[11] =  "ABS Parameters (3-6): "+proto[4]
666                labelWave[12] = "Average Choices: "+proto[5]
667                labelWave[13] = "Collimation type: "+proto[9]
668                labelWave[14] = "Panel="+detStr
669                labelWave[15] = "NumXPixels="+num2str(pixX)
670                labelWave[16] = "XPixelSize_mm="+num2str(pixSizeX)
671                labelWave[17] = "NumYPixels="+num2str(pixY)
672                labelWave[18] = "YPixelSize_mm="+num2str(pixSizeY)
673                labelWave[19] = "Duration (s)="+num2str(duration)
674                labelWave[20] = "reserved for future file definition changes"
675                labelWave[21] = "reserved for future file definition changes"
676                labelWave[22] = "reserved for future file definition changes"
677                labelWave[23] = "reserved for future file definition changes"
678                labelWave[24] = "reserved for future file definition changes"
679                labelWave[25] = "reserved for future file definition changes"
680
681                labelWave[26] = "*** Data written from "+type+" folder and may not be a fully corrected data file ***"
682//              labelWave[20] = "Data columns are Qx - Qy - Qz - I(Qx,Qy) - Err I(Qx,Qy)"
683        //      labelWave[20] = "Data columns are Qx - Qy - I(Qx,Qy) - Qz - SigmaQ_parall - SigmaQ_perp - fSubS(beam stop shadow)"
684                labelWave[27] = "Data columns are Qx - Qy - I(Qx,Qy) - err(I) - Qz - SigmaQ_parall - SigmaQ_perp - fSubS(beam stop shadow) - Mask"
685                labelWave[28] = "The error wave may not be properly propagated (1/2019)"
686                labelWave[29] = "ASCII data created " +date()+" "+time()
687                //strings can be too long to print-- must trim to 255 chars
688                for(jj=0;jj<numTextLines;jj+=1)
689                        labelWave[jj] = (labelWave[jj])[0,240]
690                endfor
691       
692       
693        // get the data waves for output
694        // QxQyQz have already been calculated for VSANS data
695               
696                WAVE data = V_getDetectorDataW(type,detStr)
697                WAVE data_err = V_getDetectorDataErrW(type,detStr)
698
699// JUN 2019 get the mask data           
700                WAVE MaskData = V_getDetectorDataW("MSK",detStr)
701
702               
703                // TOOD - replace hard wired paths with Read functions
704                // hard-wired
705                Wave qx_val = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qx_"+detStr)
706                Wave qy_val = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qy_"+detStr)
707                Wave qz_val = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qz_"+detStr)
708                Wave qTot = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qTot_"+detStr)
709               
710        ///// calculation of the resolution function (2D)
711
712        //
713                Variable acc,ssd,lambda0,yg_d,qstar,g,L1,L2,vz_1,sdd
714                // L1 = source to sample distance [cm]
715                L1 = V_getSourceAp_distance(type)
716       
717        // L2 = sample to detector distance [cm]
718                L2 = V_getDet_ActualDistance(type,detStr)               //cm
719
720        //             
721                G = 981.  //!   ACCELERATION OF GRAVITY, CM/SEC^2
722                vz_1 =  3.956E5 //      3.956E5 //!     CONVERT WAVELENGTH TO VELOCITY CM/SEC
723                acc = vz_1
724                SDD = L2                //1317
725                SSD = L1                //1627          //cm
726                lambda0 = lambda                //              15
727                YG_d = -0.5*G*SDD*(SSD+SDD)*(LAMBDA0/acc)^2
728                Print "DISTANCE BEAM FALLS DUE TO GRAVITY (CM) = ",YG_d
729        ////            Print "Gravity q* = ",-2*pi/lambda0*2*yg_d/sdd
730                qstar = -2*pi/lambda0*2*yg_d/sdd
731        //     
732        //
733        //// the gravity center is not the resolution center
734        //// gravity center = beam center
735        //// resolution center = offset y = dy + (2)*yg_d
736        /////************
737        //// do everything to write out the resolution too
738        //      // un-comment these if you want to write out qz_val and qval too, then use the proper save command
739        //      qval = CalcQval(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10)
740                Duplicate/O qTot,phi,r_dist
741                Variable xctr,yctr
742
743
744                xctr = V_getDet_beam_center_x_pix(type,detStr)
745                yctr = V_getDet_beam_center_y_pix(type,detStr)
746                phi = V_FindPhi( pixSizeX*((p+1)-xctr) , pixSizeY*((q+1)-yctr)+(2)*yg_d)                //(dx,dy+yg_d)
747                r_dist = sqrt(  (pixSizeX*((p+1)-xctr))^2 +  (pixSizeY*((q+1)-yctr)+(2)*yg_d)^2 )               //radial distance from ctr to pt
748       
749                //make everything in 1D now
750                Duplicate/O qTot SigmaQX,SigmaQY,fsubS,qval     
751                Redimension/N=(pixX*pixY) SigmaQX,SigmaQY,fsubS,qval,phi,r_dist
752
753                Variable ret1,ret2,ret3,nq
754                String collimationStr
755               
756               
757                collimationStr = proto[9]
758               
759                nq = pixX*pixY
760                ii=0
761
762// TODO
763// this loop is the slow step. it takes Å 0.7 s for F or M panels, and Å 120 s for the Back panel (6144 pts vs. 1.12e6 pts)
764// find some way to speed this up!
765// MultiThreading will be difficult as it requires all the dependent functions (HDF5 reads, etc.) to be threadsafe as well
766// and there are a lot of them... and I don't know if opening a file multiple times is a threadsafe operation?
767//  -- multiple open attempts seems like a bad idea.
768                //type = work folder
769               
770//              (this doesn't work...and isn't any faster)
771//              Duplicate/O qval dum
772//              dum = V_get2DResolution(qval,phi,r_dist,type,detStr,collimationStr,SigmaQX,SigmaQY,fsubS)
773
774v_tic()
775                do
776                        V_get2DResolution(qval[ii],phi[ii],r_dist[ii],type,detStr,collimationStr,ret1,ret2,ret3)
777                        SigmaQX[ii] = ret1     
778                        SigmaQY[ii] = ret2     
779                        fsubs[ii] = ret3       
780                        ii+=1
781                while(ii<nq)   
782v_toc()
783        ////*********************       
784                Duplicate/O qx_val,qx_val_s
785                Duplicate/O qy_val,qy_val_s
786                Duplicate/O qz_val,qz_val_s
787                Duplicate/O data,z_val_s
788                Duplicate/O SigmaQx,sigmaQx_s
789                Duplicate/O SigmaQy,sigmaQy_s
790                Duplicate/O fSubS,fSubS_s
791                Duplicate/O data_err,sw_s
792                Duplicate/O MaskData,MaskData_s
793               
794                //so that double precision data is not written out
795                Redimension/S qx_val_s,qy_val_s,qz_val_s,z_val_s,sw_s
796                Redimension/S SigmaQx_s,SigmaQy_s,fSubS_s,MaskData_s
797       
798                Redimension/N=(pixX*pixY) qx_val_s,qy_val_s,qz_val_s,z_val_s,sw_s,MaskData_s
799               
800                //not demo-compatible, but approx 8x faster!!   
801#if(strsearch(stringbykey("IGORKIND",IgorInfo(0),":",";"), "demo", 0 ) == -1)
802               
803//              Save/O/G/M="\r\n" labelWave,qx_val_s,qy_val_s,qz_val_s,z_val_s,sw_s as detSavePath      // without resolution
804                Save/O/G/M="\r\n" labelWave,qx_val_s,qy_val_s,z_val_s,sw_s,qz_val_s,SigmaQx_s,SigmaQy_s,fSubS_s,MaskData_s as detSavePath       // write out the resolution information
805#else
806                Open refNum as detSavePath
807                wfprintf refNum,"%s\r\n",labelWave
808                fprintf refnum,"\r\n"
809//              wfprintf refNum,"%8g\t%8g\t%8g\t%8g\t%8g\r\n",qx_val_s,qy_val_s,qz_val_s,z_val_s,sw_s
810                wfprintf refNum,"%8g\t%8g\t%8g\t%8g\t%8g\t%8g\t%8g\t%8g\t%8g\r\n",qx_val_s,qy_val_s,z_val_s,sw_s,qz_val_s,SigmaQx_s,SigmaQy_s,fSubS_s,MaskData_s
811                Close refNum
812#endif
813               
814                KillWaves/Z qx_val_s,qy_val_s,z_val_s,qz_val_s,SigmaQx_s,SigmaQy_s,fSubS_s,sw,sw_s,MaskData_s
815               
816                Killwaves/Z qval,sigmaQx,SigmaQy,fSubS,phi,r_dist,MaskData
817               
818                Print "QxQy_Export File written: ", V_GetFileNameFromPathNoSemi(detSavePath)
819       
820        endfor
821       
822        KillWaves/Z labelWave,dum
823        return(0)
824End
825
826
Note: See TracBrowser for help on using the repository browser.