source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Models_2D/EllipticalCylinder2D.ipf @ 200

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

Changed 2D model calculations to use a FIXED 25 integration points in an effort to get the number of integration points out of the fitting coefficient wave.

Added "Freeze Model" back to the SANS Models menu

Added the 2D model functions to the list on the model picker

Minor tweaks to the wrapper

File size: 5.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4//
5// The plotting macro sets up TWO dependencies
6// - one for the triplet calculation
7// - one for a matrix to display, a copy of the triplet
8//
9// For display, there are two copies of the matrix. One matrix is linear, and is a copy of the
10// triplet (which is ALWAYS linear). The other matrix is toggled log/lin for display
11// in the same way the 2D SANS data matrix is handled.
12//
13
14///  REQUIRES DANSE XOP for 2D FUNCTIONS
15
16//
17// the calculation is done as for the QxQy data set:
18// three waves XYZ, then converted to a matrix
19//
20Proc PlotEllipticalCylinder2D(str)                                             
21        String str
22        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
23       
24        SetDataFolder $("root:"+str)
25       
26        // Setup parameter table for model function
27        //make/O/T/N=14 parameters_EllCyl2D
28        //Make/O/D/N=14 coef_EllCyl2D
29        make/O/T/N=13 parameters_EllCyl2D
30        Make/O/D/N=13 coef_EllCyl2D
31       
32        coef_EllCyl2D[0] = 1.0
33        coef_EllCyl2D[1] = 20.0
34        coef_EllCyl2D[2] = 1.5
35        coef_EllCyl2D[3] = 400.0
36        coef_EllCyl2D[4] = 3e-6
37        coef_EllCyl2D[5] = 0.0
38        coef_EllCyl2D[6] = 1.57
39        coef_EllCyl2D[7] = 0.0
40        coef_EllCyl2D[8] = 0.0
41        coef_EllCyl2D[9] = 0.0
42        coef_EllCyl2D[10] = 0.0
43        coef_EllCyl2D[11] = 0.0
44        coef_EllCyl2D[12] = 0.0
45       
46        // now hard-wire the # of integration points
47        //coef_EllCyl2D[13] = 25
48               
49        parameters_EllCyl2D[0] = "Scale"
50        parameters_EllCyl2D[1] = "R_minor"
51        parameters_EllCyl2D[2] = "R_ratio (major/minor)"
52        parameters_EllCyl2D[3] = "Length"
53        parameters_EllCyl2D[4] = "Contrast"
54        parameters_EllCyl2D[5] = "Background"
55        parameters_EllCyl2D[6] = "Axis Theta"
56        parameters_EllCyl2D[7] = "Axis Phi"
57        parameters_EllCyl2D[8] = "Ellipse Psi"
58        parameters_EllCyl2D[9] = "Sigma of polydisp in R_minor [Angstrom]"
59        parameters_EllCyl2D[10] = "Sigma of polydisp in R_ratio"
60        parameters_EllCyl2D[11] = "Sigma of polydisp in Theta [rad]"
61        parameters_EllCyl2D[12] = "Sigma of polydisp in Phi [rad]"
62        //parameters_EllCyl2D[13] = "Num of polydisp points"
63       
64        Edit parameters_EllCyl2D,coef_EllCyl2D                                 
65       
66        // generate the triplet representation
67        Duplicate/O $(str+"_qx") xwave_EllCyl2D
68        Duplicate/O $(str+"_qy") ywave_EllCyl2D,zwave_EllCyl2D                 
69               
70        Variable/G gs_EllCyl2D=0
71        gs_EllCyl2D := EllipticalCylinder2D(coef_EllCyl2D,zwave_EllCyl2D,xwave_EllCyl2D,ywave_EllCyl2D) //AAO 2D calculation
72       
73        Display ywave_EllCyl2D vs xwave_EllCyl2D
74        modifygraph log=0
75        ModifyGraph mode=3,marker=16,zColor(ywave_EllCyl2D)={zwave_EllCyl2D,*,*,YellowHot,0}
76        ModifyGraph standoff=0
77        ModifyGraph width={Aspect,1}
78        ModifyGraph lowTrip=0.001
79        Label bottom "qx (A\\S-1\\M)"
80        Label left "qy (A\\S-1\\M)"
81        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
82       
83        // generate the matrix representation
84        ConvertQxQy2Mat(xwave_EllCyl2D,ywave_EllCyl2D,zwave_EllCyl2D,"EllCyl2D_mat")
85        Duplicate/O $"EllCyl2D_mat",$"EllCyl2D_lin"             //keep a linear-scaled version of the data
86        // _mat is for display, _lin is the real calculation
87
88        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
89        Variable/G gs_EllCyl2Dmat=0
90        gs_EllCyl2Dmat := UpdateQxQy2Mat(xwave_EllCyl2D,ywave_EllCyl2D,zwave_EllCyl2D,EllCyl2D_lin,EllCyl2D_mat)
91       
92       
93        SetDataFolder root:
94        AddModelToStrings("EllipticalCylinder2D","coef_EllCyl2D","EllCyl2D")
95End
96
97//AAO version, uses XOP if available
98// simply calls the original single point calculation with
99// a wave assignment (this will behave nicely if given point ranges)
100//
101// NON-THREADED IMPLEMENTATION
102//
103//Function EllipticalCylinder2D(cw,zw,xw,yw) : FitFunc
104//      Wave cw,zw,xw,yw
105//     
106//#if exists("EllipticalCylinderModel_D")
107//
108//      Make/O/D/N=14 EllCyl2D_tmp
109//      EllCyl2D_tmp = cw
110//      EllCyl2D_tmp[13] = 25
111//     
112//      zw = EllipticalCylinderModel_D(EllCyl2D_tmp,xw,yw)
113//     
114////    zw = EllipticalCylinderModel_D(cw,xw,yw)
115//#else
116//      Abort "You do not have the SANS Analysis XOP installed"
117//#endif
118//      return(0)
119//End
120//
121
122//threaded version of the function
123ThreadSafe Function EllipticalCylinder2D_T(cw,zw,xw,yw,p1,p2)
124        WAVE cw,zw,xw,yw
125        Variable p1,p2
126       
127#if exists("EllipticalCylinderModel_D")                 //to hide the function if XOP not installed
128
129        Make/O/D/N=14 EllCyl2D_tmp
130        EllCyl2D_tmp = cw
131        EllCyl2D_tmp[13] = 25
132       
133        zw[p1,p2]= EllipticalCylinderModel_D(EllCyl2D_tmp,xw,yw)
134       
135#endif
136
137        return 0
138End
139
140//
141//  Fit function that is actually a wrapper to dispatch the calculation to N threads
142//
143// nthreads is 1 or an even number, typically 2
144// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
145// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
146// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
147//
148Function EllipticalCylinder2D(cw,zw,xw,yw) : FitFunc
149        Wave cw,zw,xw,yw
150       
151        Variable npt=numpnts(yw)
152        Variable i,nthreads= ThreadProcessorCount
153        variable mt= ThreadGroupCreate(nthreads)
154
155        for(i=0;i<nthreads;i+=1)
156        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
157                ThreadStart mt,i,EllipticalCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
158        endfor
159
160        do
161                variable tgs= ThreadGroupWait(mt,100)
162        while( tgs != 0 )
163
164        variable dummy= ThreadGroupRelease(mt)
165       
166        return(0)
167End
Note: See TracBrowser for help on using the repository browser.