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

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

1) bug fix in the BT5 loader for USANS where an incorrect detector (of the 5) was specified (from B. Maranville). No impact on reduced data.

2) Cleaned up steps of generating DIV files and added file generation time into the DIV file that is saved.

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