source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v4.00/Models_2D/CoreShellCyl2D_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.2 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 PlotCoreShellCylinder2D(str)                                               
21        String str
22        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
23
24        if (!exists("CoreShellCylinder_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=15 parameters_CSCyl2D
32//      Make/O/D/N=15 coef_CSCyl2D
33        make/O/T/N=14 parameters_CSCyl2D
34        Make/O/D/N=14 coef_CSCyl2D
35       
36        coef_CSCyl2D[0] = 1.0
37        coef_CSCyl2D[1] = 20.0
38        coef_CSCyl2D[2] = 10.0
39        coef_CSCyl2D[3] = 200.0
40        coef_CSCyl2D[4] = 1.0e-6
41        coef_CSCyl2D[5] = 4.0e-6
42        coef_CSCyl2D[6] = 1.0e-6
43        coef_CSCyl2D[7] = 0.0
44        coef_CSCyl2D[8] = 1.57
45        coef_CSCyl2D[9] = 0.0
46        coef_CSCyl2D[10] = 0.0
47        coef_CSCyl2D[11] = 0.0
48        coef_CSCyl2D[12] = 0.0
49        coef_CSCyl2D[13] = 0.0
50        //hard-wire the number of integration points
51//      coef_CSCyl2D[14] = 10
52       
53        parameters_CSCyl2D[0] = "Scale"
54        parameters_CSCyl2D[1] = "Radius"
55        parameters_CSCyl2D[2] = "Thickness"
56        parameters_CSCyl2D[3] = "Length"
57        parameters_CSCyl2D[4] = "Core SLD"
58        parameters_CSCyl2D[5] = "Shell SLD"
59        parameters_CSCyl2D[6] = "Solvent SLD"
60        parameters_CSCyl2D[7] = "Background"
61        parameters_CSCyl2D[8] = "Axis Theta"
62        parameters_CSCyl2D[9] = "Axis Phi"
63        parameters_CSCyl2D[10] = "Sigma of polydisp in Radius [Angstrom]"
64        parameters_CSCyl2D[11] = "Sigma of polydisp in Thickness [Angstrom]"
65        parameters_CSCyl2D[12] = "Sigma of polydisp in Theta [rad]"
66        parameters_CSCyl2D[13] = "Sigma of polydisp in Phi [rad]"
67//      parameters_CSCyl2D[14] = "Num of polydisp points"
68       
69        Edit parameters_CSCyl2D,coef_CSCyl2D                                   
70       
71        // generate the triplet representation
72        Duplicate/O $(str+"_qx") xwave_CSCyl2D
73        Duplicate/O $(str+"_qy") ywave_CSCyl2D,zwave_CSCyl2D                   
74               
75        Variable/G gs_CSCyl2D=0
76        gs_CSCyl2D := CoreShellCylinder2D(coef_CSCyl2D,zwave_CSCyl2D,xwave_CSCyl2D,ywave_CSCyl2D)       //AAO 2D calculation
77       
78        Display ywave_CSCyl2D vs xwave_CSCyl2D
79        modifygraph log=0
80        ModifyGraph mode=3,marker=16,zColor(ywave_CSCyl2D)={zwave_CSCyl2D,*,*,YellowHot,0}
81        ModifyGraph standoff=0
82        ModifyGraph width={Aspect,1}
83        ModifyGraph lowTrip=0.001
84        Label bottom "qx (A\\S-1\\M)"
85        Label left "qy (A\\S-1\\M)"
86        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
87       
88        // generate the matrix representation
89        ConvertQxQy2Mat(xwave_CSCyl2D,ywave_CSCyl2D,zwave_CSCyl2D,"CSCyl2D_mat")
90        Duplicate/O $"CSCyl2D_mat",$"CSCyl2D_lin"               //keep a linear-scaled version of the data
91        // _mat is for display, _lin is the real calculation
92
93        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
94        Variable/G gs_CSCyl2Dmat=0
95        gs_CSCyl2Dmat := UpdateQxQy2Mat(xwave_CSCyl2D,ywave_CSCyl2D,zwave_CSCyl2D,CSCyl2D_lin,CSCyl2D_mat)
96       
97       
98        SetDataFolder root:
99        AddModelToStrings("CoreShellCylinder2D","coef_CSCyl2D","CSCyl2D")
100End
101
102//AAO version, uses XOP if available
103// simply calls the original single point calculation with
104// a wave assignment (this will behave nicely if given point ranges)
105//
106// NON-THREADED IMPLEMENTATION
107//
108//Function CoreShellCylinder2D(cw,zw,xw,yw) : FitFunc
109//      Wave cw,zw,xw,yw
110//     
111//#if exists("CoreShellCylinderModel_D")
112//      Make/O/D/N=15 CSCyl2D_tmp
113//      CSCyl2D_tmp = cw
114//      CSCyl2D_tmp[14] = 25
115//
116//      zw = CoreShellCylinderModel_D(CSCyl2D_tmp,xw,yw)
117//     
118////    zw = CoreShellCylinderModel_D(cw,xw,yw)
119//#else
120//      Abort "You do not have the SANS Analysis XOP installed"
121//#endif
122//      return(0)
123//End
124//
125
126//threaded version of the function
127ThreadSafe Function CoreShellCylinder2D_T(cw,zw,xw,yw,p1,p2)
128        WAVE cw,zw,xw,yw
129        Variable p1,p2
130       
131#if exists("CoreShellCylinder_2DX")                     //to hide the function if XOP not installed
132
133        Make/O/D/N=15 CSCyl2D_tmp
134        CSCyl2D_tmp = cw
135        CSCyl2D_tmp[14] = 25
136        CSCyl2D_tmp[7] = 0              //send a zero background to the calculation, add it in later
137
138        zw[p1,p2]= CoreShellCylinder_2DX(CSCyl2D_tmp,xw,yw) + cw[7]
139       
140#endif
141
142        return 0
143End
144
145//
146//  Fit function that is actually a wrapper to dispatch the calculation to N threads
147//
148// nthreads is 1 or an even number, typically 2
149// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
150// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
151// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
152//
153Function CoreShellCylinder2D(cw,zw,xw,yw) : FitFunc
154        Wave cw,zw,xw,yw
155       
156        Variable npt=numpnts(yw)
157        Variable i,nthreads= ThreadProcessorCount
158        variable mt= ThreadGroupCreate(nthreads)
159
160        for(i=0;i<nthreads;i+=1)
161        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
162                ThreadStart mt,i,CoreShellCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
163        endfor
164
165        do
166                variable tgs= ThreadGroupWait(mt,100)
167        while( tgs != 0 )
168
169        variable dummy= ThreadGroupRelease(mt)
170       
171        return(0)
172End
Note: See TracBrowser for help on using the repository browser.