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

Last change on this file since 1124 was 1124, checked in by srkline, 4 years ago

changes to read in new USANS Raw data structure, based on the file creation date.

Some additional changes to sector averaging and viewing the "avg" masks on the detector panels. still not quite complete.

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