source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/Polarization/Pol_PolarizationPanels.ipf @ 817

Last change on this file since 817 was 817, checked in by srkline, 12 years ago

more changes and addtions to the polarization reduction. basic functionality is now present, with a really large panel to gather all of the input. Lots of testing is needed.

File size: 34.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3// input panels to set and calculate polarization parameters necessary for the
4// matrix corrections to the cross sections
5//
6// -1- Fundamental Cell Parameters -- these are constants, generally not editable.
7// -2- Decay Parameters -- these are fitted values based on transmission mearurements
8// -3-
9
10
11//
12// -- need a general way to be sure to NOT re-initialize the values if the panel is closed/reopened
13//
14//
15// TODO:
16// Need a way to output the results - like in a report format
17// cell (panel 1)
18// static params
19// fit gamma params
20// graph
21//
22// and also a separate report (panel 2)
23// flipper/sm @ conditions
24// --- the report could be as simple as a screen snapshot of the panel?
25
26
27// He cell parameters. Most of these are pre-defined, so that they are supplied as a
28// static table, only edited as parameters are refined.
29//
30// work with this as kwString
31// cell=nameStr
32// lambda=num
33// Te=num
34// err_Te=num
35// mu=nnum
36// err_mu=num
37//
38//
39// for this panel, the cell parameters are stored as kw strings
40// all of the strings start w/ "gCell_"
41//
42Macro ShowCellParamPanel()
43       
44        // init folders
45        // ASK before initializing cell constants
46        // open the panel
47        DoWindow/F CellParamPanel
48        if(V_flag == 0)
49                InitPolarizationFolders()
50                DoAlert 1,"Do you want to use default parameters?"
51                if(V_flag == 1)
52                        InitPolarizationGlobals()
53                endif
54                Make_HeCell_ParamWaves()
55                CellParamPanel()
56        endif
57
58end
59
60// setup the data folder, etc
61//
62//
63Function InitPolarizationFolders()
64
65        NewDataFolder/O root:Packages:NIST:Polarization
66        NewDataFolder/O root:Packages:NIST:Polarization:Cells                   //holds the cell constants and waves
67       
68        SetDataFolder root:
69        return(0)
70End
71
72//
73// add more cells here as they are defined
74//
75Function InitPolarizationGlobals()
76
77        SetDataFolder root:Packages:NIST:Polarization:Cells
78       
79        // cell constants
80        String/G gCell_Maverick = "cell=Maverick,lambda=5.0,Te=0.87,err_Te=0.01,mu=3.184,err_mu=0.2,"
81        String/G gCell_Burgundy = "cell=Burgundy,lambda=5.0,Te=0.86,err_Te=0.01,mu=3.138,err_mu=0.15,"
82        String/G gCell_Olaf = "cell=Olaf,lambda=7.5,Te=0.86,err_Te=0.005,mu=2.97,err_mu=0.18,"
83       
84       
85        SetDataFolder root:
86        return(0)
87End
88
89
90// parse strings to fill in waves
91
92//
93Function Make_HeCell_ParamWaves()
94
95        SetDataFolder root:Packages:NIST:Polarization:Cells
96       
97        String listStr,item
98        Variable num,ii
99       
100        // get a list of the strings
101        listStr=StringList("gCell_*",";")
102        num=ItemsInList(listStr,";")
103        print listStr
104       
105        Make/O/T/N=0 CellName
106        Make/O/N=0 lambda,Te,err_Te,mu,err_mu
107       
108        // parse the strings to fill the table
109        for(ii=0;ii<num;ii+=1)
110                item = StringFromList(ii, listStr,";")
111                SVAR gStr = $item
112                InsertPoints  ii, 1, CellName,lambda,Te,err_Te,mu,err_mu
113                CellName[ii] = StringByKey("cell", gStr, "=", ",", 0)
114                lambda[ii] = NumberByKey("lambda", gStr, "=", ",", 0)
115                Te[ii] = NumberByKey("Te", gStr, "=", ",", 0)
116                err_Te[ii] = NumberByKey("err_Te", gStr, "=", ",", 0)
117                mu[ii] = NumberByKey("mu", gStr, "=", ",", 0)
118                err_mu[ii] = NumberByKey("err_mu", gStr, "=", ",", 0)
119               
120        endfor
121
122       
123        SetDataFolder root:
124        return(0)
125End
126
127// take the waves from the table and write these back to the string, only for the current experiment
128//
129Function Save_HeCell_ParamWaves()
130
131        SetDataFolder root:Packages:NIST:Polarization:Cells
132       
133        String listStr,item,dummyStr
134        Variable num,ii
135       
136        // get a list of the strings
137        listStr=StringList("gCell_*",";")
138        num=ItemsInList(listStr,";")
139        KillStrings/Z listStr
140       
141        Wave/T CellName
142        Wave lambda,Te,err_Te,mu,err_mu
143       
144        dummyStr = "cell=Maverick,lambda=5.0,Te=0.87,err_Te=0.01,mu=3.184,err_mu=0.2,"
145       
146        num=numpnts(CellName)
147       
148        // parse the table to fill the Strings
149        for(ii=0;ii<num;ii+=1)
150                item = "gCell_"+CellName[ii]
151                String/G $item = dummyStr
152                SVAR kwListStr = $item
153               
154                kwListStr = ReplaceStringByKey("cell", kwListStr, CellName[ii], "=", ",", 0)
155                kwListStr = ReplaceNumberByKey("lambda", kwListStr, lambda[ii], "=", ",", 0)
156                kwListStr = ReplaceNumberByKey("Te", kwListStr, Te[ii], "=", ",", 0)
157                kwListStr = ReplaceNumberByKey("err_Te", kwListStr, err_Te[ii], "=", ",", 0)
158                kwListStr = ReplaceNumberByKey("mu", kwListStr, mu[ii], "=", ",", 0)
159                kwListStr = ReplaceNumberByKey("err_mu", kwListStr, err_mu[ii], "=", ",", 0)
160               
161        endfor
162
163        SetDataFolder root:
164        return(0)
165End
166
167
168// makes the panel after the waves are generated
169//
170// allow edits of the cells to update the string values
171// add a button to "revert" (with warning)
172// add a button to add new cells (insert a new row in the table, then update)
173//
174Function CellParamPanel()
175
176        SetDataFolder root:Packages:NIST:Polarization:Cells
177       
178        PauseUpdate; Silent 1           // building window...
179        NewPanel /W=(775,44,1375,377) /N=CellParamPanel/K=1 as "Fundamental Cell Parameters"
180        ModifyPanel cbRGB=(65535,49151,55704)
181        ModifyPanel fixedSize=1
182
183//      ShowTools/A
184        Button button_0,pos={10,10},size={90,20},proc=AddCellButtonProc,title="Add Cell"
185        Button button_1,pos={118,10},size={130,20},proc=SaveCellParButtonProc,title="Save Parameters"
186        Button button_2,pos={265,10},size={130,20},proc=RevertCellParButtonProc,title="Revert Parameters"
187        Button button_3,pos={420,10},size={35,20},proc=CellHelpParButtonProc,title="?"
188
189       
190        Edit/W=(14,55,582,318)/HOST=#
191        ModifyTable width(Point)=0
192        RenameWindow #,T0
193
194        WAVE/T CellName
195        WAVE lambda,Te,err_Te,mu,err_mu
196
197        AppendtoTable/W=# CellName,lambda,Te,err_Te,mu,err_mu
198        SetActiveSubwindow ##
199
200        SetDataFolder root:
201        return(0)
202End
203
204Function CellHelpParButtonProc(ba) : ButtonControl
205        STRUCT WMButtonAction &ba
206
207        switch( ba.eventCode )
208                case 2: // mouse up
209                        // click code here
210                        DoAlert 0,"Help for Cell Param Panel not written yet"
211                        break
212                case -1: // control being killed
213                        break
214        endswitch
215
216        return 0
217End
218
219
220Function AddCellButtonProc(ba) : ButtonControl
221        STRUCT WMButtonAction &ba
222
223        switch( ba.eventCode )
224                case 2: // mouse up
225                        // click code here
226                        SetDataFolder root:Packages:NIST:Polarization:Cells
227
228                        WAVE/T CellName
229                        WAVE lambda,Te,err_Te,mu,err_mu
230                        Variable ii= numpnts(CellName)
231                       
232                        InsertPoints  ii, 1, CellName,lambda,Te,err_Te,mu,err_mu
233                       
234                        SetDataFolder root:
235                        break
236                case -1: // control being killed
237                        break
238        endswitch
239
240        return 0
241End
242
243Function SaveCellParButtonProc(ba) : ButtonControl
244        STRUCT WMButtonAction &ba
245
246        switch( ba.eventCode )
247                case 2: // mouse up
248                        // click code here
249                        Save_HeCell_ParamWaves()
250                        break
251                case -1: // control being killed
252                        break
253        endswitch
254
255        return 0
256End
257
258Function RevertCellParButtonProc(ba) : ButtonControl
259        STRUCT WMButtonAction &ba
260
261        switch( ba.eventCode )
262                case 2: // mouse up
263                        // click code here
264                        InitPolarizationGlobals()
265                        Make_HeCell_ParamWaves()
266                        break
267                case -1: // control being killed
268                        break
269        endswitch
270
271        return 0
272End
273
274// END PROCEDURES for He cell parameters
275/////////////////////////////////
276
277
278
279
280
281
282// Decay parameters for each cell. Results are stored in a wave note for each cell
283//
284//      muP=
285//      err_muP=
286// P0=
287//      err_P0=         ? is this needed?
288//      T0=
289// gamma=
290//      err_gamma=
291//
292// str = "muP=2,err_muP=0,P0=0.6,err_P0=0,T0=asdf,gamma=200,err_gamma=0,"
293//
294//
295// for this panel, the cell parameters are stored as kw strings
296// all of the strings start w/ "gDecay_"
297//
298Macro ShowCellDecayPanel()
299       
300        // init folders
301        // ASK before initializing cell constants
302        // open the panel
303        DoWindow/F DecayPanel
304        if(V_flag == 0)
305                InitPolarizationFolders()
306                InitDecayGlobals()
307                DecayParamPanel()
308        endif
309end
310
311Function InitDecayGlobals()
312
313        SetDataFolder root:Packages:NIST:Polarization:Cells
314       
315        String/G gMuPo = "muPo"
316        String/G gPo = "Po"
317        String/G gGamma = "gamma"
318        String/G gT0 = "today's the day"
319       
320       
321        SetDataFolder root:
322        return(0)
323End
324
325
326
327
328// makes the panel for the decay parameter and gamma fitting
329//
330Function DecayParamPanel()
331
332        SetDataFolder root:Packages:NIST:Polarization:Cells
333       
334        PauseUpdate; Silent 1           // building window...
335        NewPanel /W=(759,44,1572,713)/N=DecayPanel/K=1 as "Cell Decay Parameters"
336        ModifyPanel cbRGB=(32768,54615,65535)
337//      Button button_3,pos={505,16},size={35,20},proc=DecayHelpParButtonProc,title="?"
338        PopupMenu popup_0,pos={32,18},size={49,20},title="Cell",proc=DecayPanelPopMenuProc
339        PopupMenu popup_0,mode=1,value= #"D_CellNameList()"
340       
341        Button button_0,pos={584,365},size={70,20},proc=DecayFitButtonProc,title="Do Fit"
342       
343        GroupBox group_0,pos={550,399},size={230,149},title="FIT RESULTS",fSize=10
344        GroupBox group_0,fStyle=1
345        SetVariable setvar_0,pos={560,428},size={200,13},title="muPo of 3He"
346        SetVariable setvar_0,fStyle=1,limits={0,0,0},barmisc={0,1000}
347        SetVariable setvar_0,value= root:Packages:NIST:Polarization:Cells:gMuPo
348        SetVariable setvar_1,pos={560,460},size={200,13},title="Po of 3He"
349        SetVariable setvar_1,fStyle=1,limits={0,0,0},barmisc={0,1000}
350        SetVariable setvar_1,value= root:Packages:NIST:Polarization:Cells:gPo
351        SetVariable setvar_2,pos={560,518},size={200,13},title="Gamma (h)",fStyle=1
352        SetVariable setvar_2,limits={0,0,0},barmisc={0,1000}
353        SetVariable setvar_2,value= root:Packages:NIST:Polarization:Cells:gGamma
354        SetVariable setvar_3,pos={560,488},size={200,15},title="T0",fStyle=1
355        SetVariable setvar_3,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gT0
356       
357
358        Button button_1,pos={579,294},size={120,20},proc=CalcRowParamButton,title="Calc Sel Row"
359        Button button_2,pos={307,18},size={110,20},proc=ClearDecayWavesButton,title="Clear Table"
360        Button button_3,pos={579,333},size={120,20},proc=ShowCalcRowButton,title="Show Calc"
361        Button button_4,pos={440,18},size={110,20},proc=ClearDecayWavesRowButton,title="Clear Row"
362        Button button_5,pos={620,18},size={40,20},proc=DecayHelpParButtonProc,title="?"
363        Button button_6,pos={620,620},size={100,20},proc=WindowSnapshotButton,title="Snapshot"
364        Button button_7,pos={620,580},size={130,20},proc=ManualEnterDecayButton,title="Manual Entry"
365
366
367
368        // table
369        Edit/W=(14,55,794,275)/HOST=#
370        ModifyTable format=1,width=0
371        RenameWindow #,T0
372        SetActiveSubwindow ##
373       
374        // graph
375        Display/W=(15,291,540,652)/HOST=#  //root:yy vs root:xx
376        ModifyGraph frameStyle=2
377        ModifyGraph mode=4
378        ModifyGraph marker=19
379        ModifyGraph rgb=(0,0,0)
380        ModifyGraph msize=2
381
382        Legend
383//      ModifyGraph log(left)=1
384//      ErrorBars yy OFF
385        RenameWindow #,G0
386        SetActiveSubwindow ##
387
388        SetDataFolder root:
389        return(0)
390End
391
392// allows manual entry of Decay values
393//
394// see DecayFitButtonProc
395//
396Function ManualEnterDecayButton(ba) : ButtonControl
397        STRUCT WMButtonAction &ba
398
399        Variable selRow,err=0
400        String fname, t0str, condStr,noteStr,t1Str,cellStr
401
402        switch( ba.eventCode )
403                case 2: // mouse up
404                        // click code here
405                        Variable gamma_val,err_gamma,muPo, err_muPo, Po, err_Po, runNum
406
407                        ControlInfo/W=DecayPanel popup_0
408                        cellStr = S_Value
409                               
410//                      SetDataFolder root:Packages:NIST:Polarization:Cells:
411                       
412                        WAVE decay=$("root:Packages:NIST:Polarization:Cells:Decay_"+cellStr)            //the one that is displayed
413//                      WAVE calc=$("root:Packages:NIST:Polarization:Cells:DecayCalc_"+cellStr)         //with the results
414
415
416                        Prompt Po, "Enter Po: "         
417                        Prompt err_Po, "Enter err_Po: "         
418                        Prompt muPo, "Enter muPo: "             
419                        Prompt err_muPo, "Enter err_muPo: "             
420                        Prompt gamma_val, "Enter gamma: "               
421                        Prompt err_gamma, "Enter err_gamma: "
422                        Prompt runNum,"Run number for time=0 of decay" 
423                        DoPrompt "Enter Cell Decay Parameters", Po, err_Po, muPo, err_muPo, gamma_val, err_gamma, runNum
424                        if (V_Flag)
425                                return -1                                                               // User canceled
426                        endif
427                       
428                        fname = FindFileFromRunNumber(runNum)
429                        t0str = getFileCreationDate(fname)
430                                       
431//              for the wave note
432                        noteStr = note(decay)
433                        noteStr = ReplaceNumberByKey("muP", noteStr, MuPo ,"=", ",", 0)
434                        noteStr = ReplaceNumberByKey("P0", noteStr, Po ,"=", ",", 0)
435                        noteStr = ReplaceNumberByKey("err_muP", noteStr, err_muPo ,"=", ",", 0)
436                        noteStr = ReplaceNumberByKey("err_P0", noteStr, err_Po ,"=", ",", 0)
437                        noteStr = ReplaceNumberByKey("gamma", noteStr, gamma_val ,"=", ",", 0)
438                        noteStr = ReplaceNumberByKey("err_gamma", noteStr, err_gamma ,"=", ",", 0)
439                        noteStr = ReplaceStringByKey("T0", noteStr, t0Str  ,"=", ",", 0)
440                        // replace the string
441                        Note/K decay
442                        Note decay, noteStr
443
444                        // for the panel display
445                        SVAR gGamma  = root:Packages:NIST:Polarization:Cells:gGamma
446                        SVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo
447                        SVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo           
448                        SVAR gT0 = root:Packages:NIST:Polarization:Cells:gT0
449                       
450                        gT0 = t0Str             //for display
451                        sprintf gMuPo, "%g +/- %g",muPo, err_muPo
452                        sprintf gPo, "%g +/- %g",Po,err_Po
453                        sprintf gGamma, "%g +/- %g",gamma_val,err_gamma
454
455                       
456                        break
457                case -1: // control being killed
458                        break
459        endswitch
460
461        return 0
462End
463
464
465Function DecayPanelPopMenuProc(pa) : PopupMenuControl
466        STRUCT WMPopupAction &pa
467
468        switch( pa.eventCode )
469                case 2: // mouse up
470                        Variable popNum = pa.popNum
471                        String popStr = pa.popStr
472                       
473                        SetDataFolder root:Packages:NIST:Polarization:Cells
474
475                        // based on the selected string, display the right set of inputs
476//                      Print "now I need to display the right set of waves (2D text?) for ",popStr
477
478                        // for the given cell name, if the wave(s) exist, declare them
479                        if(exists("Decay_"+popStr) == 1)
480                                WAVE decay = $("Decay_"+popStr)
481                        else
482                                // if not, make it, and the space for the results of the calculation
483                                MakeDecayResultWaves(popStr)
484                                WAVE decay = $("root:Packages:NIST:Polarization:Cells:Decay_"+popStr)
485                        endif                   
486                        // append matrix, clearing the old one first
487                        SetDataFolder root:Packages:NIST:Polarization:Cells
488
489                        KillWindow DecayPanel#T0
490                        Edit/W=(14,55,794,275)/HOST=DecayPanel
491                        RenameWindow #,T0
492                        AppendtoTable/W=DecayPanel#T0 decay.ld                  //show the labels
493                        ModifyTable width(Point)=0
494                        ModifyTable width(decay.l)=20
495                       
496                        SetActiveSubwindow ##
497       
498                        SetDataFolder root:
499                       
500                        break
501                case -1: // control being killed
502                        break
503        endswitch
504
505        return 0
506End
507
508Function MakeDecayResultWaves(popStr)
509        String popStr
510
511        SetDataFolder root:Packages:NIST:Polarization:Cells
512
513        Make/O/D/N=(1,8) $("Decay_"+popStr)
514        WAVE decay = $("Decay_"+popStr)
515        // set the column labels
516        SetDimLabel 1,0,Trans_He_In,decay
517        SetDimLabel 1,1,Trans_He_Out,decay
518        SetDimLabel 1,2,Blocked,decay
519        SetDimLabel 1,3,mu_star,decay
520        SetDimLabel 1,4,Pol_Cell,decay
521        SetDimLabel 1,5,T_Major,decay
522        SetDimLabel 1,6,Include,decay                   //for a mask wave, non-zero is used in the fit
523        SetDimLabel 1,7,elapsed_hr,decay
524        decay[0][6] = 1                 //default to include the point
525       
526        // generate the dummy wave note now, change as needed
527        Note decay, "muP=2,err_muP=0,P0=0.6,err_P0=0,T0=asdf,gamma=200,err_gamma=0,"
528       
529        // to hold the results of the calculation
530        Make/O/D/N=(1,14) $("DecayCalc_"+popStr)
531        WAVE decayCalc = $("DecayCalc_"+popStr)
532        SetDimLabel 1,0,CR_Trans_He_In,decayCalc
533        SetDimLabel 1,1,err_CR_Trans_He_In,decayCalc
534        SetDimLabel 1,2,CR_Trans_He_Out,decayCalc
535        SetDimLabel 1,3,err_CR_Trans_He_Out,decayCalc
536        SetDimLabel 1,4,CR_Blocked,decayCalc
537        SetDimLabel 1,5,err_CR_Blocked,decayCalc
538        SetDimLabel 1,6,muPo,decayCalc
539        SetDimLabel 1,7,err_muPo,decayCalc
540        SetDimLabel 1,8,Po,decayCalc
541        SetDimLabel 1,9,err_Po,decayCalc
542        SetDimLabel 1,10,Tmaj,decayCalc
543        SetDimLabel 1,11,err_Tmaj,decayCalc
544        SetDimLabel 1,12,gamm,decayCalc
545        SetDimLabel 1,13,err_gamm,decayCalc     
546
547        SetDataFolder root:
548
549        return(0)
550End
551
552
553// since the "Decay_" table can be edited directly to increase the number of rows, it is tough
554// to increase the number of rows in the "DecayCalc_" wave and keep them in sync.
555//
556// --so make sure that the sizes match, and do them all
557//
558Function CalcRowParamButton(ba) : ButtonControl
559        STRUCT WMButtonAction &ba
560
561        Variable selRow,err=0
562        String fname, t0str, cellStr,noteStr,t1Str
563
564        switch( ba.eventCode )
565                case 2: // mouse up
566                        // click code here
567                        Variable cr1,cr2,cr3,err_cr1,err_cr2,err_cr3
568                        Variable muPo,err_muPo,Po,err_Po,Pcell,err_Pcell,Tmaj,err_Tmaj
569                        //Variable Te,err_Te,mu,err_mu
570                               
571                        ControlInfo/W=DecayPanel popup_0
572                        cellStr = S_Value
573                        WAVE w=$("root:Packages:NIST:Polarization:Cells:Decay_"+cellStr)                //the one that is displayed
574                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:DecayCalc_"+cellStr)         // behind the scenes
575                       
576                        Variable numRows,ncalc,diff
577                        numRows = DimSize(w,0)          //rows in the displayed table
578                        ncalc = DimSize(calc,0)
579                       
580                        // add rows to the DecayCalc_ matrix as needed
581                        if(numRows != ncalc)
582                                if(ncalc > numRows)
583                                        DoAlert 0,"The DecayCalc_ is larger than displayed. Seek help."
584                                        err = 1
585                                        return(err)
586                                else
587                                        diff = numRows - ncalc
588                                        InsertPoints/M=0 ncalc, diff, calc
589                                endif
590                        endif
591                       
592                       
593//                      GetSelection table, DecayPanel#T0, 1
594//                      selRow = V_startRow
595
596                        Variable sum_muP, err_avg_muP, sum_Po, err_avg_Po, avg_muP, avg_Po
597                        sum_muP = 0
598                        sum_Po = 0
599                        err_avg_muP = 0
600                        err_avg_Po = 0
601                       
602                        for(selRow=0;selRow<numRows;selRow+=1)
603                                Print "calculate the row ",selRow
604
605                                if(selRow == 0)
606                                        //find T0
607                                        fname = FindFileFromRunNumber(w[0][%Trans_He_In])
608                                        t0str = getFileCreationDate(fname)
609                                        SVAR gT0 = root:Packages:NIST:Polarization:Cells:gT0
610                                        gT0 = t0Str             //for display
611                                        noteStr = note(w)
612                                        noteStr = ReplaceStringByKey("T0", noteStr, gT0  ,"=", ",", 0)
613                                        Note/K w
614                                        Note w, noteStr
615                                        Print t0str
616                                        w[selRow][%elapsed_hr] = 0                      //by definition
617                                endif
618                               
619                                // parse the rows, report errors (there, not here), exit if any found
620                                err = ParseDecayRow(w,selRow)
621                                if(err)
622                                        return 0
623                                endif
624                               
625                                // do the calculations:
626                                // 1 for each file, return the count rate and err_CR (normalize to atten or not)
627       
628                                Print "The Blocked CR is not rescaled to zero attenuators"
629                                cr1 = TotalCR_FromRun(w[selRow][%Trans_He_In],err_cr1,0)
630                                cr2 = TotalCR_FromRun(w[selRow][%Trans_He_Out],err_cr2,0)
631                                cr3 = TotalCR_FromRun(w[selRow][%Blocked],err_cr3,1)                    //blocked beam is NOT normalized to zero attenuators
632                               
633                                calc[selRow][%CR_Trans_He_In] = cr1
634                                calc[selRow][%CR_Trans_He_Out] = cr2
635                                calc[selRow][%CR_Blocked] = cr3
636                                calc[selRow][%err_cr_Trans_He_In] = err_cr1
637                                calc[selRow][%err_cr_Trans_He_Out] = err_cr2
638                                calc[selRow][%err_cr_Blocked] = err_cr3
639       
640       
641                                // 2 find the mu and Te values for cellStr
642                                SVAR gCellKW = $("root:Packages:NIST:Polarization:Cells:gCell_"+cellStr)
643                                //(moved to a separate function, just pass the string)
644        //                      Te = NumberByKey("Te", gCellKW, "=", ",", 0)
645        //                      err_Te = NumberByKey("err_Te", gCellKW, "=", ",", 0)
646        //                      mu = NumberByKey("mu", gCellKW, "=", ",", 0)
647        //                      err_mu = NumberByKey("err_mu", gCellKW, "=", ",", 0)
648        //                     
649                                // 3 Calc muPo and error
650                                muPo = Calc_muPo(calc,gCellKW,selRow,err_muPo)
651                                calc[selRow][%muPo] = muPo
652                                calc[selRow][%err_muPo] = err_muPo
653                                w[selRow][%mu_star] = muPo
654                               
655                                // 3.5 calc Polarization of cell (no value or error stored in calc wave?)
656                                PCell = Calc_PCell(muPo,err_muPo,err_PCell)
657        //                      PCell = Calc_PCell(2,err_muPo,err_PCell)
658                                w[selRow][%Pol_Cell] = PCell
659       
660                                // 4 calc Po and error
661                                Po = Calc_Po(gCellKW,muPo,err_muPo,err_Po)
662        //                      Po = Calc_Po(gCellKW,2,err_muPo,err_Po)
663                                calc[selRow][%Po] = Po
664                                calc[selRow][%err_Po] = err_Po
665                               
666                                // 5 calc Tmaj and error
667                                Tmaj = Calc_Tmaj(gCellKW,Po,err_Po,err_Tmaj)
668                                calc[selRow][%Tmaj] = Tmaj
669                                calc[selRow][%err_Tmaj] = err_Tmaj
670                                w[selRow][%T_major] = Tmaj
671                               
672                                // elapsed hours
673                                fname = FindFileFromRunNumber(w[selRow][%Trans_He_In])
674                                t1str = getFileCreationDate(fname)
675                                w[selRow][%elapsed_hr] = ElapsedHours(t0Str,t1Str)
676                               
677                                // running average of muP and Po
678                                sum_muP += muPo
679                                sum_Po += Po
680                                err_avg_muP += err_muPo^2
681                                err_avg_Po += err_Po^2
682                               
683                        endfor          //loop over rows
684                       
685                        // now get a running average of muP, Po, and the errors
686                        avg_muP = sum_muP/numRows
687                        avg_Po = sum_Po/numRows
688                        err_avg_muP = sqrt(err_avg_muP) / numRows
689                        err_avg_Po = sqrt(err_avg_Po) / numRows
690                       
691//                      str = "muP=2,err_muP=0,P0=0.6,err_P0=0,T0=asdf,gamma=200,err_gamma=0,"
692
693                        // Don't put the average values into the wave note, but rather the results of the fit
694//                      noteStr = note(w)
695//                      noteStr = ReplaceNumberByKey("muP", noteStr, avg_muP ,"=", ",", 0)
696//                      noteStr = ReplaceNumberByKey("P0", noteStr, avg_Po ,"=", ",", 0)
697//                      noteStr = ReplaceNumberByKey("err_muP", noteStr, err_avg_muP ,"=", ",", 0)
698//                      noteStr = ReplaceNumberByKey("err_P0", noteStr, err_avg_Po ,"=", ",", 0)
699//                     
700//                      // replace the string
701//                      Note/K w
702//                      Note w, noteStr
703                                       
704                        Printf "Average muP = %g +/- %g (%g%)\r",avg_muP,err_avg_muP,err_avg_muP/avg_muP*100
705                        Printf "Average Po = %g +/- %g (%g%)\r",avg_Po,err_avg_Po,err_avg_Po/avg_Po*100
706                       
707                        //update the global values for display (not these, but after the fit)
708//                      Print " -- need to add the error to the display on the panel    "
709//                      NVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo
710//                      NVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo
711//                      gMuPo = avg_muP
712//                      gPo = avg_Po
713                       
714                        break
715                case -1: // control being killed
716                        break
717        endswitch
718
719        return 0
720End
721
722
723// calculate Tmaj and its error
724Function Calc_Tmaj(cellStr,Po,err_Po,err_Tmaj)
725        String cellStr
726        Variable Po,err_Po,&err_Tmaj
727       
728        Variable Tmaj,arg
729        Variable Te,err_Te,mu,err_mu
730// cell constants       
731        Te = NumberByKey("Te", cellStr, "=", ",", 0)
732        err_Te = NumberByKey("err_Te", cellStr, "=", ",", 0)
733        mu = NumberByKey("mu", cellStr, "=", ",", 0)
734        err_mu = NumberByKey("err_mu", cellStr, "=", ",", 0)
735       
736        Tmaj = Te*exp(-mu*(1-Po))
737       
738        //the error
739        err_Tmaj = (Tmaj/Te)^2*err_Te^2 + (Tmaj*(1-Po))^2*err_mu^2 + (Tmaj*mu)^2*err_Po^2
740        err_Tmaj = sqrt(err_Tmaj)
741       
742        Printf "Tmaj = %g +/- %g (%g%)\r",Tmaj,err_Tmaj,err_Tmaj/Tmaj*100
743
744       
745        return(Tmaj)
746End
747
748
749// calculate PCell and its error
750//
751//
752Function Calc_PCell(muPo,err_muPo,err_PCell)
753        Variable muPo,err_muPo,&err_PCell
754       
755        Variable PCell,arg
756
757        PCell = tanh(muPo)
758       
759        // error (single term, sqrt already done)
760        err_Pcell = (1 - (tanh(muPo))^2) * err_muPo
761       
762        Printf "Pcell = %g +/- %g (%g%)\r",Pcell,err_Pcell,err_Pcell/PCell*100
763
764        return(PCell)
765End
766
767// calculate Po and its error
768Function Calc_Po(cellStr,muPo,err_muPo,err_Po)
769        String cellStr
770        Variable muPo,err_muPo,&err_Po
771       
772        Variable Po,tmp
773        Variable mu,err_mu
774// cell constants       
775        mu = NumberByKey("mu", cellStr, "=", ",", 0)
776        err_mu = NumberByKey("err_mu", cellStr, "=", ",", 0)
777       
778        Po = muPo/mu
779       
780        tmp = (err_muPo/muPo)^2 + (err_mu/mu)^2
781        err_Po = Po * sqrt(tmp)
782       
783        Printf "Po = %g +/- %g (%g%)\r",Po,err_Po,err_Po/Po*100
784        return(Po)
785End
786
787// calculate muPo and its error
788Function Calc_muPo(calc,cellStr,selRow,err_muPo)
789        Wave calc
790        String cellStr
791        Variable selRow,&err_muPo
792       
793        Variable muPo,arg
794        Variable Te,err_Te,mu,err_mu
795// cell constants       
796        Te = NumberByKey("Te", cellStr, "=", ",", 0)
797        err_Te = NumberByKey("err_Te", cellStr, "=", ",", 0)
798        mu = NumberByKey("mu", cellStr, "=", ",", 0)
799        err_mu = NumberByKey("err_mu", cellStr, "=", ",", 0)
800       
801        Variable cr1,cr2,cr3,err_cr1,err_cr2,err_cr3
802        // cr1 is He in, 2 is He out, 3 is blocked
803        cr1      =      calc[selRow][%CR_Trans_He_In]
804        cr2 =   calc[selRow][%CR_Trans_He_Out]
805        cr3 =   calc[selRow][%CR_Blocked]
806        err_cr1 =       calc[selRow][%err_cr_Trans_He_In]
807        err_cr2 =       calc[selRow][%err_cr_Trans_He_Out]
808        err_cr3 =       calc[selRow][%err_cr_Blocked]
809       
810        muPo = acosh( (cr1 - cr3)/(cr2 - cr3) * (1/(Te*exp(-mu))) )
811       
812        Variable arg_err, tmp1, tmp2
813        // the error is a big mess to calculate, since it's messy argument inside acosh
814        arg = (cr1 - cr3)/(cr2 - cr3) * (1/(Te*exp(-mu)))
815        tmp2 =  (1/sqrt(arg+1)/sqrt(arg-1))^2                                   // derivative of acosh(arg) (squared)
816       
817        // calculate the error of the argument first, then the error of acosh(arg)
818        // there are 5 partial derivatives
819        arg_err = tmp2 * ( arg/(cr1 - cr3) * err_cr1 )^2                //CR in
820        arg_err += tmp2 * ( arg/(cr2 - cr3) * err_cr2 )^2       //CR out
821        arg_err += tmp2 * ((-arg/(cr1 - cr3) +  arg/(cr2 - cr3) )* err_cr3 )^2//CR bkg
822        arg_err += tmp2 * ( -arg/Te * err_Te )^2                                        //Te
823        arg_err += tmp2 * ( arg * err_mu )^2                                            //mu  (probably the dominant relative error)
824       
825        err_muPo = sqrt(arg_err)
826       
827       
828        return(muPo)
829End
830
831
832//Function testCR(num)
833//      Variable num
834//      Variable err_cr
835//     
836//      Variable noNorm=0
837//      Variable cr = TotalCR_FromRun(num,err_cr,noNorm)
838//      printf "CR = %g +/- %g (%g%)\r",cr,err_cr,err_cr/cr*100
839//      return(0)
840//End
841
842// calculate the total detector CR ane its error.
843//
844// the result is automatically normalized to 10^8 monitor counts, and to zero attenuators
845//
846// if noNorm = 1, then the normalization to attenuators is not done
847//
848Function TotalCR_FromRun(num,err_cr,noNorm)
849        Variable num,&err_cr,noNorm
850
851        String fname="",instr="",tmpStr=""
852        Variable cr,cts,err_cts,ctTime,monCts,attenNo,lambda,attenTrans,atten_err
853       
854        fname = FindFileFromRunNumber(num)
855        cts = getDetCount(fname)
856        err_cts = sqrt(cts)
857       
858        ctTime = getCountTime(fname)
859        monCts = getMonitorCount(fname)
860        attenNo = getAttenNumber(fname)
861        instr = getAcctName(fname)              //this is 11 characters
862        lambda = getWavelength(fname)
863        attenTrans = AttenuationFactor(instr,lambda,AttenNo,atten_err)
864       
865        if(noNorm==1)                   //don't normalize to attenuation
866                attenTrans=1
867                atten_err=0
868        endif
869        cr = cts/ctTime*1e8/monCts/attenTrans
870        err_cr = cr * sqrt(err_cts^2/cts^2 + atten_err^2/attenTrans^2)
871       
872        printf "CR = %g +/- %g (%g%)\r",cr,err_cr,err_cr/cr*100
873
874               
875        return(cr)
876end
877
878
879// input is VAX date and time string, t1 later than t0
880//
881Function ElapsedHours(t0Str,t1Str)
882        String t0Str,t1Str
883       
884        Variable t0,t1,elapsed
885       
886        t0 = ConvertVAXDateTime2Secs(t0Str)             //seconds
887        t1 = ConvertVAXDateTime2Secs(t1Str)
888       
889        elapsed = t1-t0
890        elapsed /= 3600                 //convert to hours
891       
892        return(elapsed)
893End
894
895// bring up a table with the calculation results
896Function ShowCalcRowButton(ba) : ButtonControl
897        STRUCT WMButtonAction &ba
898
899        switch( ba.eventCode )
900                case 2: // mouse up
901                        // click code here
902                        ControlInfo/W=DecayPanel popup_0
903                        String cellStr = S_Value
904                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:DecayCalc_"+cellStr)         //the one that is displayed
905                        edit calc.ld
906                                               
907                        break
908                case -1: // control being killed
909                        break
910        endswitch
911
912        return 0
913End
914
915
916Function DecayFitButtonProc(ba) : ButtonControl
917        STRUCT WMButtonAction &ba
918
919        String cellStr=""
920        Variable num
921
922        switch( ba.eventCode )
923                case 2: // mouse up
924                        // click code here
925
926                        ControlInfo/W=DecayPanel popup_0
927                        cellStr = S_Value
928                       
929                        SetDataFolder root:Packages:NIST:Polarization:Cells:
930                       
931                        WAVE decay=$("Decay_"+cellStr)          //the one that is displayed
932                        WAVE calc=$("DecayCalc_"+cellStr)               //the one that is displayed
933                       
934//                      make temp copies for the fit and plot, extra for mask
935                        num = DimSize(calc,0)
936                        Make/O/D/N=(num)                tmp_Mask,tmp_hr,tmp_muP,tmp_err_muP,tmp_muP2
937                       
938                        tmp_Mask = decay[p][%Include]
939                        tmp_hr = decay[p][%elapsed_hr]
940                        tmp_muP = calc[p][%muPo]
941                        tmp_muP2 = tmp_muP
942                        tmp_err_muP = calc[p][%err_muPo]
943                       
944                        tmp_muP2 = (tmp_Mask == 1) ? NaN : tmp_muP2                     //only excluded points will plot
945                       
946                        // clear old data, and plot the new
947                        //
948                        CheckDisplayed/W=DecayPanel#G0 tmp_muP,tmp_muP2,fit_tmp_muP
949                        // if both present, bit 0 + bit 1 = 3
950                        if(V_flag & 2^0)                        //check bit 0
951                                RemoveFromGraph/W=DecayPanel#G0 tmp_muP
952                        endif
953                        if(V_flag & 2^1)
954                                RemoveFromGraph/W=DecayPanel#G0 tmp_muP2
955                        endif
956                        if(V_flag & 2^2)
957                                RemoveFromGraph/W=DecayPanel#G0 fit_tmp_muP
958                        endif
959                       
960                        AppendToGraph/W=DecayPanel#G0 tmp_muP vs tmp_hr
961                        AppendToGraph/W=DecayPanel#G0 tmp_muP2 vs tmp_hr
962
963                        ModifyGraph/W=DecayPanel#G0 log(left)=1
964                        ModifyGraph/W=DecayPanel#G0 frameStyle=2
965                        ModifyGraph/W=DecayPanel#G0 mode=3
966                        ModifyGraph/W=DecayPanel#G0 marker=19
967                        ModifyGraph/W=DecayPanel#G0 rgb(tmp_muP)=(1,16019,65535),rgb(tmp_muP2)=(65535,0,0)
968                        ModifyGraph/W=DecayPanel#G0 msize=3
969                        ErrorBars/W=DecayPanel#G0 tmp_muP,Y wave=(tmp_err_muP,tmp_err_muP)
970                       
971                        Label/W=DecayPanel#G0 left "mu*P"
972                        Label/W=DecayPanel#G0 bottom "time (h)"
973                       
974// do the fit
975//       as long as the constant X0 doesn't stray from zero, exp_XOffset is OK, otherwise I'll need to switch to the exp function
976
977                        SetActiveSubwindow DecayPanel#G0                        //to get the automatic fit to show up on the graph
978
979//                      Make/O/D/N=3 fitCoef={0,5,0.05}
980//                      CurveFit/H="100"/M=2/W=0/TBOX=(0x310) exp_XOffset, kwCWave=fitCoef, tmp_muP /X=tmp_hr /D /I=1 /W=tmp_err_muP /M=tmp_Mask
981
982
983                        Make/O/D/N=3 fitCoef={0,5,0.05}
984                        CurveFit/H="100"/M=2/W=0/TBOX=(0x310) exp, kwCWave=fitCoef, tmp_muP /X=tmp_hr /D /I=1 /W=tmp_err_muP /M=tmp_Mask
985                       
986
987                        SetActiveSubwindow ##
988                       
989                       
990// then report and save the results
991//                      the exp function => y = y0 + A*exp(-Bx)
992//                      W_coef[0] = y0 should be close to zero (or fixed at zero)
993//                      W_coef[1] = A should be close to the initial muP value
994//                      W_coef[2] = B is 1/Gamma
995//                      WAVE W_coef=W_coef
996                        WAVE W_sigma=W_sigma
997                        Variable gamma_val,err_gamma,muPo, err_muPo, Po, err_Po
998                        String noteStr=""
999       
1000                        SVAR gCellKW = $("root:Packages:NIST:Polarization:Cells:gCell_"+cellStr)       
1001                        SVAR gGamma  = root:Packages:NIST:Polarization:Cells:gGamma
1002                        SVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo
1003                        SVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo
1004                       
1005                        muPo = fitCoef[1]
1006                        err_muPo = W_sigma[1]
1007                       
1008                        Po = Calc_Po(gCellKW,muPo,err_muPo,err_Po)
1009
1010                        // if exp_XOffset used
1011//                      gGamma = fitCoef[2]
1012//                      err_Gamma = W_sigma[2]
1013
1014                        // calculating the error using exp is the inverse of coef[2]:
1015                        gamma_val  = 1/fitCoef[2]
1016                        err_gamma = W_sigma[2]/(fitCoef[2])^2
1017               
1018                       
1019//              for the wave note
1020                        noteStr = note(decay)
1021                        noteStr = ReplaceNumberByKey("muP", noteStr, MuPo ,"=", ",", 0)
1022                        noteStr = ReplaceNumberByKey("P0", noteStr, Po ,"=", ",", 0)
1023                        noteStr = ReplaceNumberByKey("err_muP", noteStr, err_muPo ,"=", ",", 0)
1024                        noteStr = ReplaceNumberByKey("err_P0", noteStr, err_Po ,"=", ",", 0)
1025                        noteStr = ReplaceNumberByKey("gamma", noteStr, gamma_val ,"=", ",", 0)
1026                        noteStr = ReplaceNumberByKey("err_gamma", noteStr, err_gamma ,"=", ",", 0)
1027
1028                        // replace the string
1029                        Note/K decay
1030                        Note decay, noteStr
1031                       
1032                       
1033                        // for the panel display
1034                        sprintf gMuPo, "%g +/- %g",fitCoef[1],W_sigma[1]
1035                        sprintf gPo, "%g +/- %g",Po,err_Po
1036                        sprintf gGamma, "%g +/- %g",gamma_val,err_gamma
1037
1038                       
1039                       
1040                        SetDataFolder root:
1041                       
1042                        break
1043                case -1: // control being killed
1044                        break
1045        endswitch
1046
1047        return 0
1048End
1049
1050
1051// clear just the row
1052//
1053Function ClearDecayWavesRowButton(ba) : ButtonControl
1054        STRUCT WMButtonAction &ba
1055
1056        String popStr=""
1057        Variable selRow
1058       
1059        switch( ba.eventCode )
1060                case 2: // mouse up
1061                        // click code here
1062                        DoAlert 1,"Clear the selected row?"
1063                        if(V_flag !=1)
1064                                return(0)
1065                        endif
1066                       
1067                        SetDataFolder root:Packages:NIST:Polarization:Cells
1068
1069                        ControlInfo/W=DecayPanel popup_0
1070                        popStr = S_Value
1071                       
1072                        Wave decay = $("Decay_"+popStr)
1073                        Wave calc = $("DecayCalc_"+popStr)
1074
1075                        // Delete just those points
1076                                               
1077                        GetSelection table, DecayPanel#T0, 1
1078                        selRow = V_startRow
1079                        DeletePoints selRow,1,decay,calc                       
1080                       
1081                        // clear the graph and the results                     
1082                        NVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo
1083                        NVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo
1084                        NVAR gGamma  = root:Packages:NIST:Polarization:Cells:gGamma
1085                        SVAR gT0  = root:Packages:NIST:Polarization:Cells:gT0
1086                        gMuPo = 0
1087                        gPo = 0
1088                        gGamma = 0
1089                        gT0 = "recalculate"
1090                       
1091                       
1092                        SetDataFolder root:
1093                        break
1094                case -1: // control being killed
1095                        break
1096        endswitch
1097
1098        return 0
1099End
1100
1101
1102
1103// for this, do I want to clear everything, or just a selected row??
1104//
1105//
1106Function ClearDecayWavesButton(ba) : ButtonControl
1107        STRUCT WMButtonAction &ba
1108
1109        String popStr=""
1110       
1111        switch( ba.eventCode )
1112                case 2: // mouse up
1113                        // click code here
1114                        DoAlert 1,"Clear all of the decay waves for the selected cell?"
1115                        if(V_flag !=1)
1116                                return(0)
1117                        endif
1118                       
1119                        SetDataFolder root:Packages:NIST:Polarization:Cells
1120
1121                        ControlInfo/W=DecayPanel popup_0
1122                        popStr = S_Value
1123                       
1124                        Wave decay = $("Decay_"+popStr)
1125                        Wave calc = $("DecayCalc_"+popStr)
1126                       
1127//                      re-initialize the decay waves, so it appears as a blank, initialized table
1128
1129                        MakeDecayResultWaves(popStr)
1130                        decay = 0
1131                        calc = 0
1132       
1133                        // clear the graph and the results?     
1134                       
1135                       
1136                                       
1137                        NVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo
1138                        NVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo
1139                        NVAR gGamma  = root:Packages:NIST:Polarization:Cells:gGamma
1140                        SVAR gT0  = root:Packages:NIST:Polarization:Cells:gT0
1141                        gMuPo = 0
1142                        gPo = 0
1143                        gGamma = 0
1144                        gT0 = "recalculate"
1145                       
1146                       
1147                        SetDataFolder root:
1148                        break
1149                case -1: // control being killed
1150                        break
1151        endswitch
1152
1153        return 0
1154End
1155
1156
1157Function DecayHelpParButtonProc(ba) : ButtonControl
1158        STRUCT WMButtonAction &ba
1159
1160        switch( ba.eventCode )
1161                case 2: // mouse up
1162                        // click code here
1163                        DoAlert 0,"Help for Cell Decay Panel not written yet"
1164                        break
1165                case -1: // control being killed
1166                        break
1167        endswitch
1168
1169        return 0
1170End
1171
1172// E=-5 is a PNG, =8 is PDF
1173// there are other options to do EPS, embed fonts, etc.
1174//
1175Function WindowSnapshotButton(ba) : ButtonControl
1176        STRUCT WMButtonAction &ba
1177
1178        switch( ba.eventCode )
1179                case 2: // mouse up
1180                        // click code here
1181                        SavePICT /E=-5/SNAP=1
1182                        break
1183                case -1: // control being killed
1184                        break
1185        endswitch
1186
1187        return 0
1188End
1189
1190// null condition is not right. if the loop fails, then the
1191// retStr will be ";;;;", not zero length. What's the proper test?
1192// Does it matter? the list of default gCell_sss should already be there.
1193//
1194Function/S D_CellNameList()
1195
1196        String retStr="",listStr,item
1197        Variable num,ii
1198       
1199        SetDataFolder root:Packages:NIST:Polarization:Cells
1200
1201        // get a list of the cell strings
1202        listStr=StringList("gCell_*",";")
1203        num=ItemsInList(listStr,";")
1204//      print listStr
1205       
1206        // parse the strings to fill the table
1207        for(ii=0;ii<num;ii+=1)
1208                item = StringFromList(ii, listStr,";")
1209                SVAR gStr = $item
1210                retStr += StringByKey("cell", gStr, "=", ",", 0) + ";"
1211        endfor
1212       
1213        if(strlen(retStr) == 0)
1214                retStr = "no cells defined;"
1215        endif
1216       
1217        SetDataFolder root:             
1218        return(retStr)
1219End
1220
1221
1222// parse the row to be sure that:
1223//
1224// - files are valid numbers
1225// - files are all at same SDD
1226// - files are all with same attenuation (just print a warning to cmd)
1227//
1228Function ParseDecayRow(w,selRow)
1229        Wave w
1230        Variable selRow
1231       
1232        Variable err=0, atten1,atten2,atten3,sdd1,sdd2,sdd3
1233        String fname=""
1234        // are all file numbers valid?
1235        fname = FindFileFromRunNumber(w[selRow][%Trans_He_In])
1236        if(cmpstr(fname,"")==0)
1237                DoAlert 0,"Trans_He_In run "+num2str(w[selRow][%Trans_He_In])+" is not a valid run number"
1238                err = 1
1239        else
1240                atten1 = getAttenNumber(fname)
1241                sdd1 = getSDD(fname)
1242        endif
1243       
1244        fname = FindFileFromRunNumber(w[selRow][%Trans_He_Out])
1245        if(cmpstr(fname,"")==0)
1246                DoAlert 0,"Trans_He_Out run "+num2str(w[selRow][%Trans_He_Out])+" is not a valid run number"
1247                err = 1
1248        else
1249                atten2 = getAttenNumber(fname)
1250                sdd2 = getSDD(fname)
1251        endif
1252       
1253        fname = FindFileFromRunNumber(w[selRow][%Blocked])
1254        if(cmpstr(fname,"")==0)
1255                DoAlert 0,"Blocked run "+num2str(w[selRow][%Blocked])+" is not a valid run number"
1256                err = 1
1257        else
1258                atten3 = getAttenNumber(fname)
1259                sdd3 = getSDD(fname)
1260        endif
1261       
1262        if( (sdd1 != sdd2) || (sdd2 != sdd3) || (sdd1 != sdd3) )
1263                DoAlert 0,"Files in row "+num2str(selRow)+" are not all at the same detector distance"
1264                err = 1
1265        endif
1266       
1267        if( (atten1 != atten2) || (atten2 != atten3) || (atten1 != atten3) )
1268                DoAlert 0,"Files in row "+num2str(selRow)+" are not all collected with the same attenuation. Just so you know."
1269                err = 0
1270        endif
1271       
1272        return(err)
1273end
1274
1275
1276////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.