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

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

bits and tweaks to get 2D fitting to work. Most significant changes are the call to the 2D AAO function in the correct XY order and the FuncFit? /X={} flag which needs to be {y,x} rather than the expected {x,y}

File size: 4.9 KB
Line 
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// Nothing is threaded at this point, although I think it needs to be since upon
15// reading of the WM documentation, it looks like only "basic" fit functions (meaning
16// NOT AAO or Struct functions) are automatically threaded during curve fitting.
17//
18//
19
20//Cylinder_2D_Dist()
21
22// this is what Cylinder_2D_Dist() from our XOP is expecting
23//double dist_cylinder_2D(double pars[], double q, double phi) {
24//      SmearCylinderParameters danse_pars;
25//      danse_pars.scale        = pars[0];
26//      danse_pars.radius       = pars[1];
27//      danse_pars.length       = pars[2];
28//      danse_pars.contrast     = pars[3];
29//      danse_pars.background   = pars[4];
30//      danse_pars.cyl_theta    = pars[5];
31//      danse_pars.cyl_phi      = pars[6];
32//      danse_pars.sigma_theta  = pars[7];
33//      danse_pars.sigma_phi    = pars[8];
34//      danse_pars.sigma_radius = pars[9];
35//
36//      return smeared_cylinder_analytical_2D(&danse_pars, q, phi);     
37//     
38//};
39
40//
41// the calculation is done as for the QxQy data set:
42// three waves XYZ, then converted to a matrix
43//
44Proc PlotCylinder2D(str)                                               
45        String str
46        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
47       
48        // if any of the resolution waves are missing => abort
49//      if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
50//              Abort
51//      endif
52       
53        SetDataFolder $("root:"+str)
54       
55        // Setup parameter table for model function
56        make/O/T/N=10 parameters_Cyl2D
57        Make/O/D/N=10 coef_Cyl2D
58        coef_Cyl2D[0] = 1.0
59        coef_Cyl2D[1] = 20.0
60        coef_Cyl2D[2] = 60.0
61        coef_Cyl2D[3] = 6.0e-6
62        coef_Cyl2D[4] = 0.0
63        coef_Cyl2D[5] = 1.57
64        coef_Cyl2D[6] = 0.0
65        coef_Cyl2D[7] = 0.0
66        coef_Cyl2D[8] = 0.0
67        coef_Cyl2D[9] = 0.0
68        //NOT THE SAME ORDER AS MATHIEU'S CODE - POLYDISPERSITY OF RADIUS IS IN A DIFFERENT LOCATION FROM
69        // MATHIEU'S CylinderModel
70        parameters_Cyl2D[0] = "Scale"
71        parameters_Cyl2D[1] = "Radius"
72        parameters_Cyl2D[2] = "Length"
73        parameters_Cyl2D[3] = "Contrast"
74        parameters_Cyl2D[4] = "Background"
75        parameters_Cyl2D[5] = "Axis Theta"
76        parameters_Cyl2D[6] = "Axis Phi"
77        parameters_Cyl2D[7] = "Sigma of polydisp in Theta [rad]"
78        parameters_Cyl2D[8] = "Sigma of polydisp in Phi [rad]"
79        parameters_Cyl2D[9] = "Sigma of polydisp in Radius [A]"
80
81        Edit parameters_Cyl2D,coef_Cyl2D                                       
82       
83        // generate the triplet representation
84        Duplicate/O $(str+"_qx") xwave_Cyl2D
85        Duplicate/O $(str+"_qy") ywave_Cyl2D,zwave_Cyl2D                       
86               
87        Variable/G gs_Cyl2D=0
88        gs_Cyl2D := Cylinder2D(coef_Cyl2D,zwave_Cyl2D,ywave_Cyl2D,xwave_Cyl2D)  //AAO 2D calculation
89       
90        Display ywave_Cyl2D vs xwave_Cyl2D
91        modifygraph log=0
92        ModifyGraph mode=3,marker=16,zColor(ywave_Cyl2D)={zwave_Cyl2D,*,*,YellowHot,0}
93        ModifyGraph standoff=0
94        ModifyGraph width={Aspect,1}
95        ModifyGraph lowTrip=0.001
96        Label bottom "q (\\S-1\\M)"
97        Label left "q (\\S-1\\M)"
98        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
99       
100        // generate the matrix representation
101        ConvertQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,"Cyl2D_mat")
102        Duplicate/O $"Cyl2D_mat",$"Cyl2D_lin"           //keep a linear-scaled version of the data
103        // _mat is for display, _lin is the real calculation
104
105        Variable/G gs_Cyl2Dmat=0
106        gs_Cyl2Dmat := UpdateQxQy2Mat(xwave_Cyl2D,ywave_Cyl2D,zwave_Cyl2D,Cyl2D_lin,Cyl2D_mat)
107       
108       
109        SetDataFolder root:
110        AddModelToStrings("Cylinder2D","coef_Cyl2D","Cyl2D")
111End
112
113
114//AAO version, uses XOP if available
115// simply calls the original single point calculation with
116// a wave assignment (this will behave nicely if given point ranges)
117//
118// NON-THREADED IMPLEMENTATION
119//
120//Function Cylinder2D(cw,zw,yw,xw) : FitFunc
121//      Wave cw,zw,yw,xw
122//     
123//#if exists("Cylinder_2D_Dist")
124//      zw = Cylinder_2D_Dist(cw,xw,yw)
125//#else
126//      Abort "You do not have the SANS Analysis XOP installed"
127//#endif
128//      return(0)
129//End
130//
131
132//threaded version of the function
133ThreadSafe Function Cylinder2D_T(cw,zw,yw,xw,p1,p2)
134        WAVE cw,zw,yw,xw
135        Variable p1,p2
136       
137#if exists("Cylinder_2D_Dist")                  //to hide the function if XOP not installed
138        zw[p1,p2]= Cylinder_2D_Dist(cw,xw,yw)
139#endif
140
141//      return stopMSTimer(-2)          // time when we finished
142        return 0
143End
144
145//function that is actually a wrapper to dispatch the calculation to N threads
146//
147Function Cylinder2D(cw,zw,yw,xw) : FitFunc
148        Wave cw,zw,yw,xw
149       
150        Variable npt=numpnts(yw)
151        Variable i,nthreads= ThreadProcessorCount
152        variable mt= ThreadGroupCreate(nthreads)
153
154        for(i=0;i<nthreads;i+=1)
155//              Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
156                ThreadStart mt,i,Cylinder2D_T(cw,zw,yw,xw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
157        endfor
158
159        do
160                variable tgs= ThreadGroupWait(mt,100)
161        while( tgs != 0 )
162
163        variable dummy= ThreadGroupRelease(mt)
164       
165        return(0)
166End
Note: See TracBrowser for help on using the repository browser.