source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DIVUtils.ipf @ 1235

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

Changed the calculation of solid angle to properly reflect the tube geometry. This mode is now the (correct) default calculation. A global switch can be applied for testing to use the old method (with many warning alerts).

File size: 40.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3//
4// ********
5//
6//   JAN 2018
7//
8// TODO:
9// x- complete the description of the steps needed...
10// Data needs to be reduced to the "COR" level - that means that the
11// PLEX data has been added to work files, and the empty and blocked beam have been
12// subtracted off.
13// -- but what detector corrections should/ should not be done?
14// -- non-linear corrections are not needed, since this will strictly be a per-pixel correction
15// -- solid angle?
16// -- dead time?
17// -- efficiency?
18// -- large angle transmission?
19//
20// we may need to think more carefully about some of these since the front carriage may need to be
21// closer than the nominal 4m distance on SANS that was deemed far enough back to be "safe" from
22// the high angle issues.
23//
24// x- what about the T/B panels? Since a large chunk of these detectors may be obscured,
25//   the normalization will be way off -- and the "active" area will end up much larger
26//   than it should be - since the wings of the detector are mostly zero...
27//   ? Can I apply a mask, or will the detectors be set in a different configuration?
28//
29//
30
31
32
33
34/// DONE:
35// x- need a way to view the DIV data (each panel) and see the stats on the values
36//  (maybe a simple panel viewer, one-at-a-time, or all 4 as individuals, not on the same scale)
37
38// x- this is the basic renormalization that is done in PRODIV. see that file for all of the
39//    details of how it's used
40// x- update to VSANS file locations and data reads
41// x- expand this to do a basic renormalization of all 9 panels, and move the data into the
42//    appropriate locations for saving as a DIV file.
43// x- (YES, done) what about error propogation? Can I store the error in the data file?
44//    Makes a difference if the DIV is not collected for long "enough".
45// x- then I need to be able to read the error in (done)
46
47
48
49//
50// Simple panel to walk through the steps of generating a DIV file
51//
52Proc DIV_Setup_Panel() : Panel
53        PauseUpdate; Silent 1           // building window...
54        NewPanel /W=(1207,593,1444,953)/N=DIV_Setup_Panel/K=1
55        DoWindow/C DIV_Setup_Panel
56        Button button0,pos={54.00,10.00},size={120.00,20.00},proc=V_DIVSetupButtonProc,title="Setup Folder"
57        Button button1,pos={54.00,40.00},size={120.00,20.00},proc=V_DIVClearOldButtonProc,title="Clear Old DIV"
58        Button button1_2,pos={54.00,70.00},size={120.00,20.00},proc=V_DIVMaskButtonProc,title="Mask for DIV"
59
60        DrawText 32,130,"Reduce data for one carriage" 
61        DrawText 32,200,"Repeat for the other carriage(s)"
62       
63        Button button2,pos={54.00,145.00},size={120.00,20.00},proc=V_DIVCopyButtonProc,title="Copy"
64        Button button4,pos={54.00,235.00},size={120.00,20.00},proc=V_DIVNormalizeButtonProc,title="Normalize"
65
66        DrawText 32,290,"Once data for both (or 3) carriages\rhas been normalized, save the file"       
67       
68        Button button3,pos={54.00,300.00},size={120.00,20.00},proc=V_DIVSaveButtonProc,title="Save DIV"
69EndMacro
70
71
72
73// set up the folder structure for the DIV file to fill in
74Function V_DIVSetupButtonProc(ba) : ButtonControl
75        STRUCT WMButtonAction &ba
76
77        switch( ba.eventCode )
78                case 2: // mouse up
79                        // click code here
80                        Execute "Setup_VSANS_DIV_Struct()"
81                        break
82                case -1: // control being killed
83                        break
84        endswitch
85
86        return 0
87End
88
89
90// clear out whatever is in the current DIV folder to ensure that it is not
91// accidentally applied during the reduction of the DIV file
92//
93Function V_DIVClearOldButtonProc(ba) : ButtonControl
94        STRUCT WMButtonAction &ba
95
96        switch( ba.eventCode )
97                case 2: // mouse up
98                        // click code here
99                       
100                        KillDataFolder/Z $"root:Packages:NIST:VSANS:DIV"                        //many subfolders, so Kill all
101                        if(V_flag == 0)         // kill DF was OK
102                                NewDataFolder root:Packages:NIST:VSANS:DIV
103                                Print "DIV folder cleared successfully"
104                        else
105                                Print "DIV folder in use - could not be cleared"
106                        endif
107                        break
108                case -1: // control being killed
109                        break
110        endswitch
111
112        return 0
113End
114
115
116Function V_DIVNormalizeButtonProc(ba) : ButtonControl
117        STRUCT WMButtonAction &ba
118
119        switch( ba.eventCode )
120                case 2: // mouse up
121                        // click code here
122                        Execute "V_NormalizeDIV_proc()"
123                        break
124                case -1: // control being killed
125                        break
126        endswitch
127
128        return 0
129End
130
131
132// copies the data for a particular carriage that has been reduced to COR
133// to a storage location for later normalization
134Function V_DIVCopyButtonProc(ba) : ButtonControl
135        STRUCT WMButtonAction &ba
136
137        switch( ba.eventCode )
138                case 2: // mouse up
139                        // click code here
140                        Execute "V_DIVCopy_proc()"
141                        break
142                case -1: // control being killed
143                        break
144        endswitch
145
146        return 0
147End
148
149Function V_DIVMaskButtonProc(ba) : ButtonControl
150        STRUCT WMButtonAction &ba
151
152        switch( ba.eventCode )
153                case 2: // mouse up
154                        // click code here
155                        Execute "V_Edit_a_Mask()"
156                        break
157                case -1: // control being killed
158                        break
159        endswitch
160
161        return 0
162End
163
164Function V_DIVSaveButtonProc(ba) : ButtonControl
165        STRUCT WMButtonAction &ba
166
167        switch( ba.eventCode )
168                case 2: // mouse up
169                        // click code here
170                        Execute "Save_VSANS_DIV_Nexus()"
171                        break
172                case -1: // control being killed
173                        break
174        endswitch
175
176        return 0
177End
178
179
180
181
182
183Proc V_DIVCopy_proc(reducedFolderType,carriageStr,first)
184        String reducedFolderType="COR",carriageStr="F"
185        Variable first=1
186       
187        Vf_DIVCopy_proc(reducedFolderType,carriageStr,first)
188end
189
190
191
192Function Vf_DIVCopy_proc(reducedFolderType,carriageStr,first)
193        String reducedFolderType,carriageStr
194        Variable first
195
196        String topath = "root:Packages:NIST:VSANS:STO:entry:instrument:detector_"
197        String fromPath = "root:Packages:NIST:VSANS:COR:entry:instrument:detector_"
198        String detStrList,detStr
199        Variable num,ii
200       
201       
202        if (cmpstr(carriageStr,"B")==0)
203                if(first)
204                        V_CopyHDFToWorkFolder("COR","STO")
205                else
206                        detStr = "B"
207                        Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
208                        Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
209                endif
210//              V_NormalizeDIV_onePanel(reducedFolderType,"B")
211        else
212                // if it's the first one, copy the whole folder, otherwise just copy over what's needed
213                if(first)
214                        V_CopyHDFToWorkFolder("COR","STO")
215                else
216
217                        if(cmpstr(carriageStr,"F")==0)
218                                detStrList = "FL;FR;FT;FB;"
219                        else
220                                detStrList = "ML;MR;MT;MB;"
221                        endif
222                        num=ItemsInList(detStrlist)
223       
224                        // loop over the list of panels to copy the data
225                        for(ii=0;ii<num;ii+=1)
226                                detStr = StringFromList(ii, detStrList)
227                                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
228                                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
229                        endfor
230                endif
231       
232        endif
233       
234        return(0)
235End
236
237
238
239// this is called from the button
240//
241Proc V_NormalizeDIV_proc(carriageStr)
242        String carriageStr="F"
243//      String reducedFolderType="COR",carriageStr="F"
244//      Prompt reducedFolderType, "reduced data folder"
245        Prompt carriageStr,"panels to group",popup,"Individual;B;All 8;All F All M;"
246               
247        Vf_NormalizeDIV_proc(carriageStr)
248end
249
250
251// this function now treats all 8 panels as a single detector
252// for the normalization.
253// it is assuming that data from both carriages has been reduced to the COR stage
254// and has been copied over to the STO folder where it will be normalized before
255// copying to the DIV folder for saving.
256//
257Function Vf_NormalizeDIV_proc(carriageStr)
258        String carriageStr
259
260        if (cmpstr(carriageStr,"B")==0)
261                V_NormalizeDIV_onePanel("STO","B")
262                return (0)
263        endif
264       
265       
266        if(cmpstr(carriageStr,"All 8")==0)
267//              DoAlert 0,"data for both carriages must already be in STO"
268                V_NormalizeDIV_allEight("STO")                  //forces reduced folder type to STO
269                return (0)
270        endif
271
272        if(cmpstr(carriageStr,"All F All M")==0)
273//              DoAlert 0,"data for both carriages must already be in STO"
274                V_NormalizeDIV_oneCarriage("STO","F")
275                V_NormalizeDIV_oneCarriage("STO","M")
276                return (0)
277        endif
278
279        if(cmpstr(carriageStr,"Individual")==0)
280                V_NormalizeDIV_onePanel("STO","B")
281
282                V_NormalizeDIV_onePanel("STO","FL")
283                V_NormalizeDIV_onePanel("STO","FR")
284                V_NormalizeDIV_onePanel("STO","FT")
285                V_NormalizeDIV_onePanel("STO","FB")
286       
287                V_NormalizeDIV_onePanel("STO","ML")
288                V_NormalizeDIV_onePanel("STO","MR")
289                V_NormalizeDIV_onePanel("STO","MT")
290                V_NormalizeDIV_onePanel("STO","MB")     
291                return(0)
292        endif
293       
294        return(0)
295End
296
297
298// Normalizes all eight panels (M + F) as a single detector
299// then copies that panel over to the DIV_Struct for later saving
300//
301// type is the work folder where the (? corrected) data is currently
302//
303// DONE
304// x- data should be copied to some alternate work folder before this step
305// x- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
306//    How to handle? A mask?
307// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
308//    standard reduction has been used, but now the normalization step is a multiplication
309//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
310//    what is done in SANS)
311//
312Function V_NormalizeDIV_allEight(type)
313        String type
314
315        Variable ii,totCts,pixelX,pixelY,sumCts,sumPts,num
316        String detStr,detStrList
317       
318        detStrList = "FL;FR;FT;FB;ML;MR;MT;MB;"
319        num=ItemsInList(detStrlist)
320       
321        // loop over the list of panels (n=8) to get the sums
322        sumCts = 0
323        sumPts = 0
324        for(ii=0;ii<num;ii+=1)
325                detStr = StringFromList(ii, detStrList)
326                Wave w = V_getDetectorDataW(type,detStr)
327                Wave w_err = V_getDetectorDataErrW(type,detStr)
328       
329                //      WaveStats/Q/M=1 w
330                //      Print detStr
331                //      Print "RAW V_avg = ",V_avg
332                //      Print "RAW V_avg*V_npnts = ",V_avg*V_npnts
333       
334                // get the mask data
335                // 1== mask, 0 == no mask
336                Wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
337       
338        // work on a copy of the data and error
339//              Duplicate/O w w_copy
340//              Duplicate/O w_err w_err_copy
341               
342                w = (maskW == 1) ? NaN : w      //set masked areas to NaN
343                WaveStats/Q/M=1 w
344                sumCts += V_npnts*V_avg         // does not count the NaN values
345                sumPts += V_npnts
346               
347//              totCts = V_npnts*V_avg          // does not count the NaN values
348        //      Print "Masked V_avg = ",V_avg
349        //      Print "Masked V_npnts = ",V_npnts
350        //      Print "Masked V_avg*V_npnts = ",V_avg*V_npnts
351
352        endfor
353       
354        // now normalize each panel (in place)
355        for(ii=0;ii<num;ii+=1)
356                detStr = StringFromList(ii, detStrList)
357                Wave w = V_getDetectorDataW(type,detStr)
358                Wave w_err = V_getDetectorDataErrW(type,detStr)
359                       
360                w /= sumCts
361                w *= sumPts
362       
363                w_err /= sumCts
364                w_err *= sumPts
365
366        // DONE:
367        // x- I replace the NaN values with 1 for the DIV (the user will mask the data as
368        //    needed, and the NaN values may be an issue later...
369                w = (numtype(w) == 2) ? 1 : w                   //turns 2==NaN into 1
370       
371//     
372                // copy the normalized data to the folder to save
373                Wave w_norm = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":data")
374                Wave w_norm_err = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":linear_data_error")
375                       
376                w_norm = w
377                w_norm_err = w_err
378        endfor         
379
380//      KillWaves/Z w_copy,w_err_copy
381       
382        return(0)
383End
384
385
386
387
388// Normalizes a single carriage, treating all four panels as a single panel
389// then copies that panel over to the DIV_Struct for later saving
390//
391// type is the work folder where the (? corrected) data is currently
392//
393// DONE
394// x- data should be copied to some alternate work folder before this step
395// x- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
396//    How to handle? A mask?
397// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
398//    standard reduction has been used, but now the normalization step is a multiplication
399//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
400//    what is done in SANS)
401//
402Function V_NormalizeDIV_oneCarriage(type,carriageStr)
403        String type,carriageStr
404
405        Variable ii,totCts,pixelX,pixelY,sumCts,sumPts
406        String detStr,detStrList
407       
408        if(cmpstr(carriageStr,"F")==0)
409                detStrList = "FL;FR;FT;FB;"
410        else
411                detStrList = "ML;MR;MT;MB;"
412        endif
413
414        // loop over the list of panels (n=4) to get the sums
415        sumCts = 0
416        sumPts = 0
417        for(ii=0;ii<4;ii+=1)
418                detStr = StringFromList(ii, detStrList)
419                Wave w = V_getDetectorDataW(type,detStr)
420                Wave w_err = V_getDetectorDataErrW(type,detStr)
421       
422                //      WaveStats/Q/M=1 w
423                //      Print detStr
424                //      Print "RAW V_avg = ",V_avg
425                //      Print "RAW V_avg*V_npnts = ",V_avg*V_npnts
426       
427                // get the mask data
428                // 1== mask, 0 == no mask
429                Wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
430       
431        // work on a copy of the data and error
432//              Duplicate/O w w_copy
433//              Duplicate/O w_err w_err_copy
434               
435                w = (maskW == 1) ? NaN : w      //set masked areas to NaN
436                WaveStats/Q/M=1 w
437                sumCts += V_npnts*V_avg         // does not count the NaN values
438                sumPts += V_npnts
439               
440//              totCts = V_npnts*V_avg          // does not count the NaN values
441        //      Print "Masked V_avg = ",V_avg
442        //      Print "Masked V_npnts = ",V_npnts
443        //      Print "Masked V_avg*V_npnts = ",V_avg*V_npnts
444
445        endfor
446       
447        // now normalize each panel (in place)
448        for(ii=0;ii<4;ii+=1)
449                detStr = StringFromList(ii, detStrList)
450                Wave w = V_getDetectorDataW(type,detStr)
451                Wave w_err = V_getDetectorDataErrW(type,detStr)
452                       
453                w /= sumCts
454                w *= sumPts
455       
456                w_err /= sumCts
457                w_err *= sumPts
458
459        // DONE:
460        // x- I replace the NaN values with 1 for the DIV (the user will mask the data as
461        //    needed, and the NaN values may be an issue later...
462                w = (numtype(w) == 2) ? 1 : w                   //turns 2==NaN into 1
463       
464//     
465                // copy the normalized data to the folder to save
466                Wave w_norm = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":data")
467                Wave w_norm_err = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":linear_data_error")
468                       
469                w_norm = w
470                w_norm_err = w_err
471        endfor         
472
473//      KillWaves/Z w_copy,w_err_copy
474       
475        return(0)
476End
477
478
479
480// Normalizes a single panel
481// then copies that panel over to the DIV_Struct for later saving
482//
483// type is the work folder where the (? corrected) data is currently
484//
485// DONE
486// x- data should be copied to some alternate work folder before this step
487// x- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
488//    How to handle? A mask?
489// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
490//    standard reduction has been used, but now the normalization step is a multiplication
491//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
492//    what is done in SANS)
493//
494Function V_NormalizeDIV_onePanel(type,detStr)
495        String type,detStr
496
497        Variable ii,totCts,pixelX,pixelY
498
499
500        Wave w = V_getDetectorDataW(type,detStr)
501        Wave w_err = V_getDetectorDataErrW(type,detStr)
502//      pixelX = V_getDet_pixel_num_x(type,detStr)
503//      pixelY = V_getDet_pixel_num_y(type,detStr)
504
505//      WaveStats/Q/M=1 w
506//      Print detStr
507//      Print "RAW V_avg = ",V_avg
508//      Print "RAW V_avg*V_npnts = ",V_avg*V_npnts
509       
510        // get the mask data
511        // 1== mask, 0 == no mask
512        Wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
513
514// work on a copy of the data and error
515        Duplicate/O w w_copy
516        Duplicate/O w_err w_err_copy
517       
518        w_copy = (maskW == 1) ? NaN : w_copy   
519        WaveStats/Q/M=1 w_copy
520        totCts = V_npnts*V_avg          // does not count the NaN values
521//      Print "Masked V_avg = ",V_avg
522//      Print "Masked V_npnts = ",V_npnts
523//      Print "Masked V_avg*V_npnts = ",V_avg*V_npnts
524
525
526        w_copy /= totCts
527        w_copy *= V_npnts
528
529        w_err_copy /= totCts
530        w_err_copy *= V_npnts
531
532// DONE:
533// x- I replace the NaN values with 1 for the DIV (the user will mask the data as
534//    needed, and the NaN values may be an issue later...
535        w_copy = (numtype(w_copy) == 2) ? 1 : w_copy                    //turns 2==NaN into 1
536       
537
538// copy the normalized data to the folder to save
539        Wave w_norm = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":data")
540        Wave w_norm_err = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":linear_data_error")
541               
542        w_norm = w_copy
543        w_norm_err = w_err_copy
544
545
546        KillWaves/Z w_copy,w_err_copy
547       
548        return(0)
549End
550
551
552////
553//// Normalizes each panel independently
554//// Normalizes in-place, replacing whatever was there
555////
556//// type is the work folder where the (? corrected) data is currently
557////
558//// NOTE (Currently unused. use V_NormalizeDIV_onePanel() instead)
559////
560//// -- data should be copied to some alternate work folder before this step
561//// -- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
562////    How to handle? A mask?
563//// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
564////    standard reduction has been used, but now the normalization step is a multiplication
565////    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
566////    what is done in SANS)
567////
568//Function V_NormalizeDIV(type)
569//      String type
570//
571//      Variable ii,totCts,pixelX,pixelY
572//      String detStr
573//
574//      for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
575//              detStr = StringFromList(ii, ksDetectorListAll, ";")
576//              Wave w = V_getDetectorDataW(type,detStr)
577//              Wave w_err = V_getDetectorDataErrW(type,detStr)
578//              pixelX = V_getDet_pixel_num_x(type,detStr)
579//              pixelY = V_getDet_pixel_num_y(type,detStr)
580//
581//              totCts = sum(w,Inf,-Inf)                //sum all of the data
582//             
583//              w /= totCts
584//              w *= pixelX*pixelY
585//
586//              w_err /= totCts
587//              w_err *= pixelX*pixelY
588//             
589//      endfor
590//     
591//      return(0)
592//End
593
594
595// copies an entire work folder, all 9 detectors (at COR level)
596// to the DIV structure to write out
597//
598Function V_CopyDIVToSave(type)
599        String type
600       
601        Variable ii,totCts,pixelX,pixelY
602        String detStr
603        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
604        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
605       
606       
607        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
608                detStr = StringFromList(ii, ksDetectorListAll, ";")
609
610                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
611                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
612               
613        endfor
614       
615        return(0)
616End
617
618//
619// copies only the specified panel from a work folder, (at COR level)
620// to the DIV structure to write out
621//
622// used to replace a single panel, or to fill in carriage by carriage.
623//
624Function V_CopyDIVToSave_OnePanel(type,detStr)
625        String type,detStr
626       
627        Variable ii,totCts,pixelX,pixelY
628        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
629        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
630       
631       
632                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
633                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
634                       
635        return(0)
636End
637
638
639
640
641
642// currently, there are no dummy fill values or attributes for the fake DIV file
643//
644Proc Setup_VSANS_DIV_Struct()
645
646        // lays out the tree and fills with dummy values
647        H_Setup_VSANS_DIV_Structure()
648       
649        // writes in the attributes
650//      H_Fill_VSANS_Attributes()
651       
652        // fill in with VCALC simulation bits
653//      H_Fill_VSANS_wSim()
654       
655End
656
657Proc Save_VSANS_DIV_Nexus(fileName)
658        String fileName="Test_VSANS_DIV_file"
659
660        // save as HDF5 (no attributes saved yet)
661        Save_VSANS_file("root:VSANS_DIV_file", fileName+".h5")
662       
663//      // read in a data file using the gateway-- reads from the home path
664//      H_HDF5Gate_Read_Raw(fileName+".h5")
665//     
666//      // after reading in a "partial" file using the gateway (to generate the xref)
667//      // Save the xref to disk (for later use)
668//      Save_HDF5___xref("root:"+fileName,"HDF5___xref")
669//     
670//      // after you've generated the HDF5___xref, load it in and copy it
671//      // to the necessary folder location.
672//      Copy_HDF5___xref("root:VSANS_DIV_file", "HDF5___xref")
673//     
674//      // writes out the contents of a data folder using the gateway
675//      H_HDF5Gate_Write_Raw("root:VSANS_DIV_file", fileName+".h5")
676//
677//      // re-load the data file using the gateway-- reads from the home path
678//      // now with attributes
679//      H_HDF5Gate_Read_Raw(fileName+".h5")
680       
681End
682
683//////////////  DIV file tests
684//
685//
686//      Make/O/T/N=1    file_name       = "VSANS_DIV_test.h5"
687//
688// simple generation of a fake div file. for sans, nothing other than the creation date was written to the
689// file header. nothing more is needed (possibly)
690//
691//
692//
693// TODO -- correct the number of pixels for the BACK detector
694//
695Proc H_Setup_VSANS_DIV_Structure()
696       
697        NewDataFolder/O/S root:VSANS_DIV_file           
698
699        NewDataFolder/O/S root:VSANS_DIV_file:entry     
700                Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
701                Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
702                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
703                        Make/O/T/N=1    name    = "NG3_VSANS"
704                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
705                        Make/O/D/N=(680,1656)   data    = 1
706                        Make/O/D/N=(680,1656)   linear_data_error       = 0.01
707                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
708                        Make/O/D/N=(48,128)     data = 1
709                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
710                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
711                        Make/O/D/N=(48,128)     data = 1
712                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
713                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
714                        Make/O/D/N=(128,48)     data    = 1
715                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
716                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
717                        Make/O/D/N=(128,48)     data    = 1
718                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
719                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
720                        Make/O/D/N=(48,128)     data = 1
721                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
722                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
723                        Make/O/D/N=(48,128)     data = 1
724                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
725                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
726                        Make/O/D/N=(128,48)     data    = 1
727                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
728                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
729                        Make/O/D/N=(128,48)     data    = 1
730                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
731
732//
733// version that is NOT perfect, LR detectors are "striped"
734//
735//      NewDataFolder/O/S root:VSANS_DIV_file:entry     
736//              Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
737//              Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
738//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
739//                      Make/O/T/N=1    name    = "NG3_VSANS"
740//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
741//                      Make/O/D/N=(150,150)    data    = 1 + (enoise(0.1))
742//                      Make/O/D/N=(150,150)    linear_data_error       = 0.01*abs(gnoise(1))
743//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
744//                      Make/O/D/N=(48,128)     data
745//                      data[][0] = 1+enoise(0.1)
746//                      data[][] = data[p][0]
747//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
748//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
749//                      Make/O/D/N=(48,128)     data
750//                      data[][0] = 1+enoise(0.1)
751//                      data[][] = data[p][0]
752//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
753//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
754//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
755//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
756//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
757//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
758//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
759//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
760//                      Make/O/D/N=(48,128)     data
761//                      data[][0] = 1+enoise(0.1)
762//                      data[][] = data[p][0]
763//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
764//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
765//                      Make/O/D/N=(48,128)     data
766//                      data[][0] = 1+enoise(0.1)
767//                      data[][] = data[p][0]
768//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
769//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
770//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
771//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
772//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
773//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
774//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
775               
776               
777                // fake, empty folders so that the generic loaders can be used
778                NewDataFolder/O root:VSANS_DIV_file:entry:DAS_logs
779                NewDataFolder/O root:VSANS_DIV_file:entry:control
780                NewDataFolder/O root:VSANS_DIV_file:entry:reduction
781                NewDataFolder/O root:VSANS_DIV_file:entry:sample
782                NewDataFolder/O root:VSANS_DIV_file:entry:user
783
784                       
785        SetDataFolder root:
786
787End
788
789
790
791//
792// simple panel to display the 4 detector panels
793//
794// TODO:
795// -- label panels, axes
796// x- any manipulations, stats ?
797// x- add an "update" button (to update the status of the data - this may be automatic with an operation)
798// -- add a "load DIV" button (to make it easy)
799// -- add a "copy" button (to fill move data to STO and SUB)
800// x- add a "ratio" button
801// x- add a "difference" button
802// -- propagate the error in the arithmetic (see WorkFileMath)
803// -- un hard-wire the Front carriage from the panel proc
804
805Proc V_Display_DIV_Panels()
806        PauseUpdate; Silent 1           // building window...
807        NewPanel /W=(720,45,1530,570)/N=VSANS_DIVPanels/K=1
808        DoWindow/C VSANS_DIVPanels
809//      ModifyPanel fixedSize=1,noEdit =1
810
811
812        PopupMenu popup0,pos={17.00,10.00},size={77.00,23.00},proc=V_DispCarriagePopMenuProc,title="Carriage"
813        PopupMenu popup0,mode=1,value= #"\"F;M;B;\""
814        PopupMenu popup1,pos={134.00,10.00},size={68.00,23.00},proc=V_DispFolderPopMenuProc,title="Folder"
815        PopupMenu popup1,mode=1,popvalue="RAW",value= #"\"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;MSK;ADJ;\""
816        PopupMenu popup2,pos={246.00,10.00},size={83.00,23.00},proc=V_DispOperationPopMenuProc,title="Operation"
817        PopupMenu popup2,mode=1,value= #"\"none;ADJ=STO-SUB;ADJ=STO/SUB;\""
818        Button button0,pos={440.00,10.00},size={70.00,20.00},proc=V_DispUpdateButtonProc,title="Update"
819
820
821//      Display/W=(745,45,945,425)/HOST=#
822        Display/W=(10,45,210,425)/HOST=#
823        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
824
825        ModifyImage data ctab= {*,*,ColdWarm,0}
826        ModifyImage data ctabAutoscale=3
827        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
828        ModifyGraph mirror=2
829        ModifyGraph nticks=4
830        ModifyGraph minor=1
831        ModifyGraph fSize=9
832        ModifyGraph standoff=0
833        ModifyGraph tkLblRot(left)=90
834        ModifyGraph btLen=3
835        ModifyGraph tlOffset=-2
836        RenameWindow #,Panel_L
837        SetActiveSubwindow ##
838
839//      Display/W=(1300,45,1500,425)/HOST=#
840        Display/W=(565,45,765,425)/HOST=#
841        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FR:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
842        ModifyImage data ctab= {*,*,ColdWarm,0}
843        ModifyImage data ctabAutoscale=3
844        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
845        ModifyGraph mirror=2
846        ModifyGraph nticks=4
847        ModifyGraph minor=1
848        ModifyGraph fSize=9
849        ModifyGraph standoff=0
850        ModifyGraph tkLblRot(left)=90
851        ModifyGraph btLen=3
852        ModifyGraph tlOffset=-2
853        RenameWindow #,Panel_R
854        SetActiveSubwindow ##
855
856//      Display/W=(945,45,1300,235)/HOST=#
857        Display/W=(210,45,565,235)/HOST=#
858        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FT:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
859        ModifyImage data ctab= {*,*,ColdWarm,0}
860        ModifyImage data ctabAutoscale=3
861        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
862        ModifyGraph mirror=2
863        ModifyGraph nticks=4
864        ModifyGraph minor=1
865        ModifyGraph fSize=9
866        ModifyGraph standoff=0
867        ModifyGraph tkLblRot(left)=90
868        ModifyGraph btLen=3
869        ModifyGraph tlOffset=-2
870        RenameWindow #,Panel_T
871        SetActiveSubwindow ##
872
873//      Display/W=(945,235,1300,425)/HOST=#
874        Display/W=(210,235,565,425)/HOST=#
875        AppendImage/T/G=1 :Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:data            //  /G=1 flag prevents interpretation as RGB so 3, 4 slices display correctly
876        ModifyImage data ctab= {*,*,ColdWarm,0}
877        ModifyImage data ctabAutoscale=3
878        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
879        ModifyGraph mirror=2
880        ModifyGraph nticks=4
881        ModifyGraph minor=1
882        ModifyGraph fSize=9
883        ModifyGraph standoff=0
884        ModifyGraph tkLblRot(left)=90
885        ModifyGraph btLen=3
886        ModifyGraph tlOffset=-2
887        RenameWindow #,Panel_B
888        SetActiveSubwindow ##
889//
890
891        String/G root:Packages:NIST:VSANS:Globals:gDIVstr0 = "this is the title box0\rwith two lines"
892        String/G root:Packages:NIST:VSANS:Globals:gDIVstr1 = "this is the title box1\rwith two lines"
893        String/G root:Packages:NIST:VSANS:Globals:gDIVstr2 = "this is the title box2\rwith two lines"
894        String/G root:Packages:NIST:VSANS:Globals:gDIVstr3 = "this is the title box3\rwith two lines"
895       
896       
897        TitleBox title0 pos={15,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr0,fSize=11
898        TitleBox title1 pos={300,433},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr1,fSize=11
899        TitleBox title2 pos={300,482},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr2,fSize=11
900        TitleBox title3 pos={580,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr3,fSize=11
901
902
903        V_UpdateDIVStrings()
904End
905
906
907// called by the "update" button
908Function V_UpdatePanelDisp()
909
910        ControlInfo popup0
911        String carrStr = S_value
912       
913        ControlInfo popup1
914        String folder = S_Value
915       
916        string tmpStr=""
917        Variable isVCALC=0
918        if(cmpstr("VCALC",folder)==0)
919                isVCALC=1
920        endif
921               
922        // remove everything from each of the 4 panels
923        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_L",";")
924        if(ItemsInList(tmpStr) > 0)
925                do
926                        RemoveImage /W=VSANS_DIVPanels#Panel_L $(StringFromList(0,tmpStr,";"))          //get 1st item
927                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_L",";")                                                           //refresh list
928                while(ItemsInList(tmpStr) > 0)
929        endif
930       
931        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_R",";")
932        if(ItemsInList(tmpStr) > 0)
933                do
934                        RemoveImage /W=VSANS_DIVPanels#Panel_R $(StringFromList(0,tmpStr,";"))          //get 1st item
935                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_R",";")                                                           //refresh list
936                while(ItemsInList(tmpStr) > 0)
937        endif
938       
939        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_T",";")
940        if(ItemsInList(tmpStr) > 0)
941                do
942                        RemoveImage /W=VSANS_DIVPanels#Panel_T $(StringFromList(0,tmpStr,";"))          //get 1st item
943                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_T",";")                                                           //refresh list
944                while(ItemsInList(tmpStr) > 0)
945        endif
946       
947        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_B",";")
948        if(ItemsInList(tmpStr) > 0)
949                do
950                        RemoveImage /W=VSANS_DIVPanels#Panel_B $(StringFromList(0,tmpStr,";"))          //get 1st item
951                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_B",";")                                                           //refresh list
952                while(ItemsInList(tmpStr) > 0)
953        endif
954       
955
956        // append the new image
957        // if back, put this in the "left" postion, and nothing else
958        if(cmpstr("B",carrStr)==0)
959                if(isVCALC)
960                        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+":det_"+carrStr)         
961                        SetActiveSubwindow VSANS_DIVPanels#Panel_L
962                        ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
963                        ModifyImage ''#0 ctabAutoscale=3
964                else
965                        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+":data")         
966                        SetActiveSubwindow VSANS_DIVPanels#Panel_L
967                        ModifyImage data ctab= {*,*,ColdWarm,0}
968                        ModifyImage data ctabAutoscale=3       
969                endif
970                ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
971                ModifyGraph mirror=2
972                ModifyGraph nticks=4
973                ModifyGraph minor=1
974                ModifyGraph fSize=9
975                ModifyGraph standoff=0
976                ModifyGraph tkLblRot(left)=90
977                ModifyGraph btLen=3
978                ModifyGraph tlOffset=-2
979                SetActiveSubwindow ##
980                return(0)
981        endif
982       
983//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_L data
984        if(isVCALC)
985                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:det_"+carrStr+"L")           
986                SetActiveSubwindow VSANS_DIVPanels#Panel_L
987                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
988                ModifyImage ''#0 ctabAutoscale=3
989        else
990                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")               
991                SetActiveSubwindow VSANS_DIVPanels#Panel_L
992                ModifyImage data ctab= {*,*,ColdWarm,0}
993                ModifyImage data ctabAutoscale=3       
994        endif
995        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
996        ModifyGraph mirror=2
997        ModifyGraph nticks=4
998        ModifyGraph minor=1
999        ModifyGraph fSize=9
1000        ModifyGraph standoff=0
1001        ModifyGraph tkLblRot(left)=90
1002        ModifyGraph btLen=3
1003        ModifyGraph tlOffset=-2
1004        SetActiveSubwindow ##
1005
1006
1007//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_T data
1008        if(isVCALC)
1009                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_T $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:det_"+carrStr+"T")           
1010                SetActiveSubwindow VSANS_DIVPanels#Panel_T
1011                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
1012                ModifyImage ''#0 ctabAutoscale=3
1013        else
1014                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_T $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")               
1015                SetActiveSubwindow VSANS_DIVPanels#Panel_T
1016                ModifyImage data ctab= {*,*,ColdWarm,0}
1017                ModifyImage data ctabAutoscale=3
1018        endif
1019        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
1020        ModifyGraph mirror=2
1021        ModifyGraph nticks=4
1022        ModifyGraph minor=1
1023        ModifyGraph fSize=9
1024        ModifyGraph standoff=0
1025        ModifyGraph tkLblRot(left)=90
1026        ModifyGraph btLen=3
1027        ModifyGraph tlOffset=-2
1028        SetActiveSubwindow ##
1029       
1030//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_B data
1031        if(isVCALC)
1032                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_B $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:det_"+carrStr+"B")           
1033                SetActiveSubwindow VSANS_DIVPanels#Panel_B
1034                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
1035                ModifyImage ''#0 ctabAutoscale=3
1036        else
1037                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_B $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")               
1038                SetActiveSubwindow VSANS_DIVPanels#Panel_B
1039                ModifyImage data ctab= {*,*,ColdWarm,0}
1040                ModifyImage data ctabAutoscale=3
1041        endif
1042        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
1043        ModifyGraph mirror=2
1044        ModifyGraph nticks=4
1045        ModifyGraph minor=1
1046        ModifyGraph fSize=9
1047        ModifyGraph standoff=0
1048        ModifyGraph tkLblRot(left)=90
1049        ModifyGraph btLen=3
1050        ModifyGraph tlOffset=-2
1051        SetActiveSubwindow ##
1052
1053//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_R data
1054        if(isVCALC)
1055                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_R $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:det_"+carrStr+"R")           
1056                SetActiveSubwindow VSANS_DIVPanels#Panel_R
1057                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
1058                ModifyImage ''#0 ctabAutoscale=3
1059        else
1060                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_R $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")               
1061                SetActiveSubwindow VSANS_DIVPanels#Panel_R
1062                ModifyImage data ctab= {*,*,ColdWarm,0}
1063                ModifyImage data ctabAutoscale=3
1064        endif
1065        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
1066        ModifyGraph mirror=2
1067        ModifyGraph nticks=4
1068        ModifyGraph minor=1
1069        ModifyGraph fSize=9
1070        ModifyGraph standoff=0
1071        ModifyGraph tkLblRot(left)=90
1072        ModifyGraph btLen=3
1073        ModifyGraph tlOffset=-2
1074        SetActiveSubwindow ##
1075
1076        return(0)
1077End
1078
1079
1080
1081
1082Function V_DispFolderPopMenuProc(pa) : PopupMenuControl
1083        STRUCT WMPopupAction &pa
1084
1085        switch( pa.eventCode )
1086                case 2: // mouse up
1087                        Variable popNum = pa.popNum
1088                        String popStr = pa.popStr
1089                        break
1090                case -1: // control being killed
1091                        break
1092        endswitch
1093
1094        return 0
1095End
1096
1097Function V_DispCarriagePopMenuProc(pa) : PopupMenuControl
1098        STRUCT WMPopupAction &pa
1099
1100        switch( pa.eventCode )
1101                case 2: // mouse up
1102                        Variable popNum = pa.popNum
1103                        String popStr = pa.popStr
1104                        break
1105                case -1: // control being killed
1106                        break
1107        endswitch
1108
1109        return 0
1110End
1111
1112Function V_DispOperationPopMenuProc(pa) : PopupMenuControl
1113        STRUCT WMPopupAction &pa
1114
1115        switch( pa.eventCode )
1116                case 2: // mouse up
1117                        Variable popNum = pa.popNum
1118                        String popStr = pa.popStr
1119                        break
1120                case -1: // control being killed
1121                        break
1122        endswitch
1123
1124        return 0
1125End
1126
1127Function V_DispUpdateButtonProc(ba) : ButtonControl
1128        STRUCT WMButtonAction &ba
1129
1130        switch( ba.eventCode )
1131                case 2: // mouse up
1132                        // click code here
1133                       
1134                        // if there is an operation, do it
1135                        V_DoDIVOperation()
1136                       
1137                        // update the data that is displayed
1138                        V_UpdatePanelDisp()
1139                       
1140                       
1141                        // update the global strings
1142                        V_UpdateDIVStrings()
1143
1144                       
1145                        break
1146                case -1: // control being killed
1147                        break
1148        endswitch
1149
1150        return 0
1151End
1152
1153Function V_UpdateDIVStrings()
1154
1155        SVAR gDIVstr0 = root:Packages:NIST:VSANS:Globals:gDIVstr0
1156        SVAR gDIVstr1 = root:Packages:NIST:VSANS:Globals:gDIVstr1
1157        SVAR gDIVstr2 = root:Packages:NIST:VSANS:Globals:gDIVstr2
1158        SVAR gDIVstr3 = root:Packages:NIST:VSANS:Globals:gDIVstr3
1159       
1160        ControlInfo popup0
1161        String carrStr = S_value
1162       
1163        ControlInfo popup1
1164        String folder = S_Value
1165       
1166        String  formatStr="Avg = %g +/- %g\rMin = %g, Max = %g"
1167
1168        if(cmpstr(carrStr,"B")==0)
1169                WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_B:data")
1170                sprintf gDIVstr0,formatStr,V_avg,V_sdev,V_min,V_max
1171                gDIVStr1 = ""
1172                gDIVStr2 = ""
1173                gDIVStr3 = ""
1174                TitleBox title0 title=gDIVstr0
1175                TitleBox title1 title=gDIVstr1
1176                TitleBox title2 title=gDIVstr2
1177                TitleBox title3 title=gDIVstr3
1178                return(0)
1179        endif
1180               
1181        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")
1182        sprintf gDIVstr0,formatStr,V_avg,V_sdev,V_min,V_max
1183       
1184        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")
1185        sprintf gDIVstr1,formatStr,V_avg,V_sdev,V_min,V_max
1186       
1187        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")
1188        sprintf gDIVstr2,formatStr,V_avg,V_sdev,V_min,V_max
1189       
1190        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")
1191        sprintf gDIVstr3,formatStr,V_avg,V_sdev,V_min,V_max
1192
1193        TitleBox title0 title=gDIVstr0
1194        TitleBox title1 title=gDIVstr1
1195        TitleBox title2 title=gDIVstr2
1196        TitleBox title3 title=gDIVstr3
1197                       
1198        return(0)
1199end
1200
1201// if there is no operation called, immediately exit
1202//
1203// if there is a simple operation called, do it
1204// TODO -- if there are more than these two simple operations, a more sophisticated switch will be necessary
1205//
1206Function V_DoDIVOperation()
1207
1208        ControlInfo popup2
1209        String opStr = S_value
1210       
1211        if(cmpstr(opStr,"none")==0)
1212                return(0)
1213        endif
1214       
1215        ControlInfo popup0
1216        String carrStr = S_value
1217        // an operation is desired
1218        // hard-wired use of STO and SUB, copy results to ADJ
1219       
1220        // make sure that something is in ADJ
1221        // TODO -- reset the values of the data in ADJ, or it will look like the wrong calculation was done
1222        //V_CopyWorkFolder("STO","ADJ")         // this is a macro, use the function instead
1223        V_CopyHDFToWorkFolder("STO","ADJ")
1224
1225
1226        if(cmpstr(carrStr,"B")==0)
1227                WAVE w_sto_B = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_B:data")
1228                WAVE w_sub_B = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_B:data")
1229                Duplicate/O w_sto_B $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_B:data")
1230                WAVE w_adj_B = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_B:data")
1231        else
1232                WAVE w_sto_L = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"L:data")
1233                WAVE w_sub_L = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"L:data")
1234                Duplicate/O w_sto_L $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
1235                WAVE w_adj_L = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
1236       
1237                WAVE w_sto_R = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"R:data")
1238                WAVE w_sub_R = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"R:data")
1239                Duplicate/O w_sto_R $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
1240                WAVE w_adj_R = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
1241       
1242                WAVE w_sto_T = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"T:data")
1243                WAVE w_sub_T = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"T:data")
1244                Duplicate/O w_sto_T $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
1245                WAVE w_adj_T = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
1246       
1247                WAVE w_sto_B = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"B:data")
1248                WAVE w_sub_B = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"B:data")
1249                Duplicate/O w_sto_B $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
1250                WAVE w_adj_B = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
1251        endif
1252
1253
1254//handle the back detector separately, then exit
1255        if(cmpstr(carrStr,"B")==0)
1256                if(cmpstr(opStr,"ADJ=STO/SUB")==0)
1257                        w_adj_B = w_sto_B/w_sub_B
1258                else
1259                        w_adj_B = w_sto_B - w_sub_B
1260                endif
1261                return(0)
1262        endif
1263
1264
1265// M or F carriages     
1266        if(cmpstr(opStr,"ADJ=STO/SUB")==0)
1267                w_adj_L = w_sto_L/w_sub_L
1268                w_adj_R = w_sto_R/w_sub_R
1269                w_adj_T = w_sto_T/w_sub_T
1270                w_adj_B = w_sto_B/w_sub_B
1271        else
1272                w_adj_L = w_sto_L - w_sub_L
1273                w_adj_R = w_sto_R - w_sub_R
1274                w_adj_T = w_sto_T - w_sub_T
1275                w_adj_B = w_sto_B - w_sub_B
1276        endif
1277
1278        return(0)
1279end
1280
1281
Note: See TracBrowser for help on using the repository browser.