source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/Polarization/Pol_PolarizationCorrection.ipf @ 835

Last change on this file since 835 was 835, checked in by srkline, 11 years ago

moving the Polarization routines to a temporary "beta" menu location on the macros menu, numbering the panels.

Created a loader for the polarization routines that will load the SANS reduction if needed.

File size: 94.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3// These procedures and calculations duplicate the work of K. Krycka and WC Chen
4// in calculating the state of the He cell and subsequent correction of scattering data
5//
6//
7// SRK May 2011
8//
9//
10//
11// there is a particular sequence of things that need to be calculated
12// lots of constants, and lots of confusing, similar notation.
13//
14//
15// for this implementation, I'll follow what is described in the "PASANS"
16// writeup by K. Krycka, and I'll try to follow the equations as numbered there
17// and keep the notation as close as possible.
18//
19// error propagation was written up elsewhere, and will be implemented as well
20// - each of the calculations based on transmissions will need to have errors
21// brought in, and carried through the calculations. Some will be simple, some
22// will probably be easiest with expansions.
23//
24
25
26
27
28
29// This is a first pass at the input panel (step 3)
30// to gather all of the files and conditions necessary to do the polarization correction
31//
32//
33
34// I'll need space for 4 input files in, say SAM
35// - load in all of the UU files, adding together
36// - rename the UU data, error
37//
38// - repeat for the other three cross sections, in the SAM folder, there will be
39// scattering data for all four cross sections present.
40//
41// then add together the values for the coefficient matrix.
42// -- this can be tricky with rescaling for time, and adding to the proper row of the
43// coefficient matrix. I'll need to re-read either the monitor or the time from the header
44// of each file that was added
45//
46// Then everything is set to do the inversion.
47// -- the result of the inversion is 4 corrected data sets, with no polarization effects. "_pc"
48//
49// Now I can one-by-one, copy the correct UU, UD, etc. into "data" and "linear_data" (and the Reals, etc)
50// and run through the corrections as if it was normal SANS data
51//
52// this whole procedure is going to be essentially a big script of existing procedures
53//
54//
55//
56// TODO:
57// - need a better way of flowing through the process, to be sure that values are set
58// as needed and that one step won't fail because a previous step wasn't done yet. Combining the
59// first three panels into one w/ tabs would help a lot, but that is rather complex to implement.
60// and is still not a fool-proof situation
61//
62// X- mathod to save and restore the panel state - especially the popup selections
63//
64// -- should I force the Polarization correction to be re-done just before the protocol is
65//                      executed? Then I'm sure that the PC is done. Must do for each tab (only if part of the protocol)
66//                      Except that the procedures work on the "active" tab...
67//
68// -- When multiple files are added together, there are changes made to the RealsRead (monCts, etc.). Are these
69//              properly made, and then properly copied to the "_UU", and then properly copied back to the untagged waves
70//              for use in the reduction?
71//
72
73
74
75
76// main entry to the PolCor Panel
77Proc ShowPolCorSetup()
78
79        Variable restore=0
80        DoWindow/F PolCor_Panel
81        if(V_flag==0)
82       
83                InitProtocolPanel()             //this will reset the strings.
84               
85                restore=Initialize_PolCorPanel()
86                PolCor_Panel()
87                SetWindow PolCor_Panel hook(kill)=PolCorPanelHook               //to save the state when panel is killed
88                //disable the controls on other tabs
89                ToggleSelControls("_1_",1)
90                ToggleSelControls("_2_",1)
91               
92                //restore the entries
93                if(restore)
94                        RestorePolCorPanel()
95                endif
96               
97
98        endif
99End
100
101
102Function RestorePolCorPanel()
103        //restore the popup state
104        Wave/T/Z w=root:Packages:NIST:Polarization:PolCor_popState
105
106        Variable ii,num
107        String name,popStr,list
108       
109        list = P_GetConditionNameList()         //list of conditions
110        if(WaveExists(w))
111                num = DimSize(w,0)
112                for(ii=0;ii<num;ii+=1)
113                        name = w[ii][0]
114                        popStr = w[ii][1]
115                        if(cmpstr("none",popStr) !=0 )
116                                PopupMenu $name,win=PolCor_Panel,mode=WhichListItem(popStr, list,";",0,0),popvalue=popStr
117                        endif
118                endfor
119        endif
120        return(0)
121End
122
123
124//
125// TODO:
126// X- only re-initialize values if user wants to. maybe ask.
127//
128Function Initialize_PolCorPanel()
129
130
131        Variable ii,num
132        String name,popStr
133               
134        DoAlert 1,"Do you want to initialize, wiping out all of your entries?"
135        if(V_flag != 1)         //1== yes initialize, so everything else, restore the entries
136                return(1)
137        endif
138       
139        //initialize all of the strings for the input
140        SetDataFolder root:Packages:NIST:Polarization
141       
142        //controls are labeled "name_#_UU_#" where name is the type of control, # is the tab #, and (2nd) # is the control #
143
144/// new method using a listBox for each state   
145        Make/O/T/N=2 lbTitles
146        lbTitles[0] = "Run #"
147        lbTitles[1] = "Cell"
148       
149        Make/O/N=(10,2) lbSelWave
150        lbSelWave[][0] = 2                      //Run # column is editable
151        lbSelWave[][1] = 1                      //Cell name is a popup, not editable
152       
153        Make/O/T/N=(10,2) ListWave_0_UU=""
154        Make/O/T/N=(10,2) ListWave_0_DU=""
155        Make/O/T/N=(10,2) ListWave_0_DD=""
156        Make/O/T/N=(10,2) ListWave_0_UD=""
157        Make/O/N=(10,2) lbSelWave_0_UU
158        Make/O/N=(10,2) lbSelWave_0_DU
159        Make/O/N=(10,2) lbSelWave_0_DD
160        Make/O/N=(10,2) lbSelWave_0_UD
161        lbSelWave_0_UU[][0] = 2                 //Run # column is editable
162        lbSelWave_0_DU[][0] = 2                 //Run # column is editable
163        lbSelWave_0_DD[][0] = 2                 //Run # column is editable
164        lbSelWave_0_UD[][0] = 2                 //Run # column is editable
165        lbSelWave_0_UU[][1] = 1                 //Cell name is a popup, not editable   
166        lbSelWave_0_DU[][1] = 1                 //Cell name is a popup, not editable   
167        lbSelWave_0_DD[][1] = 1                 //Cell name is a popup, not editable   
168        lbSelWave_0_UD[][1] = 1                 //Cell name is a popup, not editable   
169       
170        Make/O/T/N=(10,2) ListWave_1_UU=""
171        Make/O/T/N=(10,2) ListWave_1_DU=""
172        Make/O/T/N=(10,2) ListWave_1_DD=""
173        Make/O/T/N=(10,2) ListWave_1_UD=""
174        Make/O/N=(10,2) lbSelWave_1_UU
175        Make/O/N=(10,2) lbSelWave_1_DU
176        Make/O/N=(10,2) lbSelWave_1_DD
177        Make/O/N=(10,2) lbSelWave_1_UD
178        lbSelWave_1_UU[][0] = 2                 //Run # column is editable
179        lbSelWave_1_DU[][0] = 2                 //Run # column is editable
180        lbSelWave_1_DD[][0] = 2                 //Run # column is editable
181        lbSelWave_1_UD[][0] = 2                 //Run # column is editable
182        lbSelWave_1_UU[][1] = 1                 //Cell name is a popup, not editable   
183        lbSelWave_1_DU[][1] = 1                 //Cell name is a popup, not editable   
184        lbSelWave_1_DD[][1] = 1                 //Cell name is a popup, not editable   
185        lbSelWave_1_UD[][1] = 1                 //Cell name is a popup, not editable           
186       
187        Make/O/T/N=(10,2) ListWave_2_UU=""
188        Make/O/T/N=(10,2) ListWave_2_DU=""
189        Make/O/T/N=(10,2) ListWave_2_DD=""
190        Make/O/T/N=(10,2) ListWave_2_UD=""
191        Make/O/N=(10,2) lbSelWave_2_UU
192        Make/O/N=(10,2) lbSelWave_2_DU
193        Make/O/N=(10,2) lbSelWave_2_DD
194        Make/O/N=(10,2) lbSelWave_2_UD
195        lbSelWave_2_UU[][0] = 2                 //Run # column is editable
196        lbSelWave_2_DU[][0] = 2                 //Run # column is editable
197        lbSelWave_2_DD[][0] = 2                 //Run # column is editable
198        lbSelWave_2_UD[][0] = 2                 //Run # column is editable
199        lbSelWave_2_UU[][1] = 1                 //Cell name is a popup, not editable   
200        lbSelWave_2_DU[][1] = 1                 //Cell name is a popup, not editable   
201        lbSelWave_2_DD[][1] = 1                 //Cell name is a popup, not editable   
202        lbSelWave_2_UD[][1] = 1                 //Cell name is a popup, not editable   
203
204
205////// old method using individual setVars and popups   
206//      for(ii=0;ii<5;ii+=1)
207//              String/G $("gStr_PolCor_0_UU_"+num2str(ii)) = "none"
208//              String/G $("gStr_PolCor_0_DU_"+num2str(ii)) = "none"
209//              String/G $("gStr_PolCor_0_DD_"+num2str(ii)) = "none"
210//              String/G $("gStr_PolCor_0_UD_"+num2str(ii)) = "none"
211//      endfor
212//
213//      for(ii=0;ii<5;ii+=1)
214//              String/G $("gStr_PolCor_1_UU_"+num2str(ii)) = "none"
215//              String/G $("gStr_PolCor_1_DU_"+num2str(ii)) = "none"
216//              String/G $("gStr_PolCor_1_DD_"+num2str(ii)) = "none"
217//              String/G $("gStr_PolCor_1_UD_"+num2str(ii)) = "none"
218//      endfor
219//     
220//      for(ii=0;ii<5;ii+=1)
221//              String/G $("gStr_PolCor_2_UU_"+num2str(ii)) = "none"
222//              String/G $("gStr_PolCor_2_DU_"+num2str(ii)) = "none"
223//              String/G $("gStr_PolCor_2_DD_"+num2str(ii)) = "none"
224//              String/G $("gStr_PolCor_2_UD_"+num2str(ii)) = "none"
225//      endfor
226////////////
227
228        SetDataFolder root:
229
230
231        return(0)
232
233end
234
235
236
237
238// controls are labeled "name_#_UU_#" where name is the type of control, # is the tab #, and (2nd) # is the control #
239// -- this will allow for future use of tabs. right now 0 will be the "SAM" data
240//
241// - always visible controls will have no "_" characters
242//
243// TODO:
244// X- tabs for SAM, EMP, and BGD
245// X- input fields for the other protocol items, like the Protocol Panel
246// X- save the popup state
247// X- need a way of saving the "protocol" since the setup is so complex.
248// - generate a report of the setup.
249// - 4-panel display (maybe a layout with labels?) Maybe a panel with 4 subwindows. Can I use color bars in them?
250//
251//
252Window PolCor_Panel()
253        PauseUpdate; Silent 1           // building window...
254        NewPanel /W=(925,44,1662,800) /K=1
255        ModifyPanel cbRGB=(64349,63913,44660)
256//      ShowTools/A
257        SetDrawEnv linethick= 2.00
258        DrawLine 10,510,600,510
259
260        TabControl PolCorTab,pos={15,27},size={708,401},proc=PolCorTabProc
261        TabControl PolCorTab,tabLabel(0)="SAM",tabLabel(1)="EMP",tabLabel(2)="BGD"
262        TabControl PolCorTab,value= 0
263       
264        // always visible
265        Button button0,pos={26,445},size={80,20},proc=LoadRawPolarizedButton,title="Load ..."
266        Button button1,pos={26,473},size={130,20},proc=PolCorButton,title="Pol Correct Data"
267        Button button2,pos={222,445},size={130,20},proc=ShowPolMatrixButton,title="Show Coef Matrix"
268        Button button3,pos={222,473},size={160,20},proc=ChangeDisplayedPolData,title="Change Displayed Data"
269        Button button4,pos={620,18},size={30,20},proc=PolCorHelpParButtonProc,title="?"
270        Button button12,pos={440,473},size={120,20},proc=Display4XSButton,title="Display 4 XS"
271        Button button13,pos={440,446},size={120,20},proc=ClearPolCorEntries,title="Clear Entries"
272
273        PopupMenu popup1,pos={210,24},size={102,20},title="Condition"
274        PopupMenu popup1, mode=1,popvalue="none",value= #"P_GetConditionNameList()"
275
276        TitleBox title0,pos={100,66},size={24,24},title="\\f01UU or + +",fSize=12
277        TitleBox title1,pos={430,66},size={24,24},title="\\f01DU or - +",fSize=12
278        TitleBox title2,pos={100,250},size={25,24},title="\\f01DD or - -",fSize=12
279        TitleBox title3,pos={430,250},size={24,24},title="\\f01UD or + -",fSize=12
280       
281        // bits to set up reduction protocol
282        Button button5,pos={126,560},size={100,20},proc=PickDIVButton,title="set DIV file"
283        Button button5,help={"This button will set the file selected in the File Catalog table to be the sensitivity file."}
284        Button button6,pos={126,590},size={100,20},proc=PickMASKButton,title="set MASK file"
285        Button button6,help={"This button will set the file selected in the File Catalog table to be the mask file."}
286        Button button7,pos={126,620},size={110,20},proc=SetABSParamsButton,title="set ABS params"
287        Button button7,help={"This button will prompt the user for absolute scaling parameters"}
288        Button button8,pos={126,650},size={150,20},proc=SetAverageParamsButtonProc,title="set AVERAGE params"
289        Button button8,help={"Prompts the user for the type of 1-D averaging to perform, as well as saving options"}
290        Button button9,pos={80,690},size={120,20},proc=ReducePolCorDataButton,title="Reduce Data"
291        Button button9,help={"Reduce PolCor data"}
292        Button button10,pos={226,690},size={120,20},proc=SavePolCorProtocolButton,title="Save Protocol"
293        Button button10,help={"Save the PolCor protocol"}
294        Button button11,pos={370,690},size={120,20},proc=RecallPolCorProtocolButton,title="Recall Protocol"
295        Button button11,help={"Recall the PolCor protocol"}             
296       
297        SetVariable setvar0,pos={322,560},size={250,15},title="file:"
298        SetVariable setvar0,help={"Filename of the detector sensitivity file to be used in the data reduction"}
299        SetVariable setvar0,limits={-Inf,Inf,0},value= root:myGlobals:Protocols:gDIV
300        SetVariable setvar1,pos={322,590},size={250,15},title="file:"
301        SetVariable setvar1,help={"Filename of the mask file to be used in the data reduction"}
302        SetVariable setvar1,limits={-Inf,Inf,0},value= root:myGlobals:Protocols:gMASK
303        SetVariable setvar2,pos={322,620},size={250,15},title="parameters:"
304        SetVariable setvar2,help={"Keyword-string of values necessary for absolute scaling of data. Remaining parameters are taken from the sample file."}
305        SetVariable setvar2,limits={-Inf,Inf,0},value= root:myGlobals:Protocols:gAbsStr
306        SetVariable setvar3,pos={322,650},size={250,15},title="parameters:"
307        SetVariable setvar3,help={"Keyword-string of choices used for averaging and saving the 1-D data files"}
308        SetVariable setvar3,limits={-Inf,Inf,0},value= root:myGlobals:Protocols:gAVE   
309       
310        CheckBox check0,pos={10,560},size={72,14},title="Sensitivity"
311        CheckBox check0,help={"If checked, the specified detector sensitivity file will be included in the data reduction. If the file name is \"ask\", then the user will be prompted for the file"}
312        CheckBox check0,value= 1
313        CheckBox check1,pos={10,590},size={72,14},title="Mask"
314        CheckBox check1,help={""}
315        CheckBox check1,value= 1
316        CheckBox check2,pos={10,620},size={72,14},title="Absolute Scale"
317        CheckBox check2,help={""}
318        CheckBox check2,value= 1
319        CheckBox check3,pos={10,650},size={72,14},title="Average and Save"
320        CheckBox check3,help={""}
321        CheckBox check3,value= 1               
322        CheckBox check4,pos={10,530},size={72,14},title="Use EMP?"
323        CheckBox check4,help={""}
324        CheckBox check4,value= 1       
325        CheckBox check5,pos={100,530},size={72,14},title="Use BGD?"
326        CheckBox check5,help={""}
327        CheckBox check5,value= 1       
328
329       
330
331// SAM Tab     
332        // UU
333        ListBox ListBox_0_UU,pos={34,102},size={200,130},proc=PolCor_FileListBoxProc,frame=2
334        ListBox ListBox_0_UU,listWave=root:Packages:NIST:Polarization:ListWave_0_UU,titleWave=root:Packages:NIST:Polarization:lbTitles
335        ListBox ListBox_0_UU,selWave=root:Packages:NIST:Polarization:lbSelWave_0_UU,mode= 6,selRow= 0,selCol= 0,editStyle= 2
336//      SetVariable setvar_0_UU_0,pos={34,102},size={70,16},title="File",fSize=10
337//      SetVariable setvar_0_UU_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UU_0
338//      SetVariable setvar_0_UU_1,pos={34,125},size={70,16},title="File",fSize=10
339//      SetVariable setvar_0_UU_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UU_1
340//      SetVariable setvar_0_UU_2,pos={34,149},size={70,16},title="File",fSize=10
341//      SetVariable setvar_0_UU_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UU_2
342//      SetVariable setvar_0_UU_3,pos={34,173},size={70,16},title="File",fSize=10
343//      SetVariable setvar_0_UU_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UU_3
344//      SetVariable setvar_0_UU_4,pos={34,197},size={70,16},title="File",fSize=10
345//      SetVariable setvar_0_UU_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UU_4
346//      PopupMenu popup_0_UU_0,pos={142,99},size={210,20},title="Cell"
347//      PopupMenu popup_0_UU_0,mode=3,popvalue="none",value= #"D_CellNameList()"
348//      PopupMenu popup_0_UU_1,pos={142,122},size={102,20},title="Cell"
349//      PopupMenu popup_0_UU_1,mode=1,popvalue="none",value= #"D_CellNameList()"
350//      PopupMenu popup_0_UU_2,pos={142,146},size={102,20},title="Cell"
351//      PopupMenu popup_0_UU_2,mode=1,popvalue="none",value= #"D_CellNameList()"
352//      PopupMenu popup_0_UU_3,pos={142,170},size={102,20},title="Cell"
353//      PopupMenu popup_0_UU_3,mode=1,popvalue="none",value= #"D_CellNameList()"
354//      PopupMenu popup_0_UU_4,pos={142,194},size={102,20},title="Cell"
355//      PopupMenu popup_0_UU_4,mode=1,popvalue="none",value= #"D_CellNameList()"
356
357        // DU
358        ListBox ListBox_0_DU,pos={368,102},size={200,130},proc=PolCor_FileListBoxProc,frame=2
359        ListBox ListBox_0_DU,listWave=root:Packages:NIST:Polarization:ListWave_0_DU,titleWave=root:Packages:NIST:Polarization:lbTitles
360        ListBox ListBox_0_DU,selWave=root:Packages:NIST:Polarization:lbSelWave_0_DU,mode= 6,selRow= 0,selCol= 0,editStyle= 2
361//      SetVariable setvar_0_DU_0,pos={368,102},size={70,16},title="File",fSize=10
362//      SetVariable setvar_0_DU_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DU_0
363//      SetVariable setvar_0_DU_1,pos={368,125},size={70,16},title="File",fSize=10
364//      SetVariable setvar_0_DU_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DU_1
365//      SetVariable setvar_0_DU_2,pos={368,149},size={70,16},title="File",fSize=10
366//      SetVariable setvar_0_DU_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DU_2
367//      SetVariable setvar_0_DU_3,pos={368,173},size={70,16},title="File",fSize=10
368//      SetVariable setvar_0_DU_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DU_3
369//      SetVariable setvar_0_DU_4,pos={368,197},size={70,16},title="File",fSize=10
370//      SetVariable setvar_0_DU_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DU_4
371//      PopupMenu popup_0_DU_0,pos={476,99},size={210,20},title="Cell"
372//      PopupMenu popup_0_DU_0,mode=3,popvalue="none",value= #"D_CellNameList()"
373//      PopupMenu popup_0_DU_1,pos={476,122},size={210,20},title="Cell"
374//      PopupMenu popup_0_DU_1,mode=3,popvalue="none",value= #"D_CellNameList()"
375//      PopupMenu popup_0_DU_2,pos={476,146},size={102,20},title="Cell"
376//      PopupMenu popup_0_DU_2,mode=1,popvalue="none",value= #"D_CellNameList()"
377//      PopupMenu popup_0_DU_3,pos={476,170},size={102,20},title="Cell"
378//      PopupMenu popup_0_DU_3,mode=1,popvalue="none",value= #"D_CellNameList()"
379//      PopupMenu popup_0_DU_4,pos={476,194},size={102,20},title="Cell"
380//      PopupMenu popup_0_DU_4,mode=1,popvalue="none",value= #"D_CellNameList()"
381
382// DD
383        ListBox ListBox_0_DD,pos={33,286},size={200,130},proc=PolCor_FileListBoxProc,frame=2
384        ListBox ListBox_0_DD,listWave=root:Packages:NIST:Polarization:ListWave_0_DD,titleWave=root:Packages:NIST:Polarization:lbTitles
385        ListBox ListBox_0_DD,selWave=root:Packages:NIST:Polarization:lbSelWave_0_DD,mode= 6,selRow= 0,selCol= 0,editStyle= 2
386//      SetVariable setvar_0_DD_0,pos={33,286},size={70,16},title="File",fSize=10
387//      SetVariable setvar_0_DD_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DD_0
388//      SetVariable setvar_0_DD_1,pos={33,309},size={70,16},title="File",fSize=10
389//      SetVariable setvar_0_DD_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DD_1
390//      SetVariable setvar_0_DD_2,pos={33,333},size={70,16},title="File",fSize=10
391//      SetVariable setvar_0_DD_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DD_2
392//      SetVariable setvar_0_DD_3,pos={33,357},size={70,16},title="File",fSize=10
393//      SetVariable setvar_0_DD_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DD_3
394//      SetVariable setvar_0_DD_4,pos={33,381},size={70,16},title="File",fSize=10
395//      SetVariable setvar_0_DD_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_DD_4
396//      PopupMenu popup_0_DD_0,pos={141,283},size={210,20},title="Cell"
397//      PopupMenu popup_0_DD_0,mode=3,popvalue="none",value= #"D_CellNameList()"
398//      PopupMenu popup_0_DD_1,pos={141,306},size={102,20},title="Cell"
399//      PopupMenu popup_0_DD_1,mode=1,popvalue="none",value= #"D_CellNameList()"
400//      PopupMenu popup_0_DD_2,pos={141,330},size={102,20},title="Cell"
401//      PopupMenu popup_0_DD_2,mode=1,popvalue="none",value= #"D_CellNameList()"
402//      PopupMenu popup_0_DD_3,pos={141,354},size={102,20},title="Cell"
403//      PopupMenu popup_0_DD_3,mode=1,popvalue="none",value= #"D_CellNameList()"
404//      PopupMenu popup_0_DD_4,pos={141,378},size={102,20},title="Cell"
405//      PopupMenu popup_0_DD_4,mode=1,popvalue="none",value= #"D_CellNameList()"
406       
407// UD
408        ListBox ListBox_0_UD,pos={368,286},size={200,130},proc=PolCor_FileListBoxProc,frame=2
409        ListBox ListBox_0_UD,listWave=root:Packages:NIST:Polarization:ListWave_0_UD,titleWave=root:Packages:NIST:Polarization:lbTitles
410        ListBox ListBox_0_UD,selWave=root:Packages:NIST:Polarization:lbSelWave_0_UD,mode= 6,selRow= 0,selCol= 0,editStyle= 2
411//      SetVariable setvar_0_UD_0,pos={368,286},size={70,16},title="File",fSize=10
412//      SetVariable setvar_0_UD_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UD_0
413//      SetVariable setvar_0_UD_1,pos={368,309},size={70,16},title="File",fSize=10
414//      SetVariable setvar_0_UD_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UD_1
415//      SetVariable setvar_0_UD_2,pos={368,333},size={70,16},title="File",fSize=10
416//      SetVariable setvar_0_UD_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UD_2
417//      SetVariable setvar_0_UD_3,pos={368,357},size={70,16},title="File",fSize=10
418//      SetVariable setvar_0_UD_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UD_3
419//      SetVariable setvar_0_UD_4,pos={368,381},size={70,16},title="File",fSize=10
420//      SetVariable setvar_0_UD_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_0_UD_4
421//      PopupMenu popup_0_UD_0,pos={476,283},size={210,20},title="Cell"
422//      PopupMenu popup_0_UD_0,mode=3,popvalue="none",value= #"D_CellNameList()"
423//      PopupMenu popup_0_UD_1,pos={476,306},size={210,20},title="Cell"
424//      PopupMenu popup_0_UD_1,mode=3,popvalue="none",value= #"D_CellNameList()"
425//      PopupMenu popup_0_UD_2,pos={476,330},size={102,20},title="Cell"
426//      PopupMenu popup_0_UD_2,mode=1,popvalue="none",value= #"D_CellNameList()"
427//      PopupMenu popup_0_UD_3,pos={476,354},size={102,20},title="Cell"
428//      PopupMenu popup_0_UD_3,mode=1,popvalue="none",value= #"D_CellNameList()"
429//      PopupMenu popup_0_UD_4,pos={476,378},size={102,20},title="Cell"
430//      PopupMenu popup_0_UD_4,mode=1,popvalue="none",value= #"D_CellNameList()"
431
432
433// EMP Tab     
434        // UU
435        ListBox ListBox_1_UU,pos={34,102},size={200,130},proc=PolCor_FileListBoxProc,frame=2
436        ListBox ListBox_1_UU,listWave=root:Packages:NIST:Polarization:ListWave_1_UU,titleWave=root:Packages:NIST:Polarization:lbTitles
437        ListBox ListBox_1_UU,selWave=root:Packages:NIST:Polarization:lbSelWave_1_UU,mode= 6,selRow= 0,selCol= 0,editStyle= 2
438//      SetVariable setvar_1_UU_0,pos={34,102},size={70,16},title="File",fSize=10
439//      SetVariable setvar_1_UU_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UU_0
440//      SetVariable setvar_1_UU_1,pos={34,125},size={70,16},title="File",fSize=10
441//      SetVariable setvar_1_UU_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UU_1
442//      SetVariable setvar_1_UU_2,pos={34,149},size={70,16},title="File",fSize=10
443//      SetVariable setvar_1_UU_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UU_2
444//      SetVariable setvar_1_UU_3,pos={34,173},size={70,16},title="File",fSize=10
445//      SetVariable setvar_1_UU_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UU_3
446//      SetVariable setvar_1_UU_4,pos={34,197},size={70,16},title="File",fSize=10
447//      SetVariable setvar_1_UU_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UU_4
448//      PopupMenu popup_1_UU_0,pos={142,99},size={210,20},title="Cell"
449//      PopupMenu popup_1_UU_0,mode=3,popvalue="none",value= #"D_CellNameList()"
450//      PopupMenu popup_1_UU_1,pos={142,122},size={102,20},title="Cell"
451//      PopupMenu popup_1_UU_1,mode=1,popvalue="none",value= #"D_CellNameList()"
452//      PopupMenu popup_1_UU_2,pos={142,146},size={102,20},title="Cell"
453//      PopupMenu popup_1_UU_2,mode=1,popvalue="none",value= #"D_CellNameList()"
454//      PopupMenu popup_1_UU_3,pos={142,170},size={102,20},title="Cell"
455//      PopupMenu popup_1_UU_3,mode=1,popvalue="none",value= #"D_CellNameList()"
456//      PopupMenu popup_1_UU_4,pos={142,194},size={102,20},title="Cell"
457//      PopupMenu popup_1_UU_4,mode=1,popvalue="none",value= #"D_CellNameList()"
458
459        // DU
460        ListBox ListBox_1_DU,pos={368,102},size={200,130},proc=PolCor_FileListBoxProc,frame=2
461        ListBox ListBox_1_DU,listWave=root:Packages:NIST:Polarization:ListWave_1_DU,titleWave=root:Packages:NIST:Polarization:lbTitles
462        ListBox ListBox_1_DU,selWave=root:Packages:NIST:Polarization:lbSelWave_1_DU,mode= 6,selRow= 0,selCol= 0,editStyle= 2
463//      SetVariable setvar_1_DU_0,pos={368,102},size={70,16},title="File",fSize=10
464//      SetVariable setvar_1_DU_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DU_0
465//      SetVariable setvar_1_DU_1,pos={368,125},size={70,16},title="File",fSize=10
466//      SetVariable setvar_1_DU_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DU_1
467//      SetVariable setvar_1_DU_2,pos={368,149},size={70,16},title="File",fSize=10
468//      SetVariable setvar_1_DU_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DU_2
469//      SetVariable setvar_1_DU_3,pos={368,173},size={70,16},title="File",fSize=10
470//      SetVariable setvar_1_DU_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DU_3
471//      SetVariable setvar_1_DU_4,pos={368,197},size={70,16},title="File",fSize=10
472//      SetVariable setvar_1_DU_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DU_4
473//      PopupMenu popup_1_DU_0,pos={476,99},size={210,20},title="Cell"
474//      PopupMenu popup_1_DU_0,mode=3,popvalue="none",value= #"D_CellNameList()"
475//      PopupMenu popup_1_DU_1,pos={476,122},size={210,20},title="Cell"
476//      PopupMenu popup_1_DU_1,mode=3,popvalue="none",value= #"D_CellNameList()"
477//      PopupMenu popup_1_DU_2,pos={476,146},size={102,20},title="Cell"
478//      PopupMenu popup_1_DU_2,mode=1,popvalue="none",value= #"D_CellNameList()"
479//      PopupMenu popup_1_DU_3,pos={476,170},size={102,20},title="Cell"
480//      PopupMenu popup_1_DU_3,mode=1,popvalue="none",value= #"D_CellNameList()"
481//      PopupMenu popup_1_DU_4,pos={476,194},size={102,20},title="Cell"
482//      PopupMenu popup_1_DU_4,mode=1,popvalue="none",value= #"D_CellNameList()"
483
484// DD
485        ListBox ListBox_1_DD,pos={33,286},size={200,130},proc=PolCor_FileListBoxProc,frame=2
486        ListBox ListBox_1_DD,listWave=root:Packages:NIST:Polarization:ListWave_1_DD,titleWave=root:Packages:NIST:Polarization:lbTitles
487        ListBox ListBox_1_DD,selWave=root:Packages:NIST:Polarization:lbSelWave_1_DD,mode= 6,selRow= 0,selCol= 0,editStyle= 2
488//      SetVariable setvar_1_DD_0,pos={33,286},size={70,16},title="File",fSize=10
489//      SetVariable setvar_1_DD_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DD_0
490//      SetVariable setvar_1_DD_1,pos={33,309},size={70,16},title="File",fSize=10
491//      SetVariable setvar_1_DD_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DD_1
492//      SetVariable setvar_1_DD_2,pos={33,333},size={70,16},title="File",fSize=10
493//      SetVariable setvar_1_DD_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DD_2
494//      SetVariable setvar_1_DD_3,pos={33,357},size={70,16},title="File",fSize=10
495//      SetVariable setvar_1_DD_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DD_3
496//      SetVariable setvar_1_DD_4,pos={33,381},size={70,16},title="File",fSize=10
497//      SetVariable setvar_1_DD_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_DD_4
498//      PopupMenu popup_1_DD_0,pos={141,283},size={210,20},title="Cell"
499//      PopupMenu popup_1_DD_0,mode=3,popvalue="none",value= #"D_CellNameList()"
500//      PopupMenu popup_1_DD_1,pos={141,306},size={102,20},title="Cell"
501//      PopupMenu popup_1_DD_1,mode=1,popvalue="none",value= #"D_CellNameList()"
502//      PopupMenu popup_1_DD_2,pos={141,330},size={102,20},title="Cell"
503//      PopupMenu popup_1_DD_2,mode=1,popvalue="none",value= #"D_CellNameList()"
504//      PopupMenu popup_1_DD_3,pos={141,354},size={102,20},title="Cell"
505//      PopupMenu popup_1_DD_3,mode=1,popvalue="none",value= #"D_CellNameList()"
506//      PopupMenu popup_1_DD_4,pos={141,378},size={102,20},title="Cell"
507//      PopupMenu popup_1_DD_4,mode=1,popvalue="none",value= #"D_CellNameList()"
508
509// UD
510        ListBox ListBox_1_UD,pos={368,286},size={200,130},proc=PolCor_FileListBoxProc,frame=2
511        ListBox ListBox_1_UD,listWave=root:Packages:NIST:Polarization:ListWave_1_UD,titleWave=root:Packages:NIST:Polarization:lbTitles
512        ListBox ListBox_1_UD,selWave=root:Packages:NIST:Polarization:lbSelWave_1_UD,mode= 6,selRow= 0,selCol= 0,editStyle= 2
513//      SetVariable setvar_1_UD_0,pos={368,286},size={70,16},title="File",fSize=10
514//      SetVariable setvar_1_UD_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UD_0
515//      SetVariable setvar_1_UD_1,pos={368,309},size={70,16},title="File",fSize=10
516//      SetVariable setvar_1_UD_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UD_1
517//      SetVariable setvar_1_UD_2,pos={368,333},size={70,16},title="File",fSize=10
518//      SetVariable setvar_1_UD_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UD_2
519//      SetVariable setvar_1_UD_3,pos={368,357},size={70,16},title="File",fSize=10
520//      SetVariable setvar_1_UD_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UD_3
521//      SetVariable setvar_1_UD_4,pos={368,381},size={70,16},title="File",fSize=10
522//      SetVariable setvar_1_UD_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_1_UD_4
523//      PopupMenu popup_1_UD_0,pos={476,283},size={210,20},title="Cell"
524//      PopupMenu popup_1_UD_0,mode=3,popvalue="none",value= #"D_CellNameList()"
525//      PopupMenu popup_1_UD_1,pos={476,306},size={210,20},title="Cell"
526//      PopupMenu popup_1_UD_1,mode=3,popvalue="none",value= #"D_CellNameList()"
527//      PopupMenu popup_1_UD_2,pos={476,330},size={102,20},title="Cell"
528//      PopupMenu popup_1_UD_2,mode=1,popvalue="none",value= #"D_CellNameList()"
529//      PopupMenu popup_1_UD_3,pos={476,354},size={102,20},title="Cell"
530//      PopupMenu popup_1_UD_3,mode=1,popvalue="none",value= #"D_CellNameList()"
531//      PopupMenu popup_1_UD_4,pos={476,378},size={102,20},title="Cell"
532//      PopupMenu popup_1_UD_4,mode=1,popvalue="none",value= #"D_CellNameList()"
533
534
535// BKG Tab     
536        // UU
537        ListBox ListBox_2_UU,pos={34,102},size={200,130},proc=PolCor_FileListBoxProc,frame=2
538        ListBox ListBox_2_UU,listWave=root:Packages:NIST:Polarization:ListWave_2_UU,titleWave=root:Packages:NIST:Polarization:lbTitles
539        ListBox ListBox_2_UU,selWave=root:Packages:NIST:Polarization:lbSelWave_2_UU,mode= 6,selRow= 0,selCol= 0,editStyle= 2
540//      SetVariable setvar_2_UU_0,pos={34,102},size={70,16},title="File",fSize=10
541//      SetVariable setvar_2_UU_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UU_0
542//      SetVariable setvar_2_UU_1,pos={34,125},size={70,16},title="File",fSize=10
543//      SetVariable setvar_2_UU_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UU_1
544//      SetVariable setvar_2_UU_2,pos={34,149},size={70,16},title="File",fSize=10
545//      SetVariable setvar_2_UU_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UU_2
546//      SetVariable setvar_2_UU_3,pos={34,173},size={70,16},title="File",fSize=10
547//      SetVariable setvar_2_UU_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UU_3
548//      SetVariable setvar_2_UU_4,pos={34,197},size={70,16},title="File",fSize=10
549//      SetVariable setvar_2_UU_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UU_4
550//      PopupMenu popup_2_UU_0,pos={142,99},size={210,20},title="Cell"
551//      PopupMenu popup_2_UU_0,mode=3,popvalue="none",value= #"D_CellNameList()"
552//      PopupMenu popup_2_UU_1,pos={142,122},size={102,20},title="Cell"
553//      PopupMenu popup_2_UU_1,mode=1,popvalue="none",value= #"D_CellNameList()"
554//      PopupMenu popup_2_UU_2,pos={142,146},size={102,20},title="Cell"
555//      PopupMenu popup_2_UU_2,mode=1,popvalue="none",value= #"D_CellNameList()"
556//      PopupMenu popup_2_UU_3,pos={142,170},size={102,20},title="Cell"
557//      PopupMenu popup_2_UU_3,mode=1,popvalue="none",value= #"D_CellNameList()"
558//      PopupMenu popup_2_UU_4,pos={142,194},size={102,20},title="Cell"
559//      PopupMenu popup_2_UU_4,mode=1,popvalue="none",value= #"D_CellNameList()"
560
561        // DU
562        ListBox ListBox_2_DU,pos={368,102},size={200,130},proc=PolCor_FileListBoxProc,frame=2
563        ListBox ListBox_2_DU,listWave=root:Packages:NIST:Polarization:ListWave_2_DU,titleWave=root:Packages:NIST:Polarization:lbTitles
564        ListBox ListBox_2_DU,selWave=root:Packages:NIST:Polarization:lbSelWave_2_DU,mode= 6,selRow= 0,selCol= 0,editStyle= 2
565//      SetVariable setvar_2_DU_0,pos={368,102},size={70,16},title="File",fSize=10
566//      SetVariable setvar_2_DU_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DU_0
567//      SetVariable setvar_2_DU_1,pos={368,125},size={70,16},title="File",fSize=10
568//      SetVariable setvar_2_DU_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DU_1
569//      SetVariable setvar_2_DU_2,pos={368,149},size={70,16},title="File",fSize=10
570//      SetVariable setvar_2_DU_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DU_2
571//      SetVariable setvar_2_DU_3,pos={368,173},size={70,16},title="File",fSize=10
572//      SetVariable setvar_2_DU_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DU_3
573//      SetVariable setvar_2_DU_4,pos={368,197},size={70,16},title="File",fSize=10
574//      SetVariable setvar_2_DU_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DU_4
575//      PopupMenu popup_2_DU_0,pos={476,99},size={210,20},title="Cell"
576//      PopupMenu popup_2_DU_0,mode=3,popvalue="none",value= #"D_CellNameList()"
577//      PopupMenu popup_2_DU_1,pos={476,122},size={210,20},title="Cell"
578//      PopupMenu popup_2_DU_1,mode=3,popvalue="none",value= #"D_CellNameList()"
579//      PopupMenu popup_2_DU_2,pos={476,146},size={102,20},title="Cell"
580//      PopupMenu popup_2_DU_2,mode=1,popvalue="none",value= #"D_CellNameList()"
581//      PopupMenu popup_2_DU_3,pos={476,170},size={102,20},title="Cell"
582//      PopupMenu popup_2_DU_3,mode=1,popvalue="none",value= #"D_CellNameList()"
583//      PopupMenu popup_2_DU_4,pos={476,194},size={102,20},title="Cell"
584//      PopupMenu popup_2_DU_4,mode=1,popvalue="none",value= #"D_CellNameList()"
585
586// DD
587        ListBox ListBox_2_DD,pos={33,286},size={200,130},proc=PolCor_FileListBoxProc,frame=2
588        ListBox ListBox_2_DD,listWave=root:Packages:NIST:Polarization:ListWave_2_DD,titleWave=root:Packages:NIST:Polarization:lbTitles
589        ListBox ListBox_2_DD,selWave=root:Packages:NIST:Polarization:lbSelWave_2_DD,mode= 6,selRow= 0,selCol= 0,editStyle= 2
590//      SetVariable setvar_2_DD_0,pos={33,286},size={70,16},title="File",fSize=10
591//      SetVariable setvar_2_DD_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DD_0
592//      SetVariable setvar_2_DD_1,pos={33,309},size={70,16},title="File",fSize=10
593//      SetVariable setvar_2_DD_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DD_1
594//      SetVariable setvar_2_DD_2,pos={33,333},size={70,16},title="File",fSize=10
595//      SetVariable setvar_2_DD_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DD_2
596//      SetVariable setvar_2_DD_3,pos={33,357},size={70,16},title="File",fSize=10
597//      SetVariable setvar_2_DD_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DD_3
598//      SetVariable setvar_2_DD_4,pos={33,381},size={70,16},title="File",fSize=10
599//      SetVariable setvar_2_DD_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_DD_4
600//      PopupMenu popup_2_DD_0,pos={141,283},size={210,20},title="Cell"
601//      PopupMenu popup_2_DD_0,mode=3,popvalue="none",value= #"D_CellNameList()"
602//      PopupMenu popup_2_DD_1,pos={141,306},size={102,20},title="Cell"
603//      PopupMenu popup_2_DD_1,mode=1,popvalue="none",value= #"D_CellNameList()"
604//      PopupMenu popup_2_DD_2,pos={141,330},size={102,20},title="Cell"
605//      PopupMenu popup_2_DD_2,mode=1,popvalue="none",value= #"D_CellNameList()"
606//      PopupMenu popup_2_DD_3,pos={141,354},size={102,20},title="Cell"
607//      PopupMenu popup_2_DD_3,mode=1,popvalue="none",value= #"D_CellNameList()"
608//      PopupMenu popup_2_DD_4,pos={141,378},size={102,20},title="Cell"
609//      PopupMenu popup_2_DD_4,mode=1,popvalue="none",value= #"D_CellNameList()"
610
611// UD
612        ListBox ListBox_2_UD,pos={368,286},size={200,130},proc=PolCor_FileListBoxProc,frame=2
613        ListBox ListBox_2_UD,listWave=root:Packages:NIST:Polarization:ListWave_2_UD,titleWave=root:Packages:NIST:Polarization:lbTitles
614        ListBox ListBox_2_UD,selWave=root:Packages:NIST:Polarization:lbSelWave_2_UD,mode= 6,selRow= 0,selCol= 0,editStyle= 2
615//      SetVariable setvar_2_UD_0,pos={368,286},size={70,16},title="File",fSize=10
616//      SetVariable setvar_2_UD_0,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UD_0
617//      SetVariable setvar_2_UD_1,pos={368,309},size={70,16},title="File",fSize=10
618//      SetVariable setvar_2_UD_1,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UD_1
619//      SetVariable setvar_2_UD_2,pos={368,333},size={70,16},title="File",fSize=10
620//      SetVariable setvar_2_UD_2,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UD_2
621//      SetVariable setvar_2_UD_3,pos={368,357},size={70,16},title="File",fSize=10
622//      SetVariable setvar_2_UD_3,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UD_3
623//      SetVariable setvar_2_UD_4,pos={368,381},size={70,16},title="File",fSize=10
624//      SetVariable setvar_2_UD_4,limits={-inf,inf,0},value= root:Packages:NIST:Polarization:gStr_PolCor_2_UD_4
625//      PopupMenu popup_2_UD_0,pos={476,283},size={210,20},title="Cell"
626//      PopupMenu popup_2_UD_0,mode=3,popvalue="none",value= #"D_CellNameList()"
627//      PopupMenu popup_2_UD_1,pos={476,306},size={210,20},title="Cell"
628//      PopupMenu popup_2_UD_1,mode=3,popvalue="none",value= #"D_CellNameList()"
629//      PopupMenu popup_2_UD_2,pos={476,330},size={102,20},title="Cell"
630//      PopupMenu popup_2_UD_2,mode=1,popvalue="none",value= #"D_CellNameList()"
631//      PopupMenu popup_2_UD_3,pos={476,354},size={102,20},title="Cell"
632//      PopupMenu popup_2_UD_3,mode=1,popvalue="none",value= #"D_CellNameList()"
633//      PopupMenu popup_2_UD_4,pos={476,378},size={102,20},title="Cell"
634//      PopupMenu popup_2_UD_4,mode=1,popvalue="none",value= #"D_CellNameList()"
635
636EndMacro
637
638// action procedure for the list box that allows the popup menu
639// -- much easier to make a contextual popup with a list box than on a table/subwindow hook
640//
641Function PolCor_FileListBoxProc(lba) : ListBoxControl
642        STRUCT WMListboxAction &lba
643
644        Variable row = lba.row
645        Variable col = lba.col
646        WAVE/T/Z listWave = lba.listWave
647        WAVE/Z selWave = lba.selWave
648       
649        switch( lba.eventCode )
650                case -1: // control being killed
651                        break
652                case 1: // mouse down
653                        if (lba.col == 1)                                                                                       // cell list
654//                              SelWave[][][0] = SelWave[p][q] & ~9                                             // de-select everything to make sure we don't leave something selected in another column
655//                              SelWave[][s.col][0] = SelWave[p][s.col] | 1                             // select all rows
656//                              ControlUpdate/W=$(s.win) $(s.ctrlName)
657                                PopupContextualMenu D_CellNameList()
658                                if (V_flag > 0)
659                                        listWave[lba.row][lba.col] = S_Selection
660                                endif
661                        endif
662                        break
663                case 3: // double click
664                        break
665                case 4: // cell selection
666                case 5: // cell selection plus shift key
667                        break
668                case 6: // begin edit
669                        break
670                case 7: // finish edit
671                        break
672                case 13: // checkbox clicked (Igor 6.2 or later)
673                        break
674        endswitch
675
676        return 0
677End
678
679
680// This hook is activated when the whole window is killed. It saves the state of the popups and list boxes.
681// -- the protocol is not saved since it can be recalled
682//
683Function PolCorPanelHook(s)
684        STRUCT WMWinHookStruct &s
685
686        Variable hookResult = 0
687
688        switch(s.eventCode)
689//              case 0:                         // Activate
690//                      // Handle activate
691//                      break
692//
693//              case 1:                         // Deactivate
694//                      // Handle deactivate
695//                      break
696                case 2:                         // kill
697                        // Handle kill
698                       
699                        // the variables with the run numbers are automatically saved and restored if not re-initialized
700                        // get a list of all of the popups
701                        String popList="",item
702                        Variable num,ii
703
704//              -- old way, with popups for the conditions
705//                      popList=ControlNameList("PolCor_Panel",";","popup_*")
706//              -- new way - list boxes automatically saved, condition popup needs to be saved
707                        popList=ControlNameList("PolCor_Panel",";","popup*")
708                        num=ItemsInList(popList,";")
709                        Make/O/T/N=(num,2) root:Packages:NIST:Polarization:PolCor_popState
710                        Wave/T w=root:Packages:NIST:Polarization:PolCor_popState
711                        for(ii=0;ii<num;ii+=1)
712                                item=StringFromList(ii, popList,";")
713                                ControlInfo/W=PolCor_Panel $item
714                                w[ii][0] = item
715                                w[ii][1] = S_Value
716                        endfor
717
718                        break
719
720        endswitch
721
722        return hookResult               // 0 if nothing done, else 1
723End
724
725// val = 1 to disable
726// val = 0 to show
727Function ToggleSelControls(str,val)
728        String str
729        Variable val
730       
731        String listStr
732        listStr = ControlNameList("PolCor_Panel", ";", "*"+str+"*")
733//      print listStr
734       
735        ModifyControlList/Z listStr  , disable=(val)
736        return(0)
737end
738
739
740Function PolCorTabProc(tca) : TabControl
741        STRUCT WMTabControlAction &tca
742
743        switch( tca.eventCode )
744                case 2: // mouse up
745                        Variable tab = tca.tab         
746                        Variable val
747//                      Print "Selected tab = ",tab
748                       
749                        val = (tab != 0)
750//                      Print "tab 0 val = ",val
751                        ToggleSelControls("_0_",val)
752                       
753                        val = (tab != 1)
754//                      Print "tab 1 val = ",val
755                        ToggleSelControls("_1_",val)
756                       
757                        val = (tab != 2)
758//                      Print "tab 2 val = ",val
759                        ToggleSelControls("_2_",val)
760                                               
761                        break
762                case -1: // control being killed
763                        break
764        endswitch
765
766        return 0
767End
768
769
770
771Function PolCorHelpParButtonProc(ba) : ButtonControl
772        STRUCT WMButtonAction &ba
773
774        switch( ba.eventCode )
775                case 2: // mouse up
776                        // click code here
777                        DoAlert 0,"Help for PolCor Panel not written yet"
778                        break
779                case -1: // control being killed
780                        break
781        endswitch
782
783        return 0
784End
785
786
787// loads the specified type of data (SAM, EMP, BGD) based on the active tab
788// loads either specified spin type or all four
789// (( now, defaults to trying to load ALL four data spin states ))
790//              - I'll have to fix this later if only 2 of the four are needed
791//  -- during loading, the proper row of the PolMatrix is filled, based on pType
792//
793// then after all data is loaded:
794//              -the inverse Inv_PolMatrix is calculated
795//              -the error in the PolMatrix is calculated
796//              -the error in Inv_PolMatrix is calculated
797//
798Function LoadRawPolarizedButton(ba) : ButtonControl
799        STRUCT WMButtonAction &ba
800
801        switch( ba.eventCode )
802                case 2: // mouse up
803                        // click code here
804                       
805                        // depends on which tab you're on
806                        // (maybe) select UD type, maybe force all to load
807                       
808                        String pType
809//                      Prompt pType,"Pol Type",popup,"UU;DU;DD;UD;All;"
810//                      DoPrompt "Type to load",pType
811//                      if (V_Flag)
812//                              return 0                                                                        // user canceled
813//                      endif
814
815                        pType = "All"
816                       
817                        if(cmpstr(pType,"All") == 0)
818                                LoadPolarizedData("UU")
819                                LoadPolarizedData("DU")
820                                LoadPolarizedData("DD")
821                                LoadPolarizedData("UD")
822                        else
823                                LoadPolarizedData(pType)
824                        endif
825                       
826                        String type
827                        Variable row,col,flag=1
828                        Variable ii,jj,aa,bb
829                       
830// The PolMatrix is filled on loading the data sets
831// once all files are added, take the SQRT of the error matrix
832// now calculate its inverse
833// -- first checking to be sure that no rows are zero - this will result in a singular matrix otherwise         
834                        ControlInfo/W=PolCor_Panel PolCorTab
835                        type = S_value
836                        WAVE matA = $("root:Packages:NIST:"+type+":PolMatrix")
837                        WAVE matA_err = $("root:Packages:NIST:"+type+":PolMatrix_err")
838                        matA_err = sqrt(matA_err)
839                       
840                        // check for zero rows before inverting -- means not all data loaded
841                        for(row=0;row<4;row+=1)
842                                if(matA[row][0] == 0 && matA[row][1] == 0 && matA[row][2] == 0 && matA[row][3] == 0)
843                                        Print "**** some elements of PolMatrix are zero. Inverse not calculated. Be sure that all four XS are loaded."
844                                        row=10
845                                        flag=0
846                                endif
847                        endfor
848                        if(flag)                //PolMatrix OK
849                                // calculate the inverse of the coefficient matrix
850                                SetDataFolder $("root:Packages:NIST:"+type)
851                                MatrixInverse/G matA
852                                Duplicate/O M_Inverse Inv_PolMatrix
853                               
854                                // now calculate the error of the inverse matrix
855                                Duplicate/O Inv_PolMatrix Inv_PolMatrix_err
856                                Inv_PolMatrix_err=0
857                               
858                                for(aa=0;aa<4;aa+=1)
859                                        for(bb=0;bb<4;bb+=1)
860                                                for(ii=0;ii<4;ii+=1)
861                                                        for(jj=0;jj<4;jj+=1)
862                                                                Inv_PolMatrix_err[aa][bb] += (Inv_PolMatrix[aa][ii])^2 * (matA_err[ii][jj])^2 * (Inv_PolMatrix[jj][bb])^2
863                                                        endfor
864                                                endfor
865//                                              Inv_PolMatrix_err[aa][bb] = sqrt(Inv_PolMatrix_err[aa][bb])
866                                        endfor
867                                endfor
868                               
869                                Inv_PolMatrix_err = sqrt(Inv_PolMatrix_err)
870       
871                               
872                        endif
873       
874       
875       
876                        SetDataFolder root:
877                       
878                        break
879                case -1: // control being killed
880                        break
881        endswitch
882
883        return 0
884End
885
886// Loading of the polarized scattering data
887//
888// with the file numbers set
889// and the conditions specified
890//
891// -- For the specified pType of data (=UU, DU, DD, UD)
892//
893// -the time midpoint is found from the list of runs (needed for PCell(t) later)
894// -raw data is loaded (from a list of run numbers)
895// -data and loaded waves are tagged with a suffix (_UU, _DU, etc.)
896// -the PolMatrix of coefficients is filled (the specified row)
897//
898// TODO:
899// X- pre-parsing is not done to check for valid file numbers. This should be done gracefully.
900// X- SAM folder is currently hard-wired
901// X- if all of the conditions are "none" - stop and report the error
902//
903Function LoadPolarizedData(pType)
904        String pType
905
906
907        String listStr="",runList="",parsedRuns,condStr
908        Variable ii,num,err,row
909                       
910        // get the current tab
911        String type,runStr,cellStr
912        Variable tabNum
913        ControlInfo/W=PolCor_Panel PolCorTab
914        type = S_value
915        Print "selected data type = ",type
916        tabNum = V_Value
917       
918       
919        // get a list of the file numbers to load, must be in proper data folder
920        SetDataFolder root:Packages:NIST:Polarization
921//                      Print "Searching  "+"gStr_PolCor_"+num2str(tabNum)+"_*"+pType+"*"
922//      listStr = StringList("gStr_PolCor_"+num2str(tabNum)+"_*"+pType+"*", ";" )
923
924        Wave/T lb=$("ListWave_"+num2str(tabNum)+"_"+pType)
925        num = DimSize(lb,0)             //should be 10, as initialized
926       
927        // if the condition (for all of the sets) is "none", get out
928        ControlInfo/W=PolCor_Panel popup1
929        condStr = S_Value
930        if(cmpstr(condStr, "none" ) == 0)
931                DoAlert 0,"Condition is not set."
932                SetDataFolder root:
933                return(0)
934        endif
935       
936//                      step through, stop at the first null run number or missing cell specification
937        for(row=0;row<num;row+=1)
938                runStr = lb[row][0]
939                CellStr = lb[row][1]
940               
941                if(strlen(runStr) > 0 && strlen(cellStr) > 0)                   //non-null entries, go on
942                        runList += runStr+","           // this is a comma-delimited list
943                else
944                        if(strlen(runStr) == 0 && strlen(cellStr) == 0)
945                                // not a problem, don't bother reporting
946                        else
947                                //report the error and stop
948                                DoAlert 0,"run number or cell is not set in row "+num2str(row)+" for type "+pType
949                                SetDataFolder root:
950                                return(0)
951                        endif
952                endif
953        endfor
954
955        Print runList
956        // check for errors
957        parsedRuns =ParseRunNumberList(runlist)
958        if(strlen(parsedRuns) == 0)
959                Print "enter a valid file number before proceeding"
960                SetDataFolder root:
961                return(0)
962        endif
963        SetDataFolder root:
964
965       
966        // find time midpoint for the files to load
967        Variable tMid
968        tMid = getTimeMidpoint(runList)
969        Print/D "time midpoint",tmid
970       
971        // this adds multiple raw data files, as specified by the list
972        err = AddFilesInList(type,parsedRuns)           // adds to a work file = type, not RAW
973        UpdateDisplayInformation(type)
974       
975        TagLoadedData(type,pType)               //see also DisplayTaggedData()
976       
977        // now add the appropriate bits to the matrix
978        if(!WaveExists($("root:Packages:NIST:"+type+":PolMatrix")))
979                Make/O/D/N=(4,4) $("root:Packages:NIST:"+type+":PolMatrix")
980                Make/O/D/N=(4,4) $("root:Packages:NIST:"+type+":PolMatrix_err")
981        endif
982        WAVE matA = $("root:Packages:NIST:"+type+":PolMatrix")
983        WAVE matA_err = $("root:Packages:NIST:"+type+":PolMatrix_err")
984
985//                      listStr = ControlNameList("PolCor_Panel",";","*"+pType+"*")
986
987        //This loops over all of the files and adds the coefficients to the PolMatrix
988        // the PolMatrix rows are cleared on pass 0 as each pType data is loaded.
989        // this way repeated loading will always result in the correct fill
990        // returns the error matrix as the squared error (take sqrt in calling function)               
991        AddToPolMatrix(matA,matA_err,pType,tMid)
992
993
994        SetDataFolder root:
995       
996        return(0)
997End
998
999
1000// by definition-- the rows are:
1001//
1002//      UU = 0
1003//      DU = 1
1004//      DD = 2
1005//      UD = 3
1006//
1007// -- check all of the math
1008// not yet using the midpoint time
1009//
1010// -- the PolMatrix_err returned from here is the squared error!
1011//
1012Function AddToPolMatrix(matA,matA_err,pType,tMid)
1013        Wave matA,matA_err
1014        String pType
1015        Variable tMid
1016       
1017        Variable row,Psm, PsmPf, PCell,err_Psm, err_PsmPf, err_PCell
1018        Variable ii,jj,muPo,err_muPo,gam,err_gam,monCts,t1,num,fileCount
1019
1020        Variable ea_uu, ea_ud, ea_dd, ea_du
1021        Variable ec_uu, ec_ud, ec_dd, ec_du
1022       
1023        String listStr,fname="",condStr,condNote,decayNote,cellStr,t0Str,t1Str,runStr
1024
1025        // get the current tab
1026        String type
1027        Variable tabNum
1028        ControlInfo/W=PolCor_Panel PolCorTab
1029        type = S_value
1030        Print "selected data type = ",type
1031        tabNum = V_Value
1032       
1033        SetDataFolder root:Packages:NIST:Polarization
1034//      listStr = StringList("gStr_PolCor_"+num2str(tabNum)+"_*"+pType+"*", ";" )
1035
1036
1037        Wave/T lb=$("ListWave_"+num2str(tabNum)+"_"+pType)
1038        num = DimSize(lb,0)             //should be 10, as initialized
1039       
1040        // if the condition (for all of the sets) is "none", get out
1041        ControlInfo/W=PolCor_Panel popup1
1042        condStr = S_Value
1043        if(cmpstr(condStr, "none" ) == 0)
1044                DoAlert 0,"Condition is not set."
1045                SetDataFolder root:
1046                return(0)
1047        endif
1048       
1049        Wave condition = $("root:Packages:NIST:Polarization:Cells:"+condStr)
1050        // get wave note from condition
1051        condNote = note(condition)
1052        // get P's from note
1053        Psm = NumberByKey("P_sm", condNote, "=", ",", 0)
1054        PsmPf = NumberByKey("P_sm_f", condNote, "=", ",", 0)
1055        err_Psm = NumberByKey("err_P_sm", condNote, "=", ",", 0)
1056        err_PsmPf = NumberByKey("err_P_sm_f", condNote, "=", ",", 0)
1057
1058
1059        // loop over the (10) rows in the listWave
1060        fileCount=0
1061        for(ii=0;ii<num;ii+=1)
1062                runStr =        lb[ii][0]               //the run number
1063                if(cmpstr(runStr, "" ) != 0)
1064               
1065                        fileCount += 1          //one more file is added
1066                        // get run number (str)
1067                        // get file name
1068                        fname = FindFileFromRunNumber(str2num(runStr))
1069               
1070                        // get the cell string to get the Decay wave
1071                        cellStr = lb[ii][1]
1072//                      print "Cell = ",cellStr
1073                        // get info to calc Pcell (from the Decay wave)
1074                        Wave decay = $("root:Packages:NIST:Polarization:Cells:Decay_"+cellStr) 
1075                        decayNote=note(decay)
1076               
1077                        t0Str = StringByKey("T0", decayNote, "=", ",", 0)
1078                        muPo = NumberByKey("muP", decayNote, "=", ",", 0)
1079                        err_muPo = NumberByKey("err_muP", decayNote, "=", ",", 0)
1080                        gam = NumberByKey("gamma", decayNote, "=", ",", 0)
1081                        err_gam = NumberByKey("err_gamma", decayNote, "=", ",", 0)
1082                        // get the elapsed time to calculate PCell at the current file time
1083                        t1str = getFileCreationDate(fname)
1084                        t1 = ElapsedHours(t0Str,t1Str)
1085                       
1086                        PCell = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t1,err_PCell)
1087                       
1088                        // get file info (monitor counts)
1089                        monCts = getMonitorCount(fname)
1090                        monCts /= 1e8           //to get a normalized value to add proportionally
1091                       
1092                        Variable err_monCts
1093                        err_monCts = sqrt(monCts)
1094                        // add appropriate values to matrix elements (switch on UU, DD, etc)
1095                        // error in monCts is a negligible contribution
1096                        strswitch(pType)
1097                                case "UU":             
1098                                        row = 0
1099                                        if(ii==0)
1100                                                matA[row][] = 0
1101                                                matA_err[row][] = 0
1102                                        endif
1103                                        ea_uu = (1+Psm)/2
1104                                        ea_du = (1-Psm)/2
1105                                        ec_uu = (1+Pcell)/2
1106                                        ec_du = (1-Pcell)/2
1107                                       
1108                                        matA[row][0] += ea_uu*ec_uu*monCts
1109                                        matA[row][1] += ea_du*ec_uu*monCts
1110                                        matA[row][2] += ea_du*ec_du*monCts
1111                                        matA[row][3] += ea_uu*ec_du*monCts
1112
1113// this seems to be too large...
1114//                                      matA_err[row][0] += (1/2*ec_uu*monCts)^2*err_Psm^2 + (1/2*ea_uu*monCts)^2*err_Pcell^2
1115//                                      matA_err[row][1] += (1/2*ec_uu*monCts)^2*err_Psm^2 + (1/2*ea_du*monCts)^2*err_Pcell^2
1116//                                      matA_err[row][2] += (1/2*ec_du*monCts)^2*err_Psm^2 + (1/2*ea_du*monCts)^2*err_Pcell^2
1117//                                      matA_err[row][3] += (1/2*ec_du*monCts)^2*err_Psm^2 + (1/2*ea_uu*monCts)^2*err_Pcell^2
1118
1119                                        matA_err[row][0] += (ea_uu*ec_uu*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1120                                        matA_err[row][1] += (ea_du*ec_uu*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1121                                        matA_err[row][2] += (ea_du*ec_du*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1122                                        matA_err[row][3] += (ea_uu*ec_du*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1123                                                                               
1124                                        break
1125                                case "DU":             
1126                                        row = 1
1127                                        if(ii==0)
1128                                                matA[row][] = 0
1129                                                matA_err[row][] = 0
1130                                        endif
1131                                        ea_ud = (1-PsmPf)/2
1132                                        ea_dd = (1+PsmPf)/2
1133                                        ec_uu = (1+Pcell)/2
1134                                        ec_du = (1-Pcell)/2
1135                                       
1136                                        matA[row][0] += ea_ud*ec_uu*monCts
1137                                        matA[row][1] += ea_dd*ec_uu*monCts
1138                                        matA[row][2] += ea_dd*ec_du*monCts
1139                                        matA[row][3] += ea_ud*ec_du*monCts
1140                                       
1141//                                      matA_err[row][0] += (1/2*(1+Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1-PsmPf)/2*monCts)^2*err_Pcell^2
1142//                                      matA_err[row][1] += (1/2*(1+Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1+PsmPf)/2*monCts)^2*err_Pcell^2
1143//                                      matA_err[row][2] += (1/2*(1-Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1+PsmPf)/2*monCts)^2*err_Pcell^2
1144//                                      matA_err[row][3] += (1/2*(1-Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1-PsmPf)/2*monCts)^2*err_Pcell^2                                     
1145
1146                                        matA_err[row][0] += (ea_ud*ec_uu*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1147                                        matA_err[row][1] += (ea_dd*ec_uu*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1148                                        matA_err[row][2] += (ea_dd*ec_du*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1149                                        matA_err[row][3] += (ea_ud*ec_du*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1150                                                       
1151                                        break   
1152                                case "DD":             
1153                                        row = 2
1154                                        if(ii==0)
1155                                                matA[row][] = 0
1156                                                matA_err[row][] = 0
1157                                        endif
1158                                        ea_ud = (1-PsmPf)/2
1159                                        ea_dd = (1+PsmPf)/2
1160                                        ec_ud = (1-Pcell)/2
1161                                        ec_dd = (1+Pcell)/2
1162                                       
1163                                        matA[row][0] += ea_ud*ec_ud*monCts
1164                                        matA[row][1] += ea_dd*ec_ud*monCts
1165                                        matA[row][2] += ea_dd*ec_dd*monCts
1166                                        matA[row][3] += ea_ud*ec_dd*monCts                                     
1167                                       
1168//                                      matA_err[row][0] += (1/2*(1-Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1-PsmPf)/2*monCts)^2*err_Pcell^2
1169//                                      matA_err[row][1] += (1/2*(1-Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1+PsmPf)/2*monCts)^2*err_Pcell^2
1170//                                      matA_err[row][2] += (1/2*(1+Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1+PsmPf)/2*monCts)^2*err_Pcell^2
1171//                                      matA_err[row][3] += (1/2*(1+Pcell)/2*monCts)^2*err_PsmPf^2 + (1/2*(1-PsmPf)/2*monCts)^2*err_Pcell^2     
1172
1173                                        matA_err[row][0] += (ea_ud*ec_ud*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1174                                        matA_err[row][1] += (ea_dd*ec_ud*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1175                                        matA_err[row][2] += (ea_dd*ec_dd*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1176                                        matA_err[row][3] += (ea_ud*ec_dd*monCts)^2 * (err_PsmPf^2/PsmPf^2 + err_Pcell^2/Pcell^2)
1177                                                                               
1178                                        break                                           
1179                                case "UD":             
1180                                        row = 3
1181                                        if(ii==0)
1182                                                matA[row][] = 0
1183                                                matA_err[row][] = 0
1184                                        endif
1185                                        ea_uu = (1+Psm)/2
1186                                        ea_du = (1-Psm)/2
1187                                        ec_ud = (1-Pcell)/2
1188                                        ec_dd = (1+Pcell)/2
1189                                       
1190                                        matA[row][0] += ea_uu*ec_ud*monCts
1191                                        matA[row][1] += ea_du*ec_ud*monCts
1192                                        matA[row][2] += ea_du*ec_dd*monCts
1193                                        matA[row][3] += ea_uu*ec_dd*monCts                                     
1194                                                                               
1195//                                      matA_err[row][0] += (1/2*(1-Pcell)/2*monCts)^2*err_Psm^2 + (1/2*(1+Psm)/2*monCts)^2*err_Pcell^2
1196//                                      matA_err[row][1] += (1/2*(1-Pcell)/2*monCts)^2*err_Psm^2 + (1/2*(1-Psm)/2*monCts)^2*err_Pcell^2
1197//                                      matA_err[row][2] += (1/2*(1+Pcell)/2*monCts)^2*err_Psm^2 + (1/2*(1-Psm)/2*monCts)^2*err_Pcell^2
1198//                                      matA_err[row][3] += (1/2*(1+Pcell)/2*monCts)^2*err_Psm^2 + (1/2*(1+Psm)/2*monCts)^2*err_Pcell^2                                 
1199
1200                                        matA_err[row][0] += (ea_uu*ec_ud*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1201                                        matA_err[row][1] += (ea_du*ec_ud*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1202                                        matA_err[row][2] += (ea_du*ec_dd*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1203                                        matA_err[row][3] += (ea_uu*ec_dd*monCts)^2 * (err_Psm^2/Psm^2 + err_Pcell^2/Pcell^2)
1204                                                                               
1205                                        break
1206                        endswitch
1207
1208                       
1209                endif
1210        endfor
1211       
1212// can't take the SQRT here, since the matrix won't necessarily be full yet,
1213       
1214// but now need to re-normalize the row based on the number of files that were added
1215// pType has only one value as passed in, so the row has already been set. It would be more correct
1216// to switch based on pType...
1217       
1218        matA[row][0] /= fileCount
1219        matA[row][1] /= fileCount
1220        matA[row][2] /= fileCount
1221        matA[row][3] /= fileCount       
1222       
1223        matA_err[row][0] /= fileCount
1224        matA_err[row][1] /= fileCount
1225        matA_err[row][2] /= fileCount
1226        matA_err[row][3] /= fileCount   
1227                               
1228        SetDataFolder root:
1229        return(0)
1230End
1231
1232
1233// duplicate the correct waves for use as the PolCor result
1234// lots of extra waves, but it makes things easier down the road
1235// type is the data folder (=SAM, etc)
1236// pType is the pol extension (=UU, etc.)
1237Function MakePCResultWaves(type,pType)
1238        String type,pType
1239
1240        ptype = "_" + pType                     // add an extra underscore
1241        String pcExt = "_pc"
1242        String destPath = "root:Packages:NIST:" + type
1243        Duplicate/O $(destPath + ":data"+pType), $(destPath + ":data"+pType+pcExt)
1244        Duplicate/O $(destPath + ":linear_data"+pType),$(destPath + ":linear_data"+pType+pcExt)
1245        Duplicate/O $(destPath + ":linear_data_error"+pType),$(destPath + ":linear_data_error"+pType+pcExt)
1246        Duplicate/O $(destPath + ":textread"+pType),$(destPath + ":textread"+pType+pcExt)
1247        Duplicate/O $(destPath + ":integersread"+pType),$(destPath + ":integersread"+pType+pcExt)
1248        Duplicate/O $(destPath + ":realsread"+pType),$(destPath + ":realsread"+pType+pcExt)
1249       
1250        return(0)
1251End
1252
1253
1254// a function to tag the data in a particular folder with the UD state
1255Function TagLoadedData(type,pType)
1256        String type,pType
1257
1258        ConvertFolderToLinearScale(type)
1259
1260        ptype = "_" + pType                     // add an extra underscore
1261        String destPath = "root:Packages:NIST:" + type
1262        Duplicate/O $(destPath + ":data"), $(destPath + ":data"+pType)
1263        Duplicate/O $(destPath + ":linear_data"),$(destPath + ":linear_data"+pType)
1264        Duplicate/O $(destPath + ":linear_data_error"),$(destPath + ":linear_data_error"+pType)
1265        Duplicate/O $(destPath + ":textread"),$(destPath + ":textread"+pType)
1266        Duplicate/O $(destPath + ":integersread"),$(destPath + ":integersread"+pType)
1267        Duplicate/O $(destPath + ":realsread"),$(destPath + ":realsread"+pType)
1268       
1269        return(0)
1270End
1271
1272
1273// a procedure (easier than a function) to point the current data to the tagged data
1274Proc DisplayTaggedData(type,pType)
1275        String type="SAM",pType="UU"
1276
1277        String/G root:myGlobals:gDataDisplayType=type
1278        ConvertFolderToLinearScale(type)
1279       
1280        ptype = "_" + pType                     // add an extra underscore
1281        String destPath = "root:Packages:NIST:" + type
1282        $(destPath + ":linear_data") = $(destPath + ":linear_data"+pType)
1283        $(destPath + ":linear_data_error") = $(destPath + ":linear_data_error"+pType)
1284        $(destPath + ":textread") = $(destPath + ":textread"+pType)
1285        $(destPath + ":integersread") = $(destPath + ":integersread"+pType)
1286        $(destPath + ":realsread") = $(destPath + ":realsread"+pType)
1287
1288// make the data equal to linear data
1289        $(destPath + ":data") = $(destPath + ":linear_data"+pType)
1290
1291        UpdateDisplayInformation(type)
1292// using fRawWindowHook() gets the log/lin correct
1293//      fRawWindowHook()
1294
1295
1296End
1297
1298
1299// this takes the 4 loaded experimental cross sections, and solves for the
1300// polarization corrected result.
1301//
1302// exp cross sections have _UU extensions
1303// polCor result has _UU_pc
1304//
1305//
1306Function PolCorButton(ba) : ButtonControl
1307        STRUCT WMButtonAction &ba
1308
1309        switch( ba.eventCode )
1310                case 2: // mouse up
1311                        // click code here
1312                       
1313                        Variable ii,jj,numRows,numCols,row,kk
1314                       
1315                        // get the current tab
1316                        String type
1317                        Variable tabNum
1318                        ControlInfo/W=PolCor_Panel PolCorTab
1319                        type = S_value
1320                        Print "selected data type = ",type
1321                        tabNum = V_Value
1322                       
1323                        // make waves for the result
1324                        // these duplicate the data and add "_pc" for later use
1325                        // linear_data_error_UU_pc etc. are created
1326                        MakePCResultWaves(type,"UU")
1327                        MakePCResultWaves(type,"DU")
1328                        MakePCResultWaves(type,"DD")
1329                        MakePCResultWaves(type,"UD")
1330                       
1331                       
1332                        SetDataFolder $("root:Packages:NIST:"+type)
1333
1334// the linear data and its errors, declare and initialize                       
1335                        WAVE linear_data_UU_pc = linear_data_UU_pc
1336                        WAVE linear_data_DU_pc = linear_data_DU_pc
1337                        WAVE linear_data_DD_pc = linear_data_DD_pc
1338                        WAVE linear_data_UD_pc = linear_data_UD_pc
1339                        WAVE linear_data_error_UU_pc = linear_data_error_UU_pc
1340                        WAVE linear_data_error_DU_pc = linear_data_error_DU_pc
1341                        WAVE linear_data_error_DD_pc = linear_data_error_DD_pc
1342                        WAVE linear_data_error_UD_pc = linear_data_error_UD_pc
1343                                               
1344                        linear_data_UU_pc = 0
1345                        linear_data_DU_pc = 0
1346                        linear_data_DD_pc = 0
1347                        linear_data_UD_pc = 0
1348                        linear_data_error_UU_pc = 0
1349                        linear_data_error_DU_pc = 0
1350                        linear_data_error_DD_pc = 0
1351                        linear_data_error_UD_pc = 0
1352                                               
1353                        // make a temp wave for the experimental data vector
1354                        Make/O/D/N=4 vecB
1355                        WAVE vecB = vecB
1356                       
1357                        // the coefficient matrix and the experimental data
1358                        WAVE matA = $("root:Packages:NIST:"+type+":PolMatrix")
1359                        WAVE linear_data_UU = linear_data_UU
1360                        WAVE linear_data_DU = linear_data_DU
1361                        WAVE linear_data_DD = linear_data_DD
1362                        WAVE linear_data_UD = linear_data_UD
1363
1364// everything needed for the error calculation
1365// the PolMatrix error matrices
1366// and the data error
1367                        WAVE inv = Inv_PolMatrix
1368                        WAVE inv_err = Inv_PolMatrix_err                       
1369                        WAVE linear_data_error_UU = linear_data_error_UU
1370                        WAVE linear_data_error_DU = linear_data_error_DU
1371                        WAVE linear_data_error_DD = linear_data_error_DD
1372                        WAVE linear_data_error_UD = linear_data_error_UD                       
1373                       
1374                        numRows = DimSize(linear_data_UU_pc, 0 )
1375                        numCols = DimSize(linear_data_UU_pc, 1 )
1376                       
1377                        // this is certainly not slow. takes < 1 second to complete the double loop.
1378                        for(ii=0;ii<numRows;ii+=1)
1379                                for(jj=0;jj<numCols;jj+=1)
1380                                        vecB[0] = linear_data_UU[ii][jj]
1381                                        vecB[1] = linear_data_DU[ii][jj]
1382                                        vecB[2] = linear_data_DD[ii][jj]
1383                                        vecB[3] = linear_data_UD[ii][jj]
1384                               
1385                                        MatrixLinearSolve/M=1 matA vecB
1386                                        // result is M_B[][0]
1387                                        WAVE M_B = M_B
1388                                        linear_data_UU_pc[ii][jj] = M_B[0][0]
1389                                        linear_data_DU_pc[ii][jj] = M_B[1][0]
1390                                        linear_data_DD_pc[ii][jj] = M_B[2][0]
1391                                        linear_data_UD_pc[ii][jj] = M_B[3][0]
1392                               
1393                       
1394                                        // and the error at each pixel, once for each of the four
1395                                        row = 0         //== UU
1396                                        for(kk=0;kk<4;kk+=1)
1397                                                linear_data_error_UU_pc[ii][jj] += inv_err[row][kk]^2*linear_data_UU[ii][jj]^2 + inv[row][kk]^2*linear_data_error_UU[ii][jj]^2
1398                                        endfor
1399                                        row = 1         //== DU
1400                                        for(kk=0;kk<4;kk+=1)
1401                                                linear_data_error_DU_pc[ii][jj] += inv_err[row][kk]^2*linear_data_DU[ii][jj]^2 + inv[row][kk]^2*linear_data_error_DU[ii][jj]^2
1402                                        endfor
1403                                        row = 2         //== DD
1404                                        for(kk=0;kk<4;kk+=1)
1405                                                linear_data_error_DD_pc[ii][jj] += inv_err[row][kk]^2*linear_data_DD[ii][jj]^2 + inv[row][kk]^2*linear_data_error_DD[ii][jj]^2
1406                                        endfor
1407                                        row = 3         //== UD
1408                                        for(kk=0;kk<4;kk+=1)
1409                                                linear_data_error_UD_pc[ii][jj] += inv_err[row][kk]^2*linear_data_UD[ii][jj]^2 + inv[row][kk]^2*linear_data_error_UD[ii][jj]^2
1410                                        endfor
1411                                       
1412                               
1413                                endfor
1414                        //      Print ii       
1415                        endfor
1416                       
1417                        // sqrt of the squared error...
1418                        linear_data_error_UU_pc = sqrt(linear_data_error_UU_pc)
1419                        linear_data_error_DU_pc = sqrt(linear_data_error_DU_pc)
1420                        linear_data_error_DD_pc = sqrt(linear_data_error_DD_pc)
1421                        linear_data_error_UD_pc = sqrt(linear_data_error_UD_pc)
1422                       
1423                       
1424                        //update the data as log of the linear. more correct to use the default scaling
1425                        // this is necessary for proper display of the data
1426                        WAVE data_UU_pc = data_UU_pc
1427                        WAVE data_DU_pc = data_DU_pc
1428                        WAVE data_DD_pc = data_DD_pc
1429                        WAVE data_UD_pc = data_UD_pc
1430                        data_UU_pc = log(linear_data_UU_pc)
1431                        data_DU_pc = log(linear_data_DU_pc)
1432                        data_DD_pc = log(linear_data_DD_pc)
1433                        data_UD_pc = log(linear_data_UD_pc)
1434                       
1435                       
1436                        SetDataFolder root:
1437                       
1438                        break
1439                case -1: // control being killed
1440                        break
1441        endswitch
1442
1443        return 0
1444End
1445
1446
1447// display all 4 XS at once in the same graph
1448// - crude right now
1449//
1450Function Display4XSButton(ba) : ButtonControl
1451        STRUCT WMButtonAction &ba
1452
1453        switch( ba.eventCode )
1454                case 2: // mouse up
1455                        // click code here
1456                        String dataType,pType,str,scaling
1457                        Prompt dataType,"Display WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;SAS;"
1458//                      Prompt pType,"Pol Type",popup,"UU;DU;DD;UD;UU_pc;DU_pc;DD_pc;UD_pc;"
1459                        Prompt scaling,"scaling",popup,"log;linear;"
1460                        DoPrompt "Change Display",dataType,scaling
1461                       
1462                        Display_4(dataType,scaling)
1463                       
1464                        break
1465                case -1: // control being killed
1466                        break
1467        endswitch
1468
1469        return 0
1470End
1471
1472
1473// Change the displayed SANS data by pointing the data with the
1474// specified tag (suffix) at data, linear_data, etc.
1475// all of the read waves are pointed too.
1476//
1477Function ChangeDisplayedPolData(ba) : ButtonControl
1478        STRUCT WMButtonAction &ba
1479
1480        switch( ba.eventCode )
1481                case 2: // mouse up
1482                        // click code here
1483                        String dataType,pType,str
1484                        Prompt dataType,"Display WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;SAS;"
1485                        Prompt pType,"Pol Type",popup,"UU;DU;DD;UD;UU_pc;DU_pc;DD_pc;UD_pc;"
1486                        DoPrompt "Change Display",dataType,pType
1487                       
1488                        sprintf str,"DisplayTaggedData(\"%s\",\"%s\")",dataType,pType
1489                        Execute str
1490                       
1491                        break
1492                case -1: // control being killed
1493                        break
1494        endswitch
1495
1496        return 0
1497End
1498
1499
1500// display the 4x4 polariztion efficiency matrix in a table, and its inverse (if it exists)
1501Function ShowPolMatrixButton(ba) : ButtonControl
1502        STRUCT WMButtonAction &ba
1503
1504        switch( ba.eventCode )
1505                case 2: // mouse up
1506                        // click code here
1507                       
1508                        // get the current tab
1509                        String type
1510                        Variable tabNum
1511                        ControlInfo/W=PolCor_Panel PolCorTab
1512                        type = S_value
1513                        Print "selected data type = ",type
1514                        tabNum = V_Value
1515                       
1516                        Wave/Z Pol = $("root:Packages:NIST:"+type+":PolMatrix")
1517                        if(WaveExists(Pol))
1518                                Edit/W=(5,44,510,251)/K=1 Pol
1519                        endif
1520                        Wave/Z Inv_Pol = $("root:Packages:NIST:"+type+":Inv_PolMatrix")
1521                        if(WaveExists(Inv_Pol))
1522                                Edit/W=(6,506,511,713)/K=1 Inv_Pol
1523                        endif
1524                        Wave/Z Pol_err = $("root:Packages:NIST:"+type+":PolMatrix_err")
1525                        if(WaveExists(Pol_err))
1526                                Edit/W=(5,275,510,482)/K=1 Pol_err
1527                        endif
1528                        Wave/Z Inv_Pol_err = $("root:Packages:NIST:"+type+":Inv_PolMatrix_err")
1529                        if(WaveExists(Inv_Pol_err))
1530                                Edit/W=(6,736,511,943)/K=1 Inv_Pol_err
1531                        endif
1532                       
1533                        break
1534                case -1: // control being killed
1535                        break
1536        endswitch
1537
1538        return 0
1539End
1540
1541// return a list of conditions, prepended with "none" for use in a popup menu
1542Function/S P_GetConditionNameList()
1543        return("none;"+D_ConditionNameList())
1544End
1545
1546
1547// for a run, or a list of runs, determine the midpoint of the data collection
1548//
1549// list is passed COMMA-delimited, like normal lists of run numbers
1550//
1551// the time is returned in seconds (equivalent to a VAX date and time)
1552//
1553Function getTimeMidpoint(listStr)
1554        String listStr
1555
1556        Variable ii,t_first,runt_first,t_last,runt_last,elap,run,t1,num,tMid
1557        String fname
1558       
1559        t1=0
1560        t_first = 1e100
1561        t_last = 0
1562       
1563        num=itemsinlist(listStr,",")
1564        for(ii=0;ii<num;ii+=1)
1565                run = str2num( StringFromList(ii, listStr ,",") )
1566                fname = FindFileFromRunNumber(run)
1567                t1 = ConvertVAXDateTime2Secs(getFileCreationDate(fname))
1568                if(t1 < t_first)
1569                        t_first = t1
1570                endif
1571                if(t1 > t_last)
1572                        t_last = t1
1573                        runt_last = getCountTime(fname)         //seconds
1574                endif
1575       
1576        endfor
1577//      print/D t_last
1578//      Print/D runt_last
1579//      print/D t_first
1580       
1581        elap = (t_last + runt_last) - t_first           // from start of first file, to end of last
1582
1583        tMid = t_first + elap/2
1584        return(tMid)
1585End
1586
1587// options to reduce one or all types, in the same manner as the load.
1588//
1589// largely copied from ReduceAFile()
1590//
1591Function ReducePolCorDataButton(ctrlName) : ButtonControl
1592        String ctrlName
1593
1594        // depends on which tab you're on
1595        // (maybe) select UD type
1596       
1597        String pType
1598//      Prompt pType,"Pol Type",popup,"UU;DU;DD;UD;All;"
1599//      DoPrompt "Type to load",pType
1600//      if (V_Flag)
1601//              return 0                                                                        // user canceled
1602//      endif
1603//      Print pType
1604
1605
1606        pType = "All"
1607
1608// get the protocol to use
1609// this is pulled from ReduceAFile()
1610        Variable err
1611        String waveStr
1612       
1613        //pick a protocol wave from the Protocols folder
1614        //must switch to protocols folder to get wavelist (missing parameter)
1615        SetDataFolder root:myGlobals:Protocols
1616        Execute "PickAProtocol()"
1617       
1618        //get the selected protocol wave choice through a global string variable
1619        SVAR protocolName = root:myGlobals:Protocols:gProtoStr
1620       
1621        //If "CreateNew" was selected, go to the questionnare, to make a new set
1622        //and put the name of the new Protocol wave in gProtoStr
1623        if(cmpstr("CreateNew",protocolName) == 0)
1624                return(0)
1625        Endif
1626       
1627        //give the full path:name to the executeProtocol function
1628        waveStr = "root:myGlobals:Protocols:"+protocolName
1629        //samStr is set at top to "ask", since this is the action always desired from "ReduceAFile"
1630               
1631        //return data folder to root before Macro is done
1632        SetDataFolder root:
1633       
1634        if(cmpstr(pType,"All") == 0)
1635                ExecutePolarizedProtocol(waveStr,"UU")
1636                ExecutePolarizedProtocol(waveStr,"DU")
1637                ExecutePolarizedProtocol(waveStr,"DD")
1638                ExecutePolarizedProtocol(waveStr,"UD")
1639        else
1640                ExecutePolarizedProtocol(waveStr,pType)
1641        endif   
1642       
1643       
1644        return(0)
1645End
1646
1647// very similar to ExecuteProtocol
1648//
1649// -- SAM, EMP, and BGD do not need to be loaded
1650// -- but they do need to be "moved" into the regular data positions
1651//    rather then their tagged locations.
1652//
1653// -- the "extensions" now all are "_UU_pc" and similar, to use the polarization corrected data and errors
1654//
1655Function ExecutePolarizedProtocol(protStr,pType)
1656        String protStr,pType
1657
1658        //protStr is the full path to the selected protocol wave
1659        WAVE/T prot = $protStr
1660        SetDataFolder root:myGlobals:Protocols
1661       
1662        Variable filesOK,err,notDone
1663        String activeType, msgStr, junkStr, pathStr="", samStr=""
1664        PathInfo catPathName                    //this is where the files are
1665        pathStr=S_path
1666       
1667        NVAR useXMLOutput = root:Packages:NIST:gXML_Write
1668       
1669        //Parse the instructions in the prot wave
1670        //0 - bkg
1671        //1 - emp
1672        //2 - div
1673        //3 - mask
1674        //4 - abs params c2-c5
1675        //5 - average params
1676        //6 = DRK file (**out of sequence)
1677
1678// don't load the SAM data, just re-tag it     
1679// the Polarization corrected data is UU_pc, DU_pc, etc.
1680// this tags it for display, and puts it in the correctly named waves
1681        String dataType,str
1682       
1683        dataType="SAM"
1684        sprintf str,"DisplayTaggedData(\"%s\",\"%s\")",dataType,pType+"_pc"
1685        Execute str
1686       
1687
1688
1689// don't load the BGD data, just re-tag it     
1690        if(cmpstr(prot[0],"none") != 0)         //if BGD is used, protStr[0] = ""
1691                dataType="BGD"
1692                sprintf str,"DisplayTaggedData(\"%s\",\"%s\")",dataType,pType+"_pc"
1693                Execute str
1694        endif
1695
1696// don't load the EMP data, just re-tag it
1697//
1698        if(cmpstr(prot[1],"none") != 0)         //if EMP is used, protStr[1] = ""
1699                dataType="EMP"
1700                sprintf str,"DisplayTaggedData(\"%s\",\"%s\")",dataType,pType+"_pc"
1701                Execute str
1702        endif
1703               
1704//
1705// from here down, the steps are identical
1706//
1707// - with the exceptions of:
1708// - file naming. Names are additionally tagged with pType
1709// - if the protocol[0] or [1] are "" <null>, then the step  will be used
1710//   the step is only skipped if the protocol is "none"
1711//
1712
1713       
1714        //do the CORRECT step based on the answers to emp and bkg subtraction
1715        //by setting the proper"mode"
1716        //1 = both emp and bgd subtraction
1717        //2 = only bgd subtraction
1718        //3 = only emp subtraction
1719        //4 = no subtraction
1720        //additional modes 091301
1721        // ------currently, for polarized reduction, DRK mode is not allowed or recognized at all...
1722        //11 = emp, bgd, drk
1723        //12 = bgd and drk
1724        //13 = emp and drk
1725        //14 = no subtractions
1726        //work.drk is from proto[6]
1727        //
1728        //subtracting just the DRK data is NOT an option - it doesnt' really make any physical sense
1729        // - in this case, DRK is skipped (equivalent to mode==4)
1730        // automatically accounts for attenuators given the lookup tables and the
1731        //desired subtractions
1732        //Attenuator lookup tables are alredy implemented (NG1 = NG7)
1733        //
1734               
1735        //dispatch to the proper "mode" of Correct()
1736        Variable mode=4,val
1737        do
1738                if( (cmpstr("none",prot[0]) == 0)       && (cmpstr("none",prot[1]) == 0) )
1739                        //no subtraction (mode = 4),
1740                        mode = 4
1741                Endif
1742                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[1],"none") == 0))
1743                        //subtract BGD only
1744                        mode=2
1745                Endif
1746                If((cmpstr(prot[0],"none") == 0) && (cmpstr(prot[1],"none") != 0))
1747                        //subtract EMP only
1748                        mode=3
1749                Endif
1750                If((cmpstr(prot[0],"none") != 0) && (cmpstr(prot[1],"none") != 0))
1751                        // bkg and emp subtraction are to be done (BOTH not "none")
1752                        mode=1
1753                Endif
1754                activeType = "COR"
1755//              //add in DRK mode (0= no used, 10 = used)
1756//              val = NumberByKey("DRKMODE",prot[6],"=","," )
1757//              mode += val
1758//              print "Correct mode = ",mode
1759                err = Correct(mode)
1760                if(err)
1761                        SetDataFolder root:
1762                        Abort "error in Correct, called from executeprotocol, normal cor"
1763                endif
1764                TagLoadedData(activeType,pType+"_pc")
1765                UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1766        While(0)
1767       
1768        //check for work.div file (prot[2])
1769        //add if needed
1770        // can't properly check the filename - so for now add and divide, if anything other than "none"
1771        //do/skip divide step based on div answer
1772        If(cmpstr("none",prot[2])!=0)           // if !0, then there's a file requested
1773                If(cmpstr("ask",prot[2]) == 0)
1774                        //ask user for file
1775                         junkStr = PromptForPath("Select the detector sensitivity file")
1776                        If(strlen(junkStr)==0)
1777                                SetDataFolder root:
1778                                Abort "No file selected, data reduction aborted"
1779                        Endif
1780                         ReadHeaderAndWork("DIV", junkStr)
1781                else
1782                        //assume it's a path, and that the first (and only) item is the path:file
1783                        //list processing is necessary to remove any final comma
1784                        junkStr = pathStr + StringFromList(0, prot[2],"," )
1785                        ReadHeaderAndWork("DIV",junkStr)
1786                Endif
1787                //got a DIV file, select the proper type of work data to DIV (= activeType)
1788                err = Divide_work(activeType)           //returns err = 1 if data doesn't exist in specified folders
1789                If(err)
1790                        SetDataFolder root:
1791                        Abort "data missing in DIV step, call from executeProtocol"
1792                Endif
1793                activeType = "CAL"
1794                TagLoadedData(activeType,pType+"_pc")
1795                UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1796        Endif
1797       
1798        Variable c2,c3,c4,c5,kappa_err
1799        //do absolute scaling if desired
1800        if(cmpstr("none",prot[4])!=0)
1801                if(cmpstr("ask",prot[4])==0)
1802                        //get the params from the user
1803                        Execute "AskForAbsoluteParams_Quest()"
1804                        //then from the list
1805                        SVAR junkAbsStr = root:myGlobals:Protocols:gAbsStr
1806                        c2 = NumberByKey("TSTAND", junkAbsStr, "=", ";")        //parse the list of values
1807                        c3 = NumberByKey("DSTAND", junkAbsStr, "=", ";")
1808                        c4 = NumberByKey("IZERO", junkAbsStr, "=", ";")
1809                        c5 = NumberByKey("XSECT", junkAbsStr, "=", ";")
1810                        kappa_err = NumberByKey("SDEV", junkAbsStr, "=", ";")
1811                else
1812                        //get the parames from the list
1813                        c2 = NumberByKey("TSTAND", prot[4], "=", ";")   //parse the list of values
1814                        c3 = NumberByKey("DSTAND", prot[4], "=", ";")
1815                        c4 = NumberByKey("IZERO", prot[4], "=", ";")
1816                        c5 = NumberByKey("XSECT", prot[4], "=", ";")
1817                        kappa_err = NumberByKey("SDEV", prot[4], "=", ";")
1818                Endif
1819                //get the sample trans and thickness from the activeType folder
1820                String destStr = "root:Packages:NIST:"+activeType+":realsread"
1821                Wave dest = $destStr
1822                Variable c0 = dest[4]           //sample transmission
1823                Variable c1 = dest[5]           //sample thickness
1824               
1825                err = Absolute_Scale(activeType,c0,c1,c2,c3,c4,c5,kappa_err)
1826                if(err)
1827                        SetDataFolder root:
1828                        Abort "Error in Absolute_Scale(), called from executeProtocol"
1829                endif
1830                activeType = "ABS"
1831                TagLoadedData(activeType,pType+"_pc")
1832                UpdateDisplayInformation(ActiveType)            //update before breaking from loop
1833        Endif
1834       
1835        //check for mask
1836        //add mask if needed
1837        // can't properly check the filename - so for now always add
1838        //doesn't change the activeType
1839        if(cmpstr("none",prot[3])!=0)
1840                If(cmpstr("ask",prot[3])==0)
1841                        //get file from user
1842                        junkStr = PromptForPath("Select Mask file")
1843                        If(strlen(junkStr)==0)
1844                                //no selection of mask file is not a fatal error, keep going, and let cirave()
1845                                //make a "null" mask
1846                                //if none desired, make sure that the old mask is deleted
1847                                //junkStr = GetDataFolder(1)
1848                                //SetDataFolder root:Packages:NIST:MSK
1849                                KillWaves/Z root:Packages:NIST:MSK:data
1850                                //SetDataFolder junkStr
1851                                DoAlert 0,"No Mask file selected, data not masked"
1852                        else
1853                                //read in the file from the dialog
1854                                ReadMCID_MASK(junkStr)
1855                        Endif
1856                else
1857                        //just read it in from the protocol
1858                        //list processing is necessary to remove any final comma
1859                        junkStr = pathStr + StringFromList(0, prot[3],"," )
1860                        ReadMCID_MASK(junkStr)
1861                Endif
1862        else
1863                //if none desired, make sure that the old mask is deleted
1864                //junkStr = GetDataFolder(1)
1865                //SetDataFolder root:Packages:NIST:MSK
1866                KillWaves/Z root:Packages:NIST:MSK:data
1867                //SetDataFolder junkStr
1868        Endif
1869       
1870        //mask data if desired (this is done automatically  in the average step) and is
1871        //not done explicitly here (if no mask in MSK folder, a null mask is created and "used")
1872       
1873        // average/save data as specified
1874       
1875        //Parse the keyword=<Value> string as needed, based on AVTYPE
1876       
1877        //average/plot first
1878        String av_type = StringByKey("AVTYPE",prot[5],"=",";")
1879        If(cmpstr(av_type,"none") != 0)
1880                If (cmpstr(av_type,"")==0)              //if the key could not be found... (if "ask" the string)
1881                        //get the averaging parameters from the user, as if the set button was hit
1882                        //in the panel
1883                        SetAverageParamsButtonProc("dummy")             //from "ProtocolAsPanel"
1884                        SVAR tempAveStr = root:myGlobals:Protocols:gAvgInfoStr
1885                        av_type = StringByKey("AVTYPE",tempAveStr,"=",";")
1886                else
1887                        //there is info in the string, use the protocol
1888                        //set the global keyword-string to prot[5]
1889                        String/G root:myGlobals:Protocols:gAvgInfoStr = prot[5]
1890                Endif
1891        Endif
1892       
1893        //convert the folder to linear scale before averaging, then revert by calling the window hook
1894        ConvertFolderToLinearScale(activeType)
1895       
1896        strswitch(av_type)      //dispatch to the proper routine to average to 1D data
1897                case "none":           
1898                        //still do nothing
1899                        break                   
1900                case "2D_ASCII":       
1901                        //do nothing
1902                        break
1903                case "QxQy_ASCII":
1904                        //do nothing
1905                        break
1906                case "PNG_Graphic":
1907                        //do nothing
1908                        break
1909                case "Rectangular":
1910                        RectangularAverageTo1D(activeType)
1911                        break
1912                case "Annular":
1913                        AnnularAverageTo1D(activeType)
1914                        break
1915                case "Circular":
1916                        CircularAverageTo1D(activeType)
1917                        break
1918                case "Sector":
1919                        CircularAverageTo1D(activeType)
1920                        break
1921                case "Sector_PlusMinus":
1922                        Sector_PlusMinus1D(activeType)
1923                        break
1924                default:       
1925                        //do nothing
1926        endswitch
1927///// end of averaging dispatch
1928        // put data back on log or lin scale as set by default
1929        fRawWindowHook()
1930       
1931        //save data if desired
1932        String fullpath = "", newfileName=""
1933        String item = StringByKey("SAVE",prot[5],"=",";")               //does user want to save data?
1934        If( (cmpstr(item,"Yes")==0) && (cmpstr(av_type,"none") != 0) )         
1935                //then save
1936                //get name from textwave of the activeType dataset
1937                String textStr = "root:Packages:NIST:"+activeType+":textread"
1938                Wave/T textPath = $textStr
1939                String tempFilename = samStr
1940                If(WaveExists(textPath) == 1)
1941#if (exists("QUOKKA")==6)
1942                        newFileName = ReplaceString(".nx.hdf", tempFilename, "")
1943#elif (exists("HFIR")==6)
1944//                      newFileName = ReplaceString(".xml",textPath[0],"")              //removes 4 chars
1945//                      newFileName = ReplaceString("SANS",newFileName,"")              //removes 4 more chars = 8
1946//                      newFileName = ReplaceString("exp",newFileName,"")                       //removes 3 more chars = 11
1947//                      newFileName = ReplaceString("scan",newFileName,"")              //removes 4 more chars = 15, should be enough?
1948                        newFileName = GetPrefixStrFromFile(textPath[0])+GetRunNumStrFromFile(textPath[0])
1949#else
1950                        newFileName = UpperStr(GetNameFromHeader(textPath[0]))          //NCNR data drops here, trims to 8 chars
1951#endif
1952                else
1953                        newFileName = ""                        //if the header is missing?
1954                        //Print "can't read the header - newfilename is null"
1955                Endif
1956               
1957                //pick ABS or AVE extension
1958                String exten = activeType
1959                if(cmpstr(exten,"ABS") != 0)
1960                        exten = "AVE"
1961                endif
1962                if(cmpstr(av_type,"2D_ASCII") == 0)
1963                        exten = "ASC"
1964                endif
1965                if(cmpstr(av_type,"QxQy_ASCII") == 0)
1966                        exten = "DAT"
1967                endif
1968               
1969                // add an "x" to the file extension if the output is XML
1970                // currently (2010), only for ABS and AVE (1D) output
1971                if( cmpstr(exten,"ABS") == 0 || cmpstr(exten,"AVE") == 0 )
1972                        if(useXMLOutput == 1)
1973                                exten += "x"
1974                        endif
1975                endif
1976                               
1977                //Path is catPathName, symbolic path
1978                //if this doesn't exist, a dialog will be presented by setting dialog = 1
1979                //
1980                // -- add in pType tag to the name
1981                //
1982                Variable dialog = 0
1983                PathInfo/S catPathName
1984                item = StringByKey("NAME",prot[5],"=",";")              //Auto or Manual naming
1985                String autoname = StringByKey("AUTONAME",prot[5],"=",";")               //autoname -  will get empty string if not present
1986                If((cmpstr(item,"Manual")==0) || (cmpstr(newFileName,"") == 0))
1987                        //manual name if requested or if no name can be derived from header
1988                        fullPath = newfileName + pType + "."+ exten //puts possible new name or null string in dialog
1989                        dialog = 1              //force dialog for user to enter name
1990                else
1991                        //auto-generate name and prepend path - won't put up any dialogs since it has all it needs
1992                        //use autoname if present
1993                        if (cmpstr(autoname,"") != 0)
1994                                fullPath = S_Path + autoname + pType + "." +exten
1995                        else
1996                                fullPath = S_Path + newFileName + pType + "." + exten
1997                        endif   
1998                Endif
1999                //
2000                strswitch(av_type)     
2001                        case "Annular":
2002                                WritePhiave_W_Protocol(activeType,fullPath,dialog)
2003                                break
2004                        case "2D_ASCII":
2005                                Fast2DExport(activeType,fullPath,dialog)
2006                                break
2007                        case "QxQy_ASCII":
2008                                QxQy_Export(activeType,fullPath,dialog)
2009                                break
2010                        case "PNG_Graphic":
2011                                SaveAsPNG(activeType,fullpath,dialog)
2012                                break
2013                        default:
2014                                if (useXMLOutput == 1)
2015                                        WriteXMLWaves_W_Protocol(activeType,fullPath,dialog)
2016                                else
2017                                        WriteWaves_W_Protocol(activeType,fullpath,dialog)
2018                                endif
2019                endswitch
2020               
2021                //Print "data written to:  "+ fullpath
2022        Endif
2023       
2024        //done with everything in protocol list
2025        return(0)
2026End
2027
2028
2029// just like the RecallProtocolButton
2030// - the reset function is different
2031//
2032Function RecallPolCorProtocolButton(ctrlName) : ButtonControl
2033        String ctrlName
2034       
2035        //will reset panel values based on a previously saved protocol
2036        //pick a protocol wave from the Protocols folder
2037        //MUST move to Protocols folder to get wavelist
2038        SetDataFolder root:myGlobals:Protocols
2039        Execute "PickAProtocol()"
2040       
2041        //get the selected protocol wave choice through a global string variable
2042        SVAR protocolName = root:myGlobals:Protocols:gProtoStr
2043
2044        //If "CreateNew" was selected, ask user to try again
2045        if(cmpstr("CreateNew",protocolName) == 0)
2046                Abort "CreateNew is for making a new Protocol. Select a previously saved Protocol"
2047        Endif
2048       
2049        //reset the panel based on the protocol textwave (currently a string)
2050        ResetToSavedPolProtocol(protocolName)
2051       
2052        SetDataFolder root:
2053        return(0)
2054end
2055
2056//function that actually parses the protocol specified by nameStr
2057//which is just the name of the wave, without a datafolder path
2058//
2059Function ResetToSavedPolProtocol(nameStr)
2060        String nameStr
2061       
2062        //allow special cases of Base and DoAll Protocols to be recalled to panel - since they "ask"
2063        //and don't need paths
2064       
2065        String catPathStr
2066        PathInfo catPathName
2067        catPathStr=S_path
2068       
2069        //SetDataFolder root:myGlobals:Protocols                //on windows, data folder seems to get reset (erratically) to root:
2070        Wave/T w=$("root:myGlobals:Protocols:" + nameStr)
2071       
2072        String fullPath="",comma=",",list="",nameList="",PathStr="",item=""
2073        Variable ii=0,numItems,checked,specialProtocol=0
2074       
2075        if((cmpstr(nameStr,"Base")==0) || (cmpstr(nameStr,"DoAll")==0))
2076                return(0)               //don't allow these
2077        Endif
2078
2079        //background = check5
2080        checked = 1
2081        nameList = w[0]
2082        If(cmpstr(nameList,"none") ==0)
2083                checked = 0
2084        Endif
2085
2086        //set the global string to display and checkbox
2087        CheckBox check5 win=PolCor_Panel,value=checked
2088
2089        //EMP = check4
2090        checked = 1
2091        nameList = w[1]
2092        If(cmpstr(nameList,"none") ==0)
2093                checked = 0
2094        Endif
2095
2096        //set the global string to display and checkbox
2097        CheckBox check4 win=PolCor_Panel,value=checked
2098       
2099       
2100        //DIV file
2101        checked = 1
2102        nameList = w[2]
2103        If(cmpstr(nameList,"none") ==0)
2104                checked = 0
2105        Endif
2106
2107        //set the global string to display and checkbox
2108        String/G root:myGlobals:Protocols:gDIV = nameList
2109        CheckBox check0 win=PolCor_Panel,value=checked
2110       
2111        //Mask file
2112        checked = 1
2113        nameList = w[3]
2114        If(cmpstr(nameList,"none") ==0)
2115                checked = 0
2116        Endif
2117
2118        //set the global string to display and checkbox
2119        String/G root:myGlobals:Protocols:gMASK = nameList
2120        CheckBox check1 win=PolCor_Panel,value=checked
2121       
2122        //4 = abs parameters
2123        list = w[4]
2124        numItems = ItemsInList(list,";")
2125        checked = 1
2126        if(numitems == 4 || numitems == 5)              //allow for protocols with no SDEV list item
2127                //correct number of parameters, assume ok
2128                String/G root:myGlobals:Protocols:gAbsStr = list
2129                CheckBox check2 win=PolCor_Panel,value=checked
2130        else
2131                item = StringFromList(0,list,";")
2132                if(cmpstr(item,"none")==0)
2133                        checked = 0
2134                        list = "none"
2135                        String/G root:myGlobals:Protocols:gAbsStr = list
2136                        CheckBox check2 win=PolCor_Panel,value=checked
2137                else
2138                        //force to "ask"
2139                        checked = 1
2140                        String/G root:myGlobals:Protocols:gAbsStr = "ask"
2141                        CheckBox check2 win=PolCor_Panel,value=checked
2142                Endif
2143        Endif
2144       
2145        //5 = averaging choices
2146        list = w[5]
2147        item = StringByKey("AVTYPE",list,"=",";")
2148        if(cmpstr(item,"none") == 0)
2149                checked = 0
2150                String/G root:myGlobals:Protocols:gAVE = "none"
2151                CheckBox check3 win=PolCor_Panel,value=checked
2152        else
2153                checked = 1
2154                String/G root:myGlobals:Protocols:gAVE = list
2155                CheckBox check3 win=PolCor_Panel,value=checked
2156        Endif
2157       
2158        //6 = DRK choice
2159
2160        //7 = unused
2161       
2162        //all has been reset, get out
2163        Return (0)
2164End
2165
2166// at a first pass, uses the regular reduction protocol         SaveProtocolButton(ctrlName)
2167//
2168// -- won't work, as it uses the MakeProtocolFromPanel function... so replace this
2169//
2170Function SavePolCorProtocolButton(ctrlName) : ButtonControl
2171        String ctrlName
2172       
2173       
2174        Variable notDone=1, newProto=1
2175        //will prompt for protocol name, and save the protocol as a text wave
2176        //prompt for name of new protocol wave to save
2177        do
2178                Execute "AskForName()"
2179                SVAR newProtocol = root:myGlobals:Protocols:gNewStr
2180               
2181                //make sure it's a valid IGOR name
2182                newProtocol = CleanupName(newProtocol,0)        //strict naming convention
2183                String/G root:myGlobals:Protocols:gNewStr=newProtocol           //reassign, if changed
2184                Print "newProtocol = ",newProtocol
2185               
2186                SetDataFolder root:myGlobals:Protocols
2187                if(WaveExists( $("root:myGlobals:Protocols:" + newProtocol) ) == 1)
2188                        //wave already exists
2189                        DoAlert 1,"That name is already in use. Do you wish to overwrite the existing protocol?"
2190                        if(V_Flag==1)
2191                                notDone = 0
2192                                newProto = 0
2193                        else
2194                                notDone = 1
2195                        endif
2196                else
2197                        //name is good
2198                        notDone = 0
2199                Endif
2200        while(notDone)
2201       
2202        //current data folder is  root:myGlobals:Protocols
2203        if(newProto)
2204                Make/O/T/N=8 $("root:myGlobals:Protocols:" + newProtocol)
2205        Endif
2206       
2207//      MakeProtocolFromPanel( $("root:myGlobals:Protocols:" + newProtocol) )
2208        MakePolProtocolFromPanel( $("root:myGlobals:Protocols:" + newProtocol) )
2209        String/G  root:myGlobals:Protocols:gProtoStr = newProtocol
2210       
2211        //the data folder WAS changed above, this must be reset to root:
2212        SetDatafolder root:     
2213               
2214        return(0)
2215End
2216
2217//function that does the guts of reading the panel controls and globals
2218//to create the necessary text fields for a protocol
2219//Wave/T w (input) is an empty text wave of 8 elements for the protocol
2220//on output, w[] is filled with the protocol strings as needed from the panel
2221//
2222Function MakePolProtocolFromPanel(w)
2223        Wave/T w
2224       
2225        //construct the protocol text wave form the panel
2226        //it is to be parsed by ExecuteProtocol() for the actual data reduction
2227        PathInfo catPathName                    //this is where the files came from
2228        String pathstr=S_path,tempStr,curList
2229        Variable checked,ii,numItems
2230       
2231        //look for checkboxes, then take each item in list and prepend the path
2232        //w[0] = background
2233        ControlInfo/W=PolCor_Panel check5
2234        checked = V_Value
2235        if(checked)
2236                w[0] = ""               // BKG will be used
2237        else
2238                w[0] = "none"           // BKG will not be used
2239        endif
2240       
2241        //w[1] = empty
2242        ControlInfo/W=PolCor_Panel check4
2243        checked = V_Value
2244        if(checked)
2245                w[1] = ""               // EMP will be used
2246        else
2247                w[1] = "none"           // EMP will not be used
2248        endif
2249
2250       
2251        //w[2] = div file
2252        ControlInfo/W=PolCor_Panel check0
2253        checked = V_value
2254        if(checked)
2255                //build the list
2256                //just read the global
2257                SVAR str=root:myGlobals:Protocols:gDIV
2258                if(cmpstr(str,"ask")==0)
2259                        w[2] = str
2260                else
2261                        tempStr = ParseRunNumberList(str)
2262                        if(strlen(tempStr)==0)
2263                                return(1)
2264                        else
2265                                w[2] = tempstr
2266                                str=tempstr
2267                        endif
2268                endif
2269        else
2270                //none used - set textwave (and global?)
2271                w[2] = "none"
2272                String/G root:myGlobals:Protocols:gDIV = "none"
2273        endif
2274       
2275        //w[3] = mask file
2276        ControlInfo/W=PolCor_Panel check1
2277        checked = V_value
2278        if(checked)
2279                //build the list
2280                //just read the global
2281                SVAR str=root:myGlobals:Protocols:gMASK
2282                if(cmpstr(str,"ask")==0)
2283                        w[3] = str
2284                else
2285                        tempstr = ParseRunNumberList(str)
2286                        if(strlen(tempstr)==0)
2287                                return(1)
2288                        else
2289                                w[3] = tempstr
2290                                str = tempstr
2291                        endif
2292                endif
2293        else
2294                //none used - set textwave (and global?)
2295                w[3] = "none"
2296                String/G root:myGlobals:Protocols:gMASK = "none"
2297        endif
2298       
2299        //w[4] = abs parameters
2300        ControlInfo/W=PolCor_Panel check2
2301        checked = V_value
2302        if(checked)
2303                //build the list
2304                //just read the global
2305                SVAR str=root:myGlobals:Protocols:gAbsStr
2306                w[4] = str
2307        else
2308                //none used - set textwave (and global?)
2309                w[4] = "none"
2310                String/G root:myGlobals:Protocols:gAbsStr = "none"
2311        endif
2312       
2313        //w[5] = averaging choices
2314        ControlInfo/W=PolCor_Panel check3
2315        checked = V_value
2316        if(checked)
2317                //just read the global
2318                SVAR avestr=root:myGlobals:Protocols:gAVE
2319                w[5] = avestr
2320        else
2321                //none used - set textwave
2322                w[5] = "AVTYPE=none;"
2323        endif
2324       
2325        //w[6]
2326        //work.DRK information
2327        SVAR drkStr=root:myGlobals:Protocols:gDRK
2328        w[6] = ""
2329       
2330        //w[7]
2331        //currently unused
2332        w[7] = ""
2333       
2334        return(0)
2335End
2336
2337
2338
2339// the data in the SAM, EMP, BKG folders will be either _UU or _UU_pc, depending if the data
2340// is as-loaded, or if it's been polarization corrected. This is to display the polarization-corrected "_pc"
2341// data sets ONLY. If you want to see the individual data sets, well that's just the SAM, EMP, BGD files.
2342// look at thum one-by-one...
2343//
2344// -- data in subsequent correction step folders do have the _pc extensions, the _pc data is
2345//              used for each step, so the _pc is redundant, but consistent
2346//
2347Function Display_4(type,scaling)
2348        String type,scaling
2349       
2350        String dest = "root:Packages:NIST:"+type
2351        NVAR isLogscale = $(dest + ":gIsLogScale")
2352
2353        SetDataFolder $("root:Packages:NIST:"+type)
2354       
2355        wave uu = linear_data_uu_pc
2356        wave d_uu = data_uu_pc
2357       
2358        wave du = linear_data_du_pc
2359        wave d_du = data_du_pc
2360       
2361        wave dd = linear_data_dd_pc
2362        wave d_dd = data_dd_pc
2363       
2364        wave ud = linear_data_ud_pc
2365        wave d_ud = data_ud_pc
2366               
2367        if(cmpstr(scaling,"log") == 0)
2368
2369                d_uu = log(uu)
2370                d_du = log(du)
2371                d_dd = log(dd)
2372                d_ud = log(ud)                 
2373               
2374                isLogScale = 1
2375                       
2376        else
2377
2378                d_uu = uu
2379                d_du = du
2380                d_dd = dd
2381                d_ud = ud
2382                       
2383                isLogScale = 0
2384
2385        endif
2386
2387        DoWindow/F SANS_X4
2388        if(V_flag==0)
2389                Display /W=(811,44,1479,758)/K=1
2390                ControlBar 100
2391                DoWindow/C SANS_X4
2392                DoWindow/T SANS_X4,type+"_pc"
2393                Button button0 pos={130,65},size={50,20},title="Do It",proc=Change4xsButtonProc
2394                PopupMenu popup0 pos={20,35},title="Data Type",value="SAM;EMP;BGD;COR;CAL;ABS;"         //RAW, SAS, DIV, etc, won't have _pc data and are not valid
2395                PopupMenu popup1 pos={190,35},title="Scaling",value="log;linear;"
2396                TitleBox title0 title="Only Polarization-corrected sets are displayed",pos={5,5}
2397
2398        else
2399                RemoveImage/Z data_uu_pc                //remove the old images (different data folder)
2400                RemoveImage/Z data_du_pc
2401                RemoveImage/Z data_dd_pc
2402                RemoveImage/Z data_ud_pc
2403               
2404                DoWindow/T SANS_X4,type+"_pc"
2405
2406        endif
2407       
2408        AppendImage/B=bot_uu/L=left_uu data_UU_pc
2409        ModifyImage data_UU_pc ctab= {*,*,YellowHot,0}
2410        AppendImage/B=bot_dd/L=left_dd data_DD_pc
2411        ModifyImage data_DD_pc ctab= {*,*,YellowHot,0}
2412        AppendImage/B=bot_du/L=left_du data_DU_pc
2413        ModifyImage data_DU_pc ctab= {*,*,YellowHot,0}
2414        AppendImage/B=bot_ud/L=left_ud data_UD_pc
2415        ModifyImage data_UD_pc ctab= {*,*,YellowHot,0}
2416       
2417        DoUpdate
2418                       
2419        ModifyGraph freePos(left_uu)={0,kwFraction},freePos(bot_uu)={0.6,kwFraction}
2420        ModifyGraph freePos(left_dd)={0,kwFraction},freePos(bot_dd)={0,kwFraction}
2421        ModifyGraph freePos(left_du)={0.6,kwFraction},freePos(bot_du)={0.6,kwFraction}
2422        ModifyGraph freePos(left_ud)={0.6,kwFraction},freePos(bot_ud)={0,kwFraction}
2423       
2424        ModifyGraph axisEnab(left_uu)={0.6,1},axisEnab(bot_uu)={0,0.4}
2425        ModifyGraph axisEnab(left_dd)={0,0.4},axisEnab(bot_dd)={0,0.4}
2426        ModifyGraph axisEnab(left_du)={0.6,1},axisEnab(bot_du)={0.6,1}
2427        ModifyGraph axisEnab(left_ud)={0,0.4},axisEnab(bot_ud)={0.6,1}
2428       
2429        ModifyGraph standoff=0
2430        ModifyGraph lblPosMode(left_uu)=4,lblPosMode(left_dd)=4,lblPosMode(left_du)=4,lblPosMode(left_ud)=4
2431        ModifyGraph lblPos(left_uu)=40,lblPos(left_dd)=40,lblPos(left_du)=40,lblPos(left_ud)=40
2432        Label left_uu "UU"
2433        Label left_dd "DD"
2434        Label left_du "DU"
2435        Label left_ud "UD"     
2436       
2437        ModifyGraph fSize=16
2438        // force a redraw to get the axes in the right spot
2439        DoUpdate
2440       
2441        SetDataFolder root:
2442        return(0)
2443End
2444
2445Function Change4xsButtonProc(ba) : ButtonControl
2446        STRUCT WMButtonAction &ba
2447
2448        String dataType,scaling
2449       
2450        switch( ba.eventCode )
2451                case 2: // mouse up
2452                        // click code here
2453                        ControlInfo popup0
2454                        dataType = S_Value
2455                        ControlInfo popup1
2456                        scaling = S_Value
2457                        Display_4(dataType,scaling)
2458                       
2459                        break
2460                case -1: // control being killed
2461                        break
2462        endswitch
2463
2464        return 0
2465End
2466
2467// clear the entries for all 4 XS for the currently selected Tab only
2468// clears both the run numbers and the cell assignments
2469//
2470Function ClearPolCorEntries(ba) : ButtonControl
2471        STRUCT WMButtonAction &ba
2472
2473        switch( ba.eventCode )
2474                case 2: // mouse up
2475                        // click code here
2476                        //
2477//                      String type
2478                        Variable tabNum
2479                        ControlInfo/W=PolCor_Panel PolCorTab
2480//                      type = S_value
2481//                      Print "selected data type = ",type,V_Value
2482                        tabNum = V_Value
2483                       
2484                        WAVE/T twDD = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_DD")
2485                        WAVE/T twUU = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_UU")
2486                        WAVE/T twUD = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_UD")
2487                        WAVE/T twDU = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_DU")
2488                       
2489                        twDD = ""
2490                        twUU = ""
2491                        twUD = ""
2492                        twDU = ""
2493                       
2494                        break
2495                case -1: // control being killed
2496                        break
2497        endswitch
2498
2499        return 0
2500End
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552//////////////////////////////////////////////////////////////
2553//
2554/////////// all of the functions below are unused. See the procedures for the
2555//// panels for the functions that interact with the input and calculated matrices
2556//
2557//
2558//
2559//
2560//
2561////
2562//// (/S) FindFileFromRunNumber(num) gets fname
2563//// [4] is trans, [41] is trans error, [40] is Twhole
2564////
2565//
2566//
2567//
2568//Constant kTe = 0.87           // transmission of the unfilled cell
2569//
2570//
2571//
2572//// calculation of mu
2573////
2574//// Known: Te ===> Global constant currently, may change later
2575////
2576//// Input: T He (unpolarized), using unpolarized beam
2577////                    T He cell out, using unpolarized beam
2578////                    T background, using unpolarized beam
2579////
2580//// Equation 7
2581////
2582//Function opacity_mu(T_he,T_out,T_bk)
2583//      Variable T_he,T_out,T_bk
2584//
2585//      Variable mu
2586//
2587//// using the global constant!
2588//
2589//      mu = (1/kTe)*(T_he - T_bk)/(T_out - t_bk)
2590//      mu = -1*ln(mu)
2591//
2592//      return(mu)
2593//End
2594//
2595//
2596//
2597//Proc calc_muP(mu, runT_he, runT_out, runT_bk)
2598//      Variable mu=3.108, runT_he, runT_out, runT_bk
2599//
2600//      Variable muP,T_he, T_out, T_bk
2601//      String fname
2602//     
2603//      fname = FindFileFromRunNumber(runT_he)
2604//      T_he = getDetCount(fname)/getMonitorCount(fname)/getCountTime(fname)    //use CR, not trans (since no real empty condition)
2605//     
2606//      fname = FindFileFromRunNumber(runT_out)
2607//      T_out = getDetCount(fname)/getMonitorCount(fname)/getCountTime(fname)
2608//     
2609//      fname = FindFileFromRunNumber(runT_bk)
2610//      T_bk = getDetCount(fname)/getMonitorCount(fname)/getCountTime(fname)
2611//     
2612//      muP = Cell_muP(mu, T_he, T_out, T_bk)
2613//     
2614//      Print "Count rates T_he, T_out, T_bk = ",T_he, T_out, T_bk
2615//      Print "Mu*P = ",muP
2616//      Print "Time = ",getFileCreationDate(fname)
2617//     
2618//end
2619//
2620//
2621//// ???? is this correct ????
2622//// -- check the form of the equation. It's not the same in some documents
2623////
2624//// calculation of mu.P(t) from exerimental measurements
2625////
2626//// Known: Te and mu
2627//// Input: T He cell (polarized cell), using unpolarized beam
2628////                    T He cell OUT, using unpolarized beam
2629////                    T background, using unpolarized beam
2630////
2631//// Equation 9, modified by multiplying the result by mu + moving tmp inside the acosh()
2632////
2633//Function Cell_muP(mu, T_he, T_out, T_bk)
2634//      Variable mu, T_he, T_out, T_bk
2635//
2636//// using the global constant!
2637//
2638//      Variable muP,tmp
2639//     
2640//      tmp = kTe*exp(-mu)              //note mu has been moved
2641//      muP = acosh( (T_he - T_bk)/(T_out - T_bk)  * (1/tmp))
2642//
2643//      return(muP)
2644//End
2645//
2646//
2647////
2648//// calculation of mu.P(t) from Gamma and t=0 value
2649////
2650//// Known: Gamma, muP_t0, t0, tn
2651////
2652//// times are in hours, Gamma [=] hours
2653//// tn is later than t0, so t0-tn is negative
2654////
2655//// Equation 11
2656////
2657//Function muP_at_t(Gam_He, muP_t0, t0, tn)
2658//      Variable Gam_He, muP_t0, t0, tn
2659//
2660//      Variable muP
2661//     
2662//      muP = muP_t0 * exp( (t0 - tn)/Gam_He )
2663//     
2664//      return(muP)
2665//End
2666//
2667//// Calculation of Pcell(t)
2668//// note that this is a time dependent quantity
2669////
2670//// Known: muP(t)
2671//// Input: nothing additional
2672////
2673//// Equation 10
2674////
2675//Function PCell(muP)
2676//      Variable muP
2677//     
2678//      Variable PCell
2679//      PCell = tanh(muP)
2680//     
2681//      return(PCell)
2682//End
2683//
2684//
2685//// calculation of Pf (flipper)
2686////
2687//// Known: nothing
2688//// Input: Tuu, Tdu, and Tdd, Tud
2689////                    (but exactly what measurement conditions?)
2690////                    ( are these T's also calculated quantities???? -- Equation(s) 12--)
2691////
2692//// Equation 14
2693////
2694//// (implementation of equation 13 is more complicated, and not implemented yet)
2695////
2696//Function Flipper_Pf(Tuu, Tdu, Tdd, Tud)
2697//      Variable Tuu, Tdu, Tdd, Tud
2698//     
2699//      Variable pf
2700//     
2701//      pf = (Tdd - Tdu)/(Tuu - Tud)
2702//     
2703//      return(pf)
2704//End
2705//
2706//
2707//
2708//// (this is only one of 4 methods, simply the first one listed)
2709//// ???? this equation doesn't match up with the equation in the SS handout
2710////
2711//// calculation of P'sm (supermirror)
2712////
2713//// Known: Pcell(t1), Pcell(t2) (some implementations need Pf )
2714//// Input: Tuu(t1), Tud(t2)
2715////
2716//// Equation 15??
2717////
2718//Function SupMir_Psm(Pcell1,Pcell2,Tuu,Tud)
2719//      Variable Pcell1,Pcell2,Tuu,Tud
2720//     
2721//      Variable Psm
2722//     
2723//      Psm = (Tuu - Tud)/(PCell1 + PCell2)
2724//     
2725//      return(Psm)
2726//End
Note: See TracBrowser for help on using the repository browser.