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

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

adding an extra column to the QxQyASCII output for VSANS. This (9th) column is the mask (=1 if the data is masked, =0 if the data is not masked)

File size: 24.4 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// TODO
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 = 27 waves!  ksBinType1
293                        detList = ksBinType1
294                       
295                        break
296                case 2:         // 5 sets
297                        detList = ksBinType2
298                        break
299                case 3:         // 3 sets
300                        detList = ksBinType3
301                        break
302                case 4:         // 9 sets
303                        detList = ksBinType4
304                        break
305                                       
306                default:
307                // do nothing, just close
308
309        endswitch
310
311        num=ItemsInList(detList)
312        for(ii=0;ii<num;ii+=1)
313                SetDataFolder $(pathStr+folderStr)
314
315                item=StringFromList(ii, detList)
316               
317                if(gIgnoreB && cmpstr(item,"B") == 0)
318                        //do nothing
319                else
320                        fileName = saveName + "_"+item+"."+exten
321                        Wave qWave = $("qBin_qxqy_"+item)
322                        Wave iWave = $("iBin_qxqy_"+item)
323                        Wave eWave = $("eBin_qxqy_"+item)
324                        KillWaves/Z tmp_q, tmp_i, tmp_s
325                        Duplicate/O qWave tmp_q
326                        Duplicate/O iWave tmp_i
327                        Duplicate/O eWave tmp_s
328                        V_Write1DData_3Col(pathStr,folderStr,fileName)
329                endif
330               
331        endfor
332       
333        SetDataFolder root:
334        return(0)
335End
336
337
338
339
340
341// TODO:
342// -- this is a temporary solution before a real writer is created
343// -- resolution is not generated here (and it shouldn't be) since resolution is not known yet.
344// -- but a real writer will need to be aware of resolution, and there may be different forms
345//
346// This saves the data in Igor Text format, an ASCII format, but NOT standard SANS columns
347// No concatenation is done. This is meant to be used for input to TRIM, or for general troubleshooting
348//
349//
350// this will bypass save dialogs
351// -- AND WILL OVERWRITE DATA WITH THE SAME NAME
352//
353Function V_Write1DData_ITX(pathStr,folderStr,saveName,binType)
354        String pathStr,folderStr,saveName
355        Variable binType
356       
357        String formatStr="",fullpath=""
358        Variable refnum,dialog=1
359
360        SetDataFolder $(pathStr+folderStr)
361
362
363        //TODO
364        //-- make sure the waves exist
365       
366//      if(WaveExists(qw) == 0)
367//              Abort "q is missing"
368//      endif
369//      if(WaveExists(iw) == 0)
370//              Abort "i is missing"
371//      endif
372//      if(WaveExists(sw) == 0)
373//              Abort "s is missing"
374//      endif
375//      if(WaveExists(resw) == 0)
376//              Abort "Resolution information is missing."
377//      endif
378       
379//      Duplicate/O qw qbar,sigQ,fs
380//      if(dimsize(resW,1) > 4)
381//              //it's USANS put -dQv back in the last 3 columns
382//              NVAR/Z dQv = USANS_dQv
383//              if(NVAR_Exists(dQv) == 0)
384//                      SetDataFolder root:
385//                      Abort "It's USANS data, and I don't know what the slit height is."
386//              endif
387//              sigQ = -dQv
388//              qbar = -dQv
389//              fs = -dQv
390//      else
391//              //it's SANS
392//              sigQ = resw[p][0]
393//              qbar = resw[p][1]
394//              fs = resw[p][2]
395//      endif
396//     
397
398
399
400        // TODO:
401        // -- currently I'm using the Save comand and the /B flag
402        //    to save the data as Igor Text format, since otherwise the command string would be
403        //    too long. Need to come up with an Igor-demo friendly save here
404        //
405        // -- see V_ExportProtocol() for a quick example of how to generate the .ITX format
406        //
407        // -- need a reader/plotter capable of handling this data. The regular data loader won't handle
408        //    all the different number of columns present, or the ITX format. See V_DataPlotting and duplicate these routines
409        //    Most of these routines take "winNameStr" as an argument, so I may be able to use them
410        //
411        // -- do I want to add the /O flag to force an overwrite if there is a name conflict?
412
413        PathInfo catPathName
414        fullPath = S_Path + saveName + ".itx"
415
416//      Open refnum as fullpath
417//      fprintf refnum,"Individual data sets written from folder %s on %s\r\n",folderStr,(date()+" "+time())
418
419        String waveStr=""
420        // can be a multiple number of columns
421               
422        switch(binType)
423                case 1:         // 9 sets = 27 waves!
424                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
425                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
426                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
427                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
428                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
429                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
430                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
431                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
432                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
433                       
434                       
435                        Save/T/M="\r\n"/B waveStr as fullPath
436
437                                               
438//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
439//                     
440//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
441//     
442//                      wfprintf refnum,formatStr,qw,iw,sw
443                        break
444                case 2:         // 5 sets
445
446                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
447                        waveStr += "qBin_qxqy_MLR;iBin_qxqy_MLR;eBin_qxqy_MLR;qBin_qxqy_MTB;iBin_qxqy_MTB;eBin_qxqy_MTB;"
448                        waveStr += "qBin_qxqy_FLR;iBin_qxqy_FLR;eBin_qxqy_FLR;qBin_qxqy_FTB;iBin_qxqy_FTB;eBin_qxqy_FTB;"
449
450                        Save/T/M="\r\n"/B waveStr as fullPath
451                       
452//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
453//                     
454//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
455//     
456//                      wfprintf refnum,formatStr,qw,iw,sw
457                        break
458                case 3:         // 3 sets
459//                      WAVE q1 = qBin_qxqy_B
460//                      WAVE i1 = iBin_qxqy_B
461//                      WAVE s1 = eBin_qxqy_B
462//                      WAVE q2 = qBin_qxqy_MLRTB
463//                      WAVE i2 = iBin_qxqy_MLRTB
464//                      WAVE s2 = eBin_qxqy_MLRTB
465//                      WAVE q3 = qBin_qxqy_FLRTB
466//                      WAVE i3 = iBin_qxqy_FLRTB
467//                      WAVE s3 = eBin_qxqy_FLRTB
468//
469//                             
470//                      Save/T/M="\r\n" q1,i1,s1,q2,i2,s2,q3,i3,s3 as fullPath
471                       
472                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
473                        waveStr += "qBin_qxqy_MLRTB;iBin_qxqy_MLRTB;eBin_qxqy_MLRTB;qBin_qxqy_FLRTB;iBin_qxqy_FLRTB;eBin_qxqy_FLRTB;"
474
475                        Save/T/M="\r\n"/B waveStr as fullPath                   
476                       
477                       
478//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
479//                     
480//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
481//     
482//                      wfprintf refnum,formatStr,qw,iw,sw
483                        break
484                case 4:         // 9 sets
485                        waveStr = "qBin_qxqy_B;iBin_qxqy_B;eBin_qxqy_B;"
486                        waveStr += "qBin_qxqy_ML;iBin_qxqy_ML;eBin_qxqy_ML;"
487                        waveStr += "qBin_qxqy_MR;iBin_qxqy_MR;eBin_qxqy_MR;"
488                        waveStr += "qBin_qxqy_MT;iBin_qxqy_MT;eBin_qxqy_MT;"
489                        waveStr += "qBin_qxqy_MB;iBin_qxqy_MB;eBin_qxqy_MB;"
490                        waveStr += "qBin_qxqy_FL;iBin_qxqy_FL;eBin_qxqy_FL;"
491                        waveStr += "qBin_qxqy_FR;iBin_qxqy_FR;eBin_qxqy_FR;"
492                        waveStr += "qBin_qxqy_FT;iBin_qxqy_FT;eBin_qxqy_FT;"
493                        waveStr += "qBin_qxqy_FB;iBin_qxqy_FB;eBin_qxqy_FB;"
494                       
495                       
496                        Save/T/M="\r\n"/B waveStr as fullPath
497
498//                      formatStr = "%15.4g %15.4g %15.4g\r\n"
499//                     
500//                      fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm)\r\n"
501//     
502//                      wfprintf refnum,formatStr,qw,iw,sw
503                        break
504                                       
505                default:
506                // do nothing, just close
507
508        endswitch
509
510//      Close refnum
511
512// TODO
513// -- clean up any waves on exit?        Only if I generate extra waves
514//      KillWaves/Z sigQ,qbar,fs
515       
516        SetDataFolder root:
517        return(0)
518End
519
520// awkward, but can't call STRUCT from Proc
521Proc Vm_Write1DData_ITX()
522        Vf_FakeSaveIQITXClick()
523End
524
525Function Vf_FakeSaveIQITXClick()
526        STRUCT WMButtonAction ba
527        ba.eventCode=2
528        V_SaveIQ_ButtonProc(ba)
529end
530
531
532///////// QxQy Export  //////////
533//
534// (see the similar-named SANS routine for additonal steps - like resolution, etc.)
535//ASCII export of data as 8-columns qx-qy-Intensity-err-qz-sigmaQ_parall-sigmaQ_perp-fShad
536// + limited header information
537//
538//      Jan 2019 -- first version, simply exports the basic matrix of data with no resolution information
539//
540//
541Function V_QxQy_Export(type,fullpath,newFileName,dialog)
542        String type,fullpath,newFileName
543        Variable dialog         //=1 will present dialog for name
544       
545        String typeStr=""
546        Variable refnum
547        String detStr="",detSavePath
548
549        SVAR gProtoStr = root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr
550       
551        // declare, or make a fake protocol if needed (if the export type is RAW)
552        String rawTag=""
553        if(cmpstr(type,"RAW")==0)
554                Make/O/T/N=(kNumProtocolSteps) proto
555                RawTag = "RAW Data File: "     
556        else
557                Wave/T proto=$("root:Packages:NIST:VSANS:Globals:Protocols:"+gProtoStr)
558        endif
559       
560        SVAR samFiles = $("root:Packages:NIST:VSANS:"+type+":gFileList")
561       
562        //check each wave - MUST exist, or will cause a crash
563//      If(!(WaveExists(data)))
564//              Abort "data DNExist QxQy_Export()"
565//      Endif
566
567        if(dialog)
568                PathInfo/S catPathName
569                fullPath = DoSaveFileDialog("Save data as")
570                If(cmpstr(fullPath,"")==0)
571                        //user cancel, don't write out a file
572                        Close/A
573                        Abort "no data file was written"
574                Endif
575                //Print "dialog fullpath = ",fullpath
576        Endif
577
578        // data values to populate the file header
579        String fileName,fileDate,fileLabel
580        Variable monCt,lambda,offset,dist,trans,thick
581        Variable bCentX,bCentY,a2,a1a2_dist,deltaLam,bstop
582        String a1Str
583        Variable pixX,pixY
584        Variable numTextLines,ii,jj,kk
585        Variable pixSizeX,pixSizeY
586        Variable duration
587
588        numTextLines = 30
589        Make/O/T/N=(numTextLines) labelWave
590
591        //
592       
593        //loop over all of the detector panels
594        NVAR gIgnoreDetB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
595
596        String detList
597        if(gIgnoreDetB)
598                detList = ksDetectorListNoB
599        else
600                detList = ksDetectorListAll
601        endif
602       
603        for(kk=0;kk<ItemsInList(detList);kk+=1)
604
605                detStr = StringFromList(kk, detList, ";")
606                detSavePath = fullPath + "_" + detStr + ".DAT"
607               
608                pixX = V_getDet_pixel_num_x(type,detStr)
609                pixY = V_getDet_pixel_num_y(type,detStr)
610               
611                fileName = newFileName
612                fileDate = V_getDataStartTime(type)             // already a string
613                fileLabel = V_getSampleDescription(type)
614               
615                monCt = V_getBeamMonNormData(type)
616                lambda = V_getWavelength(type)
617       
618        // TODO - switch based on panel type
619        //      V_getDet_LateralOffset(fname,detStr)
620        //      V_getDet_VerticalOffset(fname,detStr)
621                offset = V_getDet_LateralOffset(type,detStr)
622       
623                dist = V_getDet_ActualDistance(type,detStr)
624                trans = V_getSampleTransmission(type)
625                thick = V_getSampleThickness(type)
626               
627                bCentX = V_getDet_beam_center_x(type,detStr)
628                bCentY = V_getDet_beam_center_y(type,detStr)
629                a1Str = V_getSourceAp_size(type)                //already a string
630                a2 = V_getSampleAp2_size(type)
631                a1a2_dist = V_getSourceAp_distance(type)
632                deltaLam = V_getWavelength_spread(type)
633                // TODO -- decipher which beamstop, if any is actually in place
634        // or -- V_getBeamStopC3_size(type)
635                bstop = V_getBeamStopC2_size(type)
636
637                pixSizeX = V_getDet_x_pixel_size(type,detStr)
638                pixSizeY = V_getDet_y_pixel_size(type,detStr)
639               
640                duration = V_getCount_time(type)
641               
642        /////////
643                labelWave[0] = "FILE: "+fileName+"   CREATED: "+fileDate
644                labelWave[1] = "LABEL: "+fileLabel
645                labelWave[2] = "MON CNT   LAMBDA (A)  DET_OFF(cm)   DET_DIST(cm)   TRANS   THICK(cm)"
646                labelWave[3] = num2str(monCt)+"  "+num2str(lambda)+"       "+num2str(offset)+"     "+num2str(dist)
647                labelWave[3] += "     "+num2str(trans)+"     "+num2str(thick)
648                labelWave[4] = "BCENT(X,Y)(cm)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)"
649                labelWave[5] = num2str(bCentX)+"  "+num2str(bCentY)+"  "+a1Str+"    "+num2str(a2)+"    "
650                labelWave[5] += num2str(a1a2_dist)+"    "+num2str(deltaLam)+"    "+num2str(bstop)
651                labelWave[6] =  "SAM: "+rawTag+samFiles
652                labelWave[7] =  "BGD: "+proto[0]
653                labelWave[8] =  "EMP: "+proto[1]
654                labelWave[9] =  "DIV: "+proto[2]
655                labelWave[10] =  "MASK: "+proto[3]
656                labelWave[11] =  "ABS Parameters (3-6): "+proto[4]
657                labelWave[12] = "Average Choices: "+proto[5]
658                labelWave[13] = "Collimation type: "+proto[9]
659                labelWave[14] = "Panel="+detStr
660                labelWave[15] = "NumXPixels="+num2str(pixX)
661                labelWave[16] = "XPixelSize_mm="+num2str(pixSizeX)
662                labelWave[17] = "NumYPixels="+num2str(pixY)
663                labelWave[18] = "YPixelSize_mm="+num2str(pixSizeY)
664                labelWave[19] = "Duration (s)="+num2str(duration)
665                labelWave[20] = "reserved for future file definition changes"
666                labelWave[21] = "reserved for future file definition changes"
667                labelWave[22] = "reserved for future file definition changes"
668                labelWave[23] = "reserved for future file definition changes"
669                labelWave[24] = "reserved for future file definition changes"
670                labelWave[25] = "reserved for future file definition changes"
671
672                labelWave[26] = "*** Data written from "+type+" folder and may not be a fully corrected data file ***"
673//              labelWave[20] = "Data columns are Qx - Qy - Qz - I(Qx,Qy) - Err I(Qx,Qy)"
674        //      labelWave[20] = "Data columns are Qx - Qy - I(Qx,Qy) - Qz - SigmaQ_parall - SigmaQ_perp - fSubS(beam stop shadow)"
675                labelWave[27] = "Data columns are Qx - Qy - I(Qx,Qy) - err(I) - Qz - SigmaQ_parall - SigmaQ_perp - fSubS(beam stop shadow) - Mask"
676                labelWave[28] = "The error wave may not be properly propagated (1/2019)"
677                labelWave[29] = "ASCII data created " +date()+" "+time()
678                //strings can be too long to print-- must trim to 255 chars
679                for(jj=0;jj<numTextLines;jj+=1)
680                        labelWave[jj] = (labelWave[jj])[0,240]
681                endfor
682       
683       
684        // get the data waves for output
685        // QxQyQz have already been calculated for VSANS data
686               
687                WAVE data = V_getDetectorDataW(type,detStr)
688                WAVE data_err = V_getDetectorDataErrW(type,detStr)
689
690// JUN 2019 get the mask data           
691                WAVE MaskData = V_getDetectorDataW("MSK",detStr)
692
693               
694                // TOOD - replace hard wired paths with Read functions
695                // hard-wired
696                Wave qx_val = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qx_"+detStr)
697                Wave qy_val = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qy_"+detStr)
698                Wave qz_val = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qz_"+detStr)
699                Wave qTot = $("root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"+detStr+":qTot_"+detStr)
700               
701        ///// calculation of the resolution function (2D)
702
703        //
704                Variable acc,ssd,lambda0,yg_d,qstar,g,L1,L2,vz_1,sdd
705                // L1 = source to sample distance [cm]
706                L1 = V_getSourceAp_distance(type)
707       
708        // L2 = sample to detector distance [cm]
709                L2 = V_getDet_ActualDistance(type,detStr)               //cm
710
711        //             
712                G = 981.  //!   ACCELERATION OF GRAVITY, CM/SEC^2
713                vz_1 =  3.956E5 //      3.956E5 //!     CONVERT WAVELENGTH TO VELOCITY CM/SEC
714                acc = vz_1
715                SDD = L2                //1317
716                SSD = L1                //1627          //cm
717                lambda0 = lambda                //              15
718                YG_d = -0.5*G*SDD*(SSD+SDD)*(LAMBDA0/acc)^2
719                Print "DISTANCE BEAM FALLS DUE TO GRAVITY (CM) = ",YG_d
720        ////            Print "Gravity q* = ",-2*pi/lambda0*2*yg_d/sdd
721                qstar = -2*pi/lambda0*2*yg_d/sdd
722        //     
723        //
724        //// the gravity center is not the resolution center
725        //// gravity center = beam center
726        //// resolution center = offset y = dy + (2)*yg_d
727        /////************
728        //// do everything to write out the resolution too
729        //      // un-comment these if you want to write out qz_val and qval too, then use the proper save command
730        //      qval = CalcQval(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10)
731                Duplicate/O qTot,phi,r_dist
732                Variable xctr,yctr
733
734
735                xctr = V_getDet_beam_center_x_pix(type,detStr)
736                yctr = V_getDet_beam_center_y_pix(type,detStr)
737                phi = V_FindPhi( pixSizeX*((p+1)-xctr) , pixSizeY*((q+1)-yctr)+(2)*yg_d)                //(dx,dy+yg_d)
738                r_dist = sqrt(  (pixSizeX*((p+1)-xctr))^2 +  (pixSizeY*((q+1)-yctr)+(2)*yg_d)^2 )               //radial distance from ctr to pt
739       
740                //make everything in 1D now
741                Duplicate/O qTot SigmaQX,SigmaQY,fsubS,qval     
742                Redimension/N=(pixX*pixY) SigmaQX,SigmaQY,fsubS,qval,phi,r_dist
743
744                Variable ret1,ret2,ret3,nq
745                String collimationStr
746               
747               
748                collimationStr = proto[9]
749               
750                nq = pixX*pixY
751                ii=0
752
753// TODO
754// 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)
755// find some way to speed this up!
756// MultiThreading will be difficult as it requires all the dependent functions (HDF5 reads, etc.) to be threadsafe as well
757// and there are a lot of them... and I don't know if opening a file multiple times is a threadsafe operation?
758//  -- multiple open attempts seems like a bad idea.
759                //type = work folder
760               
761//              (this doesn't work...and isn't any faster)
762//              Duplicate/O qval dum
763//              dum = V_get2DResolution(qval,phi,r_dist,type,detStr,collimationStr,SigmaQX,SigmaQY,fsubS)
764
765v_tic()
766                do
767                        V_get2DResolution(qval[ii],phi[ii],r_dist[ii],type,detStr,collimationStr,ret1,ret2,ret3)
768                        SigmaQX[ii] = ret1     
769                        SigmaQY[ii] = ret2     
770                        fsubs[ii] = ret3       
771                        ii+=1
772                while(ii<nq)   
773v_toc()
774        ////*********************       
775                Duplicate/O qx_val,qx_val_s
776                Duplicate/O qy_val,qy_val_s
777                Duplicate/O qz_val,qz_val_s
778                Duplicate/O data,z_val_s
779                Duplicate/O SigmaQx,sigmaQx_s
780                Duplicate/O SigmaQy,sigmaQy_s
781                Duplicate/O fSubS,fSubS_s
782                Duplicate/O data_err,sw_s
783                Duplicate/O MaskData,MaskData_s
784               
785                //so that double precision data is not written out
786                Redimension/S qx_val_s,qy_val_s,qz_val_s,z_val_s,sw_s
787                Redimension/S SigmaQx_s,SigmaQy_s,fSubS_s,MaskData_s
788       
789                Redimension/N=(pixX*pixY) qx_val_s,qy_val_s,qz_val_s,z_val_s,sw_s,MaskData_s
790               
791                //not demo-compatible, but approx 8x faster!!   
792#if(strsearch(stringbykey("IGORKIND",IgorInfo(0),":",";"), "demo", 0 ) == -1)
793               
794//              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
795                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
796#else
797                Open refNum as detSavePath
798                wfprintf refNum,"%s\r\n",labelWave
799                fprintf refnum,"\r\n"
800//              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
801                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
802                Close refNum
803#endif
804               
805                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
806               
807                Killwaves/Z qval,sigmaQx,SigmaQy,fSubS,phi,r_dist,MaskData
808               
809                Print "QxQy_Export File written: ", V_GetFileNameFromPathNoSemi(detSavePath)
810       
811        endfor
812       
813        KillWaves/Z labelWave,dum
814        return(0)
815End
816
817
Note: See TracBrowser for help on using the repository browser.