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

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

changing how the DIV file is generated. Testing out different normalizations, including being able to normalize all 8 panels simultaneously rather then treating each panel individually.

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