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

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

more utilities and bug fixes to handle:
(1) generation of DIV files
(2) generation and loading of slit-smeared VSANS data sets

Loading of VSANS data sets and generating the resolution smearing matrix required adding a conditional compile statement to the PlotUtilsMacro? file, to distinguish VSANS data - crudely done now by checking to see that VSANS is defined (which will NOT be the case for a "normal" Analysis experiment. This will need to be revisited in the future.

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