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

Last change on this file since 853 was 853, checked in by srkline, 10 years ago

Some minor bug fixes to the behavior of the polarization routines.

Removed some extra function names from the fit function list

Added some equations to the Polarization documentation to record what equations are actually used. Details of the error propagation have not been added.

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