source: sans/Release/trunk/NCNR_User_Procedures/SANS_Analysis_v4.0/SANS_Models_v4.00/Models_2D/Cylinder_2D_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.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//
18// the calculation is done as for the QxQy data set:
19// three waves XYZ, then converted to a matrix
20//
21Proc PlotCylinder2D(str)                                               
22        String str
23        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
24       
25        if (!exists("Cylinder_2DX") )
26                Abort "You must have the SANSAnalysis XOP installed to use 2D models"
27        endif
28        SetDataFolder $("root:"+str)
29       
30        // NOTE THAT THE COEFFICIENTS [N] ARE IN A DIFFERENT ORDER !!!
31        // Setup parameter table for model function
32//      make/O/T/N=11 parameters_Cyl2D
33//      Make/O/D/N=11 coef_Cyl2D
34        make/O/T/N=11 parameters_Cyl2D
35        Make/O/D/N=11 coef_Cyl2D
36        coef_Cyl2D[0] = 1.0
37        coef_Cyl2D[1] = 20.0
38        coef_Cyl2D[2] = 60.0
39        coef_Cyl2D[3] = 1e-6
40        coef_Cyl2D[4] = 6.3e-6
41        coef_Cyl2D[5] = 0.0
42        coef_Cyl2D[6] = 1.57
43        coef_Cyl2D[7] = 0.0
44        coef_Cyl2D[8] = 0.0
45        coef_Cyl2D[9] = 0.0
46        coef_Cyl2D[10] = 0.0
47       
48        // currently, the number of integration points is hard-wired to be 25 in Cylinder2D_T
49        //coef_Cyl2D[11] = 25
50        //
51        parameters_Cyl2D[0] = "Scale"
52        parameters_Cyl2D[1] = "Radius"
53        parameters_Cyl2D[2] = "Length"
54        parameters_Cyl2D[3] = "SLD cylinder (A^-2)"
55        parameters_Cyl2D[4] = "SLD solvent"
56        parameters_Cyl2D[5] = "Background"
57        parameters_Cyl2D[6] = "Axis Theta"
58        parameters_Cyl2D[7] = "Axis Phi"
59       
60        parameters_Cyl2D[9] = "Sigma of polydisp in Theta [rad]"                //*****
61        parameters_Cyl2D[10] = "Sigma of polydisp in Phi [rad]"                 //*****
62        parameters_Cyl2D[8] = "Sigma of polydisp in Radius [A]"         //*****
63       
64//      parameters_Cyl2D[11] = "number of integration points"
65
66        Edit parameters_Cyl2D,coef_Cyl2D                                       
67       
68        // generate the triplet representation
69        Duplicate/O $(str+"_qx") xwave_Cyl2D
70        Duplicate/O $(str+"_qy") ywave_Cyl2D,zwave_Cyl2D                       
71               
72        Variable/G gs_Cyl2D=0
73        gs_Cyl2D := Cylinder2D(coef_Cyl2D,zwave_Cyl2D,xwave_Cyl2D,ywave_Cyl2D)  //AAO 2D calculation
74       
75        Display ywave_Cyl2D vs xwave_Cyl2D
76        modifygraph log=0
77        ModifyGraph mode=3,marker=16,zColor(ywave_Cyl2D)={zwave_Cyl2D,*,*,YellowHot,0}
78        ModifyGraph standoff=0
79        ModifyGraph width={Aspect,1}
80        ModifyGraph lowTrip=0.001
81        Label bottom "qx (A\\S-1\\M)"
82        Label left "qy (A\\S-1\\M)"
83        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
84       
85        // generate the matrix representation
86        ConvertQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,"Cyl2D_mat")
87        Duplicate/O $"Cyl2D_mat",$"Cyl2D_lin"           //keep a linear-scaled version of the data
88        // _mat is for display, _lin is the real calculation
89
90        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
91        Variable/G gs_Cyl2Dmat=0
92        gs_Cyl2Dmat := UpdateQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,Cyl2D_lin,Cyl2D_mat)
93       
94       
95        SetDataFolder root:
96        AddModelToStrings("Cylinder2D","coef_Cyl2D","Cyl2D")
97End
98
99//AAO version, uses XOP if available
100// simply calls the original single point calculation with
101// a wave assignment (this will behave nicely if given point ranges)
102//
103// NON-THREADED IMPLEMENTATION
104//
105//Function Cylinder2D(cw,zw,xw,yw) : FitFunc
106//      Wave cw,zw,xw,yw
107//     
108//#if exists("CylinderModel_D")
109//
110//      Make/O/D/N=12 Cyl2D_tmp                         // there seems to be no speed penalty for doing this...
111//      Cyl2D_tmp = cw
112//      Cyl2D_tmp[11] = 25                                      // hard-wire the number of integration points
113//     
114//      zw= CylinderModel_D(Cyl2D_tmp,xw,yw)
115//
116//      //zw = CylinderModel_D(cw,xw,yw)
117//#else
118//      Abort "You do not have the SANS Analysis XOP installed"
119//#endif
120//      return(0)
121//End
122//
123
124//threaded version of the function
125ThreadSafe Function Cylinder2D_T(cw,zw,xw,yw,p1,p2)
126        WAVE cw,zw,xw,yw
127        Variable p1,p2
128       
129#if exists("Cylinder_2DX")                      //to hide the function if XOP not installed
130
131        Make/O/D/N=12 Cyl2D_tmp                         // there seems to be no speed penalty for doing this...
132        Cyl2D_tmp = cw
133        Cyl2D_tmp[11] = 25                                      // hard-wire the number of integration points
134        Cyl2D_tmp[5] = 0                                                // send a background of zero
135       
136        zw[p1,p2]= Cylinder_2DX(Cyl2D_tmp,xw,yw) + cw[5]                //add in the proper background here
137
138#endif
139
140        return 0
141End
142
143//
144//  Fit function that is actually a wrapper to dispatch the calculation to N threads
145//
146// nthreads is 1 or an even number, typically 2
147// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
148// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
149// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
150//
151Function Cylinder2D(cw,zw,xw,yw) : FitFunc
152        Wave cw,zw,xw,yw
153       
154        Variable npt=numpnts(yw)
155        Variable i,nthreads= ThreadProcessorCount
156        variable mt= ThreadGroupCreate(nthreads)
157
158//      Variable t1=StopMSTimer(-2)
159       
160        for(i=0;i<nthreads;i+=1)
161        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
162                ThreadStart mt,i,Cylinder2D_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//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
172       
173        return(0)
174End
Note: See TracBrowser for help on using the repository browser.