source: sans/Release/trunk/NCNR_User_Procedures/SANS_Analysis_v4.0/SANS_Models_v4.00/Models_2D/Ellipsoid2D_v40.ipf @ 290

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

adding in the changes to the 2D conditional compile

File size: 5.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4//
5// !!! FOR THE ELLIPSOID, THE ANGLE THETA IS DEFINED FROM ????
6//
7// The plotting macro sets up TWO dependencies
8// - one for the triplet calculation
9// - one for a matrix to display, a copy of the triplet
10//
11// For display, there are two copies of the matrix. One matrix is linear, and is a copy of the
12// triplet (which is ALWAYS linear). The other matrix is toggled log/lin for display
13// in the same way the 2D SANS data matrix is handled.
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//
22Proc PlotEllipsoid2D(str)                                               
23        String str
24        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
25
26        if (!exists("Ellipsoid_2DX"))
27                Abort "You must have the SANSAnalysis XOP installed to use 2D models"
28        endif
29       
30        SetDataFolder $("root:"+str)
31       
32        // Setup parameter table for model function
33//      make/O/T/N=12 parameters_Ellip2D
34//      Make/O/D/N=12 coef_Ellip2D
35        make/O/T/N=12 parameters_Ellip2D
36        Make/O/D/N=12 coef_Ellip2D
37       
38        coef_Ellip2D[0] = 1.0
39        coef_Ellip2D[1] = 20.0
40        coef_Ellip2D[2] = 60.0
41        coef_Ellip2D[3] = 1.0e-6
42        coef_Ellip2D[4] = 6.3e-6
43        coef_Ellip2D[5] = 0.0
44        coef_Ellip2D[6] = 1.57
45        coef_Ellip2D[7] = 0.0
46        coef_Ellip2D[8] = 0.0
47        coef_Ellip2D[9] = 0.0
48        coef_Ellip2D[10] = 0.0
49        coef_Ellip2D[11] = 0.0
50        // hard-wire the number of integration points
51//      coef_Ellip2D[12] = 10
52       
53        parameters_Ellip2D[0] = "Scale"
54        parameters_Ellip2D[1] = "Radius_a (rotation axis)"
55        parameters_Ellip2D[2] = "Radius_b"
56        parameters_Ellip2D[3] = "SLD cylinder (A^-2)"
57        parameters_Ellip2D[4] = "SLD solvent"
58        parameters_Ellip2D[5] = "Background"
59        parameters_Ellip2D[6] = "Axis Theta"
60        parameters_Ellip2D[7] = "Axis Phi"
61        parameters_Ellip2D[8] = "Sigma of polydisp in R_a [Angstrom]"
62        parameters_Ellip2D[9] = "Sigma of polydisp in R_b [Angstrom]"
63        parameters_Ellip2D[10] = "Sigma of polydisp in Theta [rad]"
64        parameters_Ellip2D[11] = "Sigma of polydisp in Phi [rad]"
65       
66//      parameters_Ellip2D[12] = "Num of polydisp points"
67
68       
69        Edit parameters_Ellip2D,coef_Ellip2D                                   
70       
71        // generate the triplet representation
72        Duplicate/O $(str+"_qx") xwave_Ellip2D
73        Duplicate/O $(str+"_qy") ywave_Ellip2D,zwave_Ellip2D                   
74               
75        Variable/G gs_Ellip2D=0
76        gs_Ellip2D := Ellipsoid2D(coef_Ellip2D,zwave_Ellip2D,xwave_Ellip2D,ywave_Ellip2D)       //AAO 2D calculation
77       
78        Display ywave_Ellip2D vs xwave_Ellip2D
79        modifygraph log=0
80        ModifyGraph mode=3,marker=16,zColor(ywave_Ellip2D)={zwave_Ellip2D,*,*,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_Ellip2D,ywave_Ellip2D,zwave_Ellip2D,"Ellip2D_mat")
90        Duplicate/O $"Ellip2D_mat",$"Ellip2D_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_Ellip2Dmat=0
95        gs_Ellip2Dmat := UpdateQxQy2Mat(xwave_Ellip2D,ywave_Ellip2D,zwave_Ellip2D,Ellip2D_lin,Ellip2D_mat)
96       
97       
98        SetDataFolder root:
99        AddModelToStrings("Ellipsoid2D","coef_Ellip2D","Ellip2D")
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 Ellipsoid2D(cw,zw,xw,yw) : FitFunc
109//      Wave cw,zw,xw,yw
110//     
111//#if exists("EllipsoidModel_D")
112//
113//      Make/O/D/N=13 Ellip2D_tmp
114//      Ellip2D_tmp = cw
115//      Ellip2D_tmp[12] = 25
116//     
117//      zw = EllipsoidModel_D(Ellip2D_tmp,xw,yw)
118//     
119////    zw = EllipsoidModel_D(cw,xw,yw)
120//#else
121//      Abort "You do not have the SANS Analysis XOP installed"
122//#endif
123//      return(0)
124//End
125//
126
127//threaded version of the function
128ThreadSafe Function Ellipsoid2D_T(cw,zw,xw,yw,p1,p2)
129        WAVE cw,zw,xw,yw
130        Variable p1,p2
131       
132#if exists("Ellipsoid_2DX")                     //to hide the function if XOP not installed
133
134        Make/O/D/N=13 Ellip2D_tmp
135        Ellip2D_tmp = cw
136        Ellip2D_tmp[12] = 25
137        Ellip2D_tmp[5] = 0              //pass in a zero background and add it in later
138       
139        zw[p1,p2]= Ellipsoid_2DX(Ellip2D_tmp,xw,yw) + cw[5]
140       
141#endif
142
143        return 0
144End
145
146//
147//  Fit function that is actually a wrapper to dispatch the calculation to N threads
148//
149// nthreads is 1 or an even number, typically 2
150// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
151// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
152// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
153//
154Function Ellipsoid2D(cw,zw,xw,yw) : FitFunc
155        Wave cw,zw,xw,yw
156       
157        Variable npt=numpnts(yw)
158        Variable i,nthreads= ThreadProcessorCount
159        variable mt= ThreadGroupCreate(nthreads)
160
161        for(i=0;i<nthreads;i+=1)
162        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
163                ThreadStart mt,i,Ellipsoid2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
164        endfor
165
166        do
167                variable tgs= ThreadGroupWait(mt,100)
168        while( tgs != 0 )
169
170        variable dummy= ThreadGroupRelease(mt)
171       
172        return(0)
173End
Note: See TracBrowser for help on using the repository browser.