source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/Polarization/Pol_FlipperPanel.ipf @ 1138

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

Changes to:
Polarization - to correct naming errors when saving polarization panel states. Names were too long.

Event Mode - improved the re-loading of split oscillatory data sets. Also allows easier editing of the list of split files to re-load for decimation.

FFT/real space - Modified gizmo to automatically color the different SLDs present. Limitied to 5 different SLDs due to a limitation of the voxelgram. If more than 5 SLDs are present (solvent does not count), then the extra ones are not displayed. Also modified KR-3Cyl procedures to be able to save/import a table of coordinates.

File size: 40.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
3
4
5// input panels to set and calculate polarization parameters necessary for the
6// matrix corrections to the cross sections
7//
8//
9// -3-Flipper efficiency
10
11
12
13// **** search for TODO to find items still to be fixed in other procedures  **********
14
15
16
17//
18// TODO:
19// X- add a way to manually enter the P values into a "blank" condition, in case that the users
20// calculate the values in a different way. This should be as simple as a dialog to enter values and
21// change the wave note (and displayed strings).
22//
23//
24// Polarization parameters for each condition. Results are stored in a wave note for each condition
25//
26//
27// str = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf,"
28//
29// two waves per condition "Cond_Name_Cell" and "CondCalc_Name_Cell"
30//
31Proc ShowFlipperPanel()
32       
33        // init folders
34        // ASK before initializing cell constants
35        // open the panel
36        DoWindow/F FlipperPanel
37        if(V_flag == 0)
38                InitPolarizationFolders()
39                InitFlipperGlobals()
40                DrawFlipperPanel()
41        endif
42        // be sure that the panel is onscreen
43        DoIgorMenu "Control","Retrieve Window"
44end
45
46Function InitFlipperGlobals()
47
48        SetDataFolder root:Packages:NIST:Polarization:Cells
49       
50        String/G gPsmPf = "Psm*Pf"
51        String/G gPsm = "Psm"
52       
53        SetDataFolder root:
54        return(0)
55End
56
57
58//
59// makes the panel for the calculation of flipper and supermirror efficiencies
60//
61Function DrawFlipperPanel()
62
63        SetDataFolder root:Packages:NIST:Polarization:Cells
64       
65        PauseUpdate; Silent 1           // building window...
66        NewPanel /W=(250,44,1056,480)/N=FlipperPanel/K=1 as "Flipper and Supermirror"
67        ModifyPanel cbRGB=(1,52428,26586)
68       
69        PopupMenu popup_0,pos={13,8},size={49,20},title="Field Condition",proc=FlipperPanelPopMenuProc
70        PopupMenu popup_0,mode=1,value= #"D_ConditionNameList()"
71       
72        Button button_0,pos={18,288},size={100,20},proc=FlipperAverageButtonProc,title="Do Average"
73       
74        GroupBox group_0,pos={18,316},size={290,102},title="AVERAGED RESULTS",fSize=10
75        GroupBox group_0,fStyle=1
76        SetVariable setvar_0,pos={33,351},size={250,15},title="Sam_depol*Psm*Pf"
77        SetVariable setvar_0,fStyle=1
78        SetVariable setvar_0,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gPsmPf
79        SetVariable setvar_1,pos={33,383},size={250,15},title="Sam_depol*Psm",fStyle=1
80        SetVariable setvar_1,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gPsm
81//      SetVariable setvar_2,pos={560,518},size={200,13},title="Gamma (h)",fStyle=1
82//      SetVariable setvar_2,limits={0,0,0},barmisc={0,1000}
83//      SetVariable setvar_2,value= root:Packages:NIST:Polarization:Cells:gGamma
84//      SetVariable setvar_3,pos={560,488},size={200,15},title="T0",fStyle=1
85//      SetVariable setvar_3,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gT0
86       
87
88        Button button_1,pos={322,8},size={120,20},proc=AddFlipperConditionButton,title="Add Condition"
89        Button button_2,pos={482,323},size={110,20},proc=ClearAllFlipperWavesButton,title="Clear Table"
90        Button button_3,pos={330,288},size={110,20},proc=ShowFlipperCalcButton,title="Show Calc"
91        Button button_4,pos={482,288},size={110,20},proc=ClearFlipperRowButton,title="Clear Row"
92        Button button_5,pos={759,8},size={30,20},proc=FlipperHelpParButtonProc,title="?"
93        Button button_6,pos={328,358},size={110,20},proc=WindowSnapshotButton,title="Snapshot"
94        Button button_7,pos={331,323},size={110,20},proc=ManualEnterPfPsmButton,title="Manual Entry"
95
96        Button button_8,pos={615,288},size={110,20},proc=SaveFlipperPanelButton,title="Save State"
97        Button button_9,pos={615,323},size={110,20},proc=RestoreFlipperPanelButton,title="Restore State"
98       
99        // table
100        Edit/W=(14,40,794,275)/HOST=#
101        ModifyTable format=1,width=0
102        RenameWindow #,T0
103        SetActiveSubwindow ##
104
105        SetDataFolder root:
106        return(0)
107End
108
109Function SaveFlipperPanelButton(ba) : ButtonControl
110        STRUCT WMButtonAction &ba
111
112        switch( ba.eventCode )
113                case 2: // mouse up
114                        // click code here
115                        SaveFlipperTable()
116                        break
117                case -1: // control being killed
118                        break
119        endswitch
120
121        return 0
122End
123
124Function RestoreFlipperPanelButton(ba) : ButtonControl
125        STRUCT WMButtonAction &ba
126
127        switch( ba.eventCode )
128                case 2: // mouse up
129                        // click code here
130                        RestoreFlipperTable()
131                        break
132                case -1: // control being killed
133                        break
134        endswitch
135
136        return 0
137End
138
139
140// now, this does not depend on the cell, just the condition
141Function AddFlipperConditionButton(ba) : ButtonControl
142        STRUCT WMButtonAction &ba
143
144        switch( ba.eventCode )
145                case 2: // mouse up
146                        // click code here
147                       
148
149                        String condStr//, cellStr
150                        Prompt condStr,"Condition, <12 characters, NO UNDERSCORES"
151//                      Prompt cellStr,"Cell",popup,D_CellNameList()
152                        DoPrompt "Add new condition",condStr//, cellStr
153                        if(V_Flag==1)
154                                return 0                                                                        // user canceled
155                        endif
156                       
157                        if(strlen(condStr) > 12)
158                                condStr = condStr[0,11]
159                                Print "Condition String trimmed to ",condStr
160                        endif
161                       
162                        condStr = ReplaceString("_", condStr, "", 0, inf)
163                       
164                        String popStr
165//                      popStr = condStr+"_"+cellStr
166                        popStr = condStr
167                       
168                        MakeFlipperResultWaves(popStr)
169                       
170                        break
171                case -1: // control being killed
172                        break
173        endswitch
174
175        return 0
176End
177
178Function FlipperPanelPopMenuProc(pa) : PopupMenuControl
179        STRUCT WMPopupAction &pa
180
181        switch( pa.eventCode )
182                case 2: // mouse up
183                        Variable popNum = pa.popNum
184                        String popStr = pa.popStr
185                       
186                        SetDataFolder root:Packages:NIST:Polarization:Cells
187
188                        // based on the selected string, display the right set of inputs
189//                      Print "now I need to display the right set of waves (2D text?) for ",popStr
190                       
191                        if(cmpstr(popStr,"no conditions defined") == 0)
192                                SetDataFolder root:
193                                return(0)
194                        endif
195                       
196                       
197                        // for the given cell name, if the wave(s) exist, declare them
198                        if(exists(popStr) == 1)
199                                WAVE cond = $(popStr)
200                                WAVE/T cellW = $("CondCell_"+popStr[5,strlen(popStr)-1])
201                        else
202                                // if not, report an error                             
203                                DoAlert 0,"The Cond_ waves should exist, this is an error"
204                               
205                                SetDataFolder root:
206                                return(0)
207                                //MakeFlipperResultWaves(popStr)
208                                //WAVE cond = $("root:Packages:NIST:Polarization:Cells:Cond_"+popStr)
209                        endif                   
210                        // append matrix, clearing the old one first
211                        SetDataFolder root:Packages:NIST:Polarization:Cells
212
213                        KillWindow FlipperPanel#T0
214                        Edit/W=(14,55,794,275)/HOST=FlipperPanel
215                        RenameWindow #,T0
216                        AppendtoTable/W=FlipperPanel#T0 cellW                   //
217                        AppendtoTable/W=FlipperPanel#T0 cond.ld                 //show the labels
218                        ModifyTable width(Point)=0
219                        ModifyTable width(cond.l)=20
220                       
221                        SetActiveSubwindow ##
222       
223                        SetDataFolder root:
224                       
225                        // update the globals that are displayed from the wave note
226                        String nStr=Note(cond)
227                        SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf
228                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm
229                        sprintf gPsmPf, "%g +/- %g",NumberByKey("P_sm_f", nStr, "=",","),NumberByKey("err_P_sm_f", nStr, "=",",")
230                        sprintf gPsm, "%g +/- %g",NumberByKey("P_sm", nStr, "=",","),NumberByKey("err_P_sm", nStr, "=",",")
231                       
232                       
233                        break
234                case -1: // control being killed
235                        break
236        endswitch
237
238        return 0
239End
240
241// waves are:
242// "Cond_"+popStr
243// and "CondCalc_"+popStr
244// ... and now "CondCell"+popStr
245
246Function MakeFlipperResultWaves(popStr)
247        String popStr
248
249        SetDataFolder root:Packages:NIST:Polarization:Cells
250
251        Make/O/T/N=1  $("CondCell_"+popStr)
252        WAVE/T cell=$("CondCell_"+popStr)
253        cell[0] = "Enter cell name"
254//      SetDimLabel 0,-1,'Cell Name?',cell
255
256        Make/O/D/N=(1,8) $("Cond_"+popStr)
257        WAVE cond = $("Cond_"+popStr)
258        // set the column labels
259        SetDimLabel 1,0,'UU_Trans?',cond
260        SetDimLabel 1,1,'DU_Trans?',cond
261        SetDimLabel 1,2,'DD_Trans?',cond
262        SetDimLabel 1,3,'UD_Trans?',cond
263        SetDimLabel 1,4,'Blocked?',cond
264        SetDimLabel 1,5,Pol_SM_FL,cond
265        SetDimLabel 1,6,Pol_SM,cond                     //for a mask wave, non-zero is used in the fit
266        SetDimLabel 1,7,'Include?',cond
267        cond[0][7] = 1                  //default to include the point
268       
269        // generate the dummy wave note now, change as needed
270        String cellStr = StringFromList(1, popStr,"_")
271        String testStr = "P_sm_f=0,err_P_sm_f=0,P_sm=0,err_P_sm=0,T0=undefined,"
272//      testStr = ReplaceStringByKey("Cell", testStr, cellStr ,"=", ",", 0)
273        Note cond, testStr
274
275        // to hold the results of the calculation
276        Make/O/D/N=(1,14) $("CondCalc_"+popStr)
277        WAVE CondCalc = $("CondCalc_"+popStr)
278        SetDimLabel 1,0,CR_UU,CondCalc
279        SetDimLabel 1,1,err_CR_UU,CondCalc
280        SetDimLabel 1,2,CR_DU,CondCalc
281        SetDimLabel 1,3,err_CR_DU,CondCalc
282        SetDimLabel 1,4,CR_DD,CondCalc
283        SetDimLabel 1,5,err_CR_DD,CondCalc
284        SetDimLabel 1,6,CR_UD,CondCalc
285        SetDimLabel 1,7,err_CR_UD,CondCalc
286        SetDimLabel 1,8,CR_Blocked,CondCalc
287        SetDimLabel 1,9,err_CR_Blocked,CondCalc
288        SetDimLabel 1,10,P_sm_f,CondCalc
289        SetDimLabel 1,11,err_P_sm_f,CondCalc
290        SetDimLabel 1,12,P_sm,CondCalc
291        SetDimLabel 1,13,err_P_sm,CondCalc     
292
293        SetDataFolder root:
294
295        return(0)
296End
297
298
299// allows manual entry of Psm and Pf values
300//
301Function ManualEnterPfPsmButton(ba) : ButtonControl
302        STRUCT WMButtonAction &ba
303
304        Variable selRow,err=0
305        String fname, t0str, condStr,noteStr,t1Str,cellStr
306
307        switch( ba.eventCode )
308                case 2: // mouse up
309                        // click code here
310                        Variable cr1,cr2,cr3,cr4,cr5,err_cr1,err_cr2,err_cr3,err_cr4,err_cr5
311                        Variable PsmPf, err_PsmPf, Psm, err_Psm
312                               
313                        ControlInfo/W=FlipperPanel popup_0
314                        condStr = S_Value
315                        WAVE w=$("root:Packages:NIST:Polarization:Cells:"+condStr)              //the one that is displayed
316                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr[5,strlen(condStr)-1])             //the one that holds results
317                       
318
319                        Prompt PsmPf, "Enter PsmPf: "           
320                        Prompt err_PsmPf, "Enter err_PsmPf: "           
321                        Prompt Psm, "Enter Psm: "               
322                        Prompt err_Psm, "Enter err_Psm: "               
323                        DoPrompt "Enter Supermirror and Flipper Parameters", PsmPf, err_PsmPf, Psm, err_Psm
324                        if (V_Flag)
325                                return -1                                                               // User canceled
326                        endif
327                       
328//      this is the format of the note that is attached to the "Cond_" wave             
329//      String testStr = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf,"
330// the "Cell" value was filled in when the Condition was created
331       
332       
333// Put the average values into the wave note and display on the panel
334                        SVAR gT0 = root:Packages:NIST:Polarization:Cells:gT0
335                       
336                        noteStr = note(w)
337                        noteStr = ReplaceNumberByKey("P_sm_f", noteStr, PsmPf ,"=", ",", 0)
338                        noteStr = ReplaceNumberByKey("P_sm", noteStr, Psm ,"=", ",", 0)
339                        noteStr = ReplaceNumberByKey("err_P_sm_f", noteStr, err_PsmPf ,"=", ",", 0)
340                        noteStr = ReplaceNumberByKey("err_P_sm", noteStr, err_Psm ,"=", ",", 0)
341                        noteStr = ReplaceStringByKey("T0", noteStr, gT0 ,"=", ",", 0)
342                       
343                       
344                        // replace the string
345                        Note/K w
346                        Note w, noteStr
347                                       
348                        //update the global values for display 
349                        SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf
350                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm
351                        sprintf gPsmPf, "%g +/- %g",PsmPf,err_PsmPf
352                        sprintf gPsm, "%g +/- %g",Psm,err_Psm
353                       
354                        break
355                case -1: // control being killed
356                        break
357        endswitch
358
359        return 0
360End
361
362
363//
364// just recalculate everything, every time
365//
366// -- now that the cell name is entered, I need to try to catch errors where the cell decay parameters are not
367// properly calculated -- right now, invalid cell names are caught, but valid cell names with no decay data
368// behind them just calculate Inf for the polarization values. This is hopefull enough to catch someone's attention...
369//
370Function FlipperAverageButtonProc(ba) : ButtonControl
371        STRUCT WMButtonAction &ba
372
373        Variable selRow,err=0
374        String fname, t0str, condStr,noteStr,t1Str,cellStr
375
376        switch( ba.eventCode )
377                case 2: // mouse up
378                        // click code here
379                        Variable cr1,cr2,cr3,cr4,cr5,err_cr1,err_cr2,err_cr3,err_cr4,err_cr5
380                        Variable PsmPf, err_PsmPf, Psm, err_Psm
381                               
382                        ControlInfo/W=FlipperPanel popup_0
383                        condStr = S_Value
384                        WAVE w=$("root:Packages:NIST:Polarization:Cells:"+condStr)              //the one that is displayed
385                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr[5,strlen(condStr)-1])             //the one that holds results
386                        WAVE/T CellW=$("root:Packages:NIST:Polarization:Cells:CondCell_"+condStr[5,strlen(condStr)-1])          //the textW with cell name
387                       
388                        Variable numRows,ncalc,diff
389                        numRows = DimSize(w,0)          //rows in the displayed table
390                        ncalc = DimSize(calc,0)
391                       
392                        // add rows to the ConcCalc_ matrix as needed
393                        if(numRows != ncalc)
394                                if(ncalc > numRows)
395                                        DoAlert 0,"The CondCalc_ is larger than displayed. Seek help."
396                                        err = 1
397                                        return(err)
398                                else
399                                        diff = numRows - ncalc
400                                        InsertPoints/M=0 ncalc, diff, calc
401                                endif
402                        endif
403                       
404//                      noteStr=note(w)
405//                      cellStr = StringByKey("Cell", noteStr, "=", ",", 0)
406//                      Wave decay = $("root:Packages:NIST:Polarization:Cells:Decay_"+cellStr) 
407//                      noteStr=note(decay)
408//                      t0Str = StringByKey("T0", noteStr, "=", ",", 0)
409//                      Print "CellStr, T0 = ",cellStr, t0Str
410
411                        Variable sum_PsmPf, err_sum_PsmPf, sum_Psm, err_sum_Psm,nRowsIncluded=0
412                        sum_PsmPf = 0
413                        err_sum_PsmPf = 0
414                        sum_Psm = 0
415                        err_sum_Psm = 0
416                       
417                        for(selRow=0;selRow<numRows;selRow+=1)
418                                Print "calculate the row ",selRow
419
420                                //include this row of data?
421                                if(w[selRow][%'Include?'] == 1)
422                                        nRowsIncluded += 1
423                                       
424                                        // now the cell depends on the row
425                                        cellStr = CellW[selRow]
426                                        Wave/Z decay = $("root:Packages:NIST:Polarization:Cells:Decay_"+cellStr)
427                                        if(WaveExists(decay) == 0)              // catch gross errors
428                                                Abort "The cell "+cellStr+" in row "+num2str(selRow)+" does not exist"
429                                        endif
430                                        noteStr=note(decay)
431                                        t0Str = StringByKey("T0", noteStr, "=", ",", 0)
432       
433                                        // parse the rows, report errors (there, not here), exit if any found
434                                        err = ParseFlipperRow(w,selRow)
435                                        if(err)
436                                                return 0
437                                        endif
438                                       
439                                        // do the calculations:
440//                                      cr1 = TotalCR_FromRun(w[selRow][%'UU_Trans?'],err_cr1,1)
441//                                      cr2 = TotalCR_FromRun(w[selRow][%'DU_Trans?'],err_cr2,1)
442//                                      cr3 = TotalCR_FromRun(w[selRow][%'DD_Trans?'],err_cr3,1)       
443//                                      cr4 = TotalCR_FromRun(w[selRow][%'UD_Trans?'],err_cr4,1)
444//                                      cr5 = TotalCR_FromRun(w[selRow][%'Blocked?'],err_cr5,1)         //blocked beam is NOT normalized to zero attenuators
445//                                      Print "The Blocked CR is *NOT* rescaled to zero attenuators -- FlipperAverageButtonProc"
446                                        cr1 = TotalCR_FromRun(w[selRow][%'UU_Trans?'],err_cr1,0)
447                                        cr2 = TotalCR_FromRun(w[selRow][%'DU_Trans?'],err_cr2,0)
448                                        cr3 = TotalCR_FromRun(w[selRow][%'DD_Trans?'],err_cr3,0)       
449                                        cr4 = TotalCR_FromRun(w[selRow][%'UD_Trans?'],err_cr4,0)
450                                        cr5 = TotalCR_FromRun(w[selRow][%'Blocked?'],err_cr5,0)         //blocked beam is normalized to zero attenuators
451                                        Print "The Blocked CR *IS* rescaled to zero attenuators -- FlipperAverageButtonProc"
452       
453                                        calc[selRow][%cr_UU] = cr1
454                                        calc[selRow][%cr_DU] = cr2
455                                        calc[selRow][%cr_DD] = cr3
456                                        calc[selRow][%cr_UD] = cr4
457                                        calc[selRow][%cr_Blocked] = cr5
458                                        calc[selRow][%err_cr_UU] = err_cr1
459                                        calc[selRow][%err_cr_DU] = err_cr2
460                                        calc[selRow][%err_cr_DD] = err_cr3
461                                        calc[selRow][%err_cr_UD] = err_cr4
462                                        calc[selRow][%err_cr_Blocked] = err_cr5
463               
464                                        // Calc PsmPf, and assign the values
465                                        PsmPf = Calc_PsmPf(w,calc,noteStr,selRow,err_PsmPf)
466                                        calc[selRow][%P_sm_f] = PsmPf
467                                        calc[selRow][%err_P_sm_f] = err_PsmPf
468                                        w[selRow][%Pol_SM_FL] = PsmPf
469                                       
470                                        // Calc Psm, and assign the values
471                                        Psm = Calc_Psm(w,calc,noteStr,selRow,err_Psm)
472                                        calc[selRow][%P_sm] = Psm
473                                        calc[selRow][%err_P_sm] = err_Psm
474                                        w[selRow][%Pol_SM] = Psm
475       
476                                        // running average of PsmPf and Psm
477                                        sum_PsmPf += PsmPf
478                                        err_sum_PsmPf += err_PsmPf^2
479                                        sum_Psm += Psm
480                                        err_sum_Psm += err_Psm^2
481                                       
482                                endif
483                               
484                        endfor          //loop over rows
485                       
486                        // now get a running average of muP, Po, and the errors
487                        // use the actual number of rows included
488                        PsmPf = sum_PsmPf/nRowsIncluded
489                        Psm = sum_Psm/nRowsIncluded
490                        err_PsmPf = sqrt(err_sum_PsmPf) / nRowsIncluded
491                        err_Psm = sqrt(err_sum_Psm) / nRowsIncluded
492                       
493//      this is the format of the note that is attached to the "Cond_" wave             
494//      String testStr = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,"
495// the "Cell" value is not longer used
496       
497       
498// Put the average values into the wave note and display on the panel
499                        noteStr = note(w)
500                        noteStr = ReplaceNumberByKey("P_sm_f", noteStr, PsmPf ,"=", ",", 0)
501                        noteStr = ReplaceNumberByKey("P_sm", noteStr, Psm ,"=", ",", 0)
502                        noteStr = ReplaceNumberByKey("err_P_sm_f", noteStr, err_PsmPf ,"=", ",", 0)
503                        noteStr = ReplaceNumberByKey("err_P_sm", noteStr, err_Psm ,"=", ",", 0)
504                       
505                        // replace the string
506                        Note/K w
507                        Note w, noteStr
508                                       
509                        //update the global values for display 
510                        SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf
511                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm
512                        sprintf gPsmPf, "%g +/- %g",PsmPf,err_PsmPf
513                        sprintf gPsm, "%g +/- %g",Psm,err_Psm
514                       
515                        break
516                case -1: // control being killed
517                        break
518        endswitch
519
520        return 0
521End
522
523// gCellKW passed in has gamma, muPo, etc. needed for PCell(t) calculation
524//
525//      TODO:
526//  this is only using the measurement at t1 for the calculation!
527// -- do I need to recalculate at the midpoint of the time interval?
528// -- then how do I define the beginning and ending time?
529//
530Function Calc_PsmPf(w,calc,gCellKW,selRow,err_PsmPf)
531        WAVE w,calc
532        String gCellKW
533        Variable selRow,&err_PsmPf
534       
535        // DD is cr3, DU is cr2, Blocked is cr5
536        String t0Str,t1Str,t2Str,fname
537        Variable PsmPf,t1,t2,PCell_t1,PCell_t2,err_PCell_t1,err_PCell_t2
538        Variable muPo,err_muPo,gam,err_gam
539        Variable crDD, crDU,err_crDD,err_crDU,crBB, err_crBB
540       
541        t0Str = StringByKey("T0", gCellKW, "=", ",", 0)
542        muPo = NumberByKey("muP", gCellKW, "=", ",", 0)
543        err_muPo = NumberByKey("err_muP", gCellKW, "=", ",", 0)
544        gam = NumberByKey("gamma", gCellKW, "=", ",", 0)
545        err_gam = NumberByKey("err_gamma", gCellKW, "=", ",", 0)
546
547        fname = FindFileFromRunNumber(w[selRow][%'UU_Trans?'])
548        t1str = getFileCreationDate(fname)
549        t1 = ElapsedHours(t0Str,t1Str)
550       
551        fname = FindFileFromRunNumber(w[selRow][%'DU_Trans?'])
552        t2str = getFileCreationDate(fname)
553        t2 = ElapsedHours(t0Str,t2Str)
554
555        PCell_t1 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t1,err_PCell_t1)
556        PCell_t2 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t2,err_PCell_t2)
557       
558        // DD is cr3, DU is cr2, Blocked is cr5
559        crDD = calc[selRow][%cr_DD]
560        crDU = calc[selRow][%cr_DU]
561        crBB = calc[selRow][%cr_Blocked]
562        err_crDD = calc[selRow][%err_cr_DD]
563        err_crDU = calc[selRow][%err_cr_DU]
564        err_crBB = calc[selRow][%err_cr_Blocked]
565       
566        // this really needs transmissions
567//      PsmPf = (crDD - crDU)/(PCell_t1 + PCell_t2)
568       
569        // eqn (15) from the SS handout
570        Variable tmp,dfdx
571        tmp = (crDD - crBB)/(crDU - crBB)
572       
573        PsmPf = (tmp - 1)/(Pcell_t1*(1+tmp))
574       
575        dfdx = 1/(Pcell_t1*(1+tmp)) - (tmp-1)*Pcell_t1/(Pcell_t1^2*(1+tmp)^2)
576       
577        err_PsmPf = ( (tmp-1)/((1+tmp)*Pcell_t1^2) *err_Pcell_t1 )^2
578        err_PsmPf += ( dfdx / (crDU-crBB) * err_crDD)^2
579        err_PsmPf += ( dfdx*(crDD-crBB)/(crDU-crBB)^2 * err_crDU)^2
580        err_PsmPf += ( dfdx*(-tmp/(crDD-crBB) + tmp/(crDU-crBB)) * err_crBB)^2
581       
582        err_PsmPf = sqrt(err_PsmPf)
583        Printf "At t1=%g  PsmPf = %g +/- %g (%g%)\r",t1,PsmPf,err_PsmPf,err_PsmPf/PsmPf*100
584
585
586        return(PsmPf)
587end
588
589
590// gCellKW passed in has gamma, muPo, etc. needed for PCell(t) calculation
591//
592//      TODO:
593//  this is only using the measurement at t1 for the calculation!
594// -- do I need to recalculate at the midpoint of the time interval?
595// -- then how do I define the beginning and ending time?
596//
597//
598Function Calc_Psm(w,calc,gCellKW,selRow,err_Psm)
599        WAVE w,calc
600        String gCellKW
601        Variable selRow,&err_Psm
602       
603        // UU is cr1, UD is cr4, Blocked is cr5
604        String t0Str,t1Str,t2Str,fname
605        Variable Psm,t1,t2,PCell_t1,PCell_t2,err_PCell_t1,err_PCell_t2
606        Variable muPo,err_muPo,gam,err_gam
607        Variable crUU, crUD,err_crUU,err_crUD,crBB, err_crBB
608       
609        t0Str = StringByKey("T0", gCellKW, "=", ",", 0)
610        muPo = NumberByKey("muP", gCellKW, "=", ",", 0)
611        err_muPo = NumberByKey("err_muP", gCellKW, "=", ",", 0)
612        gam = NumberByKey("gamma", gCellKW, "=", ",", 0)
613        err_gam = NumberByKey("err_gamma", gCellKW, "=", ",", 0)
614
615        fname = FindFileFromRunNumber(w[selRow][%UU_Trans])
616        t1str = getFileCreationDate(fname)
617        t1 = ElapsedHours(t0Str,t1Str)
618       
619        fname = FindFileFromRunNumber(w[selRow][%DU_Trans])
620        t2str = getFileCreationDate(fname)
621        t2 = ElapsedHours(t0Str,t2Str)
622
623        PCell_t1 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t1,err_PCell_t1)
624        PCell_t2 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t2,err_PCell_t2)
625       
626        // UU is cr1, UD is cr4, Blocked is cr5
627        crUU = calc[selRow][%cr_UU]
628        crUD = calc[selRow][%cr_UD]
629        crBB = calc[selRow][%cr_Blocked]
630        err_crUU = calc[selRow][%err_cr_UU]
631        err_crUD = calc[selRow][%err_cr_UD]
632        err_crBB = calc[selRow][%err_cr_Blocked]
633       
634        // this really needs transmissions
635       
636        // eqn (14) from the SS handout
637        Variable tmp,dfdx
638        tmp = (crUU - crBB)/(crUD - crBB)
639       
640        Psm = (tmp - 1)/(Pcell_t1*(1+tmp))
641       
642        dfdx = 1/(Pcell_t1*(1+tmp)) - (tmp-1)*Pcell_t1/(Pcell_t1^2*(1+tmp)^2)
643       
644        err_Psm = ( (tmp-1)/((1+tmp)*Pcell_t1^2) *err_Pcell_t1 )^2
645        err_Psm += ( dfdx / (crUD-crBB) * err_crUU)^2
646        err_Psm += ( dfdx*(crUU-crBB)/(crUD-crBB)^2 * err_crUD)^2
647        err_Psm += ( dfdx*(-tmp/(crUU-crBB) + tmp/(crUD-crBB)) * err_crBB)^2
648       
649        err_Psm = sqrt(err_Psm)
650        Printf "At t1=%g  Psm = %g +/- %g (%g%)\r",t1,Psm,err_Psm,err_Psm/Psm*100
651
652
653        return(Psm)
654end
655
656//
657// calculate the (atomic) He polarization at some delta time
658//
659// t2 is in hours, gamma in hours
660//
661Function Calc_PHe_atT(Po,err_Po,gam,err_gam,t2,err_Pt)
662        Variable Po,err_Po,gam,err_gam,t2,&err_Pt
663
664
665        Variable Pt     
666
667        Pt = Po*exp(-t2/gam)
668       
669        Variable arg,tmp2
670        // 2 terms, no error in t2
671        err_Pt = Pt^2/Po^2*err_Po^2 + t2^2/gam^4*Pt^2*err_gam^2
672       
673        err_Pt = sqrt(err_Pt)
674       
675        Printf "At (delta)t=%g  P_He(t) = %g +/- %g (%g%)\r",t2,Pt,err_Pt,err_Pt/Pt*100
676
677        return(Pt)
678End
679
680
681
682//
683// t2 is in hours, muP0 is at t0
684//
685Function Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t2,err_PCell)
686        Variable muPo,err_muPo,gam,err_gam,t2,&err_PCell
687
688
689        Variable Pcell
690
691        PCell = tanh(muPo * exp(-t2/gam))
692//      PCell = (muPo * exp(-t2/gam))
693       
694        Variable arg,tmp2
695        arg = PCell
696        tmp2 = (1-tanh(arg)^2)^2
697        err_PCell = tmp2 * (exp(-t2/gam) * err_muPo)^2                  //dominant term (10x larger)
698        err_PCell += tmp2 * (arg*t2/gam/gam * err_gam)^2
699       
700        err_PCell = sqrt(err_Pcell)
701       
702        Printf "At t=%g  Pcell = %g +/- %g (%g%)\r",t2,Pcell,err_Pcell,err_Pcell/PCell*100
703
704        return(PCell)
705End
706
707// bring up a table with the calculation results
708Function ShowFlipperCalcButton(ba) : ButtonControl
709        STRUCT WMButtonAction &ba
710
711        switch( ba.eventCode )
712                case 2: // mouse up
713                        // click code here
714                        ControlInfo/W=FlipperPanel popup_0
715                        String condStr = S_Value
716                        condStr = condStr[5,strlen(condStr)-1]          // trim off "Calc_" from the beginning of the string
717                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr)         
718                        edit calc.ld
719                                               
720                        break
721                case -1: // control being killed
722                        break
723        endswitch
724
725        return 0
726End
727
728
729
730// clear just the row
731//
732Function ClearFlipperRowButton(ba) : ButtonControl
733        STRUCT WMButtonAction &ba
734
735        String popStr=""
736        Variable selRow
737       
738        switch( ba.eventCode )
739                case 2: // mouse up
740                        // click code here
741                        DoAlert 1,"Clear the selected row?"
742                        if(V_flag !=1)
743                                return(0)
744                        endif
745                       
746                        SetDataFolder root:Packages:NIST:Polarization:Cells
747
748                        ControlInfo/W=FlipperPanel popup_0
749                        popStr = S_Value
750                        popStr = StringFromList(1,S_Value,"_")                  //pop is "Cond_<condition>", so get list item 1
751                       
752                        Wave cond = $("Cond_"+popStr)
753                        Wave calc = $("CondCalc_"+popStr)
754                        Wave/T cellW = $("CondCell_"+popStr)
755                       
756                        // Delete just those points
757                                               
758                        GetSelection table, FlipperPanel#T0, 1
759                        selRow = V_startRow
760                        DeletePoints selRow,1,cond,calc,cellW                   
761                       
762                        // clear the graph and the results                     
763                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm
764                        SVAR gPsmPf  = root:Packages:NIST:Polarization:Cells:gPsmPf
765                        gPsm = "0"
766                        gPsmPf = "0"
767                       
768                        SetDataFolder root:
769                        break
770                case -1: // control being killed
771                        break
772        endswitch
773
774        return 0
775End
776
777
778
779// for this, do I want to clear everything, or just a selected row??
780//
781//
782Function ClearAllFlipperWavesButton(ba) : ButtonControl
783        STRUCT WMButtonAction &ba
784
785        String popStr=""
786       
787        switch( ba.eventCode )
788                case 2: // mouse up
789                        // click code here
790                        DoAlert 1,"Clear all of the flipper waves for the selected cell?"
791                        if(V_flag !=1)
792                                return(0)
793                        endif
794                       
795                        SetDataFolder root:Packages:NIST:Polarization:Cells
796
797                        ControlInfo/W=FlipperPanel popup_0
798                        popStr = StringFromList(1,S_Value,"_")                  //pop is "Cond_<condition>", so get list item 1
799                       
800                        Wave cond = $("Cond_"+popStr)
801                        Wave calc = $("CondCalc_"+popStr)
802                        Wave/T cellW = $("CondCell_"+popStr)
803                       
804//                      re-initialize the flipper waves, so it appears as a blank, initialized table
805
806                        MakeFlipperResultWaves(popStr)
807                        cond = 0
808                        calc = 0
809//                      cellW = ""
810                        cond[0][7] = 1                  //default to include the point
811
812                        // clear the graph and the results?     
813                       
814                       
815                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm
816                        SVAR gPsmPf  = root:Packages:NIST:Polarization:Cells:gPsmPf
817                        gPsm = "0"
818                        gPsmPf = "0"
819                       
820                        SetDataFolder root:
821                        break
822                case -1: // control being killed
823                        break
824        endswitch
825
826        return 0
827End
828
829
830Function FlipperHelpParButtonProc(ba) : ButtonControl
831        STRUCT WMButtonAction &ba
832
833        switch( ba.eventCode )
834                case 2: // mouse up
835                        // click code here
836                        DisplayHelpTopic/Z/K=1 "Flipper States Panel"
837                        if(V_flag !=0)
838                                DoAlert 0,"The Flipper States Panel Help file could not be found"
839                        endif
840                        break
841                case -1: // control being killed
842                        break
843        endswitch
844
845        return 0
846End
847
848
849
850// null condition is not right. if the loop fails, then the
851// retStr will be ";;;;", not zero length. What's the proper test?
852// Does it matter? the list of default gCell_sss should already be there.
853//
854Function/S D_ConditionNameList()
855
856        String listStr=""
857       
858        SetDataFolder root:Packages:NIST:Polarization:Cells
859
860        // get a list of the Condition waves
861        listStr=WaveList("Cond_*",";","")
862//      print listStr
863       
864        if(strlen(listStr) == 0)
865                listStr = "no conditions defined;"
866        endif
867       
868        SetDataFolder root:             
869        return(listStr)
870End
871
872
873// parse the row to be sure that:
874//
875// - files are valid numbers
876// - files are all at same SDD
877// - files are all with same attenuation (just print a warning to cmd)
878// - files all use the same cell
879// - files are all within 20 minutes of each other
880//
881//
882//      SetDimLabel 1,0,UU_Trans,cond
883//      SetDimLabel 1,1,DU_Trans,cond
884//      SetDimLabel 1,2,DD_Trans,cond
885//      SetDimLabel 1,3,UD_Trans,cond
886//      SetDimLabel 1,4,Blocked,cond
887//      SetDimLabel 1,5,Pol_SM_FL,cond
888//      SetDimLabel 1,6,Pol_SM,cond                     //for a mask wave, non-zero is used in the fit
889//      SetDimLabel 1,7,Include,cond
890//
891// There are 5 separate files now
892//
893Function ParseFlipperRow(w,selRow)
894        Wave w
895        Variable selRow
896       
897        Variable err=0
898        Variable atten1,atten2,atten3,atten4,atten5
899        Variable sdd1,sdd2,sdd3,sdd4,sdd5
900        Variable t1,t2,t3,t4,t5
901        String cell1,cell2,cell3,cell4,cell5
902       
903       
904        String fname=""
905       
906       
907        // are all file numbers valid?
908        fname = FindFileFromRunNumber(w[selRow][%'UU_Trans?'])
909        if(cmpstr(fname,"")==0)
910                DoAlert 0,"UU_Trans run "+num2str(w[selRow][%'UU_Trans?'])+" is not a valid run number"
911                err = 1
912        else
913                atten1 = getAttenNumber(fname)
914                sdd1 = getSDD(fname)
915        endif
916       
917        fname = FindFileFromRunNumber(w[selRow][%'DU_Trans?'])
918        if(cmpstr(fname,"")==0)
919                DoAlert 0,"DU_Trans run "+num2str(w[selRow][%'DU_Trans?'])+" is not a valid run number"
920                err = 1
921        else
922                atten2 = getAttenNumber(fname)
923                sdd2 = getSDD(fname)
924        endif
925       
926        fname = FindFileFromRunNumber(w[selRow][%'DD_Trans?'])
927        if(cmpstr(fname,"")==0)
928                DoAlert 0,"DD_Trans run "+num2str(w[selRow][%'DD_Trans?'])+" is not a valid run number"
929                err = 1
930        else
931                atten3 = getAttenNumber(fname)
932                sdd3 = getSDD(fname)
933        endif
934       
935        fname = FindFileFromRunNumber(w[selRow][%'UD_Trans?'])
936        if(cmpstr(fname,"")==0)
937                DoAlert 0,"UD_Trans run "+num2str(w[selRow][%'UD_Trans?'])+" is not a valid run number"
938                err = 1
939        else
940                atten4 = getAttenNumber(fname)
941                sdd4 = getSDD(fname)
942        endif
943       
944        fname = FindFileFromRunNumber(w[selRow][%'Blocked?'])
945        if(cmpstr(fname,"")==0)
946                DoAlert 0,"Blocked run "+num2str(w[selRow][%'Blocked?'])+" is not a valid run number"
947                err = 1
948        else
949                atten5 = getAttenNumber(fname)
950                sdd5 = getSDD(fname)
951        endif
952       
953       
954       
955        // do a check of the elapsed time from start to finish
956       
957        if( (sdd1 != sdd2) || (sdd2 != sdd3) || (sdd1 != sdd3) )
958                DoAlert 0,"Files in row "+num2str(selRow)+" are not all at the same detector distance"
959                err = 1
960        endif
961       
962
963        if( (atten1 != atten2) || (atten2 != atten3) || (atten1 != atten3) )
964                DoAlert 0,"Files in row "+num2str(selRow)+" are not all collected with the same attenuation. Just so you know."
965                err = 0
966        endif
967       
968        return(err)
969end
970
971
972////////////////////////////////////////////
973
974
975
976///////////////////////
977//
978//
979// Utilities to write out waves as Igor Text
980//
981//
982// -- TODO
983// -- add flags for SetScale, Note, DimLabels, text? (or a separate function)
984// x- add a function for 2D waves. wfprintf is not 2D aware...
985
986
987Function testWriteITX()
988
989        Variable refnum
990        String fname="a_test.itx"
991//      WAVE w=root:testMat
992//      WAVE/T w=root:testText
993        WAVE/T w=root:Packages:NIST:Polarization:ListWave_0_UU
994       
995       
996        Open/P=home refnum as fname             // creates a new file, or overwrites the existing file
997       
998        fprintf refNum,"IGOR\r"
999       
1000//      Write1DWaveToITX(w,refnum)
1001//      Write2DWaveToITX(w,refnum)
1002//      Write1DTextWaveToITX(w,refnum)
1003        Write2DTextWaveToITX(w,refnum) 
1004        Close refnum
1005
1006        return(0)
1007end
1008
1009// writes out a 1D wave as Igor Text
1010//
1011// the wave and a valid refNum to an open file are passed
1012//
1013// the file is NOT closed when exiting
1014//
1015Function Write1DWaveToITX(w,refnum)
1016        Wave w
1017        Variable refNum
1018       
1019        String tmpStr,waveStr
1020        waveStr=NameOfWave(w)
1021       
1022        fprintf refNum,"WAVES/D\t%s\r",waveStr
1023
1024        fprintf refNum,"BEGIN\r"
1025
1026        wfprintf refnum, "\t%g\r",w
1027       
1028        fprintf refNum,"END\r"
1029
1030        fprintf refnum,"X SetScale/P x 0,1,\"\", %s; SetScale y 0,0,\"\", %s\r",waveStr,waveStr
1031       
1032//      X SetScale/P x 0,1,"", fyy; SetScale y 0,0,"", fyy
1033       
1034       
1035        return(0)
1036End
1037
1038// writes out a 1D TEXT wave as Igor Text
1039//
1040// the wave and a valid refNum to an open file are passed
1041//
1042// the file is NOT closed when exiting
1043//
1044Function Write1DTextWaveToITX(w,refnum)
1045        Wave/T w
1046        Variable refNum
1047       
1048        String tmpStr,waveStr
1049        waveStr=NameOfWave(w)
1050       
1051        fprintf refNum,"WAVES/T\t%s\r",waveStr
1052
1053        fprintf refNum,"BEGIN\r"
1054
1055        wfprintf refnum, "\t\"%s\"\r",w
1056       
1057        fprintf refNum,"END\r"
1058
1059        fprintf refnum,"X SetScale/P x 0,1,\"\", %s; SetScale y 0,0,\"\", %s\r",waveStr,waveStr
1060       
1061        return(0)
1062End
1063
1064// writes out a 2D TEXT wave as Igor Text
1065//
1066// the wave and a valid refNum to an open file are passed
1067//
1068// the file is NOT closed when exiting
1069//
1070Function Write2DTextWaveToITX(w,refnum)
1071        Wave/T w
1072        Variable refNum
1073       
1074        String tmpStr,waveStr
1075        Variable row,col,ii,jj,tmp
1076       
1077        row=DimSize(w, 0 )
1078        col=DimSize(w, 1 )
1079        waveStr=NameOfWave(w)
1080               
1081        fprintf refNum,"WAVES/T/N=(%d,%d)\t%s\r",row,col,waveStr
1082        fprintf refNum,"BEGIN\r"
1083
1084        for(ii=0;ii<row;ii+=1)
1085                for(jj=0;jj<col;jj+=1)
1086                        fprintf refnum, "\t\"%s\"",w[ii][jj]
1087                endfor
1088                fprintf refnum, "\r"
1089        endfor
1090       
1091       
1092        fprintf refNum,"END\r"
1093
1094        fprintf refnum,"X SetScale/P x 0,1,\"\", %s; SetScale/P y 0,1,\"\", %s; SetScale d 0,0,\"\", %s\r",waveStr,waveStr,waveStr
1095       
1096//      X SetScale/P x 0,1,"", testMat; SetScale/P y 0,1,"", testMat; SetScale d 0,0,"", testMat
1097
1098       
1099       
1100        return(0)
1101End
1102
1103// writes out a 2D wave as Igor Text
1104//
1105// the wave and a valid refNum to an open file are passed
1106//
1107// the file is NOT closed when exiting
1108//
1109Function Write2DWaveToITX(w,refnum)
1110        Wave w
1111        Variable refNum
1112       
1113        String tmpStr,waveStr
1114        Variable row,col,ii,jj,tmp
1115       
1116        row=DimSize(w, 0 )
1117        col=DimSize(w, 1 )
1118        waveStr=NameOfWave(w)
1119               
1120        fprintf refNum,"WAVES/D/N=(%d,%d)\t%s\r",row,col,waveStr
1121        fprintf refNum,"BEGIN\r"
1122
1123        for(ii=0;ii<row;ii+=1)
1124                for(jj=0;jj<col;jj+=1)
1125                        fprintf refnum, "\t%g",w[ii][jj]
1126                endfor
1127                fprintf refnum, "\r"
1128        endfor
1129       
1130       
1131        fprintf refNum,"END\r"
1132
1133        fprintf refnum,"X SetScale/P x 0,1,\"\", %s; SetScale/P y 0,1,\"\", %s; SetScale d 0,0,\"\", %s\r",waveStr,waveStr,waveStr
1134       
1135//      X SetScale/P x 0,1,"", testMat; SetScale/P y 0,1,"", testMat; SetScale d 0,0,"", testMat
1136
1137       
1138       
1139        return(0)
1140End
1141
1142// root:Packages:NIST:Polarization:Cells:
1143// save the state of the pink panel, as CellParamSaveState.itx
1144Function SaveCellParameterTable()
1145
1146        SetDataFolder root:Packages:NIST:Polarization:Cells:
1147       
1148        // the waves are:
1149        // CellName (T)
1150        // lambda
1151        // Te, err_Te
1152        // mu, err_mu
1153       
1154        Variable refnum
1155        String fname="CellParamSaveState"
1156//      WAVE w=root:testMat
1157        WAVE/T cellName=root:Packages:NIST:Polarization:Cells:CellName
1158        WAVE lambda=root:Packages:NIST:Polarization:Cells:lambda
1159        WAVE Te=root:Packages:NIST:Polarization:Cells:Te
1160        WAVE err_Te=root:Packages:NIST:Polarization:Cells:err_Te
1161        WAVE mu=root:Packages:NIST:Polarization:Cells:mu
1162        WAVE err_mu=root:Packages:NIST:Polarization:Cells:err_mu
1163       
1164        // get the full path to the new file name before creating it
1165        fname = DoSaveFileDialog("Save the Cell Table",fname=fname,suffix=".itx")
1166        If(cmpstr(fname,"")==0)
1167                //user cancel, don't write out a file
1168                Close/A
1169                Abort "no data file was written"
1170        Endif
1171       
1172        Open/P=home refnum      as fname                // creates a new file, or overwrites the existing file 
1173       
1174        fprintf refNum,"IGOR\r"
1175       
1176        Write1DTextWaveToITX(cellName,refnum)
1177        fprintf refNum,"\r"     
1178
1179        Write1DWaveToITX(lambda,refnum)
1180        fprintf refNum,"\r"     
1181       
1182        Write1DWaveToITX(Te,refnum)
1183        fprintf refNum,"\r"     
1184
1185        Write1DWaveToITX(err_Te,refnum)
1186        fprintf refNum,"\r"     
1187       
1188        Write1DWaveToITX(mu,refnum)
1189        fprintf refNum,"\r"     
1190       
1191        Write1DWaveToITX(err_mu,refnum)
1192                       
1193        Close refnum
1194
1195        SetDataFolder root:
1196               
1197        return(0)
1198End
1199
1200//could use /P=home, but the whole point is that this is for users without Igor licenses, that can't save... so "home" won't exist...
1201Function RestoreCellParameterTable()
1202
1203        SetDataFolder root:Packages:NIST:Polarization:Cells:
1204        String fname="CellParamSaveState.itx"
1205
1206//      LoadWave/P=home/O/T fname
1207        LoadWave/O/T fname
1208       
1209        SetDataFolder root:
1210        return(0)
1211End
1212
1213
1214// saves the parameters for the cell decay table
1215//
1216//      fname = "CellDecayPanelSaveState.itx"
1217//
1218//
1219Function SaveCellDecayTable()
1220
1221        SetDataFolder root:Packages:NIST:Polarization:Cells:
1222       
1223        String listStr,item,fname,noteStr,wStr
1224        Variable num,ii,refnum
1225       
1226        fname = "CellDecaySaveState"
1227       
1228        // get a list of the Decay waves
1229        listStr=WaveList("Decay_*",";","")
1230        num=ItemsInList(listStr,";")
1231//      print listStr
1232
1233        // get the full path to the new file name before creating it
1234        fname = DoSaveFileDialog("Save the Cell Decay Table",fname=fname,suffix=".itx")
1235        If(cmpstr(fname,"")==0)
1236                //user cancel, don't write out a file
1237                Close/A
1238                Abort "no data file was written"
1239        Endif
1240
1241        Open/P=home refnum as fname             // creates a new file, or overwrites the existing file 
1242        fprintf refNum,"IGOR\r"
1243                       
1244        // Save each of the decay waves, then be sure to add the DimLabels and Wave Note
1245        for(ii=0;ii<num;ii+=1)
1246                item = StringFromList(ii, listStr,";")
1247                Wave w = $item
1248                wStr=NameOfWave(w)
1249                noteStr = note(w)
1250               
1251                Write2DWaveToITX(w,refnum)
1252               
1253//              fprintf refNum,"X SetScale/P x 0,1,\"\", %s; SetScale/P y 0,1,\"\", %s; SetScale d 0,0,\"\", %s\r",wStr,wStr,wStr
1254                fprintf refNum,"X SetDimLabel 1, 0, 'Trans_He_In?', %s\r",wStr
1255                fprintf refNum,"X SetDimLabel 1, 1, 'Trans_He_Out?', %s\r",wStr
1256                fprintf refNum,"X SetDimLabel 1, 2, 'Blocked?', %s\r",wStr
1257                fprintf refNum,"X SetDimLabel 1, 3, mu_star, %s\r",wStr
1258                fprintf refNum,"X SetDimLabel 1, 4, Effective_Pol, %s\r",wStr
1259                fprintf refNum,"X SetDimLabel 1, 5, Atomic_Pol, %s\r",wStr
1260                fprintf refNum,"X SetDimLabel 1, 6, T_Major, %s\r",wStr
1261                fprintf refNum,"X SetDimLabel 1, 7, 'Include?', %s\r",wStr
1262                fprintf refNum,"X SetDimLabel 1, 8, elapsed_hr, %s\r",wStr             
1263                fprintf refNum,"X Note %s, \"%s\"\r",wStr,noteStr
1264
1265                fprintf refNum,"\r"             //space between waves
1266        endfor 
1267
1268        // get a list of the DecayCalc_ waves
1269        listStr=WaveList("DecayCalc_*",";","")
1270        num=ItemsInList(listStr,";")   
1271       
1272        // Save each of the DecayCalc waves, and add all of the proper dim labels
1273        for(ii=0;ii<num;ii+=1)
1274                item = StringFromList(ii, listStr,";")
1275                Wave w = $item
1276                wStr=NameOfWave(w)
1277
1278                Write2DWaveToITX(w,refnum)
1279               
1280//              fprintf refNum,"X SetScale/P x 0,1,\"\", %s; SetScale/P y 0,1,\"\", %s; SetScale d 0,0,\"\", %s\r",wStr,wStr,wStr
1281                fprintf refNum,"X SetDimLabel 1, 0, CR_Trans_He_In, %s\r",wStr
1282                fprintf refNum,"X SetDimLabel 1, 1, err_CR_Trans_He_In, %s\r",wStr
1283                fprintf refNum,"X SetDimLabel 1, 2, CR_Trans_He_Out, %s\r",wStr
1284                fprintf refNum,"X SetDimLabel 1, 3, err_CR_Trans_He_Out, %s\r",wStr
1285                fprintf refNum,"X SetDimLabel 1, 4, CR_Blocked, %s\r",wStr
1286                fprintf refNum,"X SetDimLabel 1, 5, err_CR_Blocked, %s\r",wStr
1287                fprintf refNum,"X SetDimLabel 1, 6, muPo, %s\r",wStr
1288                fprintf refNum,"X SetDimLabel 1, 7, err_muPo, %s\r",wStr
1289                fprintf refNum,"X SetDimLabel 1, 8, Po, %s\r",wStr
1290                fprintf refNum,"X SetDimLabel 1, 9, err_Po, %s\r",wStr
1291                fprintf refNum,"X SetDimLabel 1, 10, Tmaj, %s\r",wStr
1292                fprintf refNum,"X SetDimLabel 1, 11, err_Tmaj, %s\r",wStr
1293                fprintf refNum,"X SetDimLabel 1, 12, gamm, %s\r",wStr
1294                fprintf refNum,"X SetDimLabel 1, 13, err_gamm, %s\r",wStr
1295
1296                fprintf refNum,"\r"     
1297        endfor 
1298       
1299        Close refnum
1300
1301        SetDataFolder root:
1302        return(0)
1303End
1304
1305// restores the waves for the cell decay table
1306//
1307//      fname = "CellDecayPanelSaveState.itx"
1308//
1309//
1310Function RestoreCellDecayTable()
1311
1312        SetDataFolder root:Packages:NIST:Polarization:Cells:
1313       
1314        String listStr,item,fname,noteStr,wStr
1315        Variable num,ii,refnum
1316       
1317        fname = "CellDecayPanelSaveState.itx"
1318        LoadWave/O/T fname
1319       
1320        SetDataFolder root:
1321        return(0)
1322End
1323
1324
1325
1326////////
1327//
1328// save the state of the Flipper panel
1329//
1330//      fname = "FlipperPanelSaveState.itx"
1331//
1332Function SaveFlipperTable()
1333
1334        SetDataFolder root:Packages:NIST:Polarization:Cells:
1335       
1336        String listStr,item,fname,noteStr,wStr
1337        Variable num,ii,refnum
1338       
1339        fname = "FlipperSaveState"
1340       
1341        // get a list of the "Condition" waves
1342        listStr=WaveList("Cond_*",";","")
1343        num=ItemsInList(listStr,";")
1344//      print listStr
1345
1346        // get the full path to the new file name before creating it
1347        fname = DoSaveFileDialog("Save the Flipper State Table",fname=fname,suffix=".itx")
1348        If(cmpstr(fname,"")==0)
1349                //user cancel, don't write out a file
1350                Close/A
1351                Abort "no data file was written"
1352        Endif
1353       
1354        Open/P=home refnum      as fname                // creates a new file, or overwrites the existing file 
1355        fprintf refNum,"IGOR\r"
1356                       
1357        // Save each of the cond waves, then be sure to add the DimLabels and Wave Note
1358        for(ii=0;ii<num;ii+=1)
1359                item = StringFromList(ii, listStr,";")
1360                Wave w = $item
1361                wStr=NameOfWave(w)
1362                noteStr = note(w)
1363               
1364                Write2DWaveToITX(w,refnum)
1365               
1366//              fprintf refNum,"X SetScale/P x 0,1,\"\", %s; SetScale/P y 0,1,\"\", %s; SetScale d 0,0,\"\", %s\r",wStr,wStr,wStr
1367                fprintf refNum,"X SetDimLabel 1, 0, 'UU_Trans?', %s\r",wStr
1368                fprintf refNum,"X SetDimLabel 1, 1, 'DU_Trans?', %s\r",wStr
1369                fprintf refNum,"X SetDimLabel 1, 2, 'DD_Trans?', %s\r",wStr
1370                fprintf refNum,"X SetDimLabel 1, 3, 'UD_Trans?', %s\r",wStr
1371                fprintf refNum,"X SetDimLabel 1, 4, 'Blocked?', %s\r",wStr
1372                fprintf refNum,"X SetDimLabel 1, 5, Pol_SM_FL, %s\r",wStr
1373                fprintf refNum,"X SetDimLabel 1, 6, Pol_SM, %s\r",wStr
1374                fprintf refNum,"X SetDimLabel 1, 7, 'Include?', %s\r",wStr
1375                fprintf refNum,"X Note %s, \"%s\"\r",wStr,noteStr
1376
1377                fprintf refNum,"\r"             //space between waves
1378        endfor 
1379
1380        // get a list of the CondCalc_ waves (2d, with dimlabels)
1381        listStr=WaveList("CondCalc_*",";","")
1382        num=ItemsInList(listStr,";")   
1383       
1384        // Save each of the DecayCalc waves, and add all of the proper dim labels
1385        for(ii=0;ii<num;ii+=1)
1386                item = StringFromList(ii, listStr,";")
1387                Wave w = $item
1388                wStr=NameOfWave(w)
1389
1390                Write2DWaveToITX(w,refnum)
1391               
1392//              fprintf refNum,"X SetScale/P x 0,1,\"\", %s; SetScale/P y 0,1,\"\", %s; SetScale d 0,0,\"\", %s\r",wStr,wStr,wStr
1393                fprintf refNum,"X SetDimLabel 1, 0, CR_UU, %s\r",wStr
1394                fprintf refNum,"X SetDimLabel 1, 1, err_CR_UU, %s\r",wStr
1395                fprintf refNum,"X SetDimLabel 1, 2, CR_DU, %s\r",wStr
1396                fprintf refNum,"X SetDimLabel 1, 3, err_CR_DU, %s\r",wStr
1397                fprintf refNum,"X SetDimLabel 1, 4, CR_DD, %s\r",wStr
1398                fprintf refNum,"X SetDimLabel 1, 5, err_CR_DD, %s\r",wStr
1399                fprintf refNum,"X SetDimLabel 1, 6, CR_UD, %s\r",wStr
1400                fprintf refNum,"X SetDimLabel 1, 7, err_CR_UD, %s\r",wStr
1401                fprintf refNum,"X SetDimLabel 1, 8, CR_Blocked, %s\r",wStr
1402                fprintf refNum,"X SetDimLabel 1, 9, err_CR_Blocked, %s\r",wStr
1403                fprintf refNum,"X SetDimLabel 1, 10, P_sm_f, %s\r",wStr
1404                fprintf refNum,"X SetDimLabel 1, 11, err_P_sm_f, %s\r",wStr
1405                fprintf refNum,"X SetDimLabel 1, 12, P_sm, %s\r",wStr
1406                fprintf refNum,"X SetDimLabel 1, 13, err_P_sm, %s\r",wStr
1407
1408                fprintf refNum,"\r"     
1409        endfor 
1410       
1411        // get a list of the CondCell_ waves (these are text, 1d)
1412        listStr=WaveList("CondCell_*",";","")
1413        num=ItemsInList(listStr,";")   
1414       
1415        // Save each of the DecayCalc waves, and add all of the proper dim labels
1416        for(ii=0;ii<num;ii+=1)
1417                item = StringFromList(ii, listStr,";")
1418                Wave w = $item
1419                wStr=NameOfWave(w)
1420
1421                Write1DTextWaveToITX(w,refnum)
1422
1423//              fprintf refnum,"X SetScale/P x 0,1,\"\", wStr; SetScale y 0,0,\"\", %s\r",wStr
1424
1425                fprintf refNum,"\r"     
1426        endfor 
1427
1428        Close refnum
1429
1430        SetDataFolder root:
1431        return(0)
1432end
1433
1434
1435
1436// restores the state of the Flipper panel
1437//
1438//      fname = "FlipperPanelSaveState.itx"
1439//
1440//
1441Function RestoreFlipperTable()
1442
1443        SetDataFolder root:Packages:NIST:Polarization:Cells:
1444       
1445        String listStr,item,fname,noteStr,wStr
1446        Variable num,ii,refnum
1447       
1448        fname = "FlipperPanelSaveState.itx"
1449        LoadWave/O/T fname
1450       
1451        SetDataFolder root:
1452        return(0)
1453End
Note: See TracBrowser for help on using the repository browser.