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

Last change on this file since 1119 was 1119, checked in by srkline, 4 years ago

added procedures to output QxQy_ASCII data. Each panel is output into its own file. Output format is the same as for 2D SANS data, including the 2D resolution function. However, reading the data back in with the SANS analysis macros currently does not redimension the data back to the matrix correctly as it assumes a square detector.

I will need to add the X and Y dimensions of each panel into the header, and then make use of these values when they are read in. Also, writing the QxQy? data is quick for the M and F panels ( 0.8 s) but is extremely slow for the back, High-res panel (120 s) since there are 1.1.E6 points there vs. 6144 pts. I'll need to find a way to speed this operation up.

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