1 | /* SimpleFit.c |
---|
2 | |
---|
3 | A simplified project designed to act as a template for your curve fitting function. |
---|
4 | The fitting function is a simple polynomial. It works but is of no practical use. |
---|
5 | */ |
---|
6 | |
---|
7 | |
---|
8 | #include "XOPStandardHeaders.h" // Include ANSI headers, Mac headers, IgorXOP.h, XOP.h and XOPSupport.h |
---|
9 | #include "SANSAnalysis.h" |
---|
10 | #include "libSANSAnalysis.h" |
---|
11 | #include "Sphere.h" |
---|
12 | |
---|
13 | // scattering from a sphere - hardly needs to be an XOP... |
---|
14 | int |
---|
15 | SphereFormX(FitParamsPtr p) |
---|
16 | { |
---|
17 | double *dp; // Pointer to double precision wave data. |
---|
18 | float *fp; // Pointer to single precision wave data. |
---|
19 | double q; //local variables of coefficient wave |
---|
20 | // int hState; |
---|
21 | // char buf[256]; |
---|
22 | |
---|
23 | if (p->waveHandle == NIL) { |
---|
24 | SetNaN64(&p->result); |
---|
25 | return NON_EXISTENT_WAVE; |
---|
26 | } |
---|
27 | |
---|
28 | q= p->x; |
---|
29 | |
---|
30 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
31 | case NT_FP32: |
---|
32 | fp= WaveData(p->waveHandle); |
---|
33 | SetNaN64(&p->result); |
---|
34 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
35 | case NT_FP64: |
---|
36 | dp= WaveData(p->waveHandle); |
---|
37 | p->result = SphereForm(dp,q); |
---|
38 | return 0; |
---|
39 | default: // We can't handle this wave data type. |
---|
40 | SetNaN64(&p->result); |
---|
41 | return REQUIRES_SP_OR_DP_WAVE; |
---|
42 | } |
---|
43 | return 0; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | // scattering from a monodisperse core-shell sphere - hardly needs to be an XOP... |
---|
48 | int |
---|
49 | CoreShellSphereX(FitParamsPtr p) |
---|
50 | { |
---|
51 | double *dp; // Pointer to double precision wave data. |
---|
52 | float *fp; // Pointer to single precision wave data. |
---|
53 | double q; //local variables of coefficient wave |
---|
54 | |
---|
55 | if (p->waveHandle == NIL) { |
---|
56 | SetNaN64(&p->result); |
---|
57 | return NON_EXISTENT_WAVE; |
---|
58 | } |
---|
59 | |
---|
60 | q= p->x; |
---|
61 | |
---|
62 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
63 | case NT_FP32: |
---|
64 | fp= WaveData(p->waveHandle); |
---|
65 | SetNaN64(&p->result); |
---|
66 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
67 | case NT_FP64: |
---|
68 | dp= WaveData(p->waveHandle); |
---|
69 | p->result = CoreShellForm(dp,q); |
---|
70 | return 0; |
---|
71 | default: // We can't handle this wave data type. |
---|
72 | SetNaN64(&p->result); |
---|
73 | return REQUIRES_SP_OR_DP_WAVE; |
---|
74 | } |
---|
75 | return 0; |
---|
76 | } |
---|
77 | |
---|
78 | // scattering from a unilamellar vesicle - hardly needs to be an XOP... |
---|
79 | // same functional form as the core-shell sphere, but more intuitive for a vesicle |
---|
80 | int |
---|
81 | VesicleFormX(FitParamsPtr p) |
---|
82 | { |
---|
83 | double *dp; // Pointer to double precision wave data. |
---|
84 | float *fp; // Pointer to single precision wave data. |
---|
85 | double q; //local variables of coefficient wave |
---|
86 | |
---|
87 | if (p->waveHandle == NIL) { |
---|
88 | SetNaN64(&p->result); |
---|
89 | return NON_EXISTENT_WAVE; |
---|
90 | } |
---|
91 | |
---|
92 | q= p->x; |
---|
93 | |
---|
94 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
95 | case NT_FP32: |
---|
96 | fp= WaveData(p->waveHandle); |
---|
97 | SetNaN64(&p->result); |
---|
98 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
99 | case NT_FP64: |
---|
100 | dp= WaveData(p->waveHandle); |
---|
101 | p->result = VesicleForm(dp,q); |
---|
102 | return 0; |
---|
103 | default: // We can't handle this wave data type. |
---|
104 | SetNaN64(&p->result); |
---|
105 | return REQUIRES_SP_OR_DP_WAVE; |
---|
106 | } |
---|
107 | return 0; |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | // scattering from a core shell sphere with a (Schulz) polydisperse core and constant shell thickness |
---|
112 | // |
---|
113 | int |
---|
114 | PolyCoreFormX(FitParamsPtr p) |
---|
115 | { |
---|
116 | double *dp; // Pointer to double precision wave data. |
---|
117 | float *fp; // Pointer to single precision wave data. |
---|
118 | double q; //local variables of coefficient wave |
---|
119 | |
---|
120 | if (p->waveHandle == NIL) { |
---|
121 | SetNaN64(&p->result); |
---|
122 | return NON_EXISTENT_WAVE; |
---|
123 | } |
---|
124 | |
---|
125 | q= p->x; |
---|
126 | |
---|
127 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
128 | case NT_FP32: |
---|
129 | fp= WaveData(p->waveHandle); |
---|
130 | SetNaN64(&p->result); |
---|
131 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
132 | case NT_FP64: |
---|
133 | dp= WaveData(p->waveHandle); |
---|
134 | p->result = PolyCoreForm(dp,q); |
---|
135 | return 0; |
---|
136 | default: // We can't handle this wave data type. |
---|
137 | SetNaN64(&p->result); |
---|
138 | return REQUIRES_SP_OR_DP_WAVE; |
---|
139 | } |
---|
140 | return 0; |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | // scattering from a uniform sphere with a (Schulz) size distribution |
---|
145 | // structure factor effects are explicitly and correctly included. |
---|
146 | // |
---|
147 | int |
---|
148 | PolyHardSpheresX(FitParamsPtr p) |
---|
149 | { |
---|
150 | double *dp; // Pointer to double precision wave data. |
---|
151 | float *fp; // Pointer to single precision wave data. |
---|
152 | double q; //local variables of coefficient wave |
---|
153 | |
---|
154 | if (p->waveHandle == NIL) { |
---|
155 | SetNaN64(&p->result); |
---|
156 | return NON_EXISTENT_WAVE; |
---|
157 | } |
---|
158 | |
---|
159 | q= p->x; |
---|
160 | |
---|
161 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
162 | case NT_FP32: |
---|
163 | fp= WaveData(p->waveHandle); |
---|
164 | SetNaN64(&p->result); |
---|
165 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
166 | case NT_FP64: |
---|
167 | dp= WaveData(p->waveHandle); |
---|
168 | p->result = PolyHardSphereIntensity(dp,q); |
---|
169 | return 0; |
---|
170 | default: // We can't handle this wave data type. |
---|
171 | SetNaN64(&p->result); |
---|
172 | return REQUIRES_SP_OR_DP_WAVE; |
---|
173 | } |
---|
174 | return 0; |
---|
175 | } |
---|
176 | |
---|
177 | // scattering from a uniform sphere with a (Schulz) size distribution, bimodal population |
---|
178 | // NO CROSS TERM IS ACCOUNTED FOR == DILUTE SOLUTION!! |
---|
179 | // |
---|
180 | int |
---|
181 | BimodalSchulzSpheresX(FitParamsPtr p) |
---|
182 | { |
---|
183 | double *dp; // Pointer to double precision wave data. |
---|
184 | float *fp; // Pointer to single precision wave data. |
---|
185 | double q; //local variables of coefficient wave |
---|
186 | |
---|
187 | if (p->waveHandle == NIL) { |
---|
188 | SetNaN64(&p->result); |
---|
189 | return NON_EXISTENT_WAVE; |
---|
190 | } |
---|
191 | |
---|
192 | q= p->x; |
---|
193 | |
---|
194 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
195 | case NT_FP32: |
---|
196 | fp= WaveData(p->waveHandle); |
---|
197 | SetNaN64(&p->result); |
---|
198 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
199 | case NT_FP64: |
---|
200 | dp= WaveData(p->waveHandle); |
---|
201 | p->result = BimodalSchulzSpheres(dp,q); |
---|
202 | return 0; |
---|
203 | default: // We can't handle this wave data type. |
---|
204 | SetNaN64(&p->result); |
---|
205 | return REQUIRES_SP_OR_DP_WAVE; |
---|
206 | } |
---|
207 | return 0; |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | // scattering from a uniform sphere with a (Schulz) size distribution |
---|
212 | // |
---|
213 | int |
---|
214 | SchulzSpheresX(FitParamsPtr p) |
---|
215 | { |
---|
216 | double *dp; // Pointer to double precision wave data. |
---|
217 | float *fp; // Pointer to single precision wave data. |
---|
218 | double q; //local variables of coefficient wave |
---|
219 | |
---|
220 | if (p->waveHandle == NIL) { |
---|
221 | SetNaN64(&p->result); |
---|
222 | return NON_EXISTENT_WAVE; |
---|
223 | } |
---|
224 | |
---|
225 | q= p->x; |
---|
226 | |
---|
227 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
228 | case NT_FP32: |
---|
229 | fp= WaveData(p->waveHandle); |
---|
230 | SetNaN64(&p->result); |
---|
231 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
232 | case NT_FP64: |
---|
233 | dp= WaveData(p->waveHandle); |
---|
234 | p->result = SchulzSpheres(dp,q); |
---|
235 | return 0; |
---|
236 | default: // We can't handle this wave data type. |
---|
237 | SetNaN64(&p->result); |
---|
238 | return REQUIRES_SP_OR_DP_WAVE; |
---|
239 | } |
---|
240 | return 0; |
---|
241 | } |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | // scattering from a uniform sphere with a rectangular size distribution |
---|
246 | // |
---|
247 | int |
---|
248 | PolyRectSpheresX(FitParamsPtr p) |
---|
249 | { |
---|
250 | double *dp; // Pointer to double precision wave data. |
---|
251 | float *fp; // Pointer to single precision wave data. |
---|
252 | double q; //local variables of coefficient wave |
---|
253 | |
---|
254 | if (p->waveHandle == NIL) { |
---|
255 | SetNaN64(&p->result); |
---|
256 | return NON_EXISTENT_WAVE; |
---|
257 | } |
---|
258 | |
---|
259 | q= p->x; |
---|
260 | |
---|
261 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
262 | case NT_FP32: |
---|
263 | fp= WaveData(p->waveHandle); |
---|
264 | SetNaN64(&p->result); |
---|
265 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
266 | case NT_FP64: |
---|
267 | dp= WaveData(p->waveHandle); |
---|
268 | p->result = PolyRectSpheres(dp,q); |
---|
269 | return 0; |
---|
270 | default: // We can't handle this wave data type. |
---|
271 | SetNaN64(&p->result); |
---|
272 | return REQUIRES_SP_OR_DP_WAVE; |
---|
273 | } |
---|
274 | return 0; |
---|
275 | } |
---|
276 | |
---|
277 | |
---|
278 | // scattering from a uniform sphere with a Gaussian size distribution |
---|
279 | // |
---|
280 | int |
---|
281 | GaussSpheresX(FitParamsPtr p) |
---|
282 | { |
---|
283 | double *dp; // Pointer to double precision wave data. |
---|
284 | float *fp; // Pointer to single precision wave data. |
---|
285 | double q; //local variables of coefficient wave |
---|
286 | |
---|
287 | if (p->waveHandle == NIL) { |
---|
288 | SetNaN64(&p->result); |
---|
289 | return NON_EXISTENT_WAVE; |
---|
290 | } |
---|
291 | |
---|
292 | q= p->x; |
---|
293 | |
---|
294 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
295 | case NT_FP32: |
---|
296 | fp= WaveData(p->waveHandle); |
---|
297 | SetNaN64(&p->result); |
---|
298 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
299 | case NT_FP64: |
---|
300 | dp= WaveData(p->waveHandle); |
---|
301 | p->result = GaussPolySphere(dp,q); |
---|
302 | return 0; |
---|
303 | default: // We can't handle this wave data type. |
---|
304 | SetNaN64(&p->result); |
---|
305 | return REQUIRES_SP_OR_DP_WAVE; |
---|
306 | } |
---|
307 | return 0; |
---|
308 | } |
---|
309 | |
---|
310 | |
---|
311 | // scattering from a uniform sphere with a LogNormal size distribution |
---|
312 | // |
---|
313 | int |
---|
314 | LogNormalSphereX(FitParamsPtr p) |
---|
315 | { |
---|
316 | double *dp; // Pointer to double precision wave data. |
---|
317 | float *fp; // Pointer to single precision wave data. |
---|
318 | double q; //local variables of coefficient wave |
---|
319 | |
---|
320 | if (p->waveHandle == NIL) { |
---|
321 | SetNaN64(&p->result); |
---|
322 | return NON_EXISTENT_WAVE; |
---|
323 | } |
---|
324 | |
---|
325 | q= p->x; |
---|
326 | |
---|
327 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
328 | case NT_FP32: |
---|
329 | fp= WaveData(p->waveHandle); |
---|
330 | SetNaN64(&p->result); |
---|
331 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
332 | case NT_FP64: |
---|
333 | dp= WaveData(p->waveHandle); |
---|
334 | p->result = LogNormalPolySphere(dp,q); |
---|
335 | return 0; |
---|
336 | default: // We can't handle this wave data type. |
---|
337 | SetNaN64(&p->result); |
---|
338 | return REQUIRES_SP_OR_DP_WAVE; |
---|
339 | } |
---|
340 | return 0; |
---|
341 | } |
---|
342 | |
---|
343 | |
---|
344 | // scattering from a core shell sphere with a (Schulz) polydisperse core and constant ratio (shell thickness)/(core radius) |
---|
345 | // - the polydispersity is of the WHOLE sphere |
---|
346 | // |
---|
347 | int |
---|
348 | PolyCoreShellRatioX(FitParamsPtr p) |
---|
349 | { |
---|
350 | double *dp; // Pointer to double precision wave data. |
---|
351 | float *fp; // Pointer to single precision wave data. |
---|
352 | double q; //local variables of coefficient wave |
---|
353 | |
---|
354 | if (p->waveHandle == NIL) { |
---|
355 | SetNaN64(&p->result); |
---|
356 | return NON_EXISTENT_WAVE; |
---|
357 | } |
---|
358 | |
---|
359 | q= p->x; |
---|
360 | |
---|
361 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
362 | case NT_FP32: |
---|
363 | fp= WaveData(p->waveHandle); |
---|
364 | SetNaN64(&p->result); |
---|
365 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
366 | case NT_FP64: |
---|
367 | dp= WaveData(p->waveHandle); |
---|
368 | p->result = PolyCoreShellRatio(dp,q); |
---|
369 | return 0; |
---|
370 | default: // We can't handle this wave data type. |
---|
371 | SetNaN64(&p->result); |
---|
372 | return REQUIRES_SP_OR_DP_WAVE; |
---|
373 | } |
---|
374 | return 0; |
---|
375 | } |
---|
376 | |
---|
377 | |
---|
378 | // scattering from a a binary population of hard spheres, 3 partial structure factors |
---|
379 | // are properly accounted for... |
---|
380 | // Input (fitting) variables are: |
---|
381 | // larger sphere radius(angstroms) = guess[0] |
---|
382 | // smaller sphere radius (A) = w[1] |
---|
383 | // number fraction of larger spheres = guess[2] |
---|
384 | // total volume fraction of spheres = guess[3] |
---|
385 | // size ratio, alpha(0<a<1) = derived |
---|
386 | // SLD(A-2) of larger particle = guess[4] |
---|
387 | // SLD(A-2) of smaller particle = guess[5] |
---|
388 | // SLD(A-2) of the solvent = guess[6] |
---|
389 | // background = guess[7] |
---|
390 | int |
---|
391 | BinaryHSX(FitParamsPtr p) |
---|
392 | { |
---|
393 | double *dp; // Pointer to double precision wave data. |
---|
394 | float *fp; // Pointer to single precision wave data. |
---|
395 | double q; //local variables of coefficient wave |
---|
396 | |
---|
397 | if (p->waveHandle == NIL) { |
---|
398 | SetNaN64(&p->result); |
---|
399 | return NON_EXISTENT_WAVE; |
---|
400 | } |
---|
401 | |
---|
402 | q= p->x; |
---|
403 | |
---|
404 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
405 | case NT_FP32: |
---|
406 | fp= WaveData(p->waveHandle); |
---|
407 | SetNaN64(&p->result); |
---|
408 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
409 | case NT_FP64: |
---|
410 | dp= WaveData(p->waveHandle); |
---|
411 | p->result = BinaryHS(dp,q); |
---|
412 | return 0; |
---|
413 | default: // We can't handle this wave data type. |
---|
414 | SetNaN64(&p->result); |
---|
415 | return REQUIRES_SP_OR_DP_WAVE; |
---|
416 | } |
---|
417 | return 0; |
---|
418 | } |
---|
419 | |
---|
420 | int |
---|
421 | BinaryHS_PSF11X(FitParamsPtr p) |
---|
422 | { |
---|
423 | double *dp; // Pointer to double precision wave data. |
---|
424 | float *fp; // Pointer to single precision wave data. |
---|
425 | double q; //local variables of coefficient wave |
---|
426 | |
---|
427 | if (p->waveHandle == NIL) { |
---|
428 | SetNaN64(&p->result); |
---|
429 | return NON_EXISTENT_WAVE; |
---|
430 | } |
---|
431 | |
---|
432 | q= p->x; |
---|
433 | |
---|
434 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
435 | case NT_FP32: |
---|
436 | fp= WaveData(p->waveHandle); |
---|
437 | SetNaN64(&p->result); |
---|
438 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
439 | case NT_FP64: |
---|
440 | dp= WaveData(p->waveHandle); |
---|
441 | p->result = BinaryHS_PSF11(dp,q); |
---|
442 | return 0; |
---|
443 | default: // We can't handle this wave data type. |
---|
444 | SetNaN64(&p->result); |
---|
445 | return REQUIRES_SP_OR_DP_WAVE; |
---|
446 | } |
---|
447 | return 0; |
---|
448 | } |
---|
449 | |
---|
450 | int |
---|
451 | BinaryHS_PSF12X(FitParamsPtr p) |
---|
452 | { |
---|
453 | double *dp; // Pointer to double precision wave data. |
---|
454 | float *fp; // Pointer to single precision wave data. |
---|
455 | double q; //local variables of coefficient wave |
---|
456 | |
---|
457 | if (p->waveHandle == NIL) { |
---|
458 | SetNaN64(&p->result); |
---|
459 | return NON_EXISTENT_WAVE; |
---|
460 | } |
---|
461 | |
---|
462 | q= p->x; |
---|
463 | |
---|
464 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
465 | case NT_FP32: |
---|
466 | fp= WaveData(p->waveHandle); |
---|
467 | SetNaN64(&p->result); |
---|
468 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
469 | case NT_FP64: |
---|
470 | dp= WaveData(p->waveHandle); |
---|
471 | p->result = BinaryHS_PSF12(dp,q); |
---|
472 | return 0; |
---|
473 | default: // We can't handle this wave data type. |
---|
474 | SetNaN64(&p->result); |
---|
475 | return REQUIRES_SP_OR_DP_WAVE; |
---|
476 | } |
---|
477 | return 0; |
---|
478 | } |
---|
479 | |
---|
480 | |
---|
481 | int |
---|
482 | BinaryHS_PSF22X(FitParamsPtr p) |
---|
483 | { |
---|
484 | double *dp; // Pointer to double precision wave data. |
---|
485 | float *fp; // Pointer to single precision wave data. |
---|
486 | double q; //local variables of coefficient wave |
---|
487 | |
---|
488 | if (p->waveHandle == NIL) { |
---|
489 | SetNaN64(&p->result); |
---|
490 | return NON_EXISTENT_WAVE; |
---|
491 | } |
---|
492 | |
---|
493 | q= p->x; |
---|
494 | |
---|
495 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
496 | case NT_FP32: |
---|
497 | fp= WaveData(p->waveHandle); |
---|
498 | SetNaN64(&p->result); |
---|
499 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
500 | case NT_FP64: |
---|
501 | dp= WaveData(p->waveHandle); |
---|
502 | p->result = BinaryHS_PSF22(dp,q); |
---|
503 | return 0; |
---|
504 | default: // We can't handle this wave data type. |
---|
505 | SetNaN64(&p->result); |
---|
506 | return REQUIRES_SP_OR_DP_WAVE; |
---|
507 | } |
---|
508 | return 0; |
---|
509 | } |
---|
510 | |
---|
511 | |
---|
512 | |
---|
513 | /* |
---|
514 | // calculates the scattering from a spherical particle made up of a core (aqueous) surrounded |
---|
515 | // by N spherical layers, each of which is a PAIR of shells, solvent + surfactant since there |
---|
516 | //must always be a surfactant layer on the outside |
---|
517 | // |
---|
518 | // bragg peaks arise naturally from the periodicity of the sample |
---|
519 | // resolution smeared version gives he most appropriate view of the model |
---|
520 | |
---|
521 | Warning: |
---|
522 | The call to WaveData() below returns a pointer to the middle |
---|
523 | of an unlocked Macintosh handle. In the unlikely event that your |
---|
524 | calculations could cause memory to move, you should copy the coefficient |
---|
525 | values to local variables or an array before such operations. |
---|
526 | */ |
---|
527 | int |
---|
528 | MultiShellSphereX(FitParamsPtr p) |
---|
529 | { |
---|
530 | double *dp; // Pointer to double precision wave data. |
---|
531 | float *fp; // Pointer to single precision wave data. |
---|
532 | double q; //local variables of coefficient wave |
---|
533 | |
---|
534 | if (p->waveHandle == NIL) { |
---|
535 | SetNaN64(&p->result); |
---|
536 | return NON_EXISTENT_WAVE; |
---|
537 | } |
---|
538 | |
---|
539 | q= p->x; |
---|
540 | |
---|
541 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
542 | case NT_FP32: |
---|
543 | fp= WaveData(p->waveHandle); |
---|
544 | SetNaN64(&p->result); |
---|
545 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
546 | case NT_FP64: |
---|
547 | dp= WaveData(p->waveHandle); |
---|
548 | p->result = MultiShell(dp,q); |
---|
549 | return 0; |
---|
550 | default: // We can't handle this wave data type. |
---|
551 | SetNaN64(&p->result); |
---|
552 | return REQUIRES_SP_OR_DP_WAVE; |
---|
553 | } |
---|
554 | return 0; |
---|
555 | } |
---|
556 | |
---|
557 | /* |
---|
558 | // calculates the scattering from a POLYDISPERSE spherical particle made up of a core (aqueous) surrounded |
---|
559 | // by N spherical layers, each of which is a PAIR of shells, solvent + surfactant since there |
---|
560 | //must always be a surfactant layer on the outside |
---|
561 | // |
---|
562 | // bragg peaks arise naturally from the periodicity of the sample |
---|
563 | // resolution smeared version gives he most appropriate view of the model |
---|
564 | // |
---|
565 | // Polydispersity is of the total (outer) radius. This is converted into a distribution of MLV's |
---|
566 | // with integer numbers of layers, with a minimum of one layer... a vesicle... depending |
---|
567 | // on the parameters, the "distribution" of MLV's that is used may be truncated |
---|
568 | // |
---|
569 | Warning: |
---|
570 | The call to WaveData() below returns a pointer to the middle |
---|
571 | of an unlocked Macintosh handle. In the unlikely event that your |
---|
572 | calculations could cause memory to move, you should copy the coefficient |
---|
573 | values to local variables or an array before such operations. |
---|
574 | */ |
---|
575 | int |
---|
576 | PolyMultiShellX(FitParamsPtr p) |
---|
577 | { |
---|
578 | double *dp; // Pointer to double precision wave data. |
---|
579 | float *fp; // Pointer to single precision wave data. |
---|
580 | double q; //local variables of coefficient wave |
---|
581 | |
---|
582 | if (p->waveHandle == NIL) { |
---|
583 | SetNaN64(&p->result); |
---|
584 | return NON_EXISTENT_WAVE; |
---|
585 | } |
---|
586 | |
---|
587 | q= p->x; |
---|
588 | |
---|
589 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
590 | case NT_FP32: |
---|
591 | fp= WaveData(p->waveHandle); |
---|
592 | SetNaN64(&p->result); |
---|
593 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
594 | case NT_FP64: |
---|
595 | dp= WaveData(p->waveHandle); |
---|
596 | p->result = PolyMultiShell(dp,q); |
---|
597 | return 0; |
---|
598 | default: // We can't handle this wave data type. |
---|
599 | SetNaN64(&p->result); |
---|
600 | return REQUIRES_SP_OR_DP_WAVE; |
---|
601 | } |
---|
602 | return 0; |
---|
603 | } |
---|
604 | |
---|
605 | // new models, 2008.... |
---|
606 | |
---|
607 | int |
---|
608 | OneShellX(FitParamsPtr p) |
---|
609 | { |
---|
610 | double *dp; // Pointer to double precision wave data. |
---|
611 | float *fp; // Pointer to single precision wave data. |
---|
612 | double q; //local variables of coefficient wave |
---|
613 | |
---|
614 | if (p->waveHandle == NIL) { |
---|
615 | SetNaN64(&p->result); |
---|
616 | return NON_EXISTENT_WAVE; |
---|
617 | } |
---|
618 | |
---|
619 | q= p->x; |
---|
620 | |
---|
621 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
622 | case NT_FP32: |
---|
623 | fp= WaveData(p->waveHandle); |
---|
624 | SetNaN64(&p->result); |
---|
625 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
626 | case NT_FP64: |
---|
627 | dp= WaveData(p->waveHandle); |
---|
628 | p->result = OneShell(dp,q); |
---|
629 | return 0; |
---|
630 | default: // We can't handle this wave data type. |
---|
631 | SetNaN64(&p->result); |
---|
632 | return REQUIRES_SP_OR_DP_WAVE; |
---|
633 | } |
---|
634 | return 0; |
---|
635 | } |
---|
636 | |
---|
637 | int |
---|
638 | TwoShellX(FitParamsPtr p) |
---|
639 | { |
---|
640 | double *dp; // Pointer to double precision wave data. |
---|
641 | float *fp; // Pointer to single precision wave data. |
---|
642 | double q; //local variables of coefficient wave |
---|
643 | |
---|
644 | if (p->waveHandle == NIL) { |
---|
645 | SetNaN64(&p->result); |
---|
646 | return NON_EXISTENT_WAVE; |
---|
647 | } |
---|
648 | |
---|
649 | q= p->x; |
---|
650 | |
---|
651 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
652 | case NT_FP32: |
---|
653 | fp= WaveData(p->waveHandle); |
---|
654 | SetNaN64(&p->result); |
---|
655 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
656 | case NT_FP64: |
---|
657 | dp= WaveData(p->waveHandle); |
---|
658 | p->result = TwoShell(dp,q); |
---|
659 | return 0; |
---|
660 | default: // We can't handle this wave data type. |
---|
661 | SetNaN64(&p->result); |
---|
662 | return REQUIRES_SP_OR_DP_WAVE; |
---|
663 | } |
---|
664 | return 0; |
---|
665 | } |
---|
666 | |
---|
667 | int |
---|
668 | ThreeShellX(FitParamsPtr p) |
---|
669 | { |
---|
670 | double *dp; // Pointer to double precision wave data. |
---|
671 | float *fp; // Pointer to single precision wave data. |
---|
672 | double q; //local variables of coefficient wave |
---|
673 | |
---|
674 | if (p->waveHandle == NIL) { |
---|
675 | SetNaN64(&p->result); |
---|
676 | return NON_EXISTENT_WAVE; |
---|
677 | } |
---|
678 | |
---|
679 | q= p->x; |
---|
680 | |
---|
681 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
682 | case NT_FP32: |
---|
683 | fp= WaveData(p->waveHandle); |
---|
684 | SetNaN64(&p->result); |
---|
685 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
686 | case NT_FP64: |
---|
687 | dp= WaveData(p->waveHandle); |
---|
688 | p->result = ThreeShell(dp,q); |
---|
689 | return 0; |
---|
690 | default: // We can't handle this wave data type. |
---|
691 | SetNaN64(&p->result); |
---|
692 | return REQUIRES_SP_OR_DP_WAVE; |
---|
693 | } |
---|
694 | return 0; |
---|
695 | } |
---|
696 | |
---|
697 | int |
---|
698 | FourShellX(FitParamsPtr p) |
---|
699 | { |
---|
700 | double *dp; // Pointer to double precision wave data. |
---|
701 | float *fp; // Pointer to single precision wave data. |
---|
702 | double q; //local variables of coefficient wave |
---|
703 | |
---|
704 | if (p->waveHandle == NIL) { |
---|
705 | SetNaN64(&p->result); |
---|
706 | return NON_EXISTENT_WAVE; |
---|
707 | } |
---|
708 | |
---|
709 | q= p->x; |
---|
710 | |
---|
711 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
712 | case NT_FP32: |
---|
713 | fp= WaveData(p->waveHandle); |
---|
714 | SetNaN64(&p->result); |
---|
715 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
716 | case NT_FP64: |
---|
717 | dp= WaveData(p->waveHandle); |
---|
718 | p->result = FourShell(dp,q); |
---|
719 | return 0; |
---|
720 | default: // We can't handle this wave data type. |
---|
721 | SetNaN64(&p->result); |
---|
722 | return REQUIRES_SP_OR_DP_WAVE; |
---|
723 | } |
---|
724 | return 0; |
---|
725 | } |
---|
726 | |
---|
727 | // |
---|
728 | |
---|
729 | int |
---|
730 | PolyOneShellX(FitParamsPtr p) |
---|
731 | { |
---|
732 | double *dp; // Pointer to double precision wave data. |
---|
733 | float *fp; // Pointer to single precision wave data. |
---|
734 | double q; //local variables of coefficient wave |
---|
735 | |
---|
736 | if (p->waveHandle == NIL) { |
---|
737 | SetNaN64(&p->result); |
---|
738 | return NON_EXISTENT_WAVE; |
---|
739 | } |
---|
740 | |
---|
741 | q= p->x; |
---|
742 | |
---|
743 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
744 | case NT_FP32: |
---|
745 | fp= WaveData(p->waveHandle); |
---|
746 | SetNaN64(&p->result); |
---|
747 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
748 | case NT_FP64: |
---|
749 | dp= WaveData(p->waveHandle); |
---|
750 | p->result = PolyOneShell(dp,q); |
---|
751 | return 0; |
---|
752 | default: // We can't handle this wave data type. |
---|
753 | SetNaN64(&p->result); |
---|
754 | return REQUIRES_SP_OR_DP_WAVE; |
---|
755 | } |
---|
756 | return 0; |
---|
757 | } |
---|
758 | |
---|
759 | int |
---|
760 | PolyTwoShellX(FitParamsPtr p) |
---|
761 | { |
---|
762 | double *dp; // Pointer to double precision wave data. |
---|
763 | float *fp; // Pointer to single precision wave data. |
---|
764 | double q; //local variables of coefficient wave |
---|
765 | |
---|
766 | if (p->waveHandle == NIL) { |
---|
767 | SetNaN64(&p->result); |
---|
768 | return NON_EXISTENT_WAVE; |
---|
769 | } |
---|
770 | |
---|
771 | q= p->x; |
---|
772 | |
---|
773 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
774 | case NT_FP32: |
---|
775 | fp= WaveData(p->waveHandle); |
---|
776 | SetNaN64(&p->result); |
---|
777 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
778 | case NT_FP64: |
---|
779 | dp= WaveData(p->waveHandle); |
---|
780 | p->result = PolyTwoShell(dp,q); |
---|
781 | return 0; |
---|
782 | default: // We can't handle this wave data type. |
---|
783 | SetNaN64(&p->result); |
---|
784 | return REQUIRES_SP_OR_DP_WAVE; |
---|
785 | } |
---|
786 | return 0; |
---|
787 | } |
---|
788 | |
---|
789 | int |
---|
790 | PolyThreeShellX(FitParamsPtr p) |
---|
791 | { |
---|
792 | double *dp; // Pointer to double precision wave data. |
---|
793 | float *fp; // Pointer to single precision wave data. |
---|
794 | double q; //local variables of coefficient wave |
---|
795 | |
---|
796 | if (p->waveHandle == NIL) { |
---|
797 | SetNaN64(&p->result); |
---|
798 | return NON_EXISTENT_WAVE; |
---|
799 | } |
---|
800 | |
---|
801 | q= p->x; |
---|
802 | |
---|
803 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
804 | case NT_FP32: |
---|
805 | fp= WaveData(p->waveHandle); |
---|
806 | SetNaN64(&p->result); |
---|
807 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
808 | case NT_FP64: |
---|
809 | dp= WaveData(p->waveHandle); |
---|
810 | p->result = PolyThreeShell(dp,q); |
---|
811 | return 0; |
---|
812 | default: // We can't handle this wave data type. |
---|
813 | SetNaN64(&p->result); |
---|
814 | return REQUIRES_SP_OR_DP_WAVE; |
---|
815 | } |
---|
816 | return 0; |
---|
817 | } |
---|
818 | |
---|
819 | int |
---|
820 | PolyFourShellX(FitParamsPtr p) |
---|
821 | { |
---|
822 | double *dp; // Pointer to double precision wave data. |
---|
823 | float *fp; // Pointer to single precision wave data. |
---|
824 | double q; //local variables of coefficient wave |
---|
825 | |
---|
826 | if (p->waveHandle == NIL) { |
---|
827 | SetNaN64(&p->result); |
---|
828 | return NON_EXISTENT_WAVE; |
---|
829 | } |
---|
830 | |
---|
831 | q= p->x; |
---|
832 | |
---|
833 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
834 | case NT_FP32: |
---|
835 | fp= WaveData(p->waveHandle); |
---|
836 | SetNaN64(&p->result); |
---|
837 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
838 | case NT_FP64: |
---|
839 | dp= WaveData(p->waveHandle); |
---|
840 | p->result = PolyFourShell(dp,q); |
---|
841 | return 0; |
---|
842 | default: // We can't handle this wave data type. |
---|
843 | SetNaN64(&p->result); |
---|
844 | return REQUIRES_SP_OR_DP_WAVE; |
---|
845 | } |
---|
846 | return 0; |
---|
847 | } |
---|
848 | |
---|
849 | // paracrystal models, 2008 |
---|
850 | int |
---|
851 | BCC_ParaCrystalX(FitParamsPtr p) |
---|
852 | { |
---|
853 | double *dp; // Pointer to double precision wave data. |
---|
854 | float *fp; // Pointer to single precision wave data. |
---|
855 | double q; //local variables of coefficient wave |
---|
856 | |
---|
857 | if (p->waveHandle == NIL) { |
---|
858 | SetNaN64(&p->result); |
---|
859 | return NON_EXISTENT_WAVE; |
---|
860 | } |
---|
861 | |
---|
862 | q= p->x; |
---|
863 | |
---|
864 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
865 | case NT_FP32: |
---|
866 | fp= WaveData(p->waveHandle); |
---|
867 | SetNaN64(&p->result); |
---|
868 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
869 | case NT_FP64: |
---|
870 | dp= WaveData(p->waveHandle); |
---|
871 | p->result = BCC_ParaCrystal(dp,q); |
---|
872 | return 0; |
---|
873 | default: // We can't handle this wave data type. |
---|
874 | SetNaN64(&p->result); |
---|
875 | return REQUIRES_SP_OR_DP_WAVE; |
---|
876 | } |
---|
877 | return 0; |
---|
878 | } |
---|
879 | |
---|
880 | |
---|
881 | int |
---|
882 | FCC_ParaCrystalX(FitParamsPtr p) |
---|
883 | { |
---|
884 | double *dp; // Pointer to double precision wave data. |
---|
885 | float *fp; // Pointer to single precision wave data. |
---|
886 | double q; //local variables of coefficient wave |
---|
887 | |
---|
888 | if (p->waveHandle == NIL) { |
---|
889 | SetNaN64(&p->result); |
---|
890 | return NON_EXISTENT_WAVE; |
---|
891 | } |
---|
892 | |
---|
893 | q= p->x; |
---|
894 | |
---|
895 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
896 | case NT_FP32: |
---|
897 | fp= WaveData(p->waveHandle); |
---|
898 | SetNaN64(&p->result); |
---|
899 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
900 | case NT_FP64: |
---|
901 | dp= WaveData(p->waveHandle); |
---|
902 | p->result = FCC_ParaCrystal(dp,q); |
---|
903 | return 0; |
---|
904 | default: // We can't handle this wave data type. |
---|
905 | SetNaN64(&p->result); |
---|
906 | return REQUIRES_SP_OR_DP_WAVE; |
---|
907 | } |
---|
908 | return 0; |
---|
909 | } |
---|
910 | |
---|
911 | |
---|
912 | int |
---|
913 | SC_ParaCrystalX(FitParamsPtr p) |
---|
914 | { |
---|
915 | double *dp; // Pointer to double precision wave data. |
---|
916 | float *fp; // Pointer to single precision wave data. |
---|
917 | double q; //local variables of coefficient wave |
---|
918 | |
---|
919 | if (p->waveHandle == NIL) { |
---|
920 | SetNaN64(&p->result); |
---|
921 | return NON_EXISTENT_WAVE; |
---|
922 | } |
---|
923 | |
---|
924 | q= p->x; |
---|
925 | |
---|
926 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
927 | case NT_FP32: |
---|
928 | fp= WaveData(p->waveHandle); |
---|
929 | SetNaN64(&p->result); |
---|
930 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
931 | case NT_FP64: |
---|
932 | dp= WaveData(p->waveHandle); |
---|
933 | p->result = SC_ParaCrystal(dp,q); |
---|
934 | return 0; |
---|
935 | default: // We can't handle this wave data type. |
---|
936 | SetNaN64(&p->result); |
---|
937 | return REQUIRES_SP_OR_DP_WAVE; |
---|
938 | } |
---|
939 | return 0; |
---|
940 | } |
---|
941 | |
---|
942 | int |
---|
943 | FuzzySpheresX(FitParamsPtr p) |
---|
944 | { |
---|
945 | double *dp; // Pointer to double precision wave data. |
---|
946 | float *fp; // Pointer to single precision wave data. |
---|
947 | double q; //local variables of coefficient wave |
---|
948 | |
---|
949 | if (p->waveHandle == NIL) { |
---|
950 | SetNaN64(&p->result); |
---|
951 | return NON_EXISTENT_WAVE; |
---|
952 | } |
---|
953 | |
---|
954 | q= p->x; |
---|
955 | |
---|
956 | switch(WaveType(p->waveHandle)){ // We can handle single and double precision coefficient waves. |
---|
957 | case NT_FP32: |
---|
958 | fp= WaveData(p->waveHandle); |
---|
959 | SetNaN64(&p->result); |
---|
960 | return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07 |
---|
961 | case NT_FP64: |
---|
962 | dp= WaveData(p->waveHandle); |
---|
963 | p->result = FuzzySpheres(dp,q); |
---|
964 | return 0; |
---|
965 | default: // We can't handle this wave data type. |
---|
966 | SetNaN64(&p->result); |
---|
967 | return REQUIRES_SP_OR_DP_WAVE; |
---|
968 | } |
---|
969 | return 0; |
---|
970 | } |
---|
971 | |
---|