source: sans/Dev/trunk/NCNR_User_Procedures/Common/Packages/Invariant/Invariant_v40.ipf @ 570

Last change on this file since 570 was 570, checked in by srkline, 13 years ago

Change (1):
In preparation for release, updated pragma IgorVersion?=6.1 in all procedures

Change (2):
As a side benefit of requiring 6.1, we can use the MultiThread? keyword to thread any model function we like. The speed benefit is only noticeable on functions that require at least one integration and at least 100 points (resolution smearing is NOT threaded, too many threadSafe issues, too little benefit). I have chosen to use the MultiThread? only on the XOP assignment. In the Igor code there are too many functions that are not explicitly declared threadsafe, making for a mess.

File size: 19.3 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
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=1e-5
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        ModifyGraph tickUnit=1
211        Label left "Intensity (1/cm)"
212        Label bottom "q (1/A)"
213        ModifyGraph rgb($NameofWave(iw))=(0,0,0)
214        ModifyGraph opaque($NameofWave(iw))=1
215        ErrorBars/T=0 $NameofWave(iw) Y,wave=(sw,sw)
216        Legend
217       
218//      Print TraceNameList("",";",1)
219       
220        //create the extra waves now, and add to plot
221        SetExtrWaves(qw)
222        Wave extr_lqi=extr_lqi
223        Wave extr_lqq=extr_lqq
224        Wave extr_hqi=extr_hqi
225        Wave extr_hqq=extr_hqq
226        AppendtoGraph extr_lqi vs extr_lqq
227        AppendtoGraph extr_hqi vs extr_hqq
228        ModifyGraph lSize(extr_lqi)=2,lSize(extr_hqi)=2
229        ModifyGraph rgb($NameofWave(iw))=(0,0,0),rgb(extr_hqi)=(2,39321,1)
230       
231        //reset the invariant values to zero
232        NVAR meas = root:Packages:NIST:invariant:gInvMeas
233        NVAR lo = root:Packages:NIST:invariant:gInvLowQ
234        NVAR hi = root:Packages:NIST:invariant:gInvHighQ
235        NVAR total = root:Packages:NIST:invariant:gInvTotal
236        meas=0
237        lo=0
238        hi=0
239        total=0
240       
241        return(0)
242End
243
244
245Function LowCheckProc(ctrlName,checked) : CheckBoxControl
246        String ctrlName
247        Variable checked
248
249        Variable val=0
250//      print "checked = ",checked
251        if(cmpstr(ctrlName,"check_0")==0)
252                if(checked)
253                        val=1
254                endif
255        endif
256        CheckBox check_0,value= Val==1
257        CheckBox check_1,value= Val==0
258End
259
260
261Proc Invariant_Panel()
262        SetDataFolder root:             //use absolute paths?
263        PauseUpdate; Silent 1           // building window...
264        NewPanel /W=(510,44,796,529) /K=2
265        DoWindow/C Invariant_Panel
266        ModifyPanel cbRGB=(65535,43690,0)
267        SetDrawLayer UserBack
268        DrawText 23,196,"Extrapolation"
269        DrawText 158,195,"Power-Law"
270        DrawText 158,211,"Extrapolation"
271        SetDrawEnv fstyle= 1
272        DrawText 58,349,"Units are [A^-3 cm^-1]"
273        SetDrawEnv fstyle= 1
274        DrawText 61,16,"Calculate the Invariant"
275        DrawLine 16,135,264,135
276        DrawLine 16,19,264,19
277        PopupMenu ywave,pos={10,60},size={231,20},proc=Inv_FilePopMenuProc,title="Data File"
278        PopupMenu ywave,help={"Select the experimental intensity values"}
279        PopupMenu ywave,mode=1,value= #"root:Packages:NIST:invariant:gDataPopList"
280        Button loadButton,pos={10,90},size={130,20},proc=Inv_Load_Proc,title="Load and Plot File"
281        Button loadButton,help={"After choosing a file, load it into memory and plot it with this button."}
282        Button Inv_PathButton,pos={10,29},size={80,20},proc=Inv_PickPathButtonProc,title="Pick Path"
283        Button DoneButton,pos={215,453},size={50,20},proc=InvDoneButton,title="Done"
284        Button DoneButton,help={"This button will close the panel and the associated graph"}
285        SetVariable setvar_0,pos={27,255},size={80,15},title="# points"
286        SetVariable setvar_0,limits={5,50,0},value= root:Packages:NIST:invariant:gNumLow
287        SetVariable setvar_1,pos={164,255},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={48,14},proc=LowCheckProc,title="Guinier"
290        CheckBox check_0,value= 1
291        CheckBox check_1,pos={23,223},size={65,14},proc=LowCheckProc,title="Power Law"
292        CheckBox check_1,value= 0
293        Button button_0,pos={29,279},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={159,279},size={90,20},proc=InvHighQ,title="Calc High Q"
296        Button button_4,pos={230,29},size={25,20},proc=Inv_HelpButtonProc,title="?"
297        GroupBox group0,pos={14,165},size={123,144},title="Low Q"
298        GroupBox group0_1,pos={147,165},size={123,144},title="High Q"
299        GroupBox group1,pos={23,318},size={239,124},title="INVARIANT"
300        ValDisplay valdisp0,pos={51,354},size={180,14},title="In measured Q-range "
301        ValDisplay valdisp0,limits={0,0,0},barmisc={0,1000}
302        ValDisplay valdisp0,value= #"root:Packages:NIST:invariant:gInvMeas"
303        ValDisplay valdisp0_1,pos={51,371},size={180,14},title="In low Q extrapolation "
304        ValDisplay valdisp0_1,limits={0,0,0},barmisc={0,1000}
305        ValDisplay valdisp0_1,value= #"root:Packages:NIST:invariant:gInvLowQ"
306        ValDisplay valdisp0_2,pos={51,388},size={180,14},title="In high Q extrapolation "
307        ValDisplay valdisp0_2,limits={0,0,0},barmisc={0,1000}
308        ValDisplay valdisp0_2,value= #"root:Packages:NIST:invariant:gInvHighQ"
309        ValDisplay valdisp0_3,pos={51,411},size={180,14},title="TOTAL "
310        ValDisplay valdisp0_3,limits={0,0,0},barmisc={0,1000}
311        ValDisplay valdisp0_3,value= #"root:Packages:NIST:invariant:gInvTotal"
312        CheckBox check0,pos={10,116},size={97,14},proc=SlitSmearedCheckProc,title="Slit-Smeared Data"
313        CheckBox check0,value= 0
314        SetVariable setvar0,pos={136,116},size={130,15},title="Slit Height (1/A)"
315        SetVariable setvar0,limits={-inf,inf,0},value= root:Packages:NIST:invariant:gDqv
316        CheckBox check2,pos={168,217},size={73,14},title="Fixed Slope?",value= 1
317        SetVariable setvar2,pos={164,235},size={80,15},title="Slope"
318        SetVariable setvar2,limits={-100,0,0},value= root:Packages:NIST:invariant:gSlopeVal
319       
320       
321        //set up a dependency to calculate the total invariant
322        root:Packages:NIST:invariant:gInvTotal := root:Packages:NIST:invariant:gInvLowQ + root:Packages:NIST:invariant:gInvMeas + root:Packages:NIST:invariant:gInvHighQ
323EndMacro
324
325
326Function InvMeasQ(ctrlName) : ButtonControl
327        String ctrlName
328       
329        //no graph, get out
330        DoWindow/F Invariant_Graph
331        if(V_flag==0)
332                return(0)
333        endif
334       
335        //do the straight calculation of the invariant of the specified data
336        Variable inv,num
337       
338        SVAR QWave = root:Packages:NIST:invariant:QWave
339        Wave qw=$QWave
340        SVAR IWave = root:Packages:NIST:invariant:IWave
341        Wave iw=$IWave
342       
343        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
344        if(isSlitSmeared)
345                inv = Invariant_SlitSmeared(qw,iw)
346        else
347                inv = Invariant(qw,iw)
348        endif
349       
350        num=numpnts(qw)
351        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
352       
353        // update the global display on the panel (there is a dependency for the total)
354        NVAR val = root:Packages:NIST:invariant:gInvMeas
355        val = inv
356       
357        return(0)
358End
359
360Function InvLowQ(ctrlName) : ButtonControl
361        String ctrlName
362       
363        //no graph, get out
364        DoWindow/F Invariant_Graph
365        if(V_flag==0)
366                return(0)
367        endif
368       
369        Variable yesGuinier=0,nume,inv
370        // do the extrapolation of the correct type
371        ControlInfo/W=Invariant_Panel check_0           //the Guinier box
372        yesGuinier = V_Value
373//      print "yesGuinier = ",yesGuinier
374        //number of points to use for fit
375        NVAR nbeg=root:Packages:NIST:invariant:gNumLow
376        //define the waves
377        Wave extr_lqi=extr_lqi
378        Wave extr_lqq=extr_lqq
379       
380        SVAR QWave = root:Packages:NIST:invariant:QWave
381        Wave qw=$QWave
382        SVAR IWave = root:Packages:NIST:invariant:IWave
383        Wave iw=$IWave
384        SVAR SWave = root:Packages:NIST:invariant:SWave
385        Wave sw=$SWave
386       
387        Wave/Z W_coef=W_coef
388        Variable/G V_FitMaxIters=300
389//      Variable numi=numpnts(iw)
390       
391        if(yesGuinier)
392                Make/O/D G_coef={1000,-1000}            //input
393                FuncFit Guinier_Fit G_coef iw[0,(nbeg-1)] /X=qw /W=sw /D
394                extr_lqi= Guinier_Fit(G_coef,extr_lqq)
395               
396                Printf "I(q=0) = %g (1/cm)\r",G_coef[0]
397                Printf "Rg = %g (A)\r",sqrt(-3*G_coef[1])
398        else
399                //do a power-law fit instead
400                Make/O/D P_coef={0,1,-1}                        //input
401                //(set background to zero and hold fixed)
402                CurveFit/H="100" Power kwCWave=P_coef  iw[0,(nbeg-1)] /X=qw /W=sw /D
403                extr_lqi=P_coef[0]+P_coef[1]*extr_lqq^P_coef[2]
404                //     
405                Printf "Pre-exponential = %g\r",P_coef[1]
406                Printf "Power law exponent = %g\r",P_coef[2]
407                //     
408        endif
409       
410        //calculate the invariant
411        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
412        if(isSlitSmeared)
413                inv = Invariant_SlitSmeared(extr_lqq,extr_lqi)
414        else
415                inv = Invariant(extr_lqq,extr_lqi)
416        endif
417       
418        nume=numpnts(extr_lqq)
419        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
420       
421        // update the global display on the panel (there is a dependency for the total)
422        NVAR val = root:Packages:NIST:invariant:gInvLowQ
423        val = inv
424       
425        return(0)
426End
427
428Function InvHighQ(ctrlName) : ButtonControl
429        String ctrlName
430       
431        //no graph, get out
432        DoWindow/F Invariant_Graph
433        if(V_flag==0)
434                return(0)
435        endif
436       
437        // do the power-law extrapolation
438       
439        Wave extr_hqi=extr_hqi
440        Wave extr_hqq=extr_hqq
441        SVAR QWave = root:Packages:NIST:invariant:QWave
442        Wave qw=$QWave
443        SVAR IWave = root:Packages:NIST:invariant:IWave
444        Wave iw=$IWave
445        SVAR SWave = root:Packages:NIST:invariant:SWave
446        Wave sw=$SWave
447       
448        Variable/G V_FitMaxIters=300
449        Variable num=numpnts(iw),nume,inv
450        NVAR nend=root:Packages:NIST:invariant:gNumHigh         //number of points for the fit
451        NVAR fixedSlope = root:Packages:NIST:invariant:gSlopeVal                //fixed slope value at high q
452
453        if(fixedSlope == 0)
454                fixedSlope = -4
455        endif
456
457        Make/O/D P_coef={0,1,-4}                        //input
458        P_coef[2] = fixedSlope
459       
460        ControlInfo/W=Invariant_Panel check2
461        if(V_Value == 1)
462                //hold the slope fixed, and the background
463                CurveFit/H="101" Power kwCWave=P_coef  iw[(num-1-nend),(num-1)] /X=qw /W=sw /D
464        else
465                //(set background to zero and hold fixed)
466                CurveFit/H="100" Power kwCWave=P_coef  iw[(num-1-nend),(num-1)] /X=qw /W=sw /D
467        endif
468       
469        extr_hqi=P_coef[0]+P_coef[1]*extr_hqq^P_coef[2]
470       
471        Printf "Pre-exponential = %g\r",P_coef[1]
472        Printf "Power law exponent = %g\r",P_coef[2]
473       
474        //calculate the invariant
475        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
476        if(isSlitSmeared)
477                inv = Invariant_SlitSmeared(extr_hqq,extr_hqi)
478        else
479                inv = Invariant(extr_hqq,extr_hqi)
480        endif
481
482        nume=numpnts(extr_hqq)
483        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
484       
485        // update the global display on the panel (there is a dependency for the total)
486        NVAR val = root:Packages:NIST:invariant:gInvHighQ
487        val = inv
488       
489        return(0)       
490End
491
492Function UnloadInvariant()
493        if (WinType("Invariant_Panel") == 7)
494                DoWindow/K Invariant_Panel
495        endif
496        if (WinType("Invariant_Graph") != 0)
497                DoWindow/K $"Invariant_Graph"
498        endif
499        if (DatafolderExists("root:Packages:NIST:invariant"))
500                KillDatafolder root:Packages:NIST:invariant
501        endif
502        SetDataFolder root:
503        Killwaves/Z integrand,G_coef,P_coef,extr_hqq,extr_hqi,extr_lqq,extr_lqi
504       
505        SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION
506        String fname="Invariant"
507        Execute/P "DELETEINCLUDE \""+fname+fileVerExt+"\""
508        Execute/P "COMPILEPROCEDURES "
509end
510
511Menu "SANS Models"
512        Submenu "Packages"
513                "Unload Invariant", UnloadInvariant()
514        End
515end
516
517Function Inv_HelpButtonProc(ctrlName) : ButtonControl
518        String ctrlName
519
520        DisplayHelpTopic/Z/K=1 "Calculate Scattering Invariant"
521        if(V_flag != 0)
522                DoAlert 0, "The Scattering Invariant Help file can not be found"
523        endif
524End
525
526Function Inv_PickPathButtonProc(ctrlName) : ButtonControl
527        String ctrlName
528
529        A_PickPath()
530        //pop the file menu
531        Inv_FilePopMenuProc("",1,"")
532End
533
534//gets a valid file list (simply not the files with ".SAn" in the name)
535//
536Function Inv_FilePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl
537        String ctrlName
538        Variable popNum
539        String popStr
540       
541        String tempStr=Inv_filterButtonProc(ctrlName)
542        if(strlen(tempStr)==0)
543                tempStr = "Pick the data path"
544        Endif
545        String/G root:Packages:NIST:invariant:gDataPopList =tempStr
546        ControlUpdate/W=Invariant_Panel ywave
547       
548End
549
550//function called byt the popups to get a file list of data that can be sorted
551// this procedure simply removes the raw data files from the string - there
552//can be lots of other junk present, but this is very fast...
553//
554// could also use the alternate procedure of keeping only file with the proper extension
555//
556Function/S Inv_filterButtonProc(ctrlName)
557        String ctrlName
558
559        String list="",newList="",item=""
560        Variable num,ii
561       
562        //check for the path
563        PathInfo catPathName
564        if(V_Flag==0)
565                DoAlert 0, "Data path does not exist - pick the data path from the button on the invariant panel"
566                Return("")
567        Endif
568       
569        list = IndexedFile(catpathName,-1,"????")
570        num=ItemsInList(list,";")
571        //print "num = ",num
572        for(ii=(num-1);ii>=0;ii-=1)
573                item = StringFromList(ii, list  ,";")
574                //simply remove all that are not raw data files (SA1 SA2 SA3)
575                if( !stringmatch(item,"*.SA1*") && !stringmatch(item,"*.SA2*") && !stringmatch(item,"*.SA3*") )
576                        if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV"))                //eliminate mac "hidden" files, pxp, and div files
577                                newlist += item + ";"
578                        endif
579                endif
580        endfor
581        //remove VAX version numbers
582        newList = A_RemoveVersNumsFromList(newList)
583        //sort
584        newList = SortList(newList,";",0)
585
586        return newlist
587End
588
589// Loads the selected file for fitting
590// and graphs the data as needed
591Proc Inv_Load_Proc(ctrlName): ButtonControl
592        String ctrlName
593       
594        //Load the data
595        String tempName="",partialName=""
596        Variable err
597        ControlInfo/W=Invariant_Panel ywave
598        //find the file from the partial filename
599        If( (cmpstr(S_value,"")==0) || (cmpstr(S_value,"none")==0) )
600                //null selection, or "none" from any popup
601                Abort "no file selected in popup menu"
602        else
603                //selection not null
604                partialName = S_value
605                //Print partialName
606        Endif
607        //get a valid file based on this partialName and catPathName
608        tempName = A_FindValidFilename(partialName)
609
610        //prepend path to tempName for read routine
611        PathInfo catPathName
612       
613        tempName = S_path + tempName
614       
615        //load in the data (into the root directory)
616        A_LoadOneDDataWithName(tempName,0)
617        //Print S_fileName
618        //Print tempName
619       
620        String cleanLastFileName = CleanupName(root:Packages:NIST:gLastFileName,0)
621        String dataStr = "root:"+cleanLastFileName+":"
622       
623        // keep global copies of the names rather than reading from the popup
624        tempName=dataStr + cleanLastFileName+"_q"
625        String/G root:Packages:NIST:invariant:QWave=tempName
626        tempName=dataStr + cleanLastFileName+"_i"
627        String/G root:Packages:NIST:invariant:IWave=tempName
628        tempName=dataStr + cleanLastFileName+"_s"
629        String/G root:Packages:NIST:invariant:SWave=tempName
630
631        //Plot, and adjust the scaling to match the axis scaling set by the popups
632        Plot_Inv_Data("")
633
634        //if the slit-smeared box is checked, try to read the slit height
635        // - if can't find it, maybe not really smeared data, so put up the Alert
636        ControlInfo/W=Invariant_Panel check0
637        if(V_Value==1)
638                SlitSmearedCheckProc("",1)
639        endif
640End
641
642Proc InvDoneButton(ctrlName): ButtonControl
643        String ctrlName
644        DoWindow/K Invariant_Graph
645        DoWindow/K Invariant_Panel
646end
647
648//get the slit height if the data is slit-smeared
649//set the globals as needed
650Function SlitSmearedCheckProc(ctrlName,checked) : CheckBoxControl
651        String ctrlName
652        Variable checked
653
654        NVAR isSlitSmeared=root:Packages:NIST:invariant:gIsSlitSmeared
655//      SVAR fileStr=root:Packages:NIST:gLastFileName
656       
657        //reset the global to the checkbox state
658        isSlitSmeared = checked         //==0 if the data is not slit smeared
659       
660        if(checked)             //get the smearing info
661                ControlInfo/W=Invariant_Panel ywave
662                String folderStr=CleanupName(S_value,0)
663                NVAR dQv=root:Packages:NIST:invariant:gDqv
664                NVAR/Z loaded_dQv = $("root:"+folderStr+":USANS_dQv")
665                if(NVAR_Exists(loaded_dQv))
666                        dQv = loaded_dQv
667                        Print "Data is slit-smeared, dqv = ",dQv
668                else
669                        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."
670                endif
671        endif
672       
673        return(0)
674End
Note: See TracBrowser for help on using the repository browser.