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

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

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

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