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 | |
---|
16 | /// REQUIRES DANSE XOP for 2D FUNCTIONS |
---|
17 | |
---|
18 | // |
---|
19 | // the calculation is done as for the QxQy data set: |
---|
20 | // three waves XYZ, then converted to a matrix |
---|
21 | // |
---|
22 | Proc PlotCylinder2D(str) |
---|
23 | String str |
---|
24 | Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4) |
---|
25 | |
---|
26 | // if any of the resolution waves are missing => abort |
---|
27 | // if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
28 | // Abort |
---|
29 | // endif |
---|
30 | |
---|
31 | SetDataFolder $("root:"+str) |
---|
32 | |
---|
33 | |
---|
34 | // NOTE THAT THE COEFFICIENTS [N] ARE IN A DIFFERENT ORDER !!! |
---|
35 | // Setup parameter table for model function |
---|
36 | make/O/T/N=11 parameters_Cyl2D |
---|
37 | Make/O/D/N=11 coef_Cyl2D |
---|
38 | coef_Cyl2D[0] = 1.0 |
---|
39 | coef_Cyl2D[1] = 20.0 |
---|
40 | coef_Cyl2D[2] = 60.0 |
---|
41 | coef_Cyl2D[3] = 6.0e-6 |
---|
42 | coef_Cyl2D[4] = 0.0 |
---|
43 | coef_Cyl2D[5] = 1.57 |
---|
44 | coef_Cyl2D[6] = 0.0 |
---|
45 | coef_Cyl2D[7] = 0.0 |
---|
46 | coef_Cyl2D[8] = 0.0 |
---|
47 | coef_Cyl2D[9] = 0.0 |
---|
48 | coef_Cyl2D[10] = 25 |
---|
49 | // |
---|
50 | parameters_Cyl2D[0] = "Scale" |
---|
51 | parameters_Cyl2D[1] = "Radius" |
---|
52 | parameters_Cyl2D[2] = "Length" |
---|
53 | parameters_Cyl2D[3] = "Contrast" |
---|
54 | parameters_Cyl2D[4] = "Background" |
---|
55 | parameters_Cyl2D[5] = "Axis Theta" |
---|
56 | parameters_Cyl2D[6] = "Axis Phi" |
---|
57 | |
---|
58 | parameters_Cyl2D[8] = "Sigma of polydisp in Theta [rad]" //***** |
---|
59 | parameters_Cyl2D[9] = "Sigma of polydisp in Phi [rad]" //***** |
---|
60 | parameters_Cyl2D[7] = "Sigma of polydisp in Radius [A]" //***** |
---|
61 | |
---|
62 | parameters_Cyl2D[10] = "number of integration points" |
---|
63 | |
---|
64 | Edit parameters_Cyl2D,coef_Cyl2D |
---|
65 | |
---|
66 | // generate the triplet representation |
---|
67 | Duplicate/O $(str+"_qx") xwave_Cyl2D |
---|
68 | Duplicate/O $(str+"_qy") ywave_Cyl2D,zwave_Cyl2D |
---|
69 | |
---|
70 | Variable/G gs_Cyl2D=0 |
---|
71 | gs_Cyl2D := Cylinder2D(coef_Cyl2D,zwave_Cyl2D,xwave_Cyl2D,ywave_Cyl2D) //AAO 2D calculation |
---|
72 | |
---|
73 | Display ywave_Cyl2D vs xwave_Cyl2D |
---|
74 | modifygraph log=0 |
---|
75 | ModifyGraph mode=3,marker=16,zColor(ywave_Cyl2D)={zwave_Cyl2D,*,*,YellowHot,0} |
---|
76 | ModifyGraph standoff=0 |
---|
77 | ModifyGraph width={Aspect,1} |
---|
78 | ModifyGraph lowTrip=0.001 |
---|
79 | Label bottom "q (\\S-1\\M)" |
---|
80 | Label left "q (\\S-1\\M)" |
---|
81 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
82 | |
---|
83 | // generate the matrix representation |
---|
84 | ConvertQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,"Cyl2D_mat") |
---|
85 | Duplicate/O $"Cyl2D_mat",$"Cyl2D_lin" //keep a linear-scaled version of the data |
---|
86 | // _mat is for display, _lin is the real calculation |
---|
87 | |
---|
88 | Variable/G gs_Cyl2Dmat=0 |
---|
89 | gs_Cyl2Dmat := UpdateQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,Cyl2D_lin,Cyl2D_mat) |
---|
90 | |
---|
91 | |
---|
92 | SetDataFolder root: |
---|
93 | AddModelToStrings("Cylinder2D","coef_Cyl2D","Cyl2D") |
---|
94 | End |
---|
95 | |
---|
96 | //AAO version, uses XOP if available |
---|
97 | // simply calls the original single point calculation with |
---|
98 | // a wave assignment (this will behave nicely if given point ranges) |
---|
99 | // |
---|
100 | // NON-THREADED IMPLEMENTATION |
---|
101 | // |
---|
102 | //Function Cylinder2D(cw,zw,xw,yw) : FitFunc |
---|
103 | // Wave cw,zw,xw,yw |
---|
104 | // |
---|
105 | //#if exists("CylinderModel_D") |
---|
106 | // zw = CylinderModel_D(cw,xw,yw) |
---|
107 | //#else |
---|
108 | // Abort "You do not have the SANS Analysis XOP installed" |
---|
109 | //#endif |
---|
110 | // return(0) |
---|
111 | //End |
---|
112 | // |
---|
113 | |
---|
114 | //threaded version of the function |
---|
115 | ThreadSafe Function Cylinder2D_T(cw,zw,xw,yw,p1,p2) |
---|
116 | WAVE cw,zw,xw,yw |
---|
117 | Variable p1,p2 |
---|
118 | |
---|
119 | #if exists("CylinderModel_D") //to hide the function if XOP not installed |
---|
120 | zw[p1,p2]= CylinderModel_D(cw,xw,yw) |
---|
121 | #endif |
---|
122 | |
---|
123 | // return stopMSTimer(-2) // time when we finished |
---|
124 | return 0 |
---|
125 | End |
---|
126 | |
---|
127 | //function that is actually a wrapper to dispatch the calculation to N threads |
---|
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 |
---|