source: sans/Dev/trunk/NCNR_User_Procedures/SANS/Analysis/Models/Packages/Invariant/Invariant_v40.ipf @ 393

Last change on this file since 393 was 393, checked in by srkline, 15 years ago

DoSaveFileDialog? now takes two optional parameters, fname and suffix that can speed file save/rename, especially when used with the subtract1D operation.

Invariant now has a new macro to solve for the volume fraction.

PNGs are used wherever possible for reports. Gizmo window are still the oddball, and are limited to native platform formats.

File size: 18.8 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4// 07 JAN 05 SRK
5// updated procedures (from SS 2002) to be used as a package
6// with the SANS analysis routines
7//
8// need to:
9// - verify accuracy (see John)
10
11// this is the main entry point for the panel
12Proc Make_Invariant_Panel()
13        DoWindow/F Invariant_Panel
14        if(V_flag==0)
15                //create global variables in root:myGlobals:invariant
16                Init_Invariant()
17                Invariant_Panel()
18        endif
19        //pop the file menu
20        Inv_FilePopMenuProc("",1,"")
21End
22
23//create the globals
24Proc Init_Invariant()
25        NewDataFolder/O root:Packages
26        NewDataFolder/O root:Packages:NIST
27        NewDataFolder/O/S root:Packages:NIST:invariant
28        Variable/G gNumLow=10
29        Variable/G gNumHigh=10
30       
31        Variable/G gInvMeas=0
32        Variable/G gInvLowQ=0
33        Variable/G gInvHighQ=0
34        Variable/G gInvTotal=0
35        String/G gDataPopList = "none"
36        Variable/G gIsSlitSmeared=0
37        Variable/G gDqv = 0.117         //default value for USANS slit height (re-read from file)
38               
39        SetDataFolder root:
40End
41
42// for testing - compare to the "perfect" value. This macro
43// calculates the invariant based on the contrast and volume fraction
44// - the extrapolated/integrated value should match this...
45Macro PrintModelInvariant(delta_rho,phi)
46        Variable delta_rho=3e-6,phi=0.1
47        // delta_rho [=] 1/A^2
48        Variable inv
49        inv = 2*pi*pi*delta_rho*delta_rho*phi*(1-phi)*1e8
50       
51        Printf "The model invariant is %g A^-3 cm^-1\r\r",inv
52End
53
54// for testing - compare to the "perfect" value. This macro
55// calculates the invariant based on the contrast and volume fraction
56// - the extrapolated/integrated value should match this...
57Macro SolveForVolumeFraction(invariant,delta_rho)
58        Variable invariant,delta_rho=6e-6
59        // delta_rho [=] 1/A^2
60        Variable phi1,phi2,arg
61       
62        arg = 1 - 4*invariant*(1e-8)/2/pi/pi/delta_rho/delta_rho
63        phi1 = (1 - sqrt(arg))/2
64        phi2 = (1 + sqrt(arg))/2
65       
66        Printf "The two solutions for phi are: %8.6f\t and %8.6f\r\r",phi1,phi2
67End
68
69
70//integrates only over the given q-range, does no interpolation
71Function Invariant(qw,iw)
72        Wave qw,iw
73       
74        Variable num,invar
75        Duplicate/O qw integrand
76        integrand = qw*qw*iw
77//      integrand /= 1e8                //convert 1/cm to 1/A
78       
79        num = numpnts(qw)
80        invar = areaXY(qw,integrand,qw[0],qw[num-1])
81       
82        return(invar)           //units of A^-3 cm^-1
83End
84
85//integrates only over the given q-range, does no interpolation
86// function is for slit smeared data
87Function Invariant_SlitSmeared(qw,iw)
88        Wave qw,iw
89       
90        Variable num,invar
91        NVAR dQv = root:Packages:NIST:invariant:gDqv
92       
93        Duplicate/O qw integrand
94        integrand = qw*iw
95//      integrand /= 1e8                //convert 1/cm to 1/A
96       
97        num = numpnts(qw)
98        invar = areaXY(qw,integrand,qw[0],qw[num-1])
99       
100        invar *= dQv            //correct for the effects of slit-smearing
101               
102        return(invar)           //units of A^-3 cm^-1
103End
104
105Function Guinier_Fit(w,x) : FitFunc
106        Wave w
107        Variable x
108       
109        //fit data to I(q) = A*exp(B*q^2)
110        // (B will be negative)
111        //two parameters
112        Variable a,b,ans
113        a=w[0]
114        b=w[1]
115        ans = a*exp(b*x*x)
116        return(ans)
117End
118
119
120//pass the wave with the q-values
121Function SetExtrWaves(w)
122        Wave w
123
124        Variable num_extr=100
125       
126        Make/O/D/N=(num_extr) extr_hqq,extr_hqi,extr_lqq,extr_lqi
127        extr_lqi=1
128        extr_hqi=1              //default values
129        //set the q-range
130        Variable qmax,qmin,num
131        qmax=10
132        qmin=0
133        num=numpnts(w)
134       
135        extr_hqq = w[num-1] + x * (qmax-w[num-1])/num_extr
136        extr_lqq = qmin + x * (w[0]-qmin)/num_extr
137       
138        return(0)
139End
140
141Function DoExtrapolate(qw,iw,sw,nbeg,nend)
142        Wave qw,iw,sw
143        Variable nbeg,nend
144       
145        Wave extr_lqi=extr_lqi
146        Wave extr_lqq=extr_lqq
147        Wave extr_hqi=extr_hqi
148        Wave extr_hqq=extr_hqq
149        Variable/G V_FitMaxIters=300
150        Variable num=numpnts(iw)
151       
152        Make/O/D G_coef={100,-100}              //input
153        FuncFit Guinier_Fit G_coef iw[0,(nbeg-1)] /X=qw /W=sw /D
154        extr_lqi= Guinier_Fit(G_coef,extr_lqq)
155       
156        Printf "I(q=0) = %g (1/cm)\r",G_coef[0]
157        Printf "Rg = %g (A)\r",sqrt(-3*G_coef[1])
158       
159        Make/O/D P_coef={0,1,-4}                        //input
160        //(set background to zero and hold fixed)
161        CurveFit/H="100" Power kwCWave=P_coef  iw[(num-1-nend),(num-1)] /X=qw /W=sw /D
162        extr_hqi=P_coef[0]+P_coef[1]*extr_hqq^P_coef[2]
163       
164        Printf "Power law exponent = %g\r",P_coef[2]
165        Printf "Pre-exponential = %g\r",P_coef[1]
166       
167        return(0)
168End
169
170//plot based on the wave selelctions
171Function Plot_Inv_Data(ctrlName) : ButtonControl
172        String ctrlName
173       
174        //access the global strings representing the last data file read in
175        SVAR QWave = root:Packages:NIST:invariant:QWave
176        SVAR IWave = root:Packages:NIST:invariant:IWave
177        SVAR SWave = root:Packages:NIST:invariant:SWave
178       
179        Wave qw=$QWave
180        Wave iw=$IWave
181        Wave sw=$SWave
182       
183        String str="",item=""
184        Variable num=0,ii
185       
186        //not used - just kill and re-draw
187        //remove everything from the graph and graph it again
188//      str = TraceNameList("",";",1)
189//      num=ItemsInList(str)
190//      for(ii=0;ii<num;ii+=1)
191//              item=StringFromList(ii, str  ,";")
192//              Print item
193//              RemoveFromGraph $item
194//      endfor
195
196        DoWindow/F invariant_graph
197        if(V_flag==1)
198                DoWindow/K invariant_graph
199        endif
200        Display /W=(5,44,375,321)/K=1 iw vs qw
201        DoWindow/C invariant_graph
202        ModifyGraph mode=3,marker=8
203        ModifyGraph grid=1
204        ModifyGraph log=1
205        ModifyGraph mirror=2
206        ModifyGraph standoff=0
207        Label left "Intensity (1/cm)"
208        Label bottom "q (1/A)"
209        ModifyGraph rgb($NameofWave(iw))=(0,0,0)
210        ModifyGraph opaque($NameofWave(iw))=1
211        ErrorBars $NameofWave(iw) Y,wave=(sw,sw)
212        Legend
213       
214//      Print TraceNameList("",";",1)
215       
216        //create the extra waves now, and add to plot
217        SetExtrWaves(qw)
218        Wave extr_lqi=extr_lqi
219        Wave extr_lqq=extr_lqq
220        Wave extr_hqi=extr_hqi
221        Wave extr_hqq=extr_hqq
222        AppendtoGraph extr_lqi vs extr_lqq
223        AppendtoGraph extr_hqi vs extr_hqq
224        ModifyGraph lSize(extr_lqi)=2,lSize(extr_hqi)=2
225        ModifyGraph rgb($NameofWave(iw))=(0,0,0),rgb(extr_hqi)=(2,39321,1)
226       
227        //reset the invariant values to zero
228        NVAR meas = root:Packages:NIST:invariant:gInvMeas
229        NVAR lo = root:Packages:NIST:invariant:gInvLowQ
230        NVAR hi = root:Packages:NIST:invariant:gInvHighQ
231        NVAR total = root:Packages:NIST:invariant:gInvTotal
232        meas=0
233        lo=0
234        hi=0
235        total=0
236       
237        return(0)
238End
239
240
241Function LowCheckProc(ctrlName,checked) : CheckBoxControl
242        String ctrlName
243        Variable checked
244
245        Variable val=0
246//      print "checked = ",checked
247        if(cmpstr(ctrlName,"check_0")==0)
248                if(checked)
249                        val=1
250                endif
251        endif
252        CheckBox check_0,value= Val==1
253        CheckBox check_1,value= Val==0
254End
255
256
257Proc Invariant_Panel()
258        SetDataFolder root:             //use absolute paths?
259        PauseUpdate; Silent 1           // building window...
260        NewPanel /W=(510,44,796,529)    /K=2
261        DoWindow/C Invariant_Panel
262        ModifyPanel cbRGB=(65535,43690,0)
263        SetDrawLayer UserBack
264        DrawText 23,196,"Extrapolation"
265        DrawText 158,195,"Power-Law"
266        DrawText 158,211,"Extrapolation"
267        SetDrawEnv fstyle= 1
268        DrawText 58,349,"Units are [A^-3 cm^-1]"
269        SetDrawEnv fstyle= 1
270        DrawText 61,16,"Calculate the Invariant"
271        DrawLine 16,135,264,135
272        DrawLine 16,19,264,19
273       
274        PopupMenu ywave,pos={10,60},size={154,19},title="Data File"
275        PopupMenu ywave,help={"Select the experimental intensity values"}
276        PopupMenu ywave,mode=1,value=root:Packages:NIST:invariant:gDataPopList,proc=Inv_FilePopMenuProc
277       
278        Button loadButton,pos={10,90},size={130,20},proc=Inv_Load_Proc,title="Load and Plot File"
279        Button loadButton,help={"After choosing a file, load it into memory and plot it with this button."}
280       
281        Button Inv_PathButton,pos={10,29},size={80,20},proc=Inv_PickPathButtonProc,title="Pick Path"
282        Button DoneButton,pos={215,453},size={50,20},proc=InvDoneButton,title="Done"
283        Button DoneButton,help={"This button will close the panel and the associated graph"}
284
285        SetVariable setvar_0,pos={27,249},size={80,15},title="# points"
286        SetVariable setvar_0,limits={5,50,0},value= root:Packages:NIST:invariant:gNumLow
287        SetVariable setvar_1,pos={166,249},size={80,15},title="# points"
288        SetVariable setvar_1,limits={5,200,0},value= root:Packages:NIST:invariant:gNumHigh
289        CheckBox check_0,pos={23,202},size={50,14},proc=LowCheckProc,title="Guinier"
290        CheckBox check_0,value= 1
291        CheckBox check_1,pos={23,223},size={68,14},proc=LowCheckProc,title="Power Law"
292        CheckBox check_1,value= 0
293        Button button_0,pos={29,275},size={90,20},proc=InvLowQ,title="Calc Low Q"
294        Button button_1,pos={56,141},size={170,20},proc=InvMeasQ,title="Calculate Measured Q"
295        Button button_2,pos={168,275},size={90,20},proc=InvHighQ,title="Calc High Q"
296//      Button button_3,pos={13,98},size={50,20},proc=Plot_Inv_Data,title="Plot"
297        Button button_4,pos={230,29},size={25,20},proc=Inv_HelpButtonProc,title="?"
298        GroupBox group0,pos={14,165},size={123,144},title="Low Q"
299        GroupBox group0_1,pos={147,165},size={123,144},title="High Q"
300        GroupBox group1,pos={23,318},size={239,124},title="INVARIANT"
301        ValDisplay valdisp0,pos={51,354},size={180,14},title="In measured Q-range "
302        ValDisplay valdisp0,limits={0,0,0},barmisc={0,1000}
303        ValDisplay valdisp0,value= #"root:Packages:NIST:invariant:gInvMeas"
304        ValDisplay valdisp0_1,pos={51,371},size={180,14},title="In low Q extrapolation "
305        ValDisplay valdisp0_1,limits={0,0,0},barmisc={0,1000}
306        ValDisplay valdisp0_1,value= #"root:Packages:NIST:invariant:gInvLowQ"
307        ValDisplay valdisp0_2,pos={51,388},size={180,14},title="In high Q extrapolation "
308        ValDisplay valdisp0_2,limits={0,0,0},barmisc={0,1000}
309        ValDisplay valdisp0_2,value= #"root:Packages:NIST:invariant:gInvHighQ"
310        ValDisplay valdisp0_3,pos={51,411},size={180,14},title="TOTAL "
311        ValDisplay valdisp0_3,limits={0,0,0},barmisc={0,1000}
312        ValDisplay valdisp0_3,value= #"root:Packages:NIST:invariant:gInvTotal"
313       
314        CheckBox check0,pos={10,116},size={101,14},proc=SlitSmearedCheckProc,title="Slit-Smeared Data"
315        CheckBox check0,value= root:Packages:NIST:invariant:gIsSlitSmeared
316        SetVariable setvar0,pos={136,116},size={130,15},title="Slit Height (1/A)"
317        SetVariable setvar0,limits={-inf,inf,0},value= root:Packages:NIST:invariant:gDqv
318       
319        //set up a dependency to calculate the total invariant
320        root:Packages:NIST:invariant:gInvTotal := root:Packages:NIST:invariant:gInvLowQ + root:Packages:NIST:invariant:gInvMeas + root:Packages:NIST:invariant:gInvHighQ
321EndMacro
322
323
324Function InvMeasQ(ctrlName) : ButtonControl
325        String ctrlName
326       
327        //no graph, get out
328        DoWindow/F Invariant_Graph
329        if(V_flag==0)
330                return(0)
331        endif
332       
333        //do the straight calculation of the invariant of the specified data
334        Variable inv,num
335       
336        SVAR QWave = root:Packages:NIST:invariant:QWave
337        Wave qw=$QWave
338        SVAR IWave = root:Packages:NIST:invariant:IWave
339        Wave iw=$IWave
340       
341        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
342        if(isSlitSmeared)
343                inv = Invariant_SlitSmeared(qw,iw)
344        else
345                inv = Invariant(qw,iw)
346        endif
347       
348        num=numpnts(qw)
349        Printf "The invariant over the measured q-range %g to %g is %g A^-3 cm^-1\r\r",qw[0],qw[(num-1)],inv
350       
351        // update the global display on the panel (there is a dependency for the total)
352        NVAR val = root:Packages:NIST:invariant:gInvMeas
353        val = inv
354       
355        return(0)
356End
357
358Function InvLowQ(ctrlName) : ButtonControl
359        String ctrlName
360       
361        //no graph, get out
362        DoWindow/F Invariant_Graph
363        if(V_flag==0)
364                return(0)
365        endif
366       
367        Variable yesGuinier=0,nume,inv
368        // do the extrapolation of the correct type
369        ControlInfo/W=Invariant_Panel check_0           //the Guinier box
370        yesGuinier = V_Value
371//      print "yesGuinier = ",yesGuinier
372        //number of points to use for fit
373        NVAR nbeg=root:Packages:NIST:invariant:gNumLow
374        //define the waves
375        Wave extr_lqi=extr_lqi
376        Wave extr_lqq=extr_lqq
377       
378        SVAR QWave = root:Packages:NIST:invariant:QWave
379        Wave qw=$QWave
380        SVAR IWave = root:Packages:NIST:invariant:IWave
381        Wave iw=$IWave
382        SVAR SWave = root:Packages:NIST:invariant:SWave
383        Wave sw=$SWave
384       
385        Wave/Z W_coef=W_coef
386        Variable/G V_FitMaxIters=300
387//      Variable numi=numpnts(iw)
388       
389        if(yesGuinier)
390                Make/O/D G_coef={1000,-1000}            //input
391                FuncFit Guinier_Fit G_coef iw[0,(nbeg-1)] /X=qw /W=sw /D
392                extr_lqi= Guinier_Fit(G_coef,extr_lqq)
393               
394                Printf "I(q=0) = %g (1/cm)\r",G_coef[0]
395                Printf "Rg = %g (A)\r",sqrt(-3*G_coef[1])
396        else
397                //do a power-law fit instead
398                Make/O/D P_coef={0,1,-1}                        //input
399                //(set background to zero and hold fixed)
400                CurveFit/H="100" Power kwCWave=P_coef  iw[0,(nbeg-1)] /X=qw /W=sw /D
401                extr_lqi=P_coef[0]+P_coef[1]*extr_lqq^P_coef[2]
402                //     
403                Printf "Pre-exponential = %g\r",P_coef[1]
404                Printf "Power law exponent = %g\r",P_coef[2]
405                //     
406        endif
407       
408        //calculate the invariant
409        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
410        if(isSlitSmeared)
411                inv = Invariant_SlitSmeared(extr_lqq,extr_lqi)
412        else
413                inv = Invariant(extr_lqq,extr_lqi)
414        endif
415       
416        nume=numpnts(extr_lqq)
417        Printf "The invariant over the q-range %g to %g is %g A^-3 cm^-1\r\r",extr_lqq[0],extr_lqq[(nume-1)],inv
418       
419        // update the global display on the panel (there is a dependency for the total)
420        NVAR val = root:Packages:NIST:invariant:gInvLowQ
421        val = inv
422       
423        return(0)
424End
425
426Function InvHighQ(ctrlName) : ButtonControl
427        String ctrlName
428       
429        //no graph, get out
430        DoWindow/F Invariant_Graph
431        if(V_flag==0)
432                return(0)
433        endif
434       
435        // do the power-law extrapolation
436       
437        Wave extr_hqi=extr_hqi
438        Wave extr_hqq=extr_hqq
439        SVAR QWave = root:Packages:NIST:invariant:QWave
440        Wave qw=$QWave
441        SVAR IWave = root:Packages:NIST:invariant:IWave
442        Wave iw=$IWave
443        SVAR SWave = root:Packages:NIST:invariant:SWave
444        Wave sw=$SWave
445       
446        Variable/G V_FitMaxIters=300
447        Variable num=numpnts(iw),nume,inv
448        NVAR nend=root:Packages:NIST:invariant:gNumHigh         //number of points for the fit
449
450        Make/O/D P_coef={0,1,-4}                        //input
451        //(set background to zero and hold fixed)
452        CurveFit/H="100" Power kwCWave=P_coef  iw[(num-1-nend),(num-1)] /X=qw /W=sw /D
453        extr_hqi=P_coef[0]+P_coef[1]*extr_hqq^P_coef[2]
454       
455        Printf "Pre-exponential = %g\r",P_coef[1]
456        Printf "Power law exponent = %g\r",P_coef[2]
457       
458        //calculate the invariant
459        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
460        if(isSlitSmeared)
461                inv = Invariant_SlitSmeared(extr_hqq,extr_hqi)
462        else
463                inv = Invariant(extr_hqq,extr_hqi)
464        endif
465
466        nume=numpnts(extr_hqq)
467        Printf "The invariant over the q-range %g to %g is %g A^-3 cm^-1\r\r",extr_hqq[0],extr_hqq[(nume-1)],inv
468       
469        // update the global display on the panel (there is a dependency for the total)
470        NVAR val = root:Packages:NIST:invariant:gInvHighQ
471        val = inv
472       
473        return(0)       
474End
475
476Function UnloadInvariant()
477        if (WinType("Invariant_Panel") == 7)
478                DoWindow/K Invariant_Panel
479        endif
480        if (WinType("Invariant_Graph") != 0)
481                DoWindow/K $"Invariant_Graph"
482        endif
483        if (DatafolderExists("root:Packages:NIST:invariant"))
484                KillDatafolder root:Packages:NIST:invariant
485        endif
486        SetDataFolder root:
487        Killwaves/Z integrand,G_coef,P_coef,extr_hqq,extr_hqi,extr_lqq,extr_lqi
488       
489        SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION
490        String fname="Invariant"
491        Execute/P "DELETEINCLUDE \""+fname+fileVerExt+"\""
492        Execute/P "COMPILEPROCEDURES "
493end
494
495Menu "SANS Models"
496        Submenu "Packages"
497                "Unload Invariant", UnloadInvariant()
498        End
499end
500
501Function Inv_HelpButtonProc(ctrlName) : ButtonControl
502        String ctrlName
503
504        DisplayHelpTopic/Z/K=1 "Calculate Scattering Invariant"
505        if(V_flag != 0)
506                DoAlert 0, "The Scattering Invariant Help file can not be found"
507        endif
508End
509
510Function Inv_PickPathButtonProc(ctrlName) : ButtonControl
511        String ctrlName
512
513        A_PickPath()
514        //pop the file menu
515        Inv_FilePopMenuProc("",1,"")
516End
517
518//gets a valid file list (simply not the files with ".SAn" in the name)
519//
520Function Inv_FilePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl
521        String ctrlName
522        Variable popNum
523        String popStr
524       
525        String tempStr=Inv_filterButtonProc(ctrlName)
526        if(strlen(tempStr)==0)
527                tempStr = "Pick the data path"
528        Endif
529        String/G root:Packages:NIST:invariant:gDataPopList =tempStr
530        ControlUpdate/W=Invariant_Panel ywave
531       
532End
533
534//function called byt the popups to get a file list of data that can be sorted
535// this procedure simply removes the raw data files from the string - there
536//can be lots of other junk present, but this is very fast...
537//
538// could also use the alternate procedure of keeping only file with the proper extension
539//
540Function/S Inv_filterButtonProc(ctrlName)
541        String ctrlName
542
543        String list="",newList="",item=""
544        Variable num,ii
545       
546        //check for the path
547        PathInfo catPathName
548        if(V_Flag==0)
549                DoAlert 0, "Data path does not exist - pick the data path from the button on the invariant panel"
550                Return("")
551        Endif
552       
553        list = IndexedFile(catpathName,-1,"????")
554        num=ItemsInList(list,";")
555        //print "num = ",num
556        for(ii=(num-1);ii>=0;ii-=1)
557                item = StringFromList(ii, list  ,";")
558                //simply remove all that are not raw data files (SA1 SA2 SA3)
559                if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") )
560                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
561                                newlist += item + ";"
562                        endif
563                endif
564        endfor
565        //remove VAX version numbers
566        newList = A_RemoveVersNumsFromList(newList)
567        //sort
568        newList = SortList(newList,";",0)
569
570        return newlist
571End
572
573// Loads the selected file for fitting
574// and graphs the data as needed
575Proc Inv_Load_Proc(ctrlName): ButtonControl
576        String ctrlName
577       
578        //Load the data
579        String tempName="",partialName=""
580        Variable err
581        ControlInfo/W=Invariant_Panel ywave
582        //find the file from the partial filename
583        If( (cmpstr(S_value,"")==0) || (cmpstr(S_value,"none")==0) )
584                //null selection, or "none" from any popup
585                Abort "no file selected in popup menu"
586        else
587                //selection not null
588                partialName = S_value
589                //Print partialName
590        Endif
591        //get a valid file based on this partialName and catPathName
592        tempName = A_FindValidFilename(partialName)
593
594        //prepend path to tempName for read routine
595        PathInfo catPathName
596       
597        tempName = S_path + tempName
598       
599        //load in the data (into the root directory)
600        A_LoadOneDDataWithName(tempName,0)
601        //Print S_fileName
602        //Print tempName
603       
604        String cleanLastFileName = CleanupName(root:Packages:NIST:gLastFileName,0)
605        String dataStr = "root:"+cleanLastFileName+":"
606       
607        // keep global copies of the names rather than reading from the popup
608        tempName=dataStr + cleanLastFileName+"_q"
609        String/G root:Packages:NIST:invariant:QWave=tempName
610        tempName=dataStr + cleanLastFileName+"_i"
611        String/G root:Packages:NIST:invariant:IWave=tempName
612        tempName=dataStr + cleanLastFileName+"_s"
613        String/G root:Packages:NIST:invariant:SWave=tempName
614
615        //Plot, and adjust the scaling to match the axis scaling set by the popups
616        Plot_Inv_Data("")
617
618        //if the slit-smeared box is checked, try to read the slit height
619        // - if can't find it, maybe not really smeared data, so put up the Alert
620        ControlInfo/W=Invariant_Panel check0
621        if(V_Value==1)
622                SlitSmearedCheckProc("",1)
623        endif
624End
625
626Proc InvDoneButton(ctrlName): ButtonControl
627        String ctrlName
628        DoWindow/K Invariant_Graph
629        DoWindow/K Invariant_Panel
630end
631
632//get the slit height if the data is slit-smeared
633//set the globals as needed
634Function SlitSmearedCheckProc(ctrlName,checked) : CheckBoxControl
635        String ctrlName
636        Variable checked
637
638        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
639        SVAR fileStr=root:Packages:NIST:gLastFileName
640       
641        //reset the global to the checkbox state
642        isSlitSmeared = checked         //==0 if the data is not slit smeared
643       
644        if(checked)             //get the smearing info
645                String cleanLastFileName = "root:"+CleanupName(fileStr,0)
646                NVAR dQv=root:Packages:NIST:invariant:gDqv
647                String tempName = cleanLastFileName+"sq"
648                Wave/Z w=$tempName
649                if(WaveExists(w) && w[0] < 0)
650                        dQv = - w[0]
651                        Print "Data is slit-smeared, dqv = ",w[0]
652                else
653                        DoAlert 0,"Can't find the slit height from the data. Enter the value manually if the data is truly slit-smeared, or uncheck the box."
654                endif
655        endif
656       
657        return(0)
658End
Note: See TracBrowser for help on using the repository browser.