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

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

some addtions:

DIV file generation is now aware of the High resolution detector, but the procedures are still awaiting data for testing.

Read Noise file can now be read in and stored in the (RAW) folder ReadNoise?. This is not a work folder and the data isnot changed from the RAW state. This image is then subtracted from other raw data as it is converted to a work file (SAM, EMP, etc.) Previously, only a constant value was subtracted. If the ReadNoise? data is not present, the constant will be subtracted. There is a menu option to load the ReadNoise? data.

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