1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.0 |
---|
3 | |
---|
4 | // "simple" version of 2D function |
---|
5 | // |
---|
6 | // The plotting macro sets up TWO dependencies |
---|
7 | // - one for the triplet calculation |
---|
8 | // - one for a matrix to display, a copy of the triplet |
---|
9 | // |
---|
10 | // For display, there are two copies of the matrix. One matrix is linear, and is a copy of the |
---|
11 | // triplet (which is ALWAYS linear). The other matrix is toggled log/lin for display |
---|
12 | // in the same way the 2D SANS data matrix is handled. |
---|
13 | // |
---|
14 | |
---|
15 | /// REQUIRES DANSE XOP for 2D FUNCTIONS |
---|
16 | |
---|
17 | // |
---|
18 | // the calculation is done as for the QxQy data set: |
---|
19 | // three waves XYZ, then converted to a matrix |
---|
20 | // |
---|
21 | Proc PlotCylinder2D(str) |
---|
22 | String str |
---|
23 | Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4) |
---|
24 | |
---|
25 | SetDataFolder $("root:"+str) |
---|
26 | |
---|
27 | |
---|
28 | // NOTE THAT THE COEFFICIENTS [N] ARE IN A DIFFERENT ORDER !!! |
---|
29 | // Setup parameter table for model function |
---|
30 | make/O/T/N=11 parameters_Cyl2D |
---|
31 | Make/O/D/N=11 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 | coef_Cyl2D[10] = 25 |
---|
43 | // |
---|
44 | parameters_Cyl2D[0] = "Scale" |
---|
45 | parameters_Cyl2D[1] = "Radius" |
---|
46 | parameters_Cyl2D[2] = "Length" |
---|
47 | parameters_Cyl2D[3] = "Contrast" |
---|
48 | parameters_Cyl2D[4] = "Background" |
---|
49 | parameters_Cyl2D[5] = "Axis Theta" |
---|
50 | parameters_Cyl2D[6] = "Axis Phi" |
---|
51 | |
---|
52 | parameters_Cyl2D[8] = "Sigma of polydisp in Theta [rad]" //***** |
---|
53 | parameters_Cyl2D[9] = "Sigma of polydisp in Phi [rad]" //***** |
---|
54 | parameters_Cyl2D[7] = "Sigma of polydisp in Radius [A]" //***** |
---|
55 | |
---|
56 | parameters_Cyl2D[10] = "number of integration points" |
---|
57 | |
---|
58 | Edit parameters_Cyl2D,coef_Cyl2D |
---|
59 | |
---|
60 | // generate the triplet representation |
---|
61 | Duplicate/O $(str+"_qx") xwave_Cyl2D |
---|
62 | Duplicate/O $(str+"_qy") ywave_Cyl2D,zwave_Cyl2D |
---|
63 | |
---|
64 | Variable/G gs_Cyl2D=0 |
---|
65 | gs_Cyl2D := Cylinder2D(coef_Cyl2D,zwave_Cyl2D,xwave_Cyl2D,ywave_Cyl2D) //AAO 2D calculation |
---|
66 | |
---|
67 | Display ywave_Cyl2D vs xwave_Cyl2D |
---|
68 | modifygraph log=0 |
---|
69 | ModifyGraph mode=3,marker=16,zColor(ywave_Cyl2D)={zwave_Cyl2D,*,*,YellowHot,0} |
---|
70 | ModifyGraph standoff=0 |
---|
71 | ModifyGraph width={Aspect,1} |
---|
72 | ModifyGraph lowTrip=0.001 |
---|
73 | Label bottom "qx (A\\S-1\\M)" |
---|
74 | Label left "qy (A\\S-1\\M)" |
---|
75 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
76 | |
---|
77 | // generate the matrix representation |
---|
78 | ConvertQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,"Cyl2D_mat") |
---|
79 | Duplicate/O $"Cyl2D_mat",$"Cyl2D_lin" //keep a linear-scaled version of the data |
---|
80 | // _mat is for display, _lin is the real calculation |
---|
81 | |
---|
82 | // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation |
---|
83 | Variable/G gs_Cyl2Dmat=0 |
---|
84 | gs_Cyl2Dmat := UpdateQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,Cyl2D_lin,Cyl2D_mat) |
---|
85 | |
---|
86 | |
---|
87 | SetDataFolder root: |
---|
88 | AddModelToStrings("Cylinder2D","coef_Cyl2D","Cyl2D") |
---|
89 | End |
---|
90 | |
---|
91 | //AAO version, uses XOP if available |
---|
92 | // simply calls the original single point calculation with |
---|
93 | // a wave assignment (this will behave nicely if given point ranges) |
---|
94 | // |
---|
95 | // NON-THREADED IMPLEMENTATION |
---|
96 | // |
---|
97 | //Function Cylinder2D(cw,zw,xw,yw) : FitFunc |
---|
98 | // Wave cw,zw,xw,yw |
---|
99 | // |
---|
100 | //#if exists("CylinderModel_D") |
---|
101 | // zw = CylinderModel_D(cw,xw,yw) |
---|
102 | //#else |
---|
103 | // Abort "You do not have the SANS Analysis XOP installed" |
---|
104 | //#endif |
---|
105 | // return(0) |
---|
106 | //End |
---|
107 | // |
---|
108 | |
---|
109 | //threaded version of the function |
---|
110 | ThreadSafe Function Cylinder2D_T(cw,zw,xw,yw,p1,p2) |
---|
111 | WAVE cw,zw,xw,yw |
---|
112 | Variable p1,p2 |
---|
113 | |
---|
114 | #if exists("CylinderModel_D") //to hide the function if XOP not installed |
---|
115 | zw[p1,p2]= CylinderModel_D(cw,xw,yw) |
---|
116 | #endif |
---|
117 | |
---|
118 | return 0 |
---|
119 | End |
---|
120 | |
---|
121 | // |
---|
122 | // Fit function that is actually a wrapper to dispatch the calculation to N threads |
---|
123 | // |
---|
124 | // nthreads is 1 or an even number, typically 2 |
---|
125 | // it doesn't matter if npt is odd. In this case, fractional point numbers are passed |
---|
126 | // and the wave indexing works just fine - I tested this with test waves of 7 and 8 points |
---|
127 | // and the points "2.5" and "3.5" evaluate correctly as 2 and 3 |
---|
128 | // |
---|
129 | Function Cylinder2D(cw,zw,xw,yw) : FitFunc |
---|
130 | Wave cw,zw,xw,yw |
---|
131 | |
---|
132 | Variable npt=numpnts(yw) |
---|
133 | Variable i,nthreads= ThreadProcessorCount |
---|
134 | variable mt= ThreadGroupCreate(nthreads) |
---|
135 | |
---|
136 | for(i=0;i<nthreads;i+=1) |
---|
137 | // Print (i*npt/nthreads),((i+1)*npt/nthreads-1) |
---|
138 | ThreadStart mt,i,Cylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) |
---|
139 | endfor |
---|
140 | |
---|
141 | do |
---|
142 | variable tgs= ThreadGroupWait(mt,100) |
---|
143 | while( tgs != 0 ) |
---|
144 | |
---|
145 | variable dummy= ThreadGroupRelease(mt) |
---|
146 | |
---|
147 | return(0) |
---|
148 | End |
---|