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

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

Added option in invariant calculation to hold the slope fixed at a user-supplied value. -4 is the typical value. If the slope in not held fixed using the checkbox, it will be fitted as ususal.

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