source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Models_2D/Sphere_2D_v40.ipf @ 253

Last change on this file since 253 was 253, checked in by ajj, 15 years ago

More renaming

File size: 3.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 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 PlotSphere2D(str)                                         
21        String str
22        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
23       
24        SetDataFolder $("root:"+str)
25       
26        Make/O/D coef_sf2D = {1.,60,1e-6,6.3e-6,0.01}                                           
27        make/o/t parameters_sf2D = {"scale","Radius (A)","SLD sphere (A-2)","SLD solvent","bkgd (cm-1)"}               
28        Edit parameters_sf2D,coef_sf2D                         
29       
30        // generate the triplet representation
31        Duplicate/O $(str+"_qx") xwave_sf2D
32        Duplicate/O $(str+"_qy") ywave_sf2D,zwave_sf2D                 
33               
34        Variable/G gs_sf2D=0
35        gs_sf2D := Sphere2D(coef_sf2D,zwave_sf2D,xwave_sf2D,ywave_sf2D) //AAO 2D calculation
36       
37        Display ywave_sf2D vs xwave_sf2D
38        modifygraph log=0
39        ModifyGraph mode=3,marker=16,zColor(ywave_sf2D)={zwave_sf2D,*,*,YellowHot,0}
40        ModifyGraph standoff=0
41        ModifyGraph width={Aspect,1}
42        ModifyGraph lowTrip=0.001
43        Label bottom "qx (A\\S-1\\M)"
44        Label left "qy (A\\S-1\\M)"
45        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
46       
47        // generate the matrix representation
48        ConvertQxQy2Mat(xwave_sf2D,ywave_sf2D,zwave_sf2D,"sf2D_mat")
49        Duplicate/O $"sf2D_mat",$"sf2D_lin"             //keep a linear-scaled version of the data
50        // _mat is for display, _lin is the real calculation
51
52        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
53        Variable/G gs_sf2Dmat=0
54        gs_sf2Dmat := UpdateQxQy2Mat(xwave_sf2D,ywave_sf2D,zwave_sf2D,sf2D_lin,sf2D_mat)
55       
56       
57        SetDataFolder root:
58        AddModelToStrings("Sphere2D","coef_sf2D","sf2D")
59End
60
61
62//threaded version of the function
63ThreadSafe Function Sphere2D_T(cw,zw,xw,yw,p1,p2)
64        WAVE cw,zw,xw,yw
65        Variable p1,p2
66       
67#if exists("Sphere_2DX")                        //to hide the function if XOP not installed
68       
69        zw[p1,p2]= Sphere_2DX(cw,xw,yw)
70
71#endif
72
73        return 0
74End
75
76//
77//  Fit function that is actually a wrapper to dispatch the calculation to N threads
78//
79// nthreads is 1 or an even number, typically 2
80// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
81// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
82// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
83//
84Function Sphere2D(cw,zw,xw,yw) : FitFunc
85        Wave cw,zw,xw,yw
86       
87        Variable npt=numpnts(yw)
88        Variable i,nthreads= ThreadProcessorCount
89        variable mt= ThreadGroupCreate(nthreads)
90
91//      Variable t1=StopMSTimer(-2)
92       
93        for(i=0;i<nthreads;i+=1)
94        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
95                ThreadStart mt,i,Sphere2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
96        endfor
97
98        do
99                variable tgs= ThreadGroupWait(mt,100)
100        while( tgs != 0 )
101
102        variable dummy= ThreadGroupRelease(mt)
103       
104//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
105       
106        return(0)
107End
Note: See TracBrowser for help on using the repository browser.