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

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

more changes to panel scaling so that they are viewed properly on a small-screen laptop

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