source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Models_2D/Cylinder_2D.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: 4.9 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 PlotCylinder2D(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        // NOTE THAT THE COEFFICIENTS [N] ARE IN A DIFFERENT ORDER !!!
27        // Setup parameter table for model function
28//      make/O/T/N=11 parameters_Cyl2D
29//      Make/O/D/N=11 coef_Cyl2D
30        make/O/T/N=10 parameters_Cyl2D
31        Make/O/D/N=10 coef_Cyl2D
32        coef_Cyl2D[0] = 1.0
33        coef_Cyl2D[1] = 20.0
34        coef_Cyl2D[2] = 60.0
35        coef_Cyl2D[3] = 6.0e-6
36        coef_Cyl2D[4] = 0.0
37        coef_Cyl2D[5] = 1.57
38        coef_Cyl2D[6] = 0.0
39        coef_Cyl2D[7] = 0.0
40        coef_Cyl2D[8] = 0.0
41        coef_Cyl2D[9] = 0.0
42       
43        // currently, the number of integration points is hard-wired to be 25 in Cylinder2D_T
44        //coef_Cyl2D[10] = 25
45        //
46        parameters_Cyl2D[0] = "Scale"
47        parameters_Cyl2D[1] = "Radius"
48        parameters_Cyl2D[2] = "Length"
49        parameters_Cyl2D[3] = "Contrast"
50        parameters_Cyl2D[4] = "Background"
51        parameters_Cyl2D[5] = "Axis Theta"
52        parameters_Cyl2D[6] = "Axis Phi"
53       
54        parameters_Cyl2D[8] = "Sigma of polydisp in Theta [rad]"                //*****
55        parameters_Cyl2D[9] = "Sigma of polydisp in Phi [rad]"                  //*****
56        parameters_Cyl2D[7] = "Sigma of polydisp in Radius [A]"         //*****
57       
58//      parameters_Cyl2D[10] = "number of integration points"
59
60        Edit parameters_Cyl2D,coef_Cyl2D                                       
61       
62        // generate the triplet representation
63        Duplicate/O $(str+"_qx") xwave_Cyl2D
64        Duplicate/O $(str+"_qy") ywave_Cyl2D,zwave_Cyl2D                       
65               
66        Variable/G gs_Cyl2D=0
67        gs_Cyl2D := Cylinder2D(coef_Cyl2D,zwave_Cyl2D,xwave_Cyl2D,ywave_Cyl2D)  //AAO 2D calculation
68       
69        Display ywave_Cyl2D vs xwave_Cyl2D
70        modifygraph log=0
71        ModifyGraph mode=3,marker=16,zColor(ywave_Cyl2D)={zwave_Cyl2D,*,*,YellowHot,0}
72        ModifyGraph standoff=0
73        ModifyGraph width={Aspect,1}
74        ModifyGraph lowTrip=0.001
75        Label bottom "qx (A\\S-1\\M)"
76        Label left "qy (A\\S-1\\M)"
77        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
78       
79        // generate the matrix representation
80        ConvertQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,"Cyl2D_mat")
81        Duplicate/O $"Cyl2D_mat",$"Cyl2D_lin"           //keep a linear-scaled version of the data
82        // _mat is for display, _lin is the real calculation
83
84        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
85        Variable/G gs_Cyl2Dmat=0
86        gs_Cyl2Dmat := UpdateQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,Cyl2D_lin,Cyl2D_mat)
87       
88       
89        SetDataFolder root:
90        AddModelToStrings("Cylinder2D","coef_Cyl2D","Cyl2D")
91End
92
93//AAO version, uses XOP if available
94// simply calls the original single point calculation with
95// a wave assignment (this will behave nicely if given point ranges)
96//
97// NON-THREADED IMPLEMENTATION
98//
99//Function Cylinder2D(cw,zw,xw,yw) : FitFunc
100//      Wave cw,zw,xw,yw
101//     
102//#if exists("CylinderModel_D")
103//
104//      Make/O/D/N=11 Cyl2D_tmp                         // there seems to be no speed penalty for doing this...
105//      Cyl2D_tmp = cw
106//      Cyl2D_tmp[10] = 25                                      // hard-wire the number of integration points
107//     
108//      zw= CylinderModel_D(Cyl2D_tmp,xw,yw)
109//
110//      //zw = CylinderModel_D(cw,xw,yw)
111//#else
112//      Abort "You do not have the SANS Analysis XOP installed"
113//#endif
114//      return(0)
115//End
116//
117
118//threaded version of the function
119ThreadSafe Function Cylinder2D_T(cw,zw,xw,yw,p1,p2)
120        WAVE cw,zw,xw,yw
121        Variable p1,p2
122       
123#if exists("CylinderModel_D")                   //to hide the function if XOP not installed
124
125        Make/O/D/N=11 Cyl2D_tmp                         // there seems to be no speed penalty for doing this...
126        Cyl2D_tmp = cw
127        Cyl2D_tmp[10] = 25                                      // hard-wire the number of integration points
128       
129        zw[p1,p2]= CylinderModel_D(Cyl2D_tmp,xw,yw)
130
131#endif
132
133        return 0
134End
135
136//
137//  Fit function that is actually a wrapper to dispatch the calculation to N threads
138//
139// nthreads is 1 or an even number, typically 2
140// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
141// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
142// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
143//
144Function Cylinder2D(cw,zw,xw,yw) : FitFunc
145        Wave cw,zw,xw,yw
146       
147        Variable npt=numpnts(yw)
148        Variable i,nthreads= ThreadProcessorCount
149        variable mt= ThreadGroupCreate(nthreads)
150
151//      Variable t1=StopMSTimer(-2)
152       
153        for(i=0;i<nthreads;i+=1)
154        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
155                ThreadStart mt,i,Cylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
156        endfor
157
158        do
159                variable tgs= ThreadGroupWait(mt,100)
160        while( tgs != 0 )
161
162        variable dummy= ThreadGroupRelease(mt)
163       
164//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
165       
166        return(0)
167End
Note: See TracBrowser for help on using the repository browser.