source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v4.00/Models_2D/EllipticalCylinder2D_v40.ipf @ 288

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

fixing the conditional compile check for 2D XOP functions, which is not allowed in Macros...

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