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

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

Minor GUI fix

File size: 65.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                NI3_TabPanelControl("",0)
507                IN3_CalculateSampleThickness()
508        endif
509        if (cmpstr("CalculateWeight",ctrlName)==0)
510                NI3_TabPanelControl("",0)
511                IN3_CalculateSampleThickness()
512        endif
513
514        if (stringmatch("CalibrateToVolume",ctrlName))
515                if(checked)
516                        CalibrateToWeight = 0
517                        CalibrateArbitrary = 0
518                else
519                        if((CalibrateToWeight+CalibrateArbitrary)!=1)
520                                CalibrateArbitrary = 1
521                                CalibrateToWeight = 0
522                        endif
523                endif
524                NI3_TabPanelControl("",0)
525        endif
526       
527        if(stringmatch("CalibrateToWeight",ctrlName) )
528                if(checked)
529                        CalibrateToVolume = 0
530                        CalibrateArbitrary = 0
531                else
532                        if((CalibrateToVolume+CalibrateArbitrary)!=1)
533                                CalibrateArbitrary = 0
534                                CalibrateToVolume = 1
535                        endif
536                endif
537                NI3_TabPanelControl("",0)
538        endif
539
540        if(stringmatch("CalibrateArbitrary",ctrlName) )
541                if(checked)
542                        CalibrateToVolume = 0
543                        CalibrateToWeight = 0
544                else
545                        if((CalibrateToVolume+CalibrateToWeight)!=1)
546                                CalibrateToWeight = 0
547                                CalibrateToVolume = 1
548                        endif
549                endif
550                NI3_TabPanelControl("",0)
551        endif
552       
553        if (cmpstr("UseMSAXSCorrection",ctrlName)==0)
554                NI3_TabPanelControl("",4)
555                //IN3_CalculateMSAXSCorrection()
556                //IN3_CalculateTransmission(1)
557                //IN3_CalculateSampleThickness()
558                IN3_RecalculateData(3)
559        endif
560       
561
562end
563//*****************************************************************************************************************
564//*****************************************************************************************************************
565//*****************************************************************************************************************
566Function IN3_COlorizeButton()
567        DOWINDOW RcurvePlotGraph
568        IF(V_FLag)
569                NVAR UseLorenz = root:Packages:Indra3:UseLorenz
570                NVAR UseModifiedGauss = root:Packages:Indra3:UseModifiedGauss
571                NVAR UseGauss = root:Packages:Indra3:UseGauss
572                if(UseModifiedGauss)
573                        Button FitModGauss,win=RcurvePlotGraph ,fColor=(16386,65535,16385)
574                else
575                        Button FitModGauss,win=RcurvePlotGraph ,fColor=(0,0,0)
576                endif
577                if(UseGauss)
578                        Button FitGauss,win=RcurvePlotGraph ,fColor=(16386,65535,16385)
579                else
580                        Button FitGauss,win=RcurvePlotGraph ,fColor=(0,0,0)
581                endif
582                if(UseLorenz)
583                        Button FitLorenz,win=RcurvePlotGraph ,fColor=(16386,65535,16385)
584                else
585                        Button FitLorenz,win=RcurvePlotGraph ,fColor=(0,0,0)
586                endif
587        endif
588end
589
590
591//*****************************************************************************************************************
592//*****************************************************************************************************************
593
594
595static Function IN3_RcurvePlot()
596        PauseUpdate; Silent 1           // building window...
597        String fldrSav0= GetDataFolder(1)
598        SetDataFolder root:Packages:Indra3:
599        Wave R_Int
600        Wave R_Qvec
601        NVAR IsBlank = root:Packages:Indra3:IsBlank
602
603//      Wave fit_PD_Intensity
604//      Wave fitX_PD_Intensity
605//      Wave R_error
606//      Wave AR_encoder
607        Wave/Z PeakFitWave
608        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
609        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
610       
611        //create main plot with R curve data
612        Display/K=1 /W=(300,36.5,900,500) R_Int vs R_Qvec as "Rocking curve plot"
613        DoWindow/C RcurvePlotGraph
614        AutoPositionWindow/M=0/R=USAXSDataReduction  RcurvePlotGraph
615//      AppendToGraph fit_PD_Intensity vs fitX_PD_Intensity
616        //modify the displayed waves
617        ModifyGraph mode(R_Int)=4
618        ModifyGraph rgb(R_Int)=(65280,0,0)
619        ModifyGraph msize(R_Int)=2
620        ModifyGraph log=1
621        ModifyGraph axOffset(bottom)=0.888889
622        ModifyGraph lblPos(left)=60,lblPos(bottom)=51
623        ModifyGraph lblLatPos(left)=-4,lblLatPos(bottom)=-2
624        Label left "Intensity"
625        Label bottom "Q [A\\S-1\\M]"
626        SetAxis bottom 1e-05, R_Qvec[numpnts(R_Qvec)-1]
627        ShowInfo
628        ControlBar 50
629        SetVariable SampleTransmission,pos={180,5},size={300,22},title="Sample transmission (peak max)"
630        SetVariable SampleTransmission,font="Times New Roman",fSize=14,proc=IN3_ParametersChanged
631        SetVariable SampleTransmission,limits={0,inf,0.005},variable= root:Packages:Indra3:SampleTransmissionPeakToPeak
632
633        SetVariable SampleAngleOffset,pos={180,25},size={300,22},title="Q offset           "
634        SetVariable SampleAngleOffset,font="Times New Roman",fSize=14,proc=IN3_ParametersChanged
635        SetVariable SampleAngleOffset,limits={-inf,inf,0.5e-6},variable= root:Packages:Indra3:SampleQOffset
636
637        Button Recalculate,pos={150,25},size={90,20},font="Times New Roman",fSize=10,proc=IN3_InputPanelButtonProc,title="Recalculate", help={"Recalculate the data"}
638        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"}
639        Button FixGain,pos={250,3},size={90,20},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fix Gain w/c A"
640
641        CheckBox UseModifiedGauss title="Mod. Gauss",proc=IN3_RplotCheckProc
642        CheckBox UseModifiedGauss variable=root:Packages:Indra3:UseModifiedGauss,mode=1,pos={345,1}
643        CheckBox UseGauss title="Gauss",proc=IN3_RplotCheckProc
644        CheckBox UseGauss variable=root:Packages:Indra3:UseGauss,mode=1,pos={345,17}
645        CheckBox UseLorenz title="Lorenz",proc=IN3_RplotCheckProc
646        CheckBox UseLorenz variable=root:Packages:Indra3:UseLorenz,mode=1,pos={345,34}
647
648        Button FitModGauss,pos={425,3},size={80,18},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fit Mod. Gauss"
649        Button FitGauss,pos={515,3},size={80,18},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fit Gauss"
650        Button FitLorenz,pos={515,25},size={80,18},font="Times New Roman",fSize=10, proc=IN3_GraphButtonProc,title="Fit Lorenz"
651
652        CheckBox DisplayPeakCenter title="Display Peak Fit",proc=IN3_RplotCheckProc
653        CheckBox DisplayPeakCenter variable=root:Packages:Indra3:DisplayPeakCenter,mode=1,pos={5,5}
654        CheckBox DisplayAlignSaAndBlank title="Display Align Sa and Blank",proc=IN3_RplotCheckProc, disable=IsBlank
655        CheckBox DisplayAlignSaAndBlank variable=root:Packages:Indra3:DisplayAlignSaAndBlank,mode=1,pos={5,25}
656//DisplayPeakCenter;DisplayAlignSaAndBlank
657        SetDrawLayer UserFront
658        IN3_COlorizeButton()
659        NVAR IsBlank=root:Packages:Indra3:IsBlank
660        if(!IsBlank)
661                Wave/Z BL_R_Int=root:Packages:Indra3:BL_R_Int
662                Wave/Z BL_R_error=root:Packages:Indra3:BL_R_error
663                Wave/Z BL_R_Qvec= root:Packages:Indra3:BL_R_Qvec
664                AppendToGraph BL_R_Int vs BL_R_Qvec
665                ModifyGraph rgb(BL_R_Int)=(0,0,0)
666                NVAR TrimDataStart=root:Packages:Indra3:TrimDataStart
667                NVAR TrimDataEnd=root:Packages:Indra3:TrimDataEnd
668                if(TrimDataStart>0)
669                        Cursor/P/W=RcurvePlotGraph A R_Int TrimDataStart       
670                endif
671                if(TrimDataEnd>0)
672                        Cursor/P/W=RcurvePlotGraph B R_Int TrimDataEnd 
673                endif
674        endif
675       
676
677        SetDataFolder fldrSav0
678End
679//***********************************************************************************************************************************
680//***********************************************************************************************************************************
681Function IN3_FixDispControlsInRcurvePlot()
682
683
684        NVAR DisplayPeakCenter = root:Packages:Indra3:DisplayPeakCenter
685        NVAR DisplayAlignSaAndBlank = root:Packages:Indra3:DisplayAlignSaAndBlank
686       
687        SetVariable SampleTransmission,win=RcurvePlotGraph, disable =DisplayPeakCenter
688        SetVariable SampleAngleOffset,win=RcurvePlotGraph, disable =DisplayPeakCenter
689
690        Button FitGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
691        Button FitModGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
692        Button FitLorenz,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
693
694        Button Recalculate,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
695        Button RemovePoint,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
696        Button FixGain,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
697
698        Checkbox UseModifiedGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
699        Checkbox UseGauss,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
700        Checkbox UseLorenz,win=RcurvePlotGraph, disable =DisplayAlignSaAndBlank
701
702end
703
704//*****************************************************************************************************************
705//*****************************************************************************************************************
706//*****************************************************************************************************************
707
708static Function IN3_PeakCenter()
709        PauseUpdate; Silent 1           // building window...
710        String fldrSav0= GetDataFolder(1)
711        SetDataFolder root:Packages:Indra3:
712        Wave R_Int
713        Wave R_Qvec
714        Wave fit_PD_Intensity
715//      Wave fitX_PD_Intensity
716//      Wave R_error
717        Wave AR_encoder
718        Wave/Z PeakFitWave
719        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
720        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
721       
722        //create main plot with R curve data
723        //create the other graph
724        Display/K=1/W=(0.431,0.03,0.8,0.399)/FG=(,GT,FR,)/PG=(,,PR,)/HOST=RcurvePlotGraph  PD_Intensity vs AR_encoder
725        AppendToGraph fit_PD_Intensity,PeakFitWave
726        //modify displayed waves
727        ModifyGraph mode(PD_Intensity)=3
728        ModifyGraph lSize(fit_PD_Intensity)=2
729        ModifyGraph lStyle(PeakFitWave)=3
730        ModifyGraph rgb(fit_PD_Intensity)=(0,0,52224),rgb(PeakFitWave)=(0,0,65280)
731        ModifyGraph nticks(bottom)=2
732        ModifyGraph lblMargin(left)=26,lblMargin(bottom)=1
733        ModifyGraph lblLatPos=-1
734        Label left "Intensity"
735        Label bottom "AR angle [deg]"
736        ErrorBars PD_Intensity Y,wave=(PD_Error,PD_Error)
737        variable center = (PeakCenterFitEndPoint + PeakCenterFitStartPoint)/2
738        variable start = max(center - 1.5 * (center - PeakCenterFitStartPoint),0)
739        variable end1 = min(center + 2 * (PeakCenterFitEndPoint-center),numpnts(AR_encoder))
740        SetAxis bottom AR_encoder[start],AR_encoder[end1]
741        Cursor/P A PD_Intensity PeakCenterFitStartPoint
742        Cursor/P B PD_Intensity PeakCenterFitEndPoint
743        RenameWindow #,PeakCenter
744        SetActiveSubwindow ##
745
746        SetDataFolder fldrSav0
747End
748//***********************************************************************************************************************************
749//***********************************************************************************************************************************
750//***********************************************************************************************************************************
751//***********************************************************************************************************************************
752//***********************************************************************************************************************************
753//***********************************************************************************************************************************
754//*****************************************************************************************************************
755//*****************************************************************************************************************
756//*****************************************************************************************************************
757
758static Function IN3_AlignSampleAndBlank()
759        PauseUpdate; Silent 1           // building window...
760        String fldrSav0= GetDataFolder(1)
761        SetDataFolder root:Packages:Indra3:
762       
763        NVAR IsBlank = root:Packages:Indra3:IsBlank
764        if(IsBlank)
765                return 0
766        endif
767        Wave R_Int
768        Wave R_Qvec
769        Wave R_Error
770//      Wave fit_PD_Intensity
771//      Wave fitX_PD_Intensity
772        Wave R_error
773        Wave AR_encoder
774        Wave PeakFitWave
775        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
776        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
777        Wave BL_R_Int
778        Wave BL_R_Qvec
779       
780        //create main plot with R curve data
781        //create the other graph
782        Display/K=1/W=(0.431,0.03,0.8,0.399)/FG=(,GT,FR,)/PG=(,,PR,)/HOST=RcurvePlotGraph  R_Int vs R_Qvec
783        AppendToGraph BL_R_Int vs BL_R_Qvec
784        //modify displayed waves
785        ModifyGraph mode(R_Int)=3
786        ModifyGraph rgb(BL_R_Int)=(0,0,0)
787        ModifyGraph lstyle(BL_R_Int)=3,lsize(BL_R_Int)=2
788        ModifyGraph nticks(bottom)=2
789        ModifyGraph lblMargin(left)=26,lblMargin(bottom)=1
790        ModifyGraph lblLatPos=-1
791        Label left "Intensity"
792        Label bottom "Q [A\S-1\M]"
793        ErrorBars R_Int Y,wave=(R_Error,R_Error)
794        variable center = (PeakCenterFitEndPoint + PeakCenterFitStartPoint)/2
795        variable start = max(center - 1.5 * abs(center - PeakCenterFitStartPoint),0)
796        variable end1 = min(center + 2.1 * abs(center - PeakCenterFitEndPoint),numpnts(AR_encoder))
797        SetAxis bottom R_Qvec[start],R_Qvec[end1]
798//      Cursor/P A R_Int PeakCenterFitStartPoint
799//      Cursor/P B R_Int PeakCenterFitEndPoint
800        RenameWindow #,AlignSampleAndBlank
801        SetActiveSubwindow ##
802
803        SetDataFolder fldrSav0
804End
805//***********************************************************************************************************************************
806//***********************************************************************************************************************************
807//***********************************************************************************************************************************
808//***********************************************************************************************************************************
809//***********************************************************************************************************************************
810//***********************************************************************************************************************************
811static Function IN3_AppendBlankToRPlot()
812        string oldDf=GetDataFolder(1)
813        setDataFolder root:Packages:Indra3
814       
815        NVAR IsBlank
816        if(!IsBlank)
817                Wave BL_R_Int
818                Wave BL_R_Qvec
819//              Wave BL_AR_encoder
820               
821                AppendToGraph/W=RcurvePlotGraph BL_R_Int vs BL_R_Qvec
822                ModifyGraph/W=RcurvePlotGraph rgb(BL_R_Int)=(0,0,0)
823
824//              AppendToGraph/W=RcurvePlotGraph#PeakCenter BL_R_Int vs BL_AR_encoder
825//              ModifyGraph/W=RcurvePlotGraph#PeakCenter rgb(BL_R_Int)=(0,0,0)
826               
827       
828        endif
829
830
831        setDataFolder OldDf     
832end
833//***********************************************************************************************************************************
834//***********************************************************************************************************************************
835//***********************************************************************************************************************************
836//***********************************************************************************************************************************
837//***********************************************************************************************************************************
838//***********************************************************************************************************************************
839
840//***************************************************************************************************************************************
841//***************************************************************************************************************************************
842//***************************************************************************************************************************************
843//***************************************************************************************************************************************
844//***************************************************************************************************************************************
845//***************************************************************************************************************************************
846
847Function IN3_GraphButtonProc(ctrlName) : ButtonControl
848        String ctrlName
849       
850        NVAR PeakCenterFitStartPoint=root:Packages:Indra3:PeakCenterFitStartPoint
851        NVAR PeakCenterFitEndPoint=root:Packages:Indra3:PeakCenterFitEndPoint
852        Wave AR_encoder=root:Packages:Indra3:AR_encoder
853        String AcsrWaveName = StringByKey("TNAME", CsrInfo(A , "RcurvePlotGraph#PeakCenter")  , ":" , ";")
854        String BcsrWaveName = StringByKey("TNAME", CsrInfo(B , "RcurvePlotGraph#PeakCenter")  , ":" , ";")
855        variable curX
856        if (!stringMatch(AcsrWaveName,"PD_Intensity"))
857                curX = xcsr(A , "RcurvePlotGraph#PeakCenter")
858                Cursor /W=RcurvePlotGraph#PeakCenter A, PD_Intensity, (BinarySearch(AR_encoder, curX ))
859        endif
860        if (!stringMatch(BcsrWaveName,"PD_Intensity"))
861                curX = xcsr(B, "RcurvePlotGraph#PeakCenter")
862                Cursor /W=RcurvePlotGraph#PeakCenter B, PD_Intensity, (BinarySearch(AR_encoder, curX )+1)
863        endif
864
865        if(stringMatch(ctrlName,"FixGain"))
866                if((strlen(csrInfo(A,"RcurvePlotGraph"))<1)||(!stringMatch(stringByKey("TNAME",csrinfo(A,"RcurvePlotGraph")),"R_Int")))
867                        DoAlert 0, "Cursor A not set or set on incorrect wave, should be on R_Int"
868                else
869                        Wave PD_range = root:Packages:Indra3:PD_range
870                        variable CurPDRange, curPntNum
871                        curPntNum=pcsr(A,"RcurvePlotGraph")
872                        CurPDRange=PD_range[curPntNum]
873                        Prompt CurPDRange, "Change the PD range for selected point"
874                        DoPrompt "Fix the PD range here", CurPDRange
875                        if(V_Flag)
876                                abort
877                        endif
878                        CurPDRange = round(CurPDRange)
879                        if(CurPDRange<1||CurPDRange>5)
880                                DoAlert 0, "PD range input is wrong, 1-5 and intergers possible only)"
881                        else
882                                PD_range[curPntNum]=CurPDRange
883                                IN3_RecalculateData(1) 
884                                DoWIndow/F USAXSDataReduction
885                        endif                   
886                endif
887               
888               
889        endif
890        if(stringMatch(ctrlName,"FitGauss"))
891                //get position of cursors from the right window and run fitting rouitne with gaussien
892                PeakCenterFitStartPoint=min(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
893                PeakCenterFitEndPoint=max(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
894                IN3_FitGaussTop("")
895                IN3_RecalculateData(1) 
896        endif
897        if(stringMatch(ctrlName,"FitModGauss"))
898                //get position of cursors from the right window and run fitting rouitne with gaussien
899                PeakCenterFitStartPoint=min(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
900                PeakCenterFitEndPoint=max(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
901                IN3_FitModGaussTop("")
902                IN3_RecalculateData(1) 
903        endif
904        if(stringMatch(ctrlName,"FitLorenz"))
905                //get position of cursors from the right window and run fitting rouitne with lorenzian
906                PeakCenterFitStartPoint=min(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
907                PeakCenterFitEndPoint=max(pcsr(A, "RcurvePlotGraph#PeakCenter"),pcsr(B, "RcurvePlotGraph#PeakCenter"))
908                IN3_FitLorenzianTop("")
909                IN3_RecalculateData(1) 
910        endif
911End
912
913///**********************************************************************************************************
914//**********************************************************************************************************
915//**********************************************************************************************************
916
917Function IN3_FitGaussTop(ctrlname) : Buttoncontrol                      // calls the Gaussien fit
918        string ctrlname
919       
920        string oldDf=GetDataFolder(1)
921        setDataFolder root:Packages:Indra3
922
923        NVAR PeakCenterFitStartPoint
924        NVAR PeakCenterFitEndPoint
925
926        Wave PD_error
927        Wave Ar_encoder
928        Wave PD_Intensity
929        Make/O/N=200 PeakFitWave
930        DoWIndow RcurvePlotGraph
931        String ExistingSubWindows
932        if(V_Flag)
933                ExistingSubWindows=ChildWindowList("RcurvePlotGraph")
934        else
935                ExistingSubWindows=""
936        endif
937        if(stringmatch(ExistingSubWindows,"*PeakCenter*"))
938                getAxis/W=RcurvePlotGraph#PeakCenter /Q bottom
939                SetScale/I x V_min, V_max,"", PeakFitWave
940        else
941                variable center = (PeakCenterFitStartPoint + PeakCenterFitEndPoint)/2
942                variable start = max(0,center - (center -PeakCenterFitStartPoint) *3 )
943                variable end1 = min(center + (PeakCenterFitEndPoint-center) *3, numpnts(Ar_encoder) )
944                SetScale/I x Ar_encoder[start], Ar_encoder[end1],"", PeakFitWave
945        endif
946        K0=0
947//      if(strlen(CsrInfo(A, "RcurvePlot")) <1  || strlen(CsrInfo(B, "RcurvePlot"))<1)
948//              return 0
949//      endif
950        CurveFit/Q/H="1000"  gauss PD_Intensity [PeakCenterFitStartPoint,PeakCenterFitEndPoint]  /X=Ar_encoder /D /W=PD_error /I=1      //Gauss
951//      print "Fitted Gaussian between points  "+num2str(PeakCenterFitStartPoint)+"   and    "+num2str(PeakCenterFitEndPoint)+"    reached Chi-squared/numpoints    " +num2str(V_chisq/(PeakCenterFitEndPoint-PeakCenterFitStartPoint))
952//      string ModifyWave
953//      ModifyWave="fit_"+WaveName("",0,1)                                              //new wave with the lorenzian fit
954//      ModifyGraph /W=RcurvePlot lsize(fit_PD_Intensity)=3, rgb(fit_PD_intensity)=(0,15872,65280)
955        NVAR BeamCenter
956        NVAR MaximumIntensity
957        NVAR PeakWidth         
958        NVAR PeakWidthArcSec           
959        Variable BeamCenterError, MaximumIntensityError, PeakWidthError
960        Wave W_coef
961        Wave W_sigma
962//      Wave FitResiduals
963//      FitResiduals= ((W_coef[0]+W_coef[1]*exp(-((Ar_encoder[p]-W_coef[2])/W_coef[3])^2)) - PD_Intensity[p])/PD_error[p]
964//      FitResiduals[0,PeakCenterFitStartPoint-1]=NaN
965//      FitResiduals[PeakCenterFitEndPoint+1,inf]=NaN
966        PeakFitWave= W_coef[0]+W_coef[1]*exp(-((x-W_coef[2])/W_coef[3])^2)
967        BeamCenter=W_coef[2]
968        BeamCenterError=W_sigma[2]
969        MaximumIntensity=W_coef[1]
970        MaximumIntensityError=W_sigma[1]
971        PeakWidth = 2*(sqrt(ln(2)))*abs(W_coef[3])
972        PeakWidthArcSec = PeakWidth*3600
973        PeakWidthError=2*(sqrt(ln(2)))*abs(W_sigma[3])
974        Variable GaussPeakWidth=2*(sqrt(ln(2)))*abs(W_coef[3])                  // properly fixed by now.
975        Variable GaussPeakWidthError=2*(sqrt(ln(2)))*abs(W_sigma[3])
976        string BmCnterStr
977        Sprintf BmCnterStr, "%8.5f", BeamCenter
978        String Width="\Z12FWHM   "+num2str(3600*GaussPeakWidth)+" +/- "+num2str(3600*GaussPeakWidthError)+"  arc-sec"
979        Width+="\rMax       "+num2str(MaximumIntensity)+"   +/-  "+num2str(MaximumIntensityError)
980        Width+="\rBm Cntr  "+BmCnterStr+"  +/-  "+num2str(BeamCenterError)+"  deg."
981        DoWindow RcurvePlotGraph
982        if(V_Flag)
983                Textbox/W=RcurvePlotGraph/K/N=text1
984                TextBox/W=RcurvePlotGraph/N=text1/F=0/B=2/X=63.96/Y=89.45 Width
985        endif
986//      ModifyGraph rgb($ModifyWave)=(0,15872,65280)
987//      KillWaves W_WaveList
988        Wave/Z R_Qvec
989        if(WaveExists(R_Qvec))
990                string ListOfWaveNames = "R_Qvec;R_Int;R_Error;Qvec;"
991                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"PeakFitFunction","Gauss")
992                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenter",num2str(BeamCenter))
993                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensity",num2str(MaximumIntensity))
994                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM",num2str(PeakWidth*3600))
995                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenterError",num2str(BeamCenterError))
996                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensityError",num2str(MaximumIntensityError))
997                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM_Error",num2str(PeakWidthError*3600))
998        endif
999        setDataFolder OldDf
1000
1001End
1002///**********************************************************************************************************
1003///**********************************************************************************************************
1004///**********************************************************************************************************
1005///**********************************************************************************************************
1006///**********************************************************************************************************
1007
1008Function IN3_FitDefaultTop()
1009        NVAR UseModifiedGauss
1010        NVAR UseGauss
1011        NVAR UseLorenz
1012
1013        if(UseModifiedGauss)
1014                IN3_FitModGaussTop("") 
1015        elseif(UseGauss)
1016                IN3_FitGaussTop("")
1017        elseif(UseLorenz)
1018                IN3_FitLorenzianTop("")
1019        else
1020                Abort "No default fiting method selected, please restart the tool"
1021       
1022        endif
1023end
1024//**********************************************************************************************************
1025//**********************************************************************************************************
1026///**********************************************************************************************************
1027///**********************************************************************************************************
1028
1029Function IN3_FitModGaussTop(ctrlname) : Buttoncontrol                   // calls the Gaussien fit
1030        string ctrlname
1031       
1032        string oldDf=GetDataFolder(1)
1033        setDataFolder root:Packages:Indra3
1034
1035        NVAR PeakCenterFitStartPoint
1036        NVAR PeakCenterFitEndPoint
1037
1038        Wave PD_error
1039        Wave Ar_encoder
1040        Wave PD_Intensity
1041        Make/O/N=200 PeakFitWave
1042        DoWIndow RcurvePlotGraph
1043        String ExistingSubWindows
1044        if(V_Flag)
1045                ExistingSubWindows=ChildWindowList("RcurvePlotGraph")
1046        else
1047                ExistingSubWindows=""
1048        endif
1049        if(stringmatch(ExistingSubWindows,"*PeakCenter*"))
1050                getAxis/W=RcurvePlotGraph#PeakCenter /Q bottom
1051                SetScale/I x V_min, V_max,"", PeakFitWave
1052        else
1053                variable center = (PeakCenterFitStartPoint + PeakCenterFitEndPoint)/2
1054                variable start = max(0,center - (center -PeakCenterFitStartPoint) *3 )
1055                variable end1 = min(center + (PeakCenterFitEndPoint-center) *3, numpnts(Ar_encoder) )
1056                SetScale/I x Ar_encoder[start], Ar_encoder[end1],"", PeakFitWave
1057        endif
1058//      K0=0
1059        MAKE/O/N=4 W_coef
1060        wavestats/Q PD_Intensity
1061        //workaround problems 2012/01, one large point appears ...
1062        Duplicate/Free PD_Intensity, tempPDInt
1063        tempPDInt[V_maxloc]=Nan
1064        wavestats/Q tempPDInt
1065        W_Coef[0]=V_max
1066        W_coef[1]=Ar_encoder[V_maxloc]
1067        FindLevels /N=5 /P/Q  tempPDInt, V_max/2
1068        wave W_FindLevels
1069        variable startPointL, endPointL
1070        if(Numpnts(W_FindLevels)==2)
1071                startPointL=W_FindLevels[0]
1072                endPointL=W_FindLevels[1]
1073        elseif(Numpnts(W_FindLevels)>2)
1074                FindLevel /P/Q W_FindLevels, V_maxloc
1075                startPointL = W_FindLevels[floor(V_LevelX)]
1076                endPointL = W_FindLevels[ceil(V_LevelX)]
1077        endif
1078        W_coef[2] = abs(Ar_encoder[startPointL] - Ar_encoder[endPointL])/(2*(2*ln(2))^0.5)
1079        W_coef[3]=2
1080        //W[3]>1                //modified 7/6/2010 per request from Fan. K3 coefficient needs to be large enough to avoid weird Peak shapes.
1081        Make/O/T/N=1 T_Constraints
1082        T_Constraints[0] = {"K3>1.3"}
1083        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
1084        NVAR BeamCenter
1085        NVAR MaximumIntensity
1086        NVAR PeakWidth         
1087        NVAR PeakWidthArcSec           
1088        Variable BeamCenterError, MaximumIntensityError, PeakWidthError
1089        Wave W_coef
1090        Wave W_sigma
1091        PeakFitWave= W_coef[0]*exp(-0.5*(abs(x-W_coef[1])/W_coef[2])^W_coef[3])
1092        BeamCenter=W_coef[1]
1093        BeamCenterError=W_sigma[1]
1094        MaximumIntensity=W_coef[0]
1095        MaximumIntensityError=W_sigma[0]
1096        PeakWidth = 2*W_coef[2]*(2*ln(2))^(1/W_coef[3])
1097        PeakWidthArcSec = PeakWidth*3600
1098        PeakWidthError= 0//2*W_sigma[2]*(2*ln(2))^(1/W_sigma[3])...........need to calcualte approximate value in the future...
1099        Variable GaussPeakWidth=PeakWidth                               //2*(sqrt(ln(2)))*abs(W_coef[3])                        // properly fixed by now.
1100        Variable GaussPeakWidthError=   PeakWidthError                                  //2*(sqrt(ln(2)))*abs(W_sigma[3])
1101        string BmCnterStr
1102        Sprintf BmCnterStr, "%8.5f", BeamCenter
1103        String Width="\Z12FWHM   "+num2str(3600*GaussPeakWidth)+" +/- "+num2str(3600*GaussPeakWidthError)+"  arc-sec"
1104        Width+="\rMax       "+num2str(MaximumIntensity)+"   +/-  "+num2str(MaximumIntensityError)
1105        Width+="\rBm Cntr  "+BmCnterStr+"  +/-  "+num2str(BeamCenterError)+"  deg."
1106        DoWindow RcurvePlotGraph
1107        if(V_Flag)
1108                Textbox/W=RcurvePlotGraph/K/N=text1
1109                TextBox/W=RcurvePlotGraph/N=text1/F=0/B=2/X=63.96/Y=89.45 Width
1110        endif
1111//      ModifyGraph rgb($ModifyWave)=(0,15872,65280)
1112//      KillWaves W_WaveList
1113        Wave/Z R_Qvec
1114        if(WaveExists(R_Qvec))
1115                string ListOfWaveNames = "R_Qvec;R_Int;R_Error;Qvec;"
1116                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"PeakFitFunction","Modified Gauss")
1117                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenter",num2str(BeamCenter))
1118                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensity",num2str(MaximumIntensity))
1119                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM",num2str(PeakWidth*3600))
1120                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenterError",num2str(BeamCenterError))
1121                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensityError",num2str(MaximumIntensityError))
1122                IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM_Error",num2str(PeakWidthError*3600))
1123        endif
1124        doupdate
1125        setDataFolder OldDf
1126
1127End
1128
1129//******************** name **************************************
1130///**********************************************************************************************************
1131//******************** FitLorenzianOnTopMacro **************************************
1132
1133Function IN3_ModifiedGauss(w,xvar) : FitFunc
1134        Wave w
1135        Variable xvar
1136
1137        //CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
1138        //CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
1139        //CurveFitDialog/ Equation:
1140        //CurveFitDialog/ f(xvar) = Amplitude*exp(-0.5*(abs(xvar-center)/cparameter)^dparameter)
1141        //CurveFitDialog/ End of Equation
1142        //CurveFitDialog/ Independent Variables 1
1143        //CurveFitDialog/ xvar
1144        //CurveFitDialog/ Coefficients 4
1145        //CurveFitDialog/ w[0] = Amplitude
1146        //CurveFitDialog/ w[1] = center
1147        //CurveFitDialog/ w[2] = cparameter
1148        //CurveFitDialog/ w[3] = dparameter
1149
1150        return w[0]*exp(-0.5*(abs(xvar-w[1])/w[2])^w[3])
1151End
1152
1153//******************** name **************************************
1154///**********************************************************************************************************
1155//******************** FitLorenzianOnTopMacro **************************************
1156Function IN3_FitLorenzianTop(ctrlname) : Buttoncontrol                  // calls the Lorenzian fit
1157        string ctrlname
1158 
1159        string oldDf=GetDataFolder(1)
1160        setDataFolder root:Packages:Indra3
1161
1162        NVAR PeakCenterFitStartPoint
1163        NVAR PeakCenterFitEndPoint
1164        Wave PD_Intensity
1165        Wave Ar_encoder
1166        Wave PD_error
1167        Make/O/N=200 PeakFitWave
1168        DoWIndow RcurvePlotGraph
1169        String ExistingSubWindows
1170        if(V_Flag)
1171                ExistingSubWindows=ChildWindowList("RcurvePlotGraph")
1172        else
1173                ExistingSubWindows=""
1174        endif
1175        if(stringmatch(ExistingSubWindows,"*PeakCenter*"))
1176                getAxis/W=RcurvePlotGraph#PeakCenter /Q bottom
1177                SetScale/I x V_min, V_max,"", PeakFitWave
1178        else
1179                variable center = (PeakCenterFitStartPoint + PeakCenterFitEndPoint)/2
1180                variable start = max(0,center - (center -PeakCenterFitStartPoint) *3 )
1181                variable end1 = min(center + (PeakCenterFitEndPoint-center) *3, numpnts(Ar_encoder) )
1182                SetScale/I x Ar_encoder[start], Ar_encoder[end1],"", PeakFitWave
1183        endif
1184
1185        K0=0
1186        CurveFit/Q/H="1000"  lor PD_Intensity [PeakCenterFitStartPoint,PeakCenterFitEndPoint]  /X=Ar_encoder /D /W=PD_error /I=1 //Lorenzian
1187//      print "Fitted Lorenzian between points  "+num2str(PeakCenterFitStartPoint)+"   and    "+num2str(PeakCenterFitEndPoint)+"    reached Chi-squared/numpoints     " +num2str(V_chisq/(PeakCenterFitEndPoint-PeakCenterFitStartPoint))
1188//      string ModifyWave
1189//      ModifyWave="fit_"+WaveName("",0,1)                                              //new wave with the lorenzian fit
1190        NVAR BeamCenter
1191        NVAR MaximumIntensity
1192        NVAR PeakWidth 
1193        NVAR PeakWidthArcSec   
1194        Variable BeamCenterError, MaximumIntensityError, PeakWidthError
1195        Wave W_coef
1196        Wave W_sigma
1197        Wave PeakFitWave
1198//      Wave FitResiduals
1199//      FitResiduals= ((W_coef[0]+W_coef[1]/((Ar_encoder[p]-W_coef[2])^2+W_coef[3]))-PD_Intensity[p])/PD_error[p]
1200//      FitResiduals[0,xcsr(A)-1]=NaN
1201//      FitResiduals[xcsr(B)+1,inf]=NaN
1202        PeakFitWave= W_coef[0]+W_coef[1]/((x-W_coef[2])^2+W_coef[3])
1203        BeamCenterError=W_sigma[2]
1204        BeamCenter=W_coef[2]
1205        MaximumIntensity=W_coef[1]/W_coef[3]
1206        MaximumIntensityError=IN2G_ErrorsForDivision(W_coef[1],W_sigma[1],W_coef[3],W_sigma[3])
1207        PeakWidth = 2*sqrt(W_coef[3])
1208        PeakWidthArcSec = PeakWidth*3600
1209        //according to Andrew, the error here needs to be propagated through fractional error
1210        //that is, error of sqrt(x), sigma(sx)=X*(sigma(X)/2*X)
1211        PeakWidthError=PeakWidth*(W_sigma[3]/(2*W_coef[3]))
1212        string BmCenterStr, BmCenterErrStr
1213        Sprintf BmCenterStr, "%8.5f", BeamCenter
1214        Sprintf BmCenterErrStr, "%8.5f", BeamCenterError
1215        String Width="\Z12FWHM   "+num2str(PeakWidth*3600)+ " +/- "+num2str(PeakWidthError*3600)+"  arc-sec"
1216        Width+="\rMax     "+num2str(MaximumIntensity)+" +/-  "+num2str(MaximumIntensityError)
1217        Width+="\rBm Cntr   : "+BmCenterStr+" +/- "+ num2str(BeamCenterError)+"  deg."
1218        DoWindow RcurvePlotGraph
1219        if(V_Flag)
1220                Textbox/W=RcurvePlotGraph/K/N=text1
1221                TextBox/W=RcurvePlotGraph/N=text1/F=0/B=2/X=63.96/Y=89.45 Width
1222        endif
1223//      ModifyGraph rgb($ModifyWave)=(0,15872,65280)
1224//      KillWaves W_WaveList
1225        string ListOfWaveNames = "R_Qvec;R_Int;R_Error;Qvec;"
1226//      IN2G_AppendNoteToListOfWaves(ListOfWaveNames, Key,notetext
1227        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"PeakFitFunction","Lorenzian")
1228        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenter",num2str(BeamCenter))
1229        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensity",num2str(MaximumIntensity))
1230        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM",num2str(sqrt(W_coef[3])*3600*2))
1231        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"BeamCenterError",num2str(BeamCenterError))
1232        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"MaximumIntensityError",num2str(MaximumIntensityError))
1233        IN2G_AppendNoteToListOfWaves(ListOfWaveNames,"FWHM_Error",num2str(sqrt(W_sigma[3])*3600*2))
1234End
1235//**********************************************************************************************************
1236//**********************************************************************************************************
1237
1238//***************************************************************************************************************************************
1239//***************************************************************************************************************************************
1240//***************************************************************************************************************************************
1241//***************************************************************************************************************************************
1242//***************************************************************************************************************************************
1243//***************************************************************************************************************************************
1244Function IN3_ParametersChanged(ctrlName,varNum,varStr,varName) : SetVariableControl
1245        String ctrlName
1246        Variable varNum
1247        String varStr
1248        String varName
1249
1250        string oldDf=GetDataFolder(1)
1251        setDataFolder root:Packages:Indra3
1252
1253        //need to sync blanks widths, if changed by user...
1254        NVAR WidthDeg=root:Packages:Indra3:BlankFWHM
1255        NVAR WidthArcSec=root:Packages:Indra3:BlankWidth
1256        if(stringmatch(ctrlName,"BlankWidth"))
1257                WidthArcSec = WidthDeg * 3600
1258        endif
1259        if(stringmatch(ctrlName,"BlankWidthArcSec"))
1260                WidthDeg =  WidthArcSec/3600
1261        endif
1262        if(stringmatch(ctrlName,"SubtractFlatBackground"))
1263                NVAR SubtractFlatBackground= root:Packages:Indra3:SubtractFlatBackground
1264                SetVariable SubtractFlatBackground,win=USAXSDataReduction,limits={0,Inf,0.05*SubtractFlatBackground}
1265        endif
1266
1267       
1268        //recalculate what needs to be done...
1269        IN3_RecalculateData(2)
1270
1271        setDataFolder OldDf
1272End
1273///*****************************************************************************************************************
1274//*****************************************************************************************************************
1275//*****************************************************************************************************************
1276//*****************************************************************************************************************
1277//*****************************************************************************************************************
1278Function IN3_UPDParametersChanged(ctrlName,varNum,varStr,varName) : SetVariableControl
1279        String ctrlName
1280        Variable varNum
1281        String varStr
1282        String varName
1283
1284        string oldDf=GetDataFolder(1)
1285        setDataFolder root:Packages:Indra3
1286        SVAR UPDList=UPDParameters
1287       
1288        if (!cmpstr(ctrlName,"VtoF"))                                           //Changing V to F
1289                UPDList=ReplaceNumberByKey("Vtof",UPDList, varNum,"=")
1290                UPDList=ReplaceNumberByKey("Vfc",UPDList, varNum,"=")
1291        endif
1292        if (!cmpstr(ctrlName,"Gain1"))                                          //Changing Gain1
1293                UPDList=ReplaceNumberByKey("Gain1",UPDList, varNum,"=")
1294        endif
1295        if (!cmpstr(ctrlName,"Gain2"))                                          //Changing Gain2
1296                UPDList=ReplaceNumberByKey("Gain2",UPDList, varNum,"=")
1297        endif
1298        if (!cmpstr(ctrlName,"Gain3"))                                          //Changing gain3
1299                UPDList=ReplaceNumberByKey("Gain3",UPDList, varNum,"=")
1300        endif
1301        if (!cmpstr(ctrlName,"Gain4"))                                          //Changing Gain4
1302                UPDList=ReplaceNumberByKey("Gain4",UPDList, varNum,"=")
1303        endif
1304        if (!cmpstr(ctrlName,"Gain5"))                                          //Changing Gain5
1305                UPDList=ReplaceNumberByKey("Gain5",UPDList, varNum,"=")
1306        endif
1307        if (!cmpstr(ctrlName,"Bkg1"))                                           //Changing Bkg 1
1308                UPDList=ReplaceNumberByKey("Bkg1",UPDList, varNum,"=")
1309        endif
1310        if (!cmpstr(ctrlName,"Bkg2"))                                           //Changing Bkg 2
1311                UPDList=ReplaceNumberByKey("Bkg2",UPDList, varNum,"=")
1312        endif
1313        if (!cmpstr(ctrlName,"Bkg3"))                                           //Changing Bkg 3
1314                UPDList=ReplaceNumberByKey("Bkg3",UPDList, varNum,"=")
1315        endif
1316        if (!cmpstr(ctrlName,"Bkg4"))                                           //Changing Bkg 4
1317                UPDList=ReplaceNumberByKey("Bkg4",UPDList, varNum,"=")
1318        endif
1319        if (!cmpstr(ctrlName,"Bkg5"))                                           //Changing Bkg 5
1320                UPDList=ReplaceNumberByKey("Bkg5",UPDList, varNum,"=")
1321        endif
1322
1323
1324        IN3_RecalculateData(1)                  //and here we recalcualte the R wave
1325        setDataFolder OldDf
1326End
1327//*****************************************************************************************************************
1328//*****************************************************************************************************************
1329//*****************************************************************************************************************
1330//*****************************************************************************************************************
1331//*****************************************************************************************************************
1332
1333Function NI3_TabPanelControl(name,tab)
1334        String name
1335        Variable tab
1336
1337        string oldDf=GetDataFolder(1)
1338        setDataFolder root:Packages:Indra3
1339        NVAR IsBlank=root:Packages:Indra3:IsBlank
1340
1341
1342
1343        NVAR CalculateWeight=root:Packages:Indra3:CalculateWeight
1344        NVAR CalculateThickness=root:Packages:Indra3:CalculateThickness
1345        NVAR CalibrateToWeight=root:Packages:Indra3:CalibrateToWeight
1346        NVAR CalibrateToVolume=root:Packages:Indra3:CalibrateToVolume
1347        NVAR CalibrateArbitrary=root:Packages:Indra3:CalibrateArbitrary
1348
1349        Button RecoverDefault,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1350        CheckBox CalibrateToVolume,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1351        CheckBox CalibrateToWeight,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1352        CheckBox CalibrateArbitrary,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1353
1354        CheckBox CalculateThickness,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1355        CheckBox CalculateWeight,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToWeight )
1356        SetVariable SampleThickness,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || CalibrateArbitrary), noedit=(CalculateThickness), frame=!CalculateThickness
1357        SetVariable SampleWeightInBeam,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToWeight || CalibrateArbitrary), noedit=CalculateWeight, frame=!CalculateWeight
1358        SetVariable SampleTransmission,win=USAXSDataReduction, disable=(tab!=0 || IsBlank)
1359        SetVariable SampleLinAbsorption,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || CalibrateArbitrary), noedit=!CalculateThickness, frame=CalculateThickness
1360        SetVariable SampleDensity,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToWeight || CalibrateArbitrary), frame=CalculateWeight, noedit=!CalculateWeight
1361        SetVariable SampleFilledFraction,win=USAXSDataReduction, disable=(tab!=0 || IsBlank || !CalibrateToVolume || CalibrateArbitrary),noedit=!CalculateThickness, frame=CalculateThickness
1362        SetVariable BeamExposureArea, win=USAXSDataReduction, disable=(tab!=0 || IsBlank || CalibrateArbitrary), noedit=!(CalculateWeight&&CalibrateToWeight), frame=!CalculateWeight
1363
1364
1365
1366        SetVariable VtoF,win=USAXSDataReduction, disable=(tab!=1)
1367        SetVariable Gain1,win=USAXSDataReduction, disable=(tab!=1)
1368        SetVariable Gain2,win=USAXSDataReduction, disable=(tab!=1)
1369        SetVariable Gain3,win=USAXSDataReduction, disable=(tab!=1)
1370        SetVariable Gain4,win=USAXSDataReduction, disable=(tab!=1)
1371        SetVariable Gain5,win=USAXSDataReduction, disable=(tab!=1)
1372        SetVariable Bkg1,win=USAXSDataReduction, disable=(tab!=1)
1373        SetVariable Bkg2,win=USAXSDataReduction, disable=(tab!=1)
1374        SetVariable Bkg3,win=USAXSDataReduction, disable=(tab!=1)
1375        SetVariable Bkg4,win=USAXSDataReduction, disable=(tab!=1)
1376        SetVariable Bkg5,win=USAXSDataReduction, disable=(tab!=1)
1377        SetVariable Bkg1Err,win=USAXSDataReduction, disable=(tab!=1)
1378        SetVariable Bkg2Err,win=USAXSDataReduction, disable=(tab!=1)
1379        SetVariable Bkg3Err,win=USAXSDataReduction, disable=(tab!=1)
1380        SetVariable Bkg4Err,win=USAXSDataReduction, disable=(tab!=1)
1381        SetVariable Bkg5Err,win=USAXSDataReduction, disable=(tab!=1)
1382
1383
1384        SetVariable SpecCommand,win=USAXSDataReduction, disable=(tab!=2)
1385        SetVariable PhotoDiodeSize,win=USAXSDataReduction, disable=(tab!=2)
1386        SetVariable Wavelength,win=USAXSDataReduction, disable=(tab!=2)
1387        SetVariable SDDistance,win=USAXSDataReduction, disable=(tab!=2)
1388        SetVariable SlitLength,win=USAXSDataReduction, disable=(tab!=2)
1389        SetVariable NumberOfSteps,win=USAXSDataReduction, disable=(tab!=2)
1390
1391        SetVariable MaximumIntensity,win=USAXSDataReduction, disable=(tab!=3)
1392        SetVariable PeakWidth,win=USAXSDataReduction, disable=(tab!=3)
1393        SetVariable PeakWidthArcSec,win=USAXSDataReduction, disable=(tab!=3)
1394        SetVariable BlankMaximum,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1395        SetVariable BlankWidth,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1396        SetVariable BlankWidthArcSec,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1397        SetVariable SubtractFlatBackground,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1398        Button RecoverDefaultBlnkVals,win=USAXSDataReduction, disable=(tab!=3 || IsBlank)
1399
1400
1401        NVAR UseMSAXSCorrection=root:Packages:Indra3:UseMSAXSCorrection
1402        CheckBox UseMSAXSCorrection,win=USAXSDataReduction, disable=(tab!=4 || IsBlank)
1403        //UseMSAXSCorrection
1404        SetVariable MSAXSCorrection,win=USAXSDataReduction, disable=(tab!=4 || !UseMSAXSCorrection || IsBlank)
1405        SetVariable MSAXSStartPoint,win=USAXSDataReduction, disable=(tab!=4 || !UseMSAXSCorrection || IsBlank)
1406        SetVariable MSAXSEndPoint,win=USAXSDataReduction, disable=(tab!=4 || !UseMSAXSCorrection || IsBlank)
1407        String ExistingSubWindows=ChildWindowList("USAXSDataReduction")
1408        if(stringmatch(ExistingSubWindows,"*MSAXSGraph*") && IsBlank)
1409                KillWindow  USAXSDataReduction#MSAXSGraph
1410                ExistingSubWindows=ChildWindowList("USAXSDataReduction")
1411        endif
1412        if(tab!=4 || !UseMSAXSCorrection)
1413                        IN3_HideMSAXSGraph()
1414        else
1415                IN3_ShowMSAXSGraph()
1416//              if(!stringmatch(ExistingSubWindows,"*MSAXSGraph*"))
1417//                      IN3_ShowMSAXSGraph()
1418//              else
1419//                      //setWindow USAXSDataReduction#MSAXSGraph, hide =0     
1420//                      IN3_ShowMSAXSGraph()
1421//              endif
1422//              if((!UseMSAXSCorrection || IsBlank) &&stringmatch(ExistingSubWindows,"*MSAXSGraph*")  )
1423//                      IN3_ShowMSAXSGraph()
1424//              endif
1425        endif
1426        //color wave in main graph as appropriate
1427        if(tab==1)
1428                IN3_ColorMainGraph(1)
1429        else
1430                IN3_ColorMainGraph(0)
1431        endif
1432       
1433        setDataFolder OldDf
1434end
1435
1436//*****************************************************************************************************************
1437//*****************************************************************************************************************
1438//*****************************************************************************************************************
1439
1440Function/T IN3_GenStringOfFolders(useBlankData)
1441        variable useBlankData
1442       
1443        string ListOfQFolders
1444        string result
1445        if (useBlankData)
1446                        result=IN2G_FindFolderWithWaveTypes("root:USAXS:", 10, "Blank_*", 1)
1447        endif
1448       
1449        return result
1450end
1451
1452
1453//*****************************************************************************************************************
1454//*****************************************************************************************************************
1455//*****************************************************************************************************************
1456//*****************************************************************************************************************
1457//*****************************************************************************************************************
Note: See TracBrowser for help on using the repository browser.