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

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

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

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