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

Last change on this file since 1079 was 1079, checked in by srkline, 5 years ago

cleanup of TODO items in code, no noteworthy changes

prepare a test release package for the January startup of VSANS, not a general release (since no changes to SANS or USANS)

File size: 27.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3//
4// ********
5// TODO -- this file is preliminary. It has not yet been tested on enough real data
6//    to generate a DIV file.
7//    Not sure how it will be measured in practice on VSANS.
8//
9//   JAN 2018
10//
11// TODO:
12// x- complete the description of the steps needed...
13// Data needs to be reduced to the "COR" level - that means that the
14// PLEX data has been added to work files, and the empty and blocked beam have been
15// subtracted off.
16// -- but what detector corrections should/ should not be done?
17// -- non-linear corrections are not needed, since this will strictly be a per-pixel correction
18// -- solid angle?
19// -- dead time?
20// -- efficiency?
21// -- large angle transmission?
22//
23// we may need to think more carefully about some of these since the front carriage may need to be
24// closer than the nominal 4m distance on SANS that was deemed far enough back to be "safe" from
25// the high angle issues.
26//
27// x- what about the T/B panels? Since a large chunk of these detectors may be obscured,
28//   the normalization will be way off -- and the "active" area will end up much larger
29//   than it should be - since the wings of the detector are mostly zero...
30//   ? Can I apply a mask, or will the detectors be set in a different configuration?
31//
32//
33
34
35
36
37/// DONE:
38// x- need a way to view the DIV data (each panel) and see the stats on the values
39//  (maybe a simple panel viewer, one-at-a-time, or all 4 as individuals, not on the same scale)
40
41// x- this is the basic renormalization that is done in PRODIV. see that file for all of the
42//    details of how it's used
43// x- update to VSANS file locations and data reads
44// x- expand this to do a basic renormalization of all 9 panels, and move the data into the
45//    appropriate locations for saving as a DIV file.
46// x- (YES, done) what about error propogation? Can I store the error in the data file?
47//    Makes a difference if the DIV is not collected for long "enough".
48// x- then I need to be able to read the error in (done)
49
50
51
52//
53// Simple panel to walk through the steps of generating a DIV file
54//
55Proc DIV_Setup_Panel() : Panel
56        PauseUpdate; Silent 1           // building window...
57        NewPanel /W=(1207,593,1444,953)/N=DIV_Setup_Panel/K=1
58        DoWindow/C DIV_Setup_Panel
59        Button button0,pos={54.00,10.00},size={120.00,20.00},proc=V_DIVSetupButtonProc,title="Setup Folder"
60        Button button1,pos={54.00,40.00},size={120.00,20.00},proc=V_DIVClearOldButtonProc,title="Clear Old DIV"
61
62        DrawText 36,110,"Reduce data for one carriage" 
63        DrawText 36,200,"Repeat for the other carriage"
64        Button button1_2,pos={74.00,130.00},size={120.00,20.00},proc=V_DIVMaskButtonProc,title="Mask for DIV"
65        Button button2,pos={74.00,160.00},size={120.00,20.00},proc=V_DIVNormalizeButtonProc,title="Normalize+Copy"
66
67        DrawText 36,290,"Once data for both carriages has\rbeen normalized, save the file"     
68       
69        Button button3,pos={54.00,300.00},size={120.00,20.00},proc=V_DIVSaveButtonProc,title="Save DIV"
70EndMacro
71
72
73
74// set up the folder structure for the DIV file to fill in
75Function V_DIVSetupButtonProc(ba) : ButtonControl
76        STRUCT WMButtonAction &ba
77
78        switch( ba.eventCode )
79                case 2: // mouse up
80                        // click code here
81                        Execute "Setup_VSANS_DIV_Struct()"
82                        break
83                case -1: // control being killed
84                        break
85        endswitch
86
87        return 0
88End
89
90
91// clear out whatever is in the current DIV folder to ensure that it is not
92// accidentally applied during the reduction of the DIV file
93//
94Function V_DIVClearOldButtonProc(ba) : ButtonControl
95        STRUCT WMButtonAction &ba
96
97        switch( ba.eventCode )
98                case 2: // mouse up
99                        // click code here
100                        V_KillWavesInFolder("DIV")
101                        break
102                case -1: // control being killed
103                        break
104        endswitch
105
106        return 0
107End
108
109
110Function V_DIVNormalizeButtonProc(ba) : ButtonControl
111        STRUCT WMButtonAction &ba
112
113        switch( ba.eventCode )
114                case 2: // mouse up
115                        // click code here
116                        Execute "V_NormalizeDIV_proc()"
117                        break
118                case -1: // control being killed
119                        break
120        endswitch
121
122        return 0
123End
124
125Function V_DIVMaskButtonProc(ba) : ButtonControl
126        STRUCT WMButtonAction &ba
127
128        switch( ba.eventCode )
129                case 2: // mouse up
130                        // click code here
131                        Execute "V_Edit_a_Mask()"
132                        break
133                case -1: // control being killed
134                        break
135        endswitch
136
137        return 0
138End
139
140Function V_DIVSaveButtonProc(ba) : ButtonControl
141        STRUCT WMButtonAction &ba
142
143        switch( ba.eventCode )
144                case 2: // mouse up
145                        // click code here
146                        Execute "Save_VSANS_DIV_Nexus()"
147                        break
148                case -1: // control being killed
149                        break
150        endswitch
151
152        return 0
153End
154
155
156
157
158Proc V_NormalizeDIV_proc(reducedFolderType,carriageStr)
159        String reducedFolderType="SAM",carriageStr="F"
160        if(cmpstr(carriageStr,"F")==0)
161                V_NormalizeDIV_onePanel(reducedFolderType,"FL")
162                V_NormalizeDIV_onePanel(reducedFolderType,"FR")
163                V_NormalizeDIV_onePanel(reducedFolderType,"FT")
164                V_NormalizeDIV_onePanel(reducedFolderType,"FB")
165        else
166                V_NormalizeDIV_onePanel(reducedFolderType,"ML")
167                V_NormalizeDIV_onePanel(reducedFolderType,"MR")
168                V_NormalizeDIV_onePanel(reducedFolderType,"MT")
169                V_NormalizeDIV_onePanel(reducedFolderType,"MB")
170        endif
171       
172end
173
174
175// Normalizes a single panel
176// then copies that panel over to the DIV_Struct for later saving
177//
178// type is the work folder where the (? corrected) data is currently
179//
180// DONE
181// x- data should be copied to some alternate work folder before this step
182// x- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
183//    How to handle? A mask?
184// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
185//    standard reduction has been used, but now the normalization step is a multiplication
186//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
187//    what is done in SANS)
188//
189Function V_NormalizeDIV_onePanel(type,detStr)
190        String type,detStr
191
192        Variable ii,totCts,pixelX,pixelY
193
194
195        Wave w = V_getDetectorDataW(type,detStr)
196        Wave w_err = V_getDetectorDataErrW(type,detStr)
197//      pixelX = V_getDet_pixel_num_x(type,detStr)
198//      pixelY = V_getDet_pixel_num_y(type,detStr)
199
200        // get the mask data
201        // 1== mask, 0 == no mask
202        Wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
203
204// work on a copy of the data and error
205        Duplicate/O w w_copy
206        Duplicate/O w_err w_err_copy
207       
208        w_copy = (maskW == 1) ? NaN : w_copy   
209        WaveStats/Q/M=1 w_copy
210        totCts = V_npnts*V_avg          // does not count the NaN values
211
212
213        w_copy /= totCts
214        w_copy *= V_npnts
215
216        w_err_copy /= totCts
217        w_err_copy *= V_npnts
218
219// TODO:
220// -- do I want to replace the NaN values with 1 for the DIV (the user will mask the data as
221//    needed, and the NaN values may be an issue later...
222        w_copy = (numtype(w_copy) == 2) ? 1 : w_copy                    //turns 2==NaN into 1
223       
224
225// copy the normalized data to the folder to save
226        Wave w_norm = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":data")
227        Wave w_norm_err = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":linear_data_error")
228               
229        w_norm = w_copy
230        w_norm_err = w_err_copy
231
232
233        KillWaves/Z w_copy,w_err_copy
234       
235        return(0)
236End
237
238
239//
240// Normalizes each panel independently
241// Normalizes in-place, replacing whatever was there
242//
243// type is the work folder where the (? corrected) data is currently
244//
245// NOTE (Currently unused. use V_NormalizeDIV_onePanel() instead)
246//
247// -- data should be copied to some alternate work folder before this step
248// -- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
249//    How to handle? A mask?
250// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
251//    standard reduction has been used, but now the normalization step is a multiplication
252//    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
253//    what is done in SANS)
254//
255Function V_NormalizeDIV(type)
256        String type
257
258        Variable ii,totCts,pixelX,pixelY
259        String detStr
260
261        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
262                detStr = StringFromList(ii, ksDetectorListAll, ";")
263                Wave w = V_getDetectorDataW(type,detStr)
264                Wave w_err = V_getDetectorDataErrW(type,detStr)
265                pixelX = V_getDet_pixel_num_x(type,detStr)
266                pixelY = V_getDet_pixel_num_y(type,detStr)
267
268                totCts = sum(w,Inf,-Inf)                //sum all of the data
269               
270                w /= totCts
271                w *= pixelX*pixelY
272
273                w_err /= totCts
274                w_err *= pixelX*pixelY
275               
276        endfor
277       
278        return(0)
279End
280
281
282// copies an entire work folder, all 9 detectors (at COR level)
283// to the DIV structure to write out
284//
285Function V_CopyDIVToSave(type)
286        String type
287       
288        Variable ii,totCts,pixelX,pixelY
289        String detStr
290        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
291        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
292       
293       
294        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
295                detStr = StringFromList(ii, ksDetectorListAll, ";")
296
297                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
298                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
299               
300        endfor
301       
302        return(0)
303End
304
305//
306// copies only the specified panel from a work folder, (at COR level)
307// to the DIV structure to write out
308//
309// used to replace a single panel, or to fill in carriage by carriage.
310//
311Function V_CopyDIVToSave_OnePanel(type,detStr)
312        String type,detStr
313       
314        Variable ii,totCts,pixelX,pixelY
315        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
316        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
317       
318       
319                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
320                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
321                       
322        return(0)
323End
324
325
326
327
328
329// currently, there are no dummy fill values or attributes for the fake DIV file
330//
331Proc Setup_VSANS_DIV_Struct()
332
333        // lays out the tree and fills with dummy values
334        H_Setup_VSANS_DIV_Structure()
335       
336        // writes in the attributes
337//      H_Fill_VSANS_Attributes()
338       
339        // fill in with VCALC simulation bits
340//      H_Fill_VSANS_wSim()
341       
342End
343
344Proc Save_VSANS_DIV_Nexus(fileName)
345        String fileName="Test_VSANS_DIV_file"
346
347        // save as HDF5 (no attributes saved yet)
348        Save_VSANS_file("root:VSANS_DIV_file", fileName+".h5")
349       
350//      // read in a data file using the gateway-- reads from the home path
351//      H_HDF5Gate_Read_Raw(fileName+".h5")
352//     
353//      // after reading in a "partial" file using the gateway (to generate the xref)
354//      // Save the xref to disk (for later use)
355//      Save_HDF5___xref("root:"+fileName,"HDF5___xref")
356//     
357//      // after you've generated the HDF5___xref, load it in and copy it
358//      // to the necessary folder location.
359//      Copy_HDF5___xref("root:VSANS_DIV_file", "HDF5___xref")
360//     
361//      // writes out the contents of a data folder using the gateway
362//      H_HDF5Gate_Write_Raw("root:VSANS_DIV_file", fileName+".h5")
363//
364//      // re-load the data file using the gateway-- reads from the home path
365//      // now with attributes
366//      H_HDF5Gate_Read_Raw(fileName+".h5")
367       
368End
369
370//////////////  DIV file tests
371//
372//
373//      Make/O/T/N=1    file_name       = "VSANS_DIV_test.h5"
374//
375// simple generation of a fake div file. for sans, nothing other than the creation date was written to the
376// file header. nothing more is needed (possibly)
377//
378//
379//
380// TODO -- correct the number of pixels for the BACK detector
381//
382Proc H_Setup_VSANS_DIV_Structure()
383       
384        NewDataFolder/O/S root:VSANS_DIV_file           
385
386        NewDataFolder/O/S root:VSANS_DIV_file:entry     
387                Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
388                Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
389                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
390                        Make/O/T/N=1    name    = "NG3_VSANS"
391                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
392                        Make/O/D/N=(150,150)    data    = 1
393                        Make/O/D/N=(150,150)    linear_data_error       = 0.01
394                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
395                        Make/O/D/N=(48,128)     data = 1
396                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
397                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
398                        Make/O/D/N=(48,128)     data = 1
399                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
400                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
401                        Make/O/D/N=(128,48)     data    = 1
402                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
403                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
404                        Make/O/D/N=(128,48)     data    = 1
405                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
406                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
407                        Make/O/D/N=(48,128)     data = 1
408                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
409                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
410                        Make/O/D/N=(48,128)     data = 1
411                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
412                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
413                        Make/O/D/N=(128,48)     data    = 1
414                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
415                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
416                        Make/O/D/N=(128,48)     data    = 1
417                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
418
419//
420// version that is NOT perfect, LR detectors are "striped"
421//
422//      NewDataFolder/O/S root:VSANS_DIV_file:entry     
423//              Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
424//              Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
425//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
426//                      Make/O/T/N=1    name    = "NG3_VSANS"
427//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
428//                      Make/O/D/N=(150,150)    data    = 1 + (enoise(0.1))
429//                      Make/O/D/N=(150,150)    linear_data_error       = 0.01*abs(gnoise(1))
430//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
431//                      Make/O/D/N=(48,128)     data
432//                      data[][0] = 1+enoise(0.1)
433//                      data[][] = data[p][0]
434//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
435//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
436//                      Make/O/D/N=(48,128)     data
437//                      data[][0] = 1+enoise(0.1)
438//                      data[][] = data[p][0]
439//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
440//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
441//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
442//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
443//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
444//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
445//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
446//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FR             
447//                      Make/O/D/N=(48,128)     data
448//                      data[][0] = 1+enoise(0.1)
449//                      data[][] = data[p][0]
450//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
451//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
452//                      Make/O/D/N=(48,128)     data
453//                      data[][0] = 1+enoise(0.1)
454//                      data[][] = data[p][0]
455//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
456//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
457//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
458//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
459//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
460//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
461//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
462               
463               
464                // fake, empty folders so that the generic loaders can be used
465                NewDataFolder/O root:VSANS_DIV_file:entry:DAS_logs
466                NewDataFolder/O root:VSANS_DIV_file:entry:control
467                NewDataFolder/O root:VSANS_DIV_file:entry:reduction
468                NewDataFolder/O root:VSANS_DIV_file:entry:sample
469                NewDataFolder/O root:VSANS_DIV_file:entry:user
470
471                       
472        SetDataFolder root:
473
474End
475
476
477
478//
479// simple panel to display the 4 detector panels
480//
481// TODO:
482// -- label panels, axes
483// x- any manipulations, stats ?
484// x- add an "update" button (to update the status of the data - this may be automatic with an operation)
485// -- add a "load DIV" button (to make it easy)
486// -- add a "copy" button (to fill move data to STO and SUB)
487// x- add a "ratio" button
488// x- add a "difference" button
489// -- propagate the error in the arithmetic (see WorkFileMath)
490// -- un hard-wire the Front carriage from the panel proc
491
492Proc V_Display_DIV_Panels()
493        PauseUpdate; Silent 1           // building window...
494        NewPanel /W=(720,45,1530,570)/N=VSANS_DIVPanels/K=1
495        DoWindow/C VSANS_DIVPanels
496//      ModifyPanel fixedSize=1,noEdit =1
497
498
499        PopupMenu popup0,pos={17.00,10.00},size={77.00,23.00},proc=V_DispCarriagePopMenuProc,title="Carriage"
500        PopupMenu popup0,mode=1,value= #"\"F;M;\""
501        PopupMenu popup1,pos={134.00,10.00},size={68.00,23.00},proc=V_DispFolderPopMenuProc,title="Folder"
502        PopupMenu popup1,mode=1,popvalue="RAW",value= #"\"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;MSK;ADJ;\""
503        PopupMenu popup2,pos={246.00,10.00},size={83.00,23.00},proc=V_DispOperationPopMenuProc,title="Operation"
504        PopupMenu popup2,mode=1,value= #"\"none;ADJ=STO-SUB;ADJ=STO/SUB;\""
505        Button button0,pos={440.00,10.00},size={70.00,20.00},proc=V_DispUpdateButtonProc,title="Update"
506
507
508//      Display/W=(745,45,945,425)/HOST=#
509        Display/W=(10,45,210,425)/HOST=#
510        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
511
512        ModifyImage data ctab= {*,*,ColdWarm,0}
513        ModifyImage data ctabAutoscale=3
514        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
515        ModifyGraph mirror=2
516        ModifyGraph nticks=4
517        ModifyGraph minor=1
518        ModifyGraph fSize=9
519        ModifyGraph standoff=0
520        ModifyGraph tkLblRot(left)=90
521        ModifyGraph btLen=3
522        ModifyGraph tlOffset=-2
523        RenameWindow #,Panel_L
524        SetActiveSubwindow ##
525
526//      Display/W=(1300,45,1500,425)/HOST=#
527        Display/W=(565,45,765,425)/HOST=#
528        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
529        ModifyImage data ctab= {*,*,ColdWarm,0}
530        ModifyImage data ctabAutoscale=3
531        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
532        ModifyGraph mirror=2
533        ModifyGraph nticks=4
534        ModifyGraph minor=1
535        ModifyGraph fSize=9
536        ModifyGraph standoff=0
537        ModifyGraph tkLblRot(left)=90
538        ModifyGraph btLen=3
539        ModifyGraph tlOffset=-2
540        RenameWindow #,Panel_R
541        SetActiveSubwindow ##
542
543//      Display/W=(945,45,1300,235)/HOST=#
544        Display/W=(210,45,565,235)/HOST=#
545        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
546        ModifyImage data ctab= {*,*,ColdWarm,0}
547        ModifyImage data ctabAutoscale=3
548        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
549        ModifyGraph mirror=2
550        ModifyGraph nticks=4
551        ModifyGraph minor=1
552        ModifyGraph fSize=9
553        ModifyGraph standoff=0
554        ModifyGraph tkLblRot(left)=90
555        ModifyGraph btLen=3
556        ModifyGraph tlOffset=-2
557        RenameWindow #,Panel_T
558        SetActiveSubwindow ##
559
560//      Display/W=(945,235,1300,425)/HOST=#
561        Display/W=(210,235,565,425)/HOST=#
562        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
563        ModifyImage data ctab= {*,*,ColdWarm,0}
564        ModifyImage data ctabAutoscale=3
565        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
566        ModifyGraph mirror=2
567        ModifyGraph nticks=4
568        ModifyGraph minor=1
569        ModifyGraph fSize=9
570        ModifyGraph standoff=0
571        ModifyGraph tkLblRot(left)=90
572        ModifyGraph btLen=3
573        ModifyGraph tlOffset=-2
574        RenameWindow #,Panel_B
575        SetActiveSubwindow ##
576//
577
578        String/G root:Packages:NIST:VSANS:Globals:gDIVstr0 = "this is the title box0\rwith two lines"
579        String/G root:Packages:NIST:VSANS:Globals:gDIVstr1 = "this is the title box1\rwith two lines"
580        String/G root:Packages:NIST:VSANS:Globals:gDIVstr2 = "this is the title box2\rwith two lines"
581        String/G root:Packages:NIST:VSANS:Globals:gDIVstr3 = "this is the title box3\rwith two lines"
582       
583       
584        TitleBox title0 pos={15,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr0,fSize=11
585        TitleBox title1 pos={300,433},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr1,fSize=11
586        TitleBox title2 pos={300,482},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr2,fSize=11
587        TitleBox title3 pos={580,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr3,fSize=11
588
589
590        V_UpdateDIVStrings()
591End
592
593
594// called by the "update" button
595Proc V_UpdatePanelDisp()
596
597        ControlInfo popup0
598        String carrStr = S_value
599       
600        ControlInfo popup1
601        String folder = S_Value
602       
603        // remove the image
604        // append the new image
605        RemoveImage/Z/W=VSANS_DIVPanels#Panel_L data
606        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")               
607        SetActiveSubwindow VSANS_DIVPanels#Panel_L
608        ModifyImage data ctab= {*,*,ColdWarm,0}
609        ModifyImage data ctabAutoscale=3
610        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
611        ModifyGraph mirror=2
612        ModifyGraph nticks=4
613        ModifyGraph minor=1
614        ModifyGraph fSize=9
615        ModifyGraph standoff=0
616        ModifyGraph tkLblRot(left)=90
617        ModifyGraph btLen=3
618        ModifyGraph tlOffset=-2
619        SetActiveSubwindow ##
620
621
622        RemoveImage/Z/W=VSANS_DIVPanels#Panel_T data
623        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_T $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")               
624        SetActiveSubwindow VSANS_DIVPanels#Panel_T
625        ModifyImage data ctab= {*,*,ColdWarm,0}
626        ModifyImage data ctabAutoscale=3
627        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
628        ModifyGraph mirror=2
629        ModifyGraph nticks=4
630        ModifyGraph minor=1
631        ModifyGraph fSize=9
632        ModifyGraph standoff=0
633        ModifyGraph tkLblRot(left)=90
634        ModifyGraph btLen=3
635        ModifyGraph tlOffset=-2
636        SetActiveSubwindow ##
637       
638        RemoveImage/Z/W=VSANS_DIVPanels#Panel_B data
639        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_B $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")               
640        SetActiveSubwindow VSANS_DIVPanels#Panel_B
641        ModifyImage data ctab= {*,*,ColdWarm,0}
642        ModifyImage data ctabAutoscale=3
643        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
644        ModifyGraph mirror=2
645        ModifyGraph nticks=4
646        ModifyGraph minor=1
647        ModifyGraph fSize=9
648        ModifyGraph standoff=0
649        ModifyGraph tkLblRot(left)=90
650        ModifyGraph btLen=3
651        ModifyGraph tlOffset=-2
652        SetActiveSubwindow ##
653
654        RemoveImage/Z/W=VSANS_DIVPanels#Panel_R data
655        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_R $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")               
656        SetActiveSubwindow VSANS_DIVPanels#Panel_R
657        ModifyImage data ctab= {*,*,ColdWarm,0}
658        ModifyImage data ctabAutoscale=3
659        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
660        ModifyGraph mirror=2
661        ModifyGraph nticks=4
662        ModifyGraph minor=1
663        ModifyGraph fSize=9
664        ModifyGraph standoff=0
665        ModifyGraph tkLblRot(left)=90
666        ModifyGraph btLen=3
667        ModifyGraph tlOffset=-2
668        SetActiveSubwindow ##
669
670End
671
672
673
674
675Function V_DispFolderPopMenuProc(pa) : PopupMenuControl
676        STRUCT WMPopupAction &pa
677
678        switch( pa.eventCode )
679                case 2: // mouse up
680                        Variable popNum = pa.popNum
681                        String popStr = pa.popStr
682                        break
683                case -1: // control being killed
684                        break
685        endswitch
686
687        return 0
688End
689
690Function V_DispCarriagePopMenuProc(pa) : PopupMenuControl
691        STRUCT WMPopupAction &pa
692
693        switch( pa.eventCode )
694                case 2: // mouse up
695                        Variable popNum = pa.popNum
696                        String popStr = pa.popStr
697                        break
698                case -1: // control being killed
699                        break
700        endswitch
701
702        return 0
703End
704
705Function V_DispOperationPopMenuProc(pa) : PopupMenuControl
706        STRUCT WMPopupAction &pa
707
708        switch( pa.eventCode )
709                case 2: // mouse up
710                        Variable popNum = pa.popNum
711                        String popStr = pa.popStr
712                        break
713                case -1: // control being killed
714                        break
715        endswitch
716
717        return 0
718End
719
720Function V_DispUpdateButtonProc(ba) : ButtonControl
721        STRUCT WMButtonAction &ba
722
723        switch( ba.eventCode )
724                case 2: // mouse up
725                        // click code here
726                       
727                        // if there is an operation, do it
728                        V_DoDIVOperation()
729                       
730                        // update the data that is displayed
731                        Execute "V_UpdatePanelDisp()"
732                       
733                       
734                        // update the global strings
735                        V_UpdateDIVStrings()
736
737                       
738                        break
739                case -1: // control being killed
740                        break
741        endswitch
742
743        return 0
744End
745
746Function V_UpdateDIVStrings()
747
748        SVAR gDIVstr0 = root:Packages:NIST:VSANS:Globals:gDIVstr0
749        SVAR gDIVstr1 = root:Packages:NIST:VSANS:Globals:gDIVstr1
750        SVAR gDIVstr2 = root:Packages:NIST:VSANS:Globals:gDIVstr2
751        SVAR gDIVstr3 = root:Packages:NIST:VSANS:Globals:gDIVstr3
752       
753        ControlInfo popup0
754        String carrStr = S_value
755       
756        ControlInfo popup1
757        String folder = S_Value
758       
759        String  formatStr="Avg = %g +/- %g\rMin = %g, Max = %g"
760       
761        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")
762        sprintf gDIVstr0,formatStr,V_avg,V_sdev,V_min,V_max
763       
764        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")
765        sprintf gDIVstr1,formatStr,V_avg,V_sdev,V_min,V_max
766       
767        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")
768        sprintf gDIVstr2,formatStr,V_avg,V_sdev,V_min,V_max
769       
770        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")
771        sprintf gDIVstr3,formatStr,V_avg,V_sdev,V_min,V_max
772
773        TitleBox title0 title=gDIVstr0
774        TitleBox title1 title=gDIVstr1
775        TitleBox title2 title=gDIVstr2
776        TitleBox title3 title=gDIVstr3
777                       
778        return(0)
779end
780
781// if there is no operation called, immediately exit
782//
783// if there is a simple operation called, do it
784// TODO -- if there are more than these two simple operations, a more sophisticated switch will be necessary
785//
786Function V_DoDIVOperation()
787
788        ControlInfo popup2
789        String opStr = S_value
790       
791        if(cmpstr(opStr,"none")==0)
792                return(0)
793        endif
794       
795        ControlInfo popup0
796        String carrStr = S_value
797        // an operation is desired
798        // hard-wired use of STO and SUB, copy results to ADJ
799       
800        // make sure that something is in ADJ
801        // TODO -- reset the values of the data in ADJ, or it will look like the wrong calculation was done
802        //V_CopyWorkFolder("STO","ADJ")         // this is a macro, use the function instead
803        V_CopyHDFToWorkFolder("STO","ADJ")
804
805        WAVE w_sto_L = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"L:data")
806        WAVE w_sub_L = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"L:data")
807        Duplicate/O w_sto_L $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
808        WAVE w_adj_L = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
809
810        WAVE w_sto_R = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"R:data")
811        WAVE w_sub_R = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"R:data")
812        Duplicate/O w_sto_R $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
813        WAVE w_adj_R = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
814
815        WAVE w_sto_T = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"T:data")
816        WAVE w_sub_T = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"T:data")
817        Duplicate/O w_sto_T $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
818        WAVE w_adj_T = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
819
820        WAVE w_sto_B = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"B:data")
821        WAVE w_sub_B = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"B:data")
822        Duplicate/O w_sto_B $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
823        WAVE w_adj_B = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
824
825       
826        if(cmpstr(opStr,"ADJ=STO/SUB")==0)
827                w_adj_L = w_sto_L/w_sub_L
828                w_adj_R = w_sto_R/w_sub_R
829                w_adj_T = w_sto_T/w_sub_T
830                w_adj_B = w_sto_B/w_sub_B
831        else
832                w_adj_L = w_sto_L - w_sub_L
833                w_adj_R = w_sto_R - w_sub_R
834                w_adj_T = w_sto_T - w_sub_T
835                w_adj_B = w_sto_B - w_sub_B
836        endif
837
838        return(0)
839end
840
841
Note: See TracBrowser for help on using the repository browser.