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

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

more fixes to DIV file generation using the high-resolution detector

added extra header lines to the the QxQy? ASCII output format. there are now 30 header lines, and 7 or so are unused to allow for future additions.

the default mask for the high res detector has been enlarged to account for the large beamstop that is used during collection of the sensitivity file.

File size: 31.8 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        Vf_NormalizeDIV_proc(reducedFolderType,carriageStr)
167end
168
169Function Vf_NormalizeDIV_proc(reducedFolderType,carriageStr)
170        String reducedFolderType,carriageStr
171
172        if (cmpstr(carriageStr,"B")==0)
173                V_NormalizeDIV_onePanel(reducedFolderType,"B")
174        elseif (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       
186        return(0)
187End
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// DONE
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// DONE:
234// x- I 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//// NOTE (Currently unused. use V_NormalizeDIV_onePanel() instead)
260////
261//// -- data should be copied to some alternate work folder before this step
262//// -- for T/B detectors, this may not work as intended if the whole detector is not illuminated.
263////    How to handle? A mask?
264//// x- is this the correct calculation of the error? (YES) It should be correct up to this point since the
265////    standard reduction has been used, but now the normalization step is a multiplication
266////    by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is
267////    what is done in SANS)
268////
269//Function V_NormalizeDIV(type)
270//      String type
271//
272//      Variable ii,totCts,pixelX,pixelY
273//      String detStr
274//
275//      for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
276//              detStr = StringFromList(ii, ksDetectorListAll, ";")
277//              Wave w = V_getDetectorDataW(type,detStr)
278//              Wave w_err = V_getDetectorDataErrW(type,detStr)
279//              pixelX = V_getDet_pixel_num_x(type,detStr)
280//              pixelY = V_getDet_pixel_num_y(type,detStr)
281//
282//              totCts = sum(w,Inf,-Inf)                //sum all of the data
283//             
284//              w /= totCts
285//              w *= pixelX*pixelY
286//
287//              w_err /= totCts
288//              w_err *= pixelX*pixelY
289//             
290//      endfor
291//     
292//      return(0)
293//End
294
295
296// copies an entire work folder, all 9 detectors (at COR level)
297// to the DIV structure to write out
298//
299Function V_CopyDIVToSave(type)
300        String type
301       
302        Variable ii,totCts,pixelX,pixelY
303        String detStr
304        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
305        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
306       
307       
308        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
309                detStr = StringFromList(ii, ksDetectorListAll, ";")
310
311                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
312                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
313               
314        endfor
315       
316        return(0)
317End
318
319//
320// copies only the specified panel from a work folder, (at COR level)
321// to the DIV structure to write out
322//
323// used to replace a single panel, or to fill in carriage by carriage.
324//
325Function V_CopyDIVToSave_OnePanel(type,detStr)
326        String type,detStr
327       
328        Variable ii,totCts,pixelX,pixelY
329        String topath = "root:VSANS_DIV_file:entry:instrument:detector_"
330        String fromPath = "root:Packages:NIST:VSANS:"+type+":entry:instrument:detector_"
331       
332       
333                Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data")
334                Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error")
335                       
336        return(0)
337End
338
339
340
341
342
343// currently, there are no dummy fill values or attributes for the fake DIV file
344//
345Proc Setup_VSANS_DIV_Struct()
346
347        // lays out the tree and fills with dummy values
348        H_Setup_VSANS_DIV_Structure()
349       
350        // writes in the attributes
351//      H_Fill_VSANS_Attributes()
352       
353        // fill in with VCALC simulation bits
354//      H_Fill_VSANS_wSim()
355       
356End
357
358Proc Save_VSANS_DIV_Nexus(fileName)
359        String fileName="Test_VSANS_DIV_file"
360
361        // save as HDF5 (no attributes saved yet)
362        Save_VSANS_file("root:VSANS_DIV_file", fileName+".h5")
363       
364//      // read in a data file using the gateway-- reads from the home path
365//      H_HDF5Gate_Read_Raw(fileName+".h5")
366//     
367//      // after reading in a "partial" file using the gateway (to generate the xref)
368//      // Save the xref to disk (for later use)
369//      Save_HDF5___xref("root:"+fileName,"HDF5___xref")
370//     
371//      // after you've generated the HDF5___xref, load it in and copy it
372//      // to the necessary folder location.
373//      Copy_HDF5___xref("root:VSANS_DIV_file", "HDF5___xref")
374//     
375//      // writes out the contents of a data folder using the gateway
376//      H_HDF5Gate_Write_Raw("root:VSANS_DIV_file", fileName+".h5")
377//
378//      // re-load the data file using the gateway-- reads from the home path
379//      // now with attributes
380//      H_HDF5Gate_Read_Raw(fileName+".h5")
381       
382End
383
384//////////////  DIV file tests
385//
386//
387//      Make/O/T/N=1    file_name       = "VSANS_DIV_test.h5"
388//
389// simple generation of a fake div file. for sans, nothing other than the creation date was written to the
390// file header. nothing more is needed (possibly)
391//
392//
393//
394// TODO -- correct the number of pixels for the BACK detector
395//
396Proc H_Setup_VSANS_DIV_Structure()
397       
398        NewDataFolder/O/S root:VSANS_DIV_file           
399
400        NewDataFolder/O/S root:VSANS_DIV_file:entry     
401                Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
402                Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
403                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
404                        Make/O/T/N=1    name    = "NG3_VSANS"
405                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
406                        Make/O/D/N=(680,1656)   data    = 1
407                        Make/O/D/N=(680,1656)   linear_data_error       = 0.01
408                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
409                        Make/O/D/N=(48,128)     data = 1
410                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
411                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
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_MT             
415                        Make/O/D/N=(128,48)     data    = 1
416                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
417                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
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_FR             
421                        Make/O/D/N=(48,128)     data = 1
422                        Make/O/D/N=(48,128)     linear_data_error       = 0.01
423                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
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_FT             
427                        Make/O/D/N=(128,48)     data    = 1
428                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
429                NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
430                        Make/O/D/N=(128,48)     data    = 1
431                        Make/O/D/N=(128,48)     linear_data_error       = 0.01
432
433//
434// version that is NOT perfect, LR detectors are "striped"
435//
436//      NewDataFolder/O/S root:VSANS_DIV_file:entry     
437//              Make/O/T/N=1    title   = "This is a DIV file for VSANS: VSANS_DIV"
438//              Make/O/T/N=1    start_date      = "2017-02-28T08:15:30-5:00"
439//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument         
440//                      Make/O/T/N=1    name    = "NG3_VSANS"
441//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_B       
442//                      Make/O/D/N=(150,150)    data    = 1 + (enoise(0.1))
443//                      Make/O/D/N=(150,150)    linear_data_error       = 0.01*abs(gnoise(1))
444//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MR             
445//                      Make/O/D/N=(48,128)     data
446//                      data[][0] = 1+enoise(0.1)
447//                      data[][] = data[p][0]
448//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
449//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_ML             
450//                      Make/O/D/N=(48,128)     data
451//                      data[][0] = 1+enoise(0.1)
452//                      data[][] = data[p][0]
453//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
454//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MT             
455//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
456//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
457//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_MB             
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_FR             
461//                      Make/O/D/N=(48,128)     data
462//                      data[][0] = 1+enoise(0.1)
463//                      data[][] = data[p][0]
464//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
465//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FL             
466//                      Make/O/D/N=(48,128)     data
467//                      data[][0] = 1+enoise(0.1)
468//                      data[][] = data[p][0]
469//                      Make/O/D/N=(48,128)     linear_data_error       = 0.01*abs(gnoise(1))
470//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FT             
471//                      Make/O/D/N=(128,48)     data    = 1 + (enoise(0.1))
472//                      Make/O/D/N=(128,48)     linear_data_error       = 0.01*abs(gnoise(1))
473//              NewDataFolder/O/S root:VSANS_DIV_file:entry:instrument:detector_FB             
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               
477               
478                // fake, empty folders so that the generic loaders can be used
479                NewDataFolder/O root:VSANS_DIV_file:entry:DAS_logs
480                NewDataFolder/O root:VSANS_DIV_file:entry:control
481                NewDataFolder/O root:VSANS_DIV_file:entry:reduction
482                NewDataFolder/O root:VSANS_DIV_file:entry:sample
483                NewDataFolder/O root:VSANS_DIV_file:entry:user
484
485                       
486        SetDataFolder root:
487
488End
489
490
491
492//
493// simple panel to display the 4 detector panels
494//
495// TODO:
496// -- label panels, axes
497// x- any manipulations, stats ?
498// x- add an "update" button (to update the status of the data - this may be automatic with an operation)
499// -- add a "load DIV" button (to make it easy)
500// -- add a "copy" button (to fill move data to STO and SUB)
501// x- add a "ratio" button
502// x- add a "difference" button
503// -- propagate the error in the arithmetic (see WorkFileMath)
504// -- un hard-wire the Front carriage from the panel proc
505
506Proc V_Display_DIV_Panels()
507        PauseUpdate; Silent 1           // building window...
508        NewPanel /W=(720,45,1530,570)/N=VSANS_DIVPanels/K=1
509        DoWindow/C VSANS_DIVPanels
510//      ModifyPanel fixedSize=1,noEdit =1
511
512
513        PopupMenu popup0,pos={17.00,10.00},size={77.00,23.00},proc=V_DispCarriagePopMenuProc,title="Carriage"
514        PopupMenu popup0,mode=1,value= #"\"F;M;B;\""
515        PopupMenu popup1,pos={134.00,10.00},size={68.00,23.00},proc=V_DispFolderPopMenuProc,title="Folder"
516        PopupMenu popup1,mode=1,popvalue="RAW",value= #"\"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;MSK;ADJ;\""
517        PopupMenu popup2,pos={246.00,10.00},size={83.00,23.00},proc=V_DispOperationPopMenuProc,title="Operation"
518        PopupMenu popup2,mode=1,value= #"\"none;ADJ=STO-SUB;ADJ=STO/SUB;\""
519        Button button0,pos={440.00,10.00},size={70.00,20.00},proc=V_DispUpdateButtonProc,title="Update"
520
521
522//      Display/W=(745,45,945,425)/HOST=#
523        Display/W=(10,45,210,425)/HOST=#
524        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
525
526        ModifyImage data ctab= {*,*,ColdWarm,0}
527        ModifyImage data ctabAutoscale=3
528        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
529        ModifyGraph mirror=2
530        ModifyGraph nticks=4
531        ModifyGraph minor=1
532        ModifyGraph fSize=9
533        ModifyGraph standoff=0
534        ModifyGraph tkLblRot(left)=90
535        ModifyGraph btLen=3
536        ModifyGraph tlOffset=-2
537        RenameWindow #,Panel_L
538        SetActiveSubwindow ##
539
540//      Display/W=(1300,45,1500,425)/HOST=#
541        Display/W=(565,45,765,425)/HOST=#
542        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
543        ModifyImage data ctab= {*,*,ColdWarm,0}
544        ModifyImage data ctabAutoscale=3
545        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
546        ModifyGraph mirror=2
547        ModifyGraph nticks=4
548        ModifyGraph minor=1
549        ModifyGraph fSize=9
550        ModifyGraph standoff=0
551        ModifyGraph tkLblRot(left)=90
552        ModifyGraph btLen=3
553        ModifyGraph tlOffset=-2
554        RenameWindow #,Panel_R
555        SetActiveSubwindow ##
556
557//      Display/W=(945,45,1300,235)/HOST=#
558        Display/W=(210,45,565,235)/HOST=#
559        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
560        ModifyImage data ctab= {*,*,ColdWarm,0}
561        ModifyImage data ctabAutoscale=3
562        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
563        ModifyGraph mirror=2
564        ModifyGraph nticks=4
565        ModifyGraph minor=1
566        ModifyGraph fSize=9
567        ModifyGraph standoff=0
568        ModifyGraph tkLblRot(left)=90
569        ModifyGraph btLen=3
570        ModifyGraph tlOffset=-2
571        RenameWindow #,Panel_T
572        SetActiveSubwindow ##
573
574//      Display/W=(945,235,1300,425)/HOST=#
575        Display/W=(210,235,565,425)/HOST=#
576        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
577        ModifyImage data ctab= {*,*,ColdWarm,0}
578        ModifyImage data ctabAutoscale=3
579        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
580        ModifyGraph mirror=2
581        ModifyGraph nticks=4
582        ModifyGraph minor=1
583        ModifyGraph fSize=9
584        ModifyGraph standoff=0
585        ModifyGraph tkLblRot(left)=90
586        ModifyGraph btLen=3
587        ModifyGraph tlOffset=-2
588        RenameWindow #,Panel_B
589        SetActiveSubwindow ##
590//
591
592        String/G root:Packages:NIST:VSANS:Globals:gDIVstr0 = "this is the title box0\rwith two lines"
593        String/G root:Packages:NIST:VSANS:Globals:gDIVstr1 = "this is the title box1\rwith two lines"
594        String/G root:Packages:NIST:VSANS:Globals:gDIVstr2 = "this is the title box2\rwith two lines"
595        String/G root:Packages:NIST:VSANS:Globals:gDIVstr3 = "this is the title box3\rwith two lines"
596       
597       
598        TitleBox title0 pos={15,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr0,fSize=11
599        TitleBox title1 pos={300,433},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr1,fSize=11
600        TitleBox title2 pos={300,482},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr2,fSize=11
601        TitleBox title3 pos={580,450},size={112,36},title=root:Packages:NIST:VSANS:Globals:gDIVstr3,fSize=11
602
603
604        V_UpdateDIVStrings()
605End
606
607
608// called by the "update" button
609Function V_UpdatePanelDisp()
610
611        ControlInfo popup0
612        String carrStr = S_value
613       
614        ControlInfo popup1
615        String folder = S_Value
616       
617        string tmpStr=""
618        Variable isVCALC=0
619        if(cmpstr("VCALC",folder)==0)
620                isVCALC=1
621        endif
622               
623        // remove everything from each of the 4 panels
624        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_L",";")
625        if(ItemsInList(tmpStr) > 0)
626                do
627                        RemoveImage /W=VSANS_DIVPanels#Panel_L $(StringFromList(0,tmpStr,";"))          //get 1st item
628                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_L",";")                                                           //refresh list
629                while(ItemsInList(tmpStr) > 0)
630        endif
631       
632        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_R",";")
633        if(ItemsInList(tmpStr) > 0)
634                do
635                        RemoveImage /W=VSANS_DIVPanels#Panel_R $(StringFromList(0,tmpStr,";"))          //get 1st item
636                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_R",";")                                                           //refresh list
637                while(ItemsInList(tmpStr) > 0)
638        endif
639       
640        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_T",";")
641        if(ItemsInList(tmpStr) > 0)
642                do
643                        RemoveImage /W=VSANS_DIVPanels#Panel_T $(StringFromList(0,tmpStr,";"))          //get 1st item
644                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_T",";")                                                           //refresh list
645                while(ItemsInList(tmpStr) > 0)
646        endif
647       
648        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_B",";")
649        if(ItemsInList(tmpStr) > 0)
650                do
651                        RemoveImage /W=VSANS_DIVPanels#Panel_B $(StringFromList(0,tmpStr,";"))          //get 1st item
652                        tmpStr = ImageNameList("VSANS_DIVPanels#Panel_B",";")                                                           //refresh list
653                while(ItemsInList(tmpStr) > 0)
654        endif
655       
656
657        // append the new image
658        // if back, put this in the "left" postion, and nothing else
659        if(cmpstr("B",carrStr)==0)
660                if(isVCALC)
661                        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+":det_"+carrStr)         
662                        SetActiveSubwindow VSANS_DIVPanels#Panel_L
663                        ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
664                        ModifyImage ''#0 ctabAutoscale=3
665                else
666                        AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+":data")         
667                        SetActiveSubwindow VSANS_DIVPanels#Panel_L
668                        ModifyImage data ctab= {*,*,ColdWarm,0}
669                        ModifyImage data ctabAutoscale=3       
670                endif
671                ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
672                ModifyGraph mirror=2
673                ModifyGraph nticks=4
674                ModifyGraph minor=1
675                ModifyGraph fSize=9
676                ModifyGraph standoff=0
677                ModifyGraph tkLblRot(left)=90
678                ModifyGraph btLen=3
679                ModifyGraph tlOffset=-2
680                SetActiveSubwindow ##
681                return(0)
682        endif
683       
684//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_L data
685        if(isVCALC)
686                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:det_"+carrStr+"L")           
687                SetActiveSubwindow VSANS_DIVPanels#Panel_L
688                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
689                ModifyImage ''#0 ctabAutoscale=3
690        else
691                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_L $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")               
692                SetActiveSubwindow VSANS_DIVPanels#Panel_L
693                ModifyImage data ctab= {*,*,ColdWarm,0}
694                ModifyImage data ctabAutoscale=3       
695        endif
696        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
697        ModifyGraph mirror=2
698        ModifyGraph nticks=4
699        ModifyGraph minor=1
700        ModifyGraph fSize=9
701        ModifyGraph standoff=0
702        ModifyGraph tkLblRot(left)=90
703        ModifyGraph btLen=3
704        ModifyGraph tlOffset=-2
705        SetActiveSubwindow ##
706
707
708//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_T data
709        if(isVCALC)
710                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_T $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:det_"+carrStr+"T")           
711                SetActiveSubwindow VSANS_DIVPanels#Panel_T
712                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
713                ModifyImage ''#0 ctabAutoscale=3
714        else
715                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_T $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")               
716                SetActiveSubwindow VSANS_DIVPanels#Panel_T
717                ModifyImage data ctab= {*,*,ColdWarm,0}
718                ModifyImage data ctabAutoscale=3
719        endif
720        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
721        ModifyGraph mirror=2
722        ModifyGraph nticks=4
723        ModifyGraph minor=1
724        ModifyGraph fSize=9
725        ModifyGraph standoff=0
726        ModifyGraph tkLblRot(left)=90
727        ModifyGraph btLen=3
728        ModifyGraph tlOffset=-2
729        SetActiveSubwindow ##
730       
731//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_B data
732        if(isVCALC)
733                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_B $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:det_"+carrStr+"B")           
734                SetActiveSubwindow VSANS_DIVPanels#Panel_B
735                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
736                ModifyImage ''#0 ctabAutoscale=3
737        else
738                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_B $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")               
739                SetActiveSubwindow VSANS_DIVPanels#Panel_B
740                ModifyImage data ctab= {*,*,ColdWarm,0}
741                ModifyImage data ctabAutoscale=3
742        endif
743        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
744        ModifyGraph mirror=2
745        ModifyGraph nticks=4
746        ModifyGraph minor=1
747        ModifyGraph fSize=9
748        ModifyGraph standoff=0
749        ModifyGraph tkLblRot(left)=90
750        ModifyGraph btLen=3
751        ModifyGraph tlOffset=-2
752        SetActiveSubwindow ##
753
754//      RemoveImage/Z/W=VSANS_DIVPanels#Panel_R data
755        if(isVCALC)
756                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_R $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:det_"+carrStr+"R")           
757                SetActiveSubwindow VSANS_DIVPanels#Panel_R
758                ModifyImage ''#0 ctab= {*,*,ColdWarm,0}
759                ModifyImage ''#0 ctabAutoscale=3
760        else
761                AppendImage/T/G=1/W=VSANS_DIVPanels#Panel_R $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")               
762                SetActiveSubwindow VSANS_DIVPanels#Panel_R
763                ModifyImage data ctab= {*,*,ColdWarm,0}
764                ModifyImage data ctabAutoscale=3
765        endif
766        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14
767        ModifyGraph mirror=2
768        ModifyGraph nticks=4
769        ModifyGraph minor=1
770        ModifyGraph fSize=9
771        ModifyGraph standoff=0
772        ModifyGraph tkLblRot(left)=90
773        ModifyGraph btLen=3
774        ModifyGraph tlOffset=-2
775        SetActiveSubwindow ##
776
777        return(0)
778End
779
780
781
782
783Function V_DispFolderPopMenuProc(pa) : PopupMenuControl
784        STRUCT WMPopupAction &pa
785
786        switch( pa.eventCode )
787                case 2: // mouse up
788                        Variable popNum = pa.popNum
789                        String popStr = pa.popStr
790                        break
791                case -1: // control being killed
792                        break
793        endswitch
794
795        return 0
796End
797
798Function V_DispCarriagePopMenuProc(pa) : PopupMenuControl
799        STRUCT WMPopupAction &pa
800
801        switch( pa.eventCode )
802                case 2: // mouse up
803                        Variable popNum = pa.popNum
804                        String popStr = pa.popStr
805                        break
806                case -1: // control being killed
807                        break
808        endswitch
809
810        return 0
811End
812
813Function V_DispOperationPopMenuProc(pa) : PopupMenuControl
814        STRUCT WMPopupAction &pa
815
816        switch( pa.eventCode )
817                case 2: // mouse up
818                        Variable popNum = pa.popNum
819                        String popStr = pa.popStr
820                        break
821                case -1: // control being killed
822                        break
823        endswitch
824
825        return 0
826End
827
828Function V_DispUpdateButtonProc(ba) : ButtonControl
829        STRUCT WMButtonAction &ba
830
831        switch( ba.eventCode )
832                case 2: // mouse up
833                        // click code here
834                       
835                        // if there is an operation, do it
836                        V_DoDIVOperation()
837                       
838                        // update the data that is displayed
839                        V_UpdatePanelDisp()
840                       
841                       
842                        // update the global strings
843                        V_UpdateDIVStrings()
844
845                       
846                        break
847                case -1: // control being killed
848                        break
849        endswitch
850
851        return 0
852End
853
854Function V_UpdateDIVStrings()
855
856        SVAR gDIVstr0 = root:Packages:NIST:VSANS:Globals:gDIVstr0
857        SVAR gDIVstr1 = root:Packages:NIST:VSANS:Globals:gDIVstr1
858        SVAR gDIVstr2 = root:Packages:NIST:VSANS:Globals:gDIVstr2
859        SVAR gDIVstr3 = root:Packages:NIST:VSANS:Globals:gDIVstr3
860       
861        ControlInfo popup0
862        String carrStr = S_value
863       
864        ControlInfo popup1
865        String folder = S_Value
866       
867        String  formatStr="Avg = %g +/- %g\rMin = %g, Max = %g"
868
869        if(cmpstr(carrStr,"B")==0)
870                WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_B:data")
871                sprintf gDIVstr0,formatStr,V_avg,V_sdev,V_min,V_max
872                gDIVStr1 = ""
873                gDIVStr2 = ""
874                gDIVStr3 = ""
875                TitleBox title0 title=gDIVstr0
876                TitleBox title1 title=gDIVstr1
877                TitleBox title2 title=gDIVstr2
878                TitleBox title3 title=gDIVstr3
879                return(0)
880        endif
881               
882        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"L:data")
883        sprintf gDIVstr0,formatStr,V_avg,V_sdev,V_min,V_max
884       
885        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"T:data")
886        sprintf gDIVstr1,formatStr,V_avg,V_sdev,V_min,V_max
887       
888        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"B:data")
889        sprintf gDIVstr2,formatStr,V_avg,V_sdev,V_min,V_max
890       
891        WaveStats/Q $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+carrStr+"R:data")
892        sprintf gDIVstr3,formatStr,V_avg,V_sdev,V_min,V_max
893
894        TitleBox title0 title=gDIVstr0
895        TitleBox title1 title=gDIVstr1
896        TitleBox title2 title=gDIVstr2
897        TitleBox title3 title=gDIVstr3
898                       
899        return(0)
900end
901
902// if there is no operation called, immediately exit
903//
904// if there is a simple operation called, do it
905// TODO -- if there are more than these two simple operations, a more sophisticated switch will be necessary
906//
907Function V_DoDIVOperation()
908
909        ControlInfo popup2
910        String opStr = S_value
911       
912        if(cmpstr(opStr,"none")==0)
913                return(0)
914        endif
915       
916        ControlInfo popup0
917        String carrStr = S_value
918        // an operation is desired
919        // hard-wired use of STO and SUB, copy results to ADJ
920       
921        // make sure that something is in ADJ
922        // TODO -- reset the values of the data in ADJ, or it will look like the wrong calculation was done
923        //V_CopyWorkFolder("STO","ADJ")         // this is a macro, use the function instead
924        V_CopyHDFToWorkFolder("STO","ADJ")
925
926
927        if(cmpstr(carrStr,"B")==0)
928                WAVE w_sto_B = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_B:data")
929                WAVE w_sub_B = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_B:data")
930                Duplicate/O w_sto_B $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_B:data")
931                WAVE w_adj_B = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_B:data")
932        else
933                WAVE w_sto_L = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"L:data")
934                WAVE w_sub_L = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"L:data")
935                Duplicate/O w_sto_L $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
936                WAVE w_adj_L = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"L:data")
937       
938                WAVE w_sto_R = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"R:data")
939                WAVE w_sub_R = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"R:data")
940                Duplicate/O w_sto_R $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
941                WAVE w_adj_R = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"R:data")
942       
943                WAVE w_sto_T = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"T:data")
944                WAVE w_sub_T = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"T:data")
945                Duplicate/O w_sto_T $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
946                WAVE w_adj_T = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"T:data")
947       
948                WAVE w_sto_B = $("root:Packages:NIST:VSANS:STO:entry:instrument:detector_"+carrStr+"B:data")
949                WAVE w_sub_B = $("root:Packages:NIST:VSANS:SUB:entry:instrument:detector_"+carrStr+"B:data")
950                Duplicate/O w_sto_B $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
951                WAVE w_adj_B = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+carrStr+"B:data")
952        endif
953
954
955//handle the back detector separately, then exit
956        if(cmpstr(carrStr,"B")==0)
957                if(cmpstr(opStr,"ADJ=STO/SUB")==0)
958                        w_adj_B = w_sto_B/w_sub_B
959                else
960                        w_adj_B = w_sto_B - w_sub_B
961                endif
962                return(0)
963        endif
964
965
966// M or F carriages     
967        if(cmpstr(opStr,"ADJ=STO/SUB")==0)
968                w_adj_L = w_sto_L/w_sub_L
969                w_adj_R = w_sto_R/w_sub_R
970                w_adj_T = w_sto_T/w_sub_T
971                w_adj_B = w_sto_B/w_sub_B
972        else
973                w_adj_L = w_sto_L - w_sub_L
974                w_adj_R = w_sto_R - w_sub_R
975                w_adj_T = w_sto_T - w_sub_T
976                w_adj_B = w_sto_B - w_sub_B
977        endif
978
979        return(0)
980end
981
982
Note: See TracBrowser for help on using the repository browser.