source: User Procedures/Indra 2/IN3_Calculations.ipf @ 13

Last change on this file since 13 was 13, checked in by ilavsky, 9 years ago

Added Indra calibration options, modified Plotting tool to handle Intensity calibrations and also modified ASCII import to handle the different choices on calibration.
Hopefully fixed Indra 2 calibration for weight calibration.

File size: 66.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=1.06
3
4//1.06 modified for weight calibration
5//1.05 FIxed bump to Compiler when no data selected in Data selection popup.
6//1.04 2/2013, JIL: modified to enable calibration per weight
7//1.03 2/2013 fixed Process next sample for changed control procedures.
8//1.02 4/2012 modified q shifts step to be 0.5e-6, 10x less than before.
9//1.01 2/2012 modified function Modified gauss to handle bad points appearing in this cycle in the data. Moved some button adn add option to fix PD range
10
11
12//***********************************************************************************************************************************
13//***********************************************************************************************************************************
14//***********************************************************************************************************************************
15//***********************************************************************************************************************************
16Function IN3_InputPanelButtonProc(B_Struct) : ButtonControl
17        STRUCT WMButtonAction &B_Struct
18
19        String ctrlName
20        ctrlName = B_Struct.ctrlName
21        string winNm=B_Struct.win
22
23        if(B_Struct.eventcode!=2)
24                return 1
25        endif
26        string oldDf=GetDataFolder(1)
27        setDataFolder root:Packages:Indra3
28
29        if (cmpstr(ctrlName,"SelectNextSampleAndProcess")==0)
30                SVAR DataFolderName=root:Packages:Indra3:DataFolderName
31                SVAR LastSample=root:Packages:Indra3:LastSample
32                String AllFolders=IR2P_GenStringOfFolders(winNm=winNm)
33                string ShortOldSaName = StringFromList(ItemsInList(LastSample, ":")-1, LastSample , ":")
34                variable CurrentFolder=WhichListItem(ShortOldSaName,AllFolders)
35                string ShortNewSaName = StringFromList(CurrentFolder+1, AllFolders , ";")
36                if(CurrentFolder>=0)
37                        DataFolderName = ReplaceString(ShortOldSaName, DataFolderName,ShortNewSaName)
38                        PopupMenu SelectDataFolder,mode=1,win=USAXSDataReduction, popvalue=ShortNewSaName
39                endif
40                DoWIndow/F USAXSDataReduction
41        endif
42
43        if (cmpstr(ctrlName,"ProcessData")==0 || cmpstr(ctrlName,"SelectNextSampleAndProcess")==0)
44                SVAR DataFolderName=    root:Packages:Indra3:DataFolderName
45                if(stringMatch(DataFolderName,"---"))
46                        setDataFolder oldDf
47                        abort
48                endif
49                IN3_LoadData()          //load data in the tool.
50                IN3_LoadBlank()
51                IN3_SetPDParameters()
52                        //      hopefully not needed any more IN2A_CleanWavesForSPECtroubles()                          //clean the waves with USAXS data for Spec timing troubles, if needed
53                IN3_GetMeasParam()     
54                IN3_RecalculateData(0)
55                IN3_GraphData()         //create graphs
56                IN3_ReturnCursorBack()
57                IN3_FitDefaultTop()
58                IN3_RecalculateData(4)
59                IN3_FitDefaultTop()
60                IN3_RecalculateData(1)
61                TabControl DataTabs , value= 0, win=USAXSDataReduction
62                NI3_TabPanelControl("",0)
63                DoWIndow/F USAXSDataReduction
64        endif
65        if (cmpstr(ctrlName,"Recalculate")==0)
66                IN3_RecalculateData(1) 
67                DoWIndow/F USAXSDataReduction
68        endif
69        if (cmpstr(ctrlName,"SaveResults")==0)
70                IN3_SaveData() 
71                NVAR UserSavedData=root:Packages:Indra3:UserSavedData
72                UserSavedData=1
73                IN3_FixSaveData()
74                DoWIndow/F USAXSDataReduction
75        endif
76        if (cmpstr(ctrlName,"RecoverDefault")==0)
77                NVAR SampleThickness
78                NVAR SampleThicknessBckp
79                SampleThickness = SampleThicknessBckp
80                IN3_RecalculateData(2)
81                DoWIndow/F USAXSDataReduction
82        endif
83        if (cmpstr(ctrlName,"RecoverDefaultBlnkVals")==0)
84                NVAR BlankWidthBckp
85                NVAR BlankWidth
86                BlankWidth = BlankWidthBckp
87                NVAR BlankFWHMBckp
88                NVAR BlankFWHM
89                BlankFWHM = BlankFWHMBckp
90                NVAR BlankMaximumBckp
91                NVAR BlankMaximum
92                BlankMaximum = BlankMaximumBckp
93                IN3_RecalculateData(2)
94                DoWIndow/F USAXSDataReduction
95        endif
96
97
98
99        if (cmpstr(ctrlName,"RemovePoint")==0)
100                if (strlen(CsrWave(A))==0)
101                        Abort "cursor A is not in the graph...nothing to do..."
102                endif
103                variable pointNumberToBeRemoved=xcsr(A)
104                if (strlen(CsrWave(B))!=0)
105                        DoAlert 0, "Remove cursor B [square] before proceeding"
106                else
107                        //this part should be done always
108                        Wave FixMe=CsrWaveRef(A)
109                        FixMe[pointNumberToBeRemoved]=NaN
110                        //if we need to fix more waves, it can be done here
111                endif
112                cursor/P A, $CsrWave(A), pointNumberToBeRemoved+1               //set the cursor to the right so we do not scare user
113                DoWIndow/F USAXSDataReduction
114        endif
115       
116        setDataFolder OldDf
117end
118
119//***********************************************************************************************************************************
120//***********************************************************************************************************************************
121//***********************************************************************************************************************************
122//***********************************************************************************************************************************
123
124static Function IN3_ReturnCursorBack()
125
126        string oldDf=GetDataFolder(1)
127        setDataFolder root:Packages:Indra3
128        Wave R_Int
129        Wave R_Qvec
130       
131        NVAR/Z OldStartQValueForEvaluation
132        if(NVAR_Exists(OldStartQValueForEvaluation))
133                Cursor /P /W=RcurvePlotGraph  A  R_Int  round(BinarySearchInterp(R_Qvec, OldStartQValueForEvaluation ))
134        endif
135
136        setDataFolder OldDf
137
138end
139//***********************************************************************************************************************************
140//***********************************************************************************************************************************
141//***********************************************************************************************************************************
142//***********************************************************************************************************************************
143static Function IN3_FixSaveData()
144
145                //fix display in the panel to reflect saved data...
146                NVAR UserSavedData=root:Packages:Indra3:UserSavedData
147                if(!UserSavedData)
148                        Button SaveResults fColor=(65280,0,0), win=USAXSDataReduction
149                        TitleBox SavedData pos={200,135}, title="  Data   NOT   saved  ", fColor=(0,0,0), frame=1,labelBack=(65280,0,0), win=USAXSDataReduction
150                else
151                        Button SaveResults , win=USAXSDataReduction, fColor=(47872,47872,47872)
152                        TitleBox SavedData pos={200,135}, title="  Data   are   saved  ", fColor=(0,0,0),labelBack=(47872,47872,47872),  frame=2, win=USAXSDataReduction
153                endif
154end
155//***********************************************************************************************************************************
156//***********************************************************************************************************************************
157//***********************************************************************************************************************************
158//***********************************************************************************************************************************
159
160static Function IN3_GetMeasParam()              //sets various spray parameters
161
162
163        string oldDf=GetDataFolder(1)
164        setDataFolder root:Packages:Indra3
165
166        SVAR SpecCommand
167        NVAR PhotoDiodeSize
168        NVAR Wavelength
169        NVAR SlitLength
170        NVAR NumberOfSteps
171        NVAR SDDistance
172        SVAR MeasurementParameters
173       
174        string specCommandSeparated= ReduceSpaceRunsInString(SpecCommand,1)
175        if (!cmpstr(SpecCommandSeparated[0,0]," "))
176                SpecCommandSeparated = SpecCommandSeparated[1,inf]                                              // remove any leading space
177        endif
178        SpecCommandSeparated = ChangePartsOfString(SpecCommandSeparated," ",";")                // one space is name separator
179
180        //      Following macro calls are know  to me
181        //      13 items: uascan motor start center finish minstep dy0 SDD_mm ay0 SAD_mm exponent intervals time.... new slit smeared macro with AY movement
182        //      14 items: sbuascan motor start center finish minstep dy0 asrp SDD_mm ay0 SAD_mm exponent intervals time.... old slit smeared macro before AY movement
183       
184        if (ItemsInList(SpecCommandSeparated)==13)
185                SDDistance=str2num(StringFromList(7,SpecCommandSeparated))
186        endif
187        if (ItemsInList(SpecCommandSeparated)==14)
188                SDDistance=str2num(StringFromList(8,SpecCommandSeparated))
189        endif
190        Variable ScanSteps=str2num(StringFromList(ItemsInList(SpecCommandSeparated)-2,SpecCommandSeparated))
191//fix for mono communication failure
192        if(numtype(NumberByKey("DCM_energy",MeasurementParameters,"="))!=0)
193                MeasurementParameters=ReplaceStringByKey("DCM_energy",MeasurementParameters,num2str(12),"=")
194                print "Warning>>>>  Nan found as energy for monochromator. Set to default 12keV. Change in IN3_GetMeasParam() in IN3_Calcualtions.ipf is needed"
195        endif
196
197
198        wavelength=12.398424437/NumberByKey("DCM_energy",MeasurementParameters,"=")
199        SlitLength=0.5*((4*pi)/wavelength)*sin(PhotoDiodeSize/(2*SDDistance))
200        NumberOfSteps=ScanSteps
201
202        MeasurementParameters=ReplaceStringByKey("Wavelength",MeasurementParameters,num2str(wavelength),"=")
203        MeasurementParameters=ReplaceStringByKey("SlitLength",MeasurementParameters,num2str(SlitLength),"=")
204        MeasurementParameters=ReplaceStringByKey("NumberOfSteps",MeasurementParameters,num2str(ScanSteps),"=")
205        MeasurementParameters=ReplaceStringByKey("SDDistance",MeasurementParameters,num2str(SDDistance),"=")
206       
207        IN2G_AppendNoteToAllWaves("Wavelength",num2str(wavelength))
208        IN2G_AppendNoteToAllWaves("SlitLength",num2str(SlitLength))
209        IN2G_AppendNoteToAllWaves("NumberOfSteps",num2str(ScanSteps))
210        IN2G_AppendNoteToAllWaves("SDDistance",num2str(SDDistance))
211
212        setDataFolder OldDf
213
214
215end
216//***********************************************************************************************************************************
217//***********************************************************************************************************************************
218//***********************************************************************************************************************************
219//***********************************************************************************************************************************
220
221static Function IN3_SetPDParameters()                           //setup PD parameters
222       
223        string oldDf=GetDataFolder(1)
224        setDataFolder root:Packages:Indra3
225       
226        SVAR UPD=UPDParameters                                          //define the global holding places
227        NVAR UPD_DK1=root:Packages:Indra3:UPD_DK1
228        NVAR UPD_DK2=root:Packages:Indra3:UPD_DK2
229        NVAR UPD_DK3=root:Packages:Indra3:UPD_DK3
230        NVAR UPD_DK4=root:Packages:Indra3:UPD_DK4
231        NVAR UPD_DK5=root:Packages:Indra3:UPD_DK5
232        NVAR UPD_G1=root:Packages:Indra3:UPD_G1
233        NVAR UPD_G2=root:Packages:Indra3:UPD_G2
234        NVAR UPD_G3=root:Packages:Indra3:UPD_G3
235        NVAR UPD_G4=root:Packages:Indra3:UPD_G4
236        NVAR UPD_G5=root:Packages:Indra3:UPD_G5
237        NVAR UPD_Vfc=root:Packages:Indra3:UPD_Vfc
238        NVAR UPD_DK1Err=root:packages:Indra3:UPD_DK1Err
239        NVAR UPD_DK2Err=root:packages:Indra3:UPD_DK2Err
240        NVAR UPD_DK3Err=root:packages:Indra3:UPD_DK3Err
241        NVAR UPD_DK4Err=root:packages:Indra3:UPD_DK4Err
242        NVAR UPD_DK5Err=root:packages:Indra3:UPD_DK5Err
243
244        UPD_Vfc =  NumberByKey("Vfc", UPD,"=")                                          //put the numbers in there
245        UPD_DK1=NumberByKey("Bkg1", UPD,"=")
246        UPD_G1=NumberByKey("Gain1", UPD,"=")
247        UPD_DK2=NumberByKey("Bkg2", UPD,"=")
248        UPD_G2=NumberByKey("Gain2", UPD,"=")
249        UPD_DK3=NumberByKey("Bkg3", UPD,"=")
250        UPD_G3=NumberByKey("Gain3", UPD,"=")
251        UPD_DK4=NumberByKey("Bkg4", UPD,"=")
252        UPD_G4=NumberByKey("Gain4", UPD,"=")
253        UPD_DK5=NumberByKey("Bkg5", UPD,"=")
254        UPD_G5=NumberByKey("Gain5", UPD,"=")
255        UPD_DK1Err=NumberByKey("Bkg1Err", UPD,"=")
256        UPD_DK2Err=NumberByKey("Bkg2Err", UPD,"=")
257        UPD_DK3Err=NumberByKey("Bkg3Err", UPD,"=")
258        UPD_DK4Err=NumberByKey("Bkg4Err", UPD,"=")
259        UPD_DK5Err=NumberByKey("Bkg5Err", UPD,"=")
260        if (UPD_DK1Err<=0)
261                UPD_DK1Err=1
262        endif
263        if (UPD_DK2Err<=0)
264                UPD_DK2Err=1
265        endif
266        if (UPD_DK3Err<=0)
267                UPD_DK3Err=1
268        endif
269        if (UPD_DK4Err<=0)
270                UPD_DK4Err=1
271        endif
272        if (UPD_DK5Err<=0)
273                UPD_DK5Err=1
274        endif
275
276        setDataFolder OldDf
277
278end
279//***********************************************************************************************************************************
280//***********************************************************************************************************************************
281//***********************************************************************************************************************************
282//***********************************************************************************************************************************
283static Function IN3_LoadData()
284
285        string oldDf=GetDataFolder(1)
286        setDataFolder root:Packages:Indra3
287       
288        //First Kill all ecistsing waves
289        DoWindow RcurvePlotGraph
290        if(V_Flag)
291                DoWindow/K RcurvePlotGraph
292        endif
293        String ListOfWaves  = DataFolderDir (2)[6,inf]
294        variable i
295        For(i=0;i<ItemsInList(ListOfWaves,",");i+=1)
296                Wave/Z tempWv=$(StringFromList(i, ListOfWaves,","))
297                KillWaves/Z tempWv
298        endfor
299       
300                SVAR LastSample=root:Packages:Indra3:LastSample
301                SVAR DFloc=root:Packages:Indra3:DataFolderName
302                if (cmpstr(DFloc,"---")==0 ||strlen(DFloc)<1)
303                        abort
304                endif
305                LastSample = DFloc
306                Wave/Z OrigAR_encoder=$(DFloc+"AR_encoder")
307                if(!WaveExists(OrigAR_encoder))
308                        return 0
309                endif
310                Duplicate/O OrigAR_encoder, AR_encoder
311                Wave OrigPD_range=$(DFloc+"PD_range")
312                Duplicate/O OrigPD_range, PD_range
313                Wave OrigUSAXS_PD=$(DFloc+"USAXS_PD")
314                Duplicate/O OrigUSAXS_PD, USAXS_PD
315                Wave OrigMeasTime=$(DFloc+"MeasTime")
316                Duplicate/O OrigMeasTime, MeasTime
317                Wave OrigMonitor=$(DFloc+"Monitor")
318                Duplicate/O OrigMonitor, Monitor
319                Wave/Z OringI0_gain=$(DFloc+"I0_gain")
320                if(WaveExists(OringI0_gain))
321                        Duplicate/O OringI0_gain, I0_gain
322                endif
323
324                SVAR OrigSpecCommand =$(DFloc+"SpecCommand")
325                SVAR/Z OrigSpecMotors =$(DFloc+"SpecMotors")
326                SVAR OrigSpecSourceFileName =$(DFloc+"SpecSourceFileName")
327                SVAR OrigSpecComment =$(DFloc+"SpecComment")
328                SVAR OrigMeasurementParameters =$(DFloc+"MeasurementParameters")
329                SVAR OrigUPDParameters =$(DFloc+"UPDParameters")
330                SVAR OrigPathToRawData =$(DFloc+"PathToRawData")
331                string/g SpecCommand = OrigSpecCommand
332                string/g SpecSourceFileName = OrigSpecSourceFileName
333                string/g SpecComment = OrigSpecComment
334                string/g MeasurementParameters = OrigMeasurementParameters
335                string/g UPDParameters = OrigUPDParameters
336                string/g PathToRawData = OrigPathToRawData
337                SVAR userFriendlySamplename = root:Packages:Indra3:userFriendlySamplename
338                userFriendlySamplename = OrigSpecComment
339               
340                SVAR Parameters=root:Packages:Indra3:ListOfASBParameters
341                Parameters=ReplaceStringByKey("Sample",Parameters,DFloc,"=")            //write results into ASBparameters
342
343                string IsItSBUSAXS=StringByKey("SPECCOMMAND", note(OrigAR_encoder), "=")[0,7]                   //find out if this is SBUSAXS
344                string Calibrate
345                if (cmpstr(IsItSBUSAXS,"sbuascan")==0)                          //SBUSAXS, do not let user to select USAXS calibration
346                        Calibrate="SBUSAXS;"
347                else                                                                                                                                                   
348                        Calibrate="USAXS;"                              //and if it is USAXS data, do not let user select SBUSAXS calibration
349                endif
350                Parameters=ReplaceStringByKey("Calibrate",Parameters,Calibrate,"=")
351                NVAR SampleThickness
352                SampleThickness=NumberByKey("thickness", OrigMeasurementParameters,"=")
353                if(SVAR_Exists(OrigSpecMotors))
354                        string/g SpecMotors = OrigSpecMotors
355                        NVAR BeamExposureArea
356                        BeamExposureArea=NumberByKey("uslitverap", SpecMotors,":")* NumberByKey("uslithorap", SpecMotors,":")
357                endif
358                NVAR SampleThicknessBckp
359                SampleThicknessBckp = SampleThickness
360                //rezero some old stuff here...
361                NVAR SampleQOffset= root:Packages:Indra3:SampleQOffset
362                SampleQOffset=0
363                NVAR DisplayPeakCenter=root:Packages:Indra3:DisplayPeakCenter
364                DisplayPeakCenter=1
365                NVAR DisplayAlignSaAndBlank=root:Packages:Indra3:DisplayAlignSaAndBlank
366                DisplayAlignSaAndBlank=0
367                NVAR Qmin = root:Packages:Indra3:MSAXSStartPoint
368                NVAR Qmax=root:Packages:Indra3:MSAXSEndPoint
369//              Qmin=0
370//              Qmax=0
371                NVAR UserSavedData
372                UserSavedData=0
373                IN3_FixSaveData()
374        setDataFolder OldDf
375end
376
377//***********************************************************************************************************************************
378//***********************************************************************************************************************************
379//***********************************************************************************************************************************
380//***********************************************************************************************************************************
381//***********************************************************************************************************************************
382//***********************************************************************************************************************************
383static Function IN3_LoadBlank()
384        string oldDf=GetDataFolder(1)
385        setDataFolder root:Packages:Indra3
386       
387        NVAR IsBlank  = root:Packages:Indra3:IsBlank
388
389        if(!IsBlank)
390                SVAR BlankName = root:Packages:Indra3:BlankName
391                if(strlen(BlankName)<4)
392                        abort "Error, select first the Blank name - if none available, create one first"
393                endif
394                Wave BL_R_IntL = $(BlankName+"Blank_R_Int")
395                Wave BL_R_errorL = $(BlankName+"Blank_R_error")
396                Wave BL_R_QvecL = $(BlankName+"Blank_R_Qvec")
397                Duplicate/O BL_R_IntL, BL_R_Int
398                Duplicate/O BL_R_errorL, BL_R_error
399                Duplicate/O BL_R_QvecL, BL_R_Qvec
400                SVAR Parameters=ListOfASBParameters
401                Parameters=ReplaceStringByKey("Blank",Parameters,BlankName,"=")
402                NVAR BlankFWHM
403                NVAR BlankMaximum
404                NVAR BlankWidth
405                NVAR BlankWidthBckp
406                NVAR BlankFWHMBckp
407                NVAR BlankMaximumBckp
408                NVAR OrigBlankFWHM = $(BlankName+"PeakWidth")
409                NVAR OrigBlankMaximum = $(BlankName+"MaximumIntensity")
410                BlankFWHM= OrigBlankFWHM
411                BlankMaximum=OrigBlankMaximum
412                BlankWidth=OrigBlankFWHM*3600   //in arc seconds
413                BlankWidthBckp = BlankWidth
414                BlankFWHMBckp = BlankFWHM
415                BlankMaximumBckp = BlankMaximum
416        endif
417
418        setDataFolder OldDf     
419end
420//***********************************************************************************************************************************
421//***********************************************************************************************************************************
422//***********************************************************************************************************************************
423//***********************************************************************************************************************************
424//***********************************************************************************************************************************
425//***********************************************************************************************************************************
426
427//*****************************************************************************************************************
428//*****************************************************************************************************************
429//*****************************************************************************************************************
430//*****************************************************************************************************************
431//*****************************************************************************************************************
432
433
434
435static Function IN3_GraphData()
436
437        string oldDf=GetDataFolder(1)
438        setDataFolder root:Packages:Indra3
439        DoWindow RcurvePlotGraph
440        if(V_Flag)
441                DoWindow/K RcurvePlotGraph
442        endif
443        IN3_RcurvePlot()
444        IN3_DisplayRightSubwindow()
445        IN3_FixDispControlsInRcurvePlot()
446
447       
448
449        setDataFolder OldDf
450
451end
452//***********************************************************************************************************************************
453//***********************************************************************************************************************************
454//***********************************************************************************************************************************
455//***********************************************************************************************************************************
456Function IN3_DisplayRightSubwindow()
457
458        NVAR DisplayPeakCenter =root:Packages:Indra3:DisplayPeakCenter
459        NVAR DisplayAlignSaAndBlank=root:Packages:Indra3:DisplayAlignSaAndBlank
460
461        String ExistingSubWindows=ChildWindowList("RcurvePlotGraph")
462        if(stringmatch(ExistingSubWindows,"*PeakCenter*"))
463                KillWindow RcurvePlotGraph#PeakCenter
464        endif
465        if(stringmatch(ExistingSubWindows,"*AlignSampleAndBlank*"))
466                KillWindow RcurvePlotGraph#AlignSampleAndBlank
467        endif
468       
469        if(DisplayPeakCenter)
470                IN3_PeakCenter()
471        elseif(DisplayAlignSaAndBlank)
472                IN3_AlignSampleAndBlank()
473        endif
474end
475
476//*****************************************************************************************************************
477//*****************************************************************************************************************
478//*****************************************************************************************************************
479//*****************************************************************************************************************
480//*****************************************************************************************************************
481
482
483//checbox control procedure
484Function IN3_MainPanelCheckBox(ctrlName,checked) : CheckBoxControl
485        String ctrlName
486        Variable checked
487
488        NVAR CalculateWeight=root:Packages:Indra3:CalculateWeight
489        NVAR CalculateThickness=root:Packages:Indra3:CalculateThickness
490        NVAR CalibrateToWeight=root:Packages:Indra3:CalibrateToWeight
491        NVAR CalibrateToVolume=root:Packages:Indra3:CalibrateToVolume
492        NVAR CalibrateArbitrary=root:Packages:Indra3:CalibrateArbitrary
493
494       
495        if (cmpstr("IsBlank",ctrlName)==0)
496                NVAR IsBlank=root:Packages:Indra3:IsBlank
497                PopupMenu SelectBlankFolder, disable = IsBlank
498               
499        endif
500        if (cmpstr("RecalculateAutomatically",ctrlName)==0)
501
502        endif
503        NVAR CalculateWeight=root:Packages:Indra3:CalculateWeight
504        NVAR CalculateThickness=root:Packages:Indra3:CalculateThickness
505        if (cmpstr("CalculateThickness",ctrlName)==0)
506                SetVariable SampleThickness, win=USAXSDataReduction, noedit=CalculateThickness, frame=!CalculateThickness
507                SetVariable SampleLinAbsorption, win=USAXSDataReduction, noedit=!CalculateThickness, frame=CalculateThickness
508                SetVariable SampleFilledFraction, win=USAXSDataReduction, noedit=!CalculateThickness, frame=CalculateThickness
509                IN3_CalculateSampleThickness()
510        endif
511        if (cmpstr("CalculateWeight",ctrlName)==0)
512                SetVariable SampleWeightInBeam, win=USAXSDataReduction, noedit=CalculateWeight, frame=!CalculateWeight
513                SetVariable SampleDensity, win=USAXSDataReduction, frame=CalculateWeight
514                SetVariable SampleThickness, win=USAXSDataReduction, noedit=CalculateThickness, frame=!CalculateThickness
515                SetVariable BeamExposureArea, win=USAXSDataReduction, noedit=!CalculateWeight, frame=CalculateWeight
516                IN3_CalculateSampleThickness()
517        endif
518
519        if (stringmatch("CalibrateToVolume",ctrlName))
520                if(checked)
521                        CalibrateToWeight = 0
522                        CalibrateArbitrary = 0
523                else
524                        if((CalibrateToWeight+CalibrateArbitrary)!=1)
525                                CalibrateArbitrary = 1
526                                CalibrateToWeight = 0
527                        endif
528                endif
529                NI3_TabPanelControl("",0)
530                SetVariable BeamExposureArea, win=USAXSDataReduction, noedit=!(CalculateWeight&&CalibrateToWeight), frame=!CalculateWeight
531        endif
532       
533        if(stringmatch("CalibrateToWeight",ctrlName) )
534                if(checked)
535                        CalibrateToVolume = 0
536                        CalibrateArbitrary = 0
537                else
538                        if((CalibrateToVolume+CalibrateArbitrary)!=1)
539                                CalibrateArbitrary = 0
540                                CalibrateToVolume = 1
541                        endif
542                endif
543                NI3_TabPanelControl("",0)
544                SetVariable BeamExposureArea, win=USAXSDataReduction, noedit=!(CalculateWeight&&CalibrateToWeight), frame=!CalculateWeight
545        endif
546
547        if(stringmatch("CalibrateArbitrary",ctrlName) )
548                if(checked)
549                        CalibrateToVolume = 0
550                        CalibrateToWeight = 0
551                else
552                        if((CalibrateToVolume+CalibrateToWeight)!=1)
553                                CalibrateToWeight = 0
554                                CalibrateToVolume = 1
555                        endif
556                endif
557                NI3_TabPanelControl("",0)
558                SetVariable BeamExposureArea, win=USAXSDataReduction, noedit=!(CalculateWeight&&CalibrateToWeight), frame=!CalculateWeight
559        endif
560       
561        if (cmpstr("UseMSAXSCorrection",ctrlName)==0)
562                NI3_TabPanelControl("",4)
563                //IN3_CalculateMSAXSCorrection()
564                //IN3_CalculateTransmission(1)
565                //IN3_CalculateSampleThickness()
566                IN3_RecalculateData(3)
567        endif
568       
569
570end
571//*****************************************************************************************************************
572//*****************************************************************************************************************
573//*****************************************************************************************************************
574Function IN3_COlorizeButton()
575        DOWINDOW RcurvePlotGraph
576        IF(V_FLag)
577                NVAR UseLorenz = root:Packages:Indra3:UseLorenz
578                NVAR UseModifiedGauss = root:Packages:Indra3:UseModifiedGauss
579                NVAR UseGauss = root:Packages:Indra3:UseGauss
580                if(UseModifiedGauss)
581                        Button FitModGauss,win=RcurvePlotGraph ,fColor=(16386,65535,16385)
582                else
583                        Button FitModGauss,win=RcurvePlotGraph ,fColor=(0,0,0)
584                endif
585                if(UseGauss)
586                        Button FitGauss,win=RcurvePlotGraph ,fColor=(16386,65535,16385)
587                else
588                        Button FitGauss,win=RcurvePlotGraph ,fColor=(0,0,0)
589                endif
590                if(UseLorenz)
591                        Button FitLorenz,win=RcurvePlotGraph ,fColor=(16386,65535,16385)
592                else
593                        Button FitLorenz,win=RcurvePlotGraph ,fColor=(0,0,0)
594                endif
595        endif
596end
597
598
599//*****************************************************************************************************************
600//*****************************************************************************************************************
601
602
603static Function IN3_RcurvePlot()
604        PauseUpdate; Silent 1           // building window...
605        String fldrSav0= GetDataFolder(1)
606        SetDataFolder root:Packages:Indra3:
607        Wave R_Int
608        Wave R_Qvec
609        NVAR IsBlank = root:Packages:Indra3:IsBlank
610
611//      Wave fit_PD_Intensity
612//      Wave fitX_PD_Intensity
613//      Wave R_error
614//      Wave AR_encoder
615        Wave/Z PeakFitWave
616        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
617        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
618       
619        //create main plot with R curve data
620        Display/K=1 /W=(300,36.5,900,500) R_Int vs R_Qvec as "Rocking curve plot"
621        DoWindow/C RcurvePlotGraph
622        AutoPositionWindow/M=0/R=USAXSDataReduction  RcurvePlotGraph
623//      AppendToGraph fit_PD_Intensity vs fitX_PD_Intensity
624        //modify the displayed waves
625        ModifyGraph mode(R_Int)=4
626        ModifyGraph rgb(R_Int)=(65280,0,0)
627        ModifyGraph msize(R_Int)=2
628        ModifyGraph log=1
629        ModifyGraph axOffset(bottom)=0.888889
630        ModifyGraph lblPos(left)=60,lblPos(bottom)=51
631        ModifyGraph lblLatPos(left)=-4,lblLatPos(bottom)=-2
632        Label left "Intensity"
633        Label bottom "Q [A\\S-1\\M]"
634        SetAxis bottom 1e-05, R_Qvec[numpnts(R_Qvec)-1]
635        ShowInfo
636        ControlBar 50
637        SetVariable SampleTransmission,pos={180,5},size={300,22},title="Sample transmission (peak max)"
638        SetVariable SampleTransmission,font="Times New Roman",fSize=14,proc=IN3_ParametersChanged
639        SetVariable SampleTransmission,limits={0,inf,0.005},variable= root:Packages:Indra3:SampleTransmissionPeakToPeak
640
641        SetVariable SampleAngleOffset,pos={180,25},size={300,22},title="Q offset           "
642        SetVariable SampleAngleOffset,font="Times New Roman",fSize=14,proc=IN3_ParametersChanged
643        SetVariable SampleAngleOffset,limits={-inf,inf,0.5e-6},variable= root:Packages:Indra3:SampleQOffset
644
645        Button Recalculate,pos={150,25},size={90,20},font="Times New Roman",fSize=10,proc=IN3_InputPanelButtonProc,title="Recalculate", help={"Recalculate the data"}
646        Button RemovePoint,pos={250,25},size={90,20},font="Times New Roman",fSize=10,proc=IN3_InputPanelButtonProc,title="Remove pnt w/csr A", help={"Remove point with cursor A"}
647        Button FixGain,pos={250,3},size={90,20},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fix Gain w/c A"
648
649        CheckBox UseModifiedGauss title="Mod. Gauss",proc=IN3_RplotCheckProc
650        CheckBox UseModifiedGauss variable=root:Packages:Indra3:UseModifiedGauss,mode=1,pos={345,1}
651        CheckBox UseGauss title="Gauss",proc=IN3_RplotCheckProc
652        CheckBox UseGauss variable=root:Packages:Indra3:UseGauss,mode=1,pos={345,17}
653        CheckBox UseLorenz title="Lorenz",proc=IN3_RplotCheckProc
654        CheckBox UseLorenz variable=root:Packages:Indra3:UseLorenz,mode=1,pos={345,34}
655
656        Button FitModGauss,pos={425,3},size={80,18},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fit Mod. Gauss"
657        Button FitGauss,pos={515,3},size={80,18},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fit Gauss"
658        Button FitLorenz,pos={515,25},size={80,18},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fit Lorenz"
659
660        CheckBox DisplayPeakCenter title="Display Peak Fit",proc=IN3_RplotCheckProc
661        CheckBox DisplayPeakCenter variable=root:Packages:Indra3:DisplayPeakCenter,mode=1,pos={5,5}
662        CheckBox DisplayAlignSaAndBlank title="Display Align Sa and Blank",proc=IN3_RplotCheckProc, disable=IsBlank
663        CheckBox DisplayAlignSaAndBlank variable=root:Packages:Indra3:DisplayAlignSaAndBlank,mode=1,pos={5,25}
664//DisplayPeakCenter;DisplayAlignSaAndBlank
665        SetDrawLayer UserFront
666        IN3_COlorizeButton()
667        NVAR IsBlank=root:Packages:Indra3:IsBlank
668        if(!IsBlank)
669                Wave/Z BL_R_Int=root:Packages:Indra3:BL_R_Int
670                Wave/Z BL_R_error=root:Packages:Indra3:BL_R_error
671                Wave/Z BL_R_Qvec= root:Packages:Indra3:BL_R_Qvec
672                AppendToGraph BL_R_Int vs BL_R_Qvec
673                ModifyGraph rgb(BL_R_Int)=(0,0,0)
674                NVAR TrimDataStart=root:Packages:Indra3:TrimDataStart
675                NVAR TrimDataEnd=root:Packages:Indra3:TrimDataEnd
676                if(TrimDataStart>0)
677                        Cursor/P/W=RcurvePlotGraph A R_Int TrimDataStart       
678                endif
679                if(TrimDataEnd>0)
680                        Cursor/P/W=RcurvePlotGraph B R_Int TrimDataEnd 
681                endif
682        endif
683       
684
685        SetDataFolder fldrSav0
686End
687//***********************************************************************************************************************************
688//***********************************************************************************************************************************
689Function IN3_FixDispControlsInRcurvePlot()
690
691
692        NVAR DisplayPeakCenter = root:Packages:Indra3:DisplayPeakCenter
693        NVAR DisplayAlignSaAndBlank = root:Packages:Indra3:DisplayAlignSaAndBlank
694       
695        SetVariable SampleTransmission,win=RcurvePlotGraph, disable =DisplayPeakCenter
696        SetVariable SampleAngleOffset,win=RcurvePlotGraph, disable =DisplayPeakCenter
697
698        Button FitGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
699        Button FitModGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
700        Button FitLorenz,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
701
702        Button Recalculate,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
703        Button RemovePoint,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
704        Button FixGain,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
705
706        Checkbox UseModifiedGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
707        Checkbox UseGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
708        Checkbox UseLorenz,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
709
710end
711
712//*****************************************************************************************************************
713//*****************************************************************************************************************
714//*****************************************************************************************************************
715
716static Function IN3_PeakCenter()
717        PauseUpdate; Silent 1           // building window...
718        String fldrSav0= GetDataFolder(1)
719        SetDataFolder root:Packages:Indra3:
720        Wave R_Int
721        Wave R_Qvec
722        Wave fit_PD_Intensity
723//      Wave fitX_PD_Intensity
724//      Wave R_error
725        Wave AR_encoder
726        Wave/Z PeakFitWave
727        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
728        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
729       
730        //create main plot with R curve data
731        //create the other graph
732        Display/K=1/W=(0.431,0.03,0.8,0.399)/FG=(,GT,FR,)/PG=(,,PR,)/HOST=RcurvePlotGraph  PD_Intensity vs AR_encoder
733        AppendToGraph fit_PD_Intensity,PeakFitWave
734        //modify displayed waves
735        ModifyGraph mode(PD_Intensity)=3
736        ModifyGraph lSize(fit_PD_Intensity)=2
737        ModifyGraph lStyle(PeakFitWave)=3
738        ModifyGraph rgb(fit_PD_Intensity)=(0,0,52224),rgb(PeakFitWave)=(0,0,65280)
739        ModifyGraph nticks(bottom)=2
740        ModifyGraph lblMargin(left)=26,lblMargin(bottom)=1
741        ModifyGraph lblLatPos=-1
742        Label left "Intensity"
743        Label bottom "AR angle [deg]"
744        ErrorBars PD_Intensity Y,wave=(PD_Error,PD_Error)
745        variable center = (PeakCenterFitEndPoint + PeakCenterFitStartPoint)/2
746        variable start = max(center - 1.5 * (center - PeakCenterFitStartPoint),0)
747        variable end1 = min(center + 2 * (PeakCenterFitEndPoint-center),numpnts(AR_encoder))
748        SetAxis bottom AR_encoder[start],AR_encoder[end1]
749        Cursor/P A PD_Intensity PeakCenterFitStartPoint
750        Cursor/P B PD_Intensity PeakCenterFitEndPoint
751        RenameWindow #,PeakCenter
752        SetActiveSubwindow ##
753
754        SetDataFolder fldrSav0
755End
756//***********************************************************************************************************************************
757//***********************************************************************************************************************************
758//***********************************************************************************************************************************
759//***********************************************************************************************************************************
760//***********************************************************************************************************************************
761//***********************************************************************************************************************************
762//*****************************************************************************************************************
763//*****************************************************************************************************************
764//*****************************************************************************************************************
765
766static Function IN3_AlignSampleAndBlank()
767        PauseUpdate; Silent 1           // building window...
768        String fldrSav0= GetDataFolder(1)
769        SetDataFolder root:Packages:Indra3:
770       
771        NVAR IsBlank = root:Packages:Indra3:IsBlank
772        if(IsBlank)
773                return 0
774        endif
775        Wave R_Int
776        Wave R_Qvec
777        Wave R_Error
778//      Wave fit_PD_Intensity
779//      Wave fitX_PD_Intensity
780        Wave R_error
781        Wave AR_encoder
782        Wave PeakFitWave
783        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
784        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
785        Wave BL_R_Int
786        Wave BL_R_Qvec
787       
788        //create main plot with R curve data
789        //create the other graph
790        Display/K=1/W=(0.431,0.03,0.8,0.399)/FG=(,GT,FR,)/PG=(,,PR,)/HOST=RcurvePlotGraph  R_Int vs R_Qvec
791        AppendToGraph BL_R_Int vs BL_R_Qvec
792        //modify displayed waves
793        ModifyGraph mode(R_Int)=3
794        ModifyGraph rgb(BL_R_Int)=(0,0,0)
795        ModifyGraph lstyle(BL_R_Int)=3,lsize(BL_R_Int)=2
796        ModifyGraph nticks(bottom)=2
797        ModifyGraph lblMargin(left)=26,lblMargin(bottom)=1
798        ModifyGraph lblLatPos=-1
799        Label left "Intensity"
800        Label bottom "Q [A\S-1\M]"
801        ErrorBars R_Int Y,wave=(R_Error,R_Error)
802        variable center = (PeakCenterFitEndPoint + PeakCenterFitStartPoint)/2
803        variable start = max(center - 1.5 * abs(center - PeakCenterFitStartPoint),0)
804        variable end1 = min(center + 2.1 * abs(center - PeakCenterFitEndPoint),numpnts(AR_encoder))
805        SetAxis bottom R_Qvec[start],R_Qvec[end1]
806//      Cursor/P A R_Int PeakCenterFitStartPoint
807//      Cursor/P B R_Int PeakCenterFitEndPoint
808        RenameWindow #,AlignSampleAndBlank
809        SetActiveSubwindow ##
810
811        SetDataFolder fldrSav0
812End
813//***********************************************************************************************************************************
814//***********************************************************************************************************************************
815//***********************************************************************************************************************************
816//***********************************************************************************************************************************
817//***********************************************************************************************************************************
818//***********************************************************************************************************************************
819static Function IN3_AppendBlankToRPlot()
820        string oldDf=GetDataFolder(1)
821        setDataFolder root:Packages:Indra3
822       
823        NVAR IsBlank
824        if(!IsBlank)
825                Wave BL_R_Int
826                Wave BL_R_Qvec
827//              Wave BL_AR_encoder
828               
829                AppendToGraph/W=RcurvePlotGraph BL_R_Int vs BL_R_Qvec
830                ModifyGraph/W=RcurvePlotGraph rgb(BL_R_Int)=(0,0,0)
831
832//              AppendToGraph/W=RcurvePlotGraph#PeakCenter BL_R_Int vs BL_AR_encoder
833//              ModifyGraph/W=RcurvePlotGraph#PeakCenter rgb(BL_R_Int)=(0,0,0)
834               
835       
836        endif
837
838
839        setDataFolder OldDf     
840end
841//***********************************************************************************************************************************
842//***********************************************************************************************************************************
843//***********************************************************************************************************************************
844//***********************************************************************************************************************************
845//***********************************************************************************************************************************
846//***********************************************************************************************************************************
847
848//***************************************************************************************************************************************
849//***************************************************************************************************************************************
850//***************************************************************************************************************************************
851//***************************************************************************************************************************************
852//***************************************************************************************************************************************
853//***************************************************************************************************************************************
854
855Function IN3_GraphButtonProc(ctrlName) : ButtonControl
856        String ctrlName
857       
858        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
859        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
860        Wave AR_encoder=root:Packages:Indra3:AR_encoder
861        String AcsrWaveName = StringByKey("TNAME", CsrInfo(A , "RcurvePlotGraph#PeakCenter")  , ":" , ";")
862        String BcsrWaveName = StringByKey("TNAME", CsrInfo(B , "RcurvePlotGraph#PeakCenter")  , ":" , ";")
863        variable curX
864        if (!stringMatch(AcsrWaveName,"PD_Intensity"))
865                curX = xcsr(A , "RcurvePlotGraph#PeakCenter")
866                Cursor /W=RcurvePlotGraph#PeakCenter A, PD_Intensity, (BinarySearch(AR_encoder, curX ))
867        endif
868        if (!stringMatch(BcsrWaveName,"PD_Intensity"))
869                curX = xcsr(B, "RcurvePlotGraph#PeakCenter")
870                Cursor /W=RcurvePlotGraph#PeakCenter B, PD_Intensity, (BinarySearch(AR_encoder, curX )+1)
871        endif
872
873        if(stringMatch(ctrlName,"FixGain"))
874                if((strlen(csrInfo(A,"RcurvePlotGraph"))<1)||(!stringMatch(stringByKey("TNAME",csrinfo(A,"RcurvePlotGraph")),"R_Int")))
875                        DoAlert 0, "Cursor A not set or set on incorrect wave, should be on R_Int"
876                else
877                        Wave PD_range = root:Packages:Indra3:PD_range
878                        variable CurPDRange, curPntNum
879                        curPntNum=pcsr(A,"RcurvePlotGraph")
880                        CurPDRange=PD_range[curPntNum]
881                        Prompt CurPDRange, "Change the PD range for selected point"
882                        DoPrompt "Fix the PD range here", CurPDRange
883                        if(V_Flag)
884                                abort
885                        endif
886                        CurPDRange = round(CurPDRange)
887                        if(CurPDRange<1||CurPDRange>5)
888                                DoAlert 0, "PD range input is wrong, 1-5 and intergers possible only)"
889                        else
890                                PD_range[curPntNum]=CurPDRange
891                                IN3_RecalculateData(1) 
892                                DoWIndow/F USAXSDataReduction
893                        endif                   
894                endif
895               
896               
897        endif
898        if(stringMatch(ctrlName,"FitGauss"))
899                //get position of cursors from the right window and run fitting rouitne with gaussien
900                PeakCenterFitStartPoint=min(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
901                PeakCenterFitEndPoint=max(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
902                IN3_FitGaussTop("")
903                IN3_RecalculateData(1) 
904        endif
905        if(stringMatch(ctrlName,"FitModGauss"))
906                //get position of cursors from the right window and run fitting rouitne with gaussien
907                PeakCenterFitStartPoint=min(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
908                PeakCenterFitEndPoint=max(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
909                IN3_FitModGaussTop("")
910                IN3_RecalculateData(1) 
911        endif
912        if(stringMatch(ctrlName,"FitLorenz"))
913                //get position of cursors from the right window and run fitting rouitne with lorenzian
914                PeakCenterFitStartPoint=min(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
915                PeakCenterFitEndPoint=max(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
916                IN3_FitLorenzianTop("")
917                IN3_RecalculateData(1) 
918        endif
919End
920
921///**********************************************************************************************************
922//**********************************************************************************************************
923//**********************************************************************************************************
924
925Function IN3_FitGaussTop(ctrlname) : Buttoncontrol                      // calls the Gaussien fit
926        string ctrlname
927       
928        string oldDf=GetDataFolder(1)
929        setDataFolder root:Packages:Indra3
930
931        NVAR PeakCenterFitStartPoint
932        NVAR PeakCenterFitEndPoint
933
934        Wave PD_error
935        Wave Ar_encoder
936        Wave PD_Intensity
937        Make/O/N=200 PeakFitWave
938        DoWIndow RcurvePlotGraph
939        String ExistingSubWindows
940        if(V_Flag)
941                ExistingSubWindows=ChildWindowList("RcurvePlotGraph")
942        else
943                ExistingSubWindows=""
944        endif
945        if(stringmatch(ExistingSubWindows,"*PeakCenter*"))
946                getAxis/W=RcurvePlotGraph#PeakCenter /Q bottom
947                SetScale/I x V_min, V_max,"", PeakFitWave
948        else
949                variable center = (PeakCenterFitStartPoint + PeakCenterFitEndPoint)/2
950                variable start = max(0,center - (center -PeakCenterFitStartPoint) *3 )
951                variable end1 = min(center + (PeakCenterFitEndPoint-center) *3, numpnts(Ar_encoder) )
952                SetScale/I x Ar_encoder[start], Ar_encoder[end1],"", PeakFitWave
953        endif
954        K0=0
955//      if(strlen(CsrInfo(A, "RcurvePlot")) <1  || strlen(CsrInfo(B, "RcurvePlot"))<1)
956//              return 0
957//      endif
958        CurveFit/Q/H="1000"  gauss PD_Intensity [PeakCenterFitStartPoint,PeakCenterFitEndPoint]  /X=Ar_encoder /D /W=PD_error /I=1      //Gauss
959//      print "Fitted Gaussian between points  "+num2str(PeakCenterFitStartPoint)+"   and    "+num2str(PeakCenterFitEndPoint)+"    reached Chi-squared/numpoints    " +num2str(V_chisq/(PeakCenterFitEndPoint-PeakCenterFitStartPoint))
960//      string ModifyWave
961//      ModifyWave="fit_"+WaveName("",0,1)                                              //new wave with the lorenzian fit
962//      ModifyGraph /W=RcurvePlot lsize(fit_PD_Intensity)=3, rgb(fit_PD_intensity)=(0,15872,65280)
963        NVAR BeamCenter
964        NVAR MaximumIntensity
965        NVAR PeakWidth         
966        NVAR PeakWidthArcSec           
967        Variable BeamCenterError, MaximumIntensityError, PeakWidthError
968        Wave W_coef
969        Wave W_sigma
970//      Wave FitResiduals
971//      FitResiduals= ((W_coef[0]+W_coef[1]*exp(-((Ar_encoder[p]-W_coef[2])/W_coef[3])^2)) - PD_Intensity[p])/PD_error[p]
972//      FitResiduals[0,PeakCenterFitStartPoint-1]=NaN
973//      FitResiduals[PeakCenterFitEndPoint+1,inf]=NaN
974        PeakFitWave= W_coef[0]+W_coef[1]*exp(-((x-W_coef[2])/W_coef[3])^2)
975        BeamCenter=W_coef[2]
976        BeamCenterError=W_sigma[2]
977        MaximumIntensity=W_coef[1]
978        MaximumIntensityError=W_sigma[1]
979        PeakWidth = 2*(sqrt(ln(2)))*abs(W_coef[3])
980        PeakWidthArcSec = PeakWidth*3600
981        PeakWidthError=2*(sqrt(ln(2)))*abs(W_sigma[3])
982        Variable GaussPeakWidth=2*(sqrt(ln(2)))*abs(W_coef[3])                  // properly fixed by now.
983        Variable GaussPeakWidthError=2*(sqrt(ln(2)))*abs(W_sigma[3])
984        string BmCnterStr
985        Sprintf BmCnterStr, "%8.5f", BeamCenter
986        String Width="\Z12FWHM   "+num2str(3600*GaussPeakWidth)+" +/- "+num2str(3600*GaussPeakWidthError)+"  arc-sec"
987        Width+="\rMax       "+num2str(MaximumIntensity)+"   +/-  "+num2str(MaximumIntensityError)
988        Width+="\rBm Cntr  "+BmCnterStr+"  +/-  "+num2str(BeamCenterError)+"  deg."
989        DoWindow RcurvePlotGraph
990        if(V_Flag)
991                Textbox/W=RcurvePlotGraph/K/N=text1
992                TextBox/W=RcurvePlotGraph/N=text1/F=0/B=2/X=63.96/Y=89.45 Width
993        endif
994//      ModifyGraph rgb($ModifyWave)=(0,15872,65280)
995//      KillWaves W_WaveList
996        Wave/Z R_Qvec
997        if(WaveExists(R_Qvec))
998                string ListOfWaveNames = "R_Qvec;R_Int;R_Error;Qvec;"
999                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"PeakFitFunction","Gauss")
1000                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenter",num2str(BeamCenter))
1001                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensity",num2str(MaximumIntensity))
1002                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM",num2str(PeakWidth*3600))
1003                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenterError",num2str(BeamCenterError))
1004                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensityError",num2str(MaximumIntensityError))
1005                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM_Error",num2str(PeakWidthError*3600))
1006        endif
1007        setDataFolder OldDf
1008
1009End
1010///**********************************************************************************************************
1011///**********************************************************************************************************
1012///**********************************************************************************************************
1013///**********************************************************************************************************
1014///**********************************************************************************************************
1015
1016Function IN3_FitDefaultTop()
1017        NVAR UseModifiedGauss
1018        NVAR UseGauss
1019        NVAR UseLorenz
1020
1021        if(UseModifiedGauss)
1022                IN3_FitModGaussTop("") 
1023        elseif(UseGauss)
1024                IN3_FitGaussTop("")
1025        elseif(UseLorenz)
1026                IN3_FitLorenzianTop("")
1027        else
1028                Abort "No default fiting method selected, please restart the tool"
1029       
1030        endif
1031end
1032//**********************************************************************************************************
1033//**********************************************************************************************************
1034///**********************************************************************************************************
1035///**********************************************************************************************************
1036
1037Function IN3_FitModGaussTop(ctrlname) : Buttoncontrol                   // calls the Gaussien fit
1038        string ctrlname
1039       
1040        string oldDf=GetDataFolder(1)
1041        setDataFolder root:Packages:Indra3
1042
1043        NVAR PeakCenterFitStartPoint
1044        NVAR PeakCenterFitEndPoint
1045
1046        Wave PD_error
1047        Wave Ar_encoder
1048        Wave PD_Intensity
1049        Make/O/N=200 PeakFitWave
1050        DoWIndow RcurvePlotGraph
1051        String ExistingSubWindows
1052        if(V_Flag)
1053                ExistingSubWindows=ChildWindowList("RcurvePlotGraph")
1054        else
1055                ExistingSubWindows=""
1056        endif
1057        if(stringmatch(ExistingSubWindows,"*PeakCenter*"))
1058                getAxis/W=RcurvePlotGraph#PeakCenter /Q bottom
1059                SetScale/I x V_min, V_max,"", PeakFitWave
1060        else
1061                variable center = (PeakCenterFitStartPoint + PeakCenterFitEndPoint)/2
1062                variable start = max(0,center - (center -PeakCenterFitStartPoint) *3 )
1063                variable end1 = min(center + (PeakCenterFitEndPoint-center) *3, numpnts(Ar_encoder) )
1064                SetScale/I x Ar_encoder[start], Ar_encoder[end1],"", PeakFitWave
1065        endif
1066//      K0=0
1067        MAKE/O/N=4 W_coef
1068        wavestats/Q PD_Intensity
1069        //workaround problems 2012/01, one large point appears ...
1070        Duplicate/Free PD_Intensity, tempPDInt
1071        tempPDInt[V_maxloc]=Nan
1072        wavestats/Q tempPDInt
1073        W_Coef[0]=V_max
1074        W_coef[1]=Ar_encoder[V_maxloc]
1075        FindLevels /N=5 /P/Q  tempPDInt, V_max/2
1076        wave W_FindLevels
1077        variable startPointL, endPointL
1078        if(Numpnts(W_FindLevels)==2)
1079                startPointL=W_FindLevels[0]
1080                endPointL=W_FindLevels[1]
1081        elseif(Numpnts(W_FindLevels)>2)
1082                FindLevel /P/Q W_FindLevels, V_maxloc
1083                startPointL = W_FindLevels[floor(V_LevelX)]
1084                endPointL = W_FindLevels[ceil(V_LevelX)]
1085        endif
1086        W_coef[2] = abs(Ar_encoder[startPointL] - Ar_encoder[endPointL])/(2*(2*ln(2))^0.5)
1087        W_coef[3]=2
1088        //W[3]>1                //modified 7/6/2010 per request from Fan. K3 coefficient needs to be large enough to avoid weird Peak shapes.
1089        Make/O/T/N=1 T_Constraints
1090        T_Constraints[0] = {"K3>1.3"}
1091        FuncFit/Q/NTHR=0  IN3_ModifiedGauss W_coef PD_Intensity [PeakCenterFitStartPoint,PeakCenterFitEndPoint]  /X=Ar_encoder /D /W=PD_error /I=1 /C=T_Constraints     //Gauss
1092        NVAR BeamCenter
1093        NVAR MaximumIntensity
1094        NVAR PeakWidth         
1095        NVAR PeakWidthArcSec           
1096        Variable BeamCenterError, MaximumIntensityError, PeakWidthError
1097        Wave W_coef
1098        Wave W_sigma
1099        PeakFitWave= W_coef[0]*exp(-0.5*(abs(x-W_coef[1])/W_coef[2])^W_coef[3])
1100        BeamCenter=W_coef[1]
1101        BeamCenterError=W_sigma[1]
1102        MaximumIntensity=W_coef[0]
1103        MaximumIntensityError=W_sigma[0]
1104        PeakWidth = 2*W_coef[2]*(2*ln(2))^(1/W_coef[3])
1105        PeakWidthArcSec = PeakWidth*3600
1106        PeakWidthError= 0//2*W_sigma[2]*(2*ln(2))^(1/W_sigma[3])...........need to calcualte approximate value in the future...
1107        Variable GaussPeakWidth=PeakWidth                               //2*(sqrt(ln(2)))*abs(W_coef[3])                        // properly fixed by now.
1108        Variable GaussPeakWidthError=   PeakWidthError                                  //2*(sqrt(ln(2)))*abs(W_sigma[3])
1109        string BmCnterStr
1110        Sprintf BmCnterStr, "%8.5f", BeamCenter
1111        String Width="\Z12FWHM   "+num2str(3600*GaussPeakWidth)+" +/- "+num2str(3600*GaussPeakWidthError)+"  arc-sec"
1112        Width+="\rMax       "+num2str(MaximumIntensity)+"   +/-  "+num2str(MaximumIntensityError)
1113        Width+="\rBm Cntr  "+BmCnterStr+"  +/-  "+num2str(BeamCenterError)+"  deg."
1114        DoWindow RcurvePlotGraph
1115        if(V_Flag)
1116                Textbox/W=RcurvePlotGraph/K/N=text1
1117                TextBox/W=RcurvePlotGraph/N=text1/F=0/B=2/X=63.96/Y=89.45 Width
1118        endif
1119//      ModifyGraph rgb($ModifyWave)=(0,15872,65280)
1120//      KillWaves W_WaveList
1121        Wave/Z R_Qvec
1122        if(WaveExists(R_Qvec))
1123                string ListOfWaveNames = "R_Qvec;R_Int;R_Error;Qvec;"
1124                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"PeakFitFunction","Modified Gauss")
1125                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenter",num2str(BeamCenter))
1126                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensity",num2str(MaximumIntensity))
1127                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM",num2str(PeakWidth*3600))
1128                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenterError",num2str(BeamCenterError))
1129                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensityError",num2str(MaximumIntensityError))
1130                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM_Error",num2str(PeakWidthError*3600))
1131        endif
1132        doupdate
1133        setDataFolder OldDf
1134
1135End
1136
1137//******************** name **************************************
1138///**********************************************************************************************************
1139//******************** FitLorenzianOnTopMacro **************************************
1140
1141Function IN3_ModifiedGauss(w,xvar) : FitFunc
1142        Wave w
1143        Variable xvar
1144
1145        //CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
1146        //CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
1147        //CurveFitDialog/ Equation:
1148        //CurveFitDialog/ f(xvar) = Amplitude*exp(-0.5*(abs(xvar-center)/cparameter)^dparameter)
1149        //CurveFitDialog/ End of Equation
1150        //CurveFitDialog/ Independent Variables 1
1151        //CurveFitDialog/ xvar
1152        //CurveFitDialog/ Coefficients 4
1153        //CurveFitDialog/ w[0] = Amplitude
1154        //CurveFitDialog/ w[1] = center
1155        //CurveFitDialog/ w[2] = cparameter
1156        //CurveFitDialog/ w[3] = dparameter
1157
1158        return w[0]*exp(-0.5*(abs(xvar-w[1])/w[2])^w[3])
1159End
1160
1161//******************** name **************************************
1162///**********************************************************************************************************
1163//******************** FitLorenzianOnTopMacro **************************************
1164Function IN3_FitLorenzianTop(ctrlname) : Buttoncontrol                  // calls the Lorenzian fit
1165        string ctrlname
1166 
1167        string oldDf=GetDataFolder(1)
1168        setDataFolder root:Packages:Indra3
1169
1170        NVAR PeakCenterFitStartPoint
1171        NVAR PeakCenterFitEndPoint
1172        Wave PD_Intensity
1173        Wave Ar_encoder
1174        Wave PD_error
1175        Make/O/N=200 PeakFitWave
1176        DoWIndow RcurvePlotGraph
1177        String ExistingSubWindows
1178        if(V_Flag)
1179                ExistingSubWindows=ChildWindowList("RcurvePlotGraph")
1180        else
1181                ExistingSubWindows=""
1182        endif
1183        if(stringmatch(ExistingSubWindows,"*PeakCenter*"))
1184                getAxis/W=RcurvePlotGraph#PeakCenter /Q bottom
1185                SetScale/I x V_min, V_max,"", PeakFitWave
1186        else
1187                variable center = (PeakCenterFitStartPoint + PeakCenterFitEndPoint)/2
1188                variable start = max(0,center - (center -PeakCenterFitStartPoint) *3 )
1189                variable end1 = min(center + (PeakCenterFitEndPoint-center) *3, numpnts(Ar_encoder) )
1190                SetScale/I x Ar_encoder[start], Ar_encoder[end1],"", PeakFitWave
1191        endif
1192
1193        K0=0
1194        CurveFit/Q/H="1000"  lor PD_Intensity [PeakCenterFitStartPoint,PeakCenterFitEndPoint]  /X=Ar_encoder /D /W=PD_error /I=1 //Lorenzian
1195//      print "Fitted Lorenzian between points  "+num2str(PeakCenterFitStartPoint)+"   and    "+num2str(PeakCenterFitEndPoint)+"    reached Chi-squared/numpoints     " +num2str(V_chisq/(PeakCenterFitEndPoint-PeakCenterFitStartPoint))
1196//      string ModifyWave
1197//      ModifyWave="fit_"+WaveName("",0,1)                                              //new wave with the lorenzian fit
1198        NVAR BeamCenter
1199        NVAR MaximumIntensity
1200        NVAR PeakWidth 
1201        NVAR PeakWidthArcSec   
1202        Variable BeamCenterError, MaximumIntensityError, PeakWidthError
1203        Wave W_coef
1204        Wave W_sigma
1205        Wave PeakFitWave
1206//      Wave FitResiduals
1207//      FitResiduals= ((W_coef[0]+W_coef[1]/((Ar_encoder[p]-W_coef[2])^2+W_coef[3]))-PD_Intensity[p])/PD_error[p]
1208//      FitResiduals[0,xcsr(A)-1]=NaN
1209//      FitResiduals[xcsr(B)+1,inf]=NaN
1210        PeakFitWave= W_coef[0]+W_coef[1]/((x-W_coef[2])^2+W_coef[3])
1211        BeamCenterError=W_sigma[2]
1212        BeamCenter=W_coef[2]
1213        MaximumIntensity=W_coef[1]/W_coef[3]
1214        MaximumIntensityError=IN2G_ErrorsForDivision(W_coef[1],W_sigma[1],W_coef[3],W_sigma[3])
1215        PeakWidth = 2*sqrt(W_coef[3])
1216        PeakWidthArcSec = PeakWidth*3600
1217        //according to Andrew, the error here needs to be propagated through fractional error
1218        //that is, error of sqrt(x), sigma(sx)=X*(sigma(X)/2*X)
1219        PeakWidthError=PeakWidth*(W_sigma[3]/(2*W_coef[3]))
1220        string BmCenterStr, BmCenterErrStr
1221        Sprintf BmCenterStr, "%8.5f", BeamCenter
1222        Sprintf BmCenterErrStr, "%8.5f", BeamCenterError
1223        String Width="\Z12FWHM   "+num2str(PeakWidth*3600)+ " +/- "+num2str(PeakWidthError*3600)+"  arc-sec"
1224        Width+="\rMax     "+num2str(MaximumIntensity)+" +/-  "+num2str(MaximumIntensityError)
1225        Width+="\rBm Cntr   : "+BmCenterStr+" +/- "+ num2str(BeamCenterError)+"  deg."
1226        DoWindow RcurvePlotGraph
1227        if(V_Flag)
1228                Textbox/W=RcurvePlotGraph/K/N=text1
1229                TextBox/W=RcurvePlotGraph/N=text1/F=0/B=2/X=63.96/Y=89.45 Width
1230        endif
1231//      ModifyGraph rgb($ModifyWave)=(0,15872,65280)
1232//      KillWaves W_WaveList
1233        string ListOfWaveNames = "R_Qvec;R_Int;R_Error;Qvec;"
1234//      IN2G_AppendNoteToListOfWaves(ListOfWaveNames, Key,notetext
1235        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"PeakFitFunction","Lorenzian")
1236        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenter",num2str(BeamCenter))
1237        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensity",num2str(MaximumIntensity))
1238        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM",num2str(sqrt(W_coef[3])*3600*2))
1239        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenterError",num2str(BeamCenterError))
1240        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensityError",num2str(MaximumIntensityError))
1241        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM_Error",num2str(sqrt(W_sigma[3])*3600*2))
1242End
1243//**********************************************************************************************************
1244//**********************************************************************************************************
1245
1246//***************************************************************************************************************************************
1247//***************************************************************************************************************************************
1248//***************************************************************************************************************************************
1249//***************************************************************************************************************************************
1250//***************************************************************************************************************************************
1251//***************************************************************************************************************************************
1252Function IN3_ParametersChanged(ctrlName,varNum,varStr,varName) : SetVariableControl
1253        String ctrlName
1254        Variable varNum
1255        String varStr
1256        String varName
1257
1258        string oldDf=GetDataFolder(1)
1259        setDataFolder root:Packages:Indra3
1260
1261        //need to sync blanks widths, if changed by user...
1262        NVAR WidthDeg=root:Packages:Indra3:BlankFWHM
1263        NVAR WidthArcSec=root:Packages:Indra3:BlankWidth
1264        if(stringmatch(ctrlName,"BlankWidth"))
1265                WidthArcSec = WidthDeg * 3600
1266        endif
1267        if(stringmatch(ctrlName,"BlankWidthArcSec"))
1268                WidthDeg =  WidthArcSec/3600
1269        endif
1270        if(stringmatch(ctrlName,"SubtractFlatBackground"))
1271                NVAR SubtractFlatBackground= root:Packages:Indra3:SubtractFlatBackground
1272                SetVariable SubtractFlatBackground,win=USAXSDataReduction,limits={0,Inf,0.05*SubtractFlatBackground}
1273        endif
1274
1275       
1276        //recalculate what needs to be done...
1277        IN3_RecalculateData(2)
1278
1279        setDataFolder OldDf
1280End
1281///*****************************************************************************************************************
1282//*****************************************************************************************************************
1283//*****************************************************************************************************************
1284//*****************************************************************************************************************
1285//*****************************************************************************************************************
1286Function IN3_UPDParametersChanged(ctrlName,varNum,varStr,varName) : SetVariableControl
1287        String ctrlName
1288        Variable varNum
1289        String varStr
1290        String varName
1291
1292        string oldDf=GetDataFolder(1)
1293        setDataFolder root:Packages:Indra3
1294        SVAR UPDList=UPDParameters
1295       
1296        if (!cmpstr(ctrlName,"VtoF"))                                           //Changing V to F
1297                UPDList=ReplaceNumberByKey("Vtof",UPDList, varNum,"=")
1298                UPDList=ReplaceNumberByKey("Vfc",UPDList, varNum,"=")
1299        endif
1300        if (!cmpstr(ctrlName,"Gain1"))                                          //Changing Gain1
1301                UPDList=ReplaceNumberByKey("Gain1",UPDList, varNum,"=")
1302        endif
1303        if (!cmpstr(ctrlName,"Gain2"))                                          //Changing Gain2
1304                UPDList=ReplaceNumberByKey("Gain2",UPDList, varNum,"=")
1305        endif
1306        if (!cmpstr(ctrlName,"Gain3"))                                          //Changing gain3
1307                UPDList=ReplaceNumberByKey("Gain3",UPDList, varNum,"=")
1308        endif
1309        if (!cmpstr(ctrlName,"Gain4"))                                          //Changing Gain4
1310                UPDList=ReplaceNumberByKey("Gain4",UPDList, varNum,"=")
1311        endif
1312        if (!cmpstr(ctrlName,"Gain5"))                                          //Changing Gain5
1313                UPDList=ReplaceNumberByKey("Gain5",UPDList, varNum,"=")
1314        endif
1315        if (!cmpstr(ctrlName,"Bkg1"))                                           //Changing Bkg 1
1316                UPDList=ReplaceNumberByKey("Bkg1",UPDList, varNum,"=")
1317        endif
1318        if (!cmpstr(ctrlName,"Bkg2"))                                           //Changing Bkg 2
1319                UPDList=ReplaceNumberByKey("Bkg2",UPDList, varNum,"=")
1320        endif
1321        if (!cmpstr(ctrlName,"Bkg3"))                                           //Changing Bkg 3
1322                UPDList=ReplaceNumberByKey("Bkg3",UPDList, varNum,"=")
1323        endif
1324        if (!cmpstr(ctrlName,"Bkg4"))                                           //Changing Bkg 4
1325                UPDList=ReplaceNumberByKey("Bkg4",UPDList, varNum,"=")
1326        endif
1327        if (!cmpstr(ctrlName,"Bkg5"))                                           //Changing Bkg 5
1328                UPDList=ReplaceNumberByKey("Bkg5",UPDList, varNum,"=")
1329        endif
1330
1331
1332        IN3_RecalculateData(1)                  //and here we recalcualte the R wave
1333        setDataFolder OldDf
1334End
1335//*****************************************************************************************************************
1336//*****************************************************************************************************************
1337//*****************************************************************************************************************
1338//*****************************************************************************************************************
1339//*****************************************************************************************************************
1340
1341Function NI3_TabPanelControl(name,tab)
1342        String name
1343        Variable tab
1344
1345        string oldDf=GetDataFolder(1)
1346        setDataFolder root:Packages:Indra3
1347        NVAR IsBlank=root:Packages:Indra3:IsBlank
1348
1349
1350
1351        NVAR CalculateWeight=root:Packages:Indra3:CalculateWeight
1352        NVAR CalculateThickness=root:Packages:Indra3:CalculateThickness
1353        NVAR CalibrateToWeight=root:Packages:Indra3:CalibrateToWeight
1354        NVAR CalibrateToVolume=root:Packages:Indra3:CalibrateToVolume
1355        NVAR CalibrateArbitrary=root:Packages:Indra3:CalibrateArbitrary
1356
1357        Button RecoverDefault,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1358        CheckBox CalibrateToVolume,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1359        CheckBox CalibrateToWeight,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1360        CheckBox CalibrateArbitrary,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1361
1362        CheckBox CalculateThickness,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1363        CheckBox CalculateWeight,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToWeight )
1364        SetVariable SampleThickness,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || CalibrateArbitrary), noedit=!(CalculateThickness||CalculateWeight), frame=CalculateThickness
1365        SetVariable SampleWeightInBeam,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToWeight || CalibrateArbitrary)
1366        SetVariable SampleTransmission,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1367        SetVariable SampleLinAbsorption,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || CalibrateArbitrary), noedit=!CalculateThickness, frame=CalculateThickness
1368        SetVariable SampleDensity,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToWeight || CalibrateArbitrary), frame=CalculateWeight
1369        SetVariable SampleFilledFraction,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToVolume || CalibrateArbitrary),noedit=!CalculateThickness, frame=CalculateThickness
1370        SetVariable BeamExposureArea, win=USAXSDataReduction, disable=(tab!=0 || IsBlank || CalibrateArbitrary), noedit=!(CalculateWeight&&CalibrateToWeight), frame=!CalculateWeight
1371
1372
1373
1374        SetVariable VtoF,win=USAXSDataReduction, disable=(tab!=1)
1375        SetVariable Gain1,win=USAXSDataReduction, disable=(tab!=1)
1376        SetVariable Gain2,win=USAXSDataReduction, disable=(tab!=1)
1377        SetVariable Gain3,win=USAXSDataReduction, disable=(tab!=1)
1378        SetVariable Gain4,win=USAXSDataReduction, disable=(tab!=1)
1379        SetVariable Gain5,win=USAXSDataReduction, disable=(tab!=1)
1380        SetVariable Bkg1,win=USAXSDataReduction, disable=(tab!=1)
1381        SetVariable Bkg2,win=USAXSDataReduction, disable=(tab!=1)
1382        SetVariable Bkg3,win=USAXSDataReduction, disable=(tab!=1)
1383        SetVariable Bkg4,win=USAXSDataReduction, disable=(tab!=1)
1384        SetVariable Bkg5,win=USAXSDataReduction, disable=(tab!=1)
1385        SetVariable Bkg1Err,win=USAXSDataReduction, disable=(tab!=1)
1386        SetVariable Bkg2Err,win=USAXSDataReduction, disable=(tab!=1)
1387        SetVariable Bkg3Err,win=USAXSDataReduction, disable=(tab!=1)
1388        SetVariable Bkg4Err,win=USAXSDataReduction, disable=(tab!=1)
1389        SetVariable Bkg5Err,win=USAXSDataReduction, disable=(tab!=1)
1390
1391
1392        SetVariable SpecCommand,win=USAXSDataReduction, disable=(tab!=2)
1393        SetVariable PhotoDiodeSize,win=USAXSDataReduction, disable=(tab!=2)
1394        SetVariable Wavelength,win=USAXSDataReduction, disable=(tab!=2)
1395        SetVariable SDDistance,win=USAXSDataReduction, disable=(tab!=2)
1396        SetVariable SlitLength,win=USAXSDataReduction, disable=(tab!=2)
1397        SetVariable NumberOfSteps,win=USAXSDataReduction, disable=(tab!=2)
1398
1399        SetVariable MaximumIntensity,win=USAXSDataReduction, disable=(tab!=3)
1400        SetVariable PeakWidth,win=USAXSDataReduction, disable=(tab!=3)
1401        SetVariable PeakWidthArcSec,win=USAXSDataReduction, disable=(tab!=3)
1402        SetVariable BlankMaximum,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1403        SetVariable BlankWidth,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1404        SetVariable BlankWidthArcSec,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1405        SetVariable SubtractFlatBackground,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1406        Button RecoverDefaultBlnkVals,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1407
1408
1409        NVAR UseMSAXSCorrection=root:Packages:Indra3:UseMSAXSCorrection
1410        CheckBox UseMSAXSCorrection,win=USAXSDataReduction, disable=(tab!=4 || IsBlank)
1411        //UseMSAXSCorrection
1412        SetVariable MSAXSCorrection,win=USAXSDataReduction, disable=(tab!=4 || !UseMSAXSCorrection || IsBlank)
1413        SetVariable MSAXSStartPoint,win=USAXSDataReduction, disable=(tab!=4 || !UseMSAXSCorrection || IsBlank)
1414        SetVariable MSAXSEndPoint,win=USAXSDataReduction, disable=(tab!=4 || !UseMSAXSCorrection || IsBlank)
1415        String ExistingSubWindows=ChildWindowList("USAXSDataReduction")
1416        if(stringmatch(ExistingSubWindows,"*MSAXSGraph*") && IsBlank)
1417                KillWindow  USAXSDataReduction#MSAXSGraph
1418                ExistingSubWindows=ChildWindowList("USAXSDataReduction")
1419        endif
1420        if(tab!=4 || !UseMSAXSCorrection)
1421                        IN3_HideMSAXSGraph()
1422        else
1423                IN3_ShowMSAXSGraph()
1424//              if(!stringmatch(ExistingSubWindows,"*MSAXSGraph*"))
1425//                      IN3_ShowMSAXSGraph()
1426//              else
1427//                      //setWindow USAXSDataReduction#MSAXSGraph, hide =0     
1428//                      IN3_ShowMSAXSGraph()
1429//              endif
1430//              if((!UseMSAXSCorrection || IsBlank) &&stringmatch(ExistingSubWindows,"*MSAXSGraph*")  )
1431//                      IN3_ShowMSAXSGraph()
1432//              endif
1433        endif
1434        //color wave in main graph as appropriate
1435        if(tab==1)
1436                IN3_ColorMainGraph(1)
1437        else
1438                IN3_ColorMainGraph(0)
1439        endif
1440       
1441        setDataFolder OldDf
1442end
1443
1444//*****************************************************************************************************************
1445//*****************************************************************************************************************
1446//*****************************************************************************************************************
1447
1448Function/T IN3_GenStringOfFolders(useBlankData)
1449        variable useBlankData
1450       
1451        string ListOfQFolders
1452        string result
1453        if (useBlankData)
1454                        result=IN2G_FindFolderWithWaveTypes("root:USAXS:", 10, "Blank_*", 1)
1455        endif
1456       
1457        return result
1458end
1459
1460
1461//*****************************************************************************************************************
1462//*****************************************************************************************************************
1463//*****************************************************************************************************************
1464//*****************************************************************************************************************
1465//*****************************************************************************************************************
Note: See TracBrowser for help on using the repository browser.