source: sans/Analysis/branches/ajj_23APR07/XOPs/SANSAnalysis/XOP/StructureFactor.c @ 102

Last change on this file since 102 was 102, checked in by ajj, 16 years ago

Switched to generic library header so that the XOP code doesn't have redundant defines for internal library functions.

File size: 4.5 KB
Line 
1/*      SimpleFit.c
2
3A simplified project designed to act as a template for your curve fitting function.
4The fitting function is a simple polynomial. It works but is of no practical use.
5*/
6
7#pragma XOP_SET_STRUCT_PACKING                  // All structures are 2-byte-aligned.
8
9#include "XOPStandardHeaders.h"                 // Include ANSI headers, Mac headers, IgorXOP.h, XOP.h and XOPSupport.h
10#include "SANSAnalysis.h"
11#include "libSANSAnalysis.h"
12#include "StructureFactor.h"
13
14
15//Hard Sphere Structure Factor
16//
17int
18HardSphereStructX(FitParamsPtr p)
19{
20        double *dp;                             // Pointer to double precision wave data.
21        float *fp;                              // Pointer to single precision wave data.
22        double q;
23       
24        if (p->waveHandle == NIL) {
25                SetNaN64(&p->result);
26                return NON_EXISTENT_WAVE;
27        }
28       
29        q= p->x;
30       
31        switch(WaveType(p->waveHandle)){                        // We can handle single and double precision coefficient waves.
32                case NT_FP32:
33                        fp= WaveData(p->waveHandle);
34                        SetNaN64(&p->result);
35                        return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07                   
36                case NT_FP64:
37                        dp= WaveData(p->waveHandle);
38                        p->result = HardSphereStruct(dp,q);
39                        return 0;
40                default:                                                                // We can't handle this wave data type.
41                        SetNaN64(&p->result);
42                        return REQUIRES_SP_OR_DP_WAVE;
43        }
44        return 0;
45}
46
47//Sticky Hard Sphere Structure Factor
48//
49int
50StickyHS_StructX(FitParamsPtr p)
51{
52        double *dp;                             // Pointer to double precision wave data.
53        float *fp;                              // Pointer to single precision wave data.
54        double q;
55       
56        if (p->waveHandle == NIL) {
57                SetNaN64(&p->result);
58                return NON_EXISTENT_WAVE;
59        }
60       
61        q= p->x;
62       
63        switch(WaveType(p->waveHandle)){                        // We can handle single and double precision coefficient waves.
64                case NT_FP32:
65                        fp= WaveData(p->waveHandle);
66                        SetNaN64(&p->result);
67                        return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07                   
68                case NT_FP64:
69                        dp= WaveData(p->waveHandle);
70                        p->result = StickyHS_Struct(dp,q);
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
79
80//     SUBROUTINE SQWELL: CALCULATES THE STRUCTURE FACTOR FOR A
81//                        DISPERSION OF MONODISPERSE HARD SPHERES
82//     IN THE Mean Spherical APPROXIMATION ASSUMING THE SPHERES
83//     INTERACT THROUGH A SQUARE WELL POTENTIAL.
84//** not the best choice of closure ** see note below
85//     REFS:  SHARMA,SHARMA, PHYSICA 89A,(1977),212
86int
87SquareWellStructX(FitParamsPtr p)
88{
89        double *dp;                             // Pointer to double precision wave data.
90        float *fp;                              // Pointer to single precision wave data.
91        double q;
92       
93        if (p->waveHandle == NIL) {
94                SetNaN64(&p->result);
95                return NON_EXISTENT_WAVE;
96        }
97       
98        q= p->x;
99       
100        switch(WaveType(p->waveHandle)){                        // We can handle single and double precision coefficient waves.
101                case NT_FP32:
102                        fp= WaveData(p->waveHandle);
103                        SetNaN64(&p->result);
104                        return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07                   
105                case NT_FP64:
106                        dp= WaveData(p->waveHandle);
107                        p->result = SquareWellStruct(dp,q);
108                default:                                                                // We can't handle this wave data type.
109                        SetNaN64(&p->result);
110                        return REQUIRES_SP_OR_DP_WAVE;
111        }
112       
113        return 0;
114}
115
116// Hayter-Penfold (rescaled) MSA structure factor for screened Coulomb interactions
117//
118int
119HayterPenfoldMSAX(FitParamsPtr p)
120{
121        double *dp;                             // Pointer to double precision wave data.
122        float *fp;                              // Pointer to single precision wave data.
123        double q;
124       
125        if (p->waveHandle == NIL) {
126                SetNaN64(&p->result);
127                return NON_EXISTENT_WAVE;
128        }
129       
130        q= p->x;
131       
132        switch(WaveType(p->waveHandle)){                        // We can handle single and double precision coefficient waves.
133                case NT_FP32:
134                        fp= WaveData(p->waveHandle);
135                        SetNaN64(&p->result);
136                        return REQUIRES_SP_OR_DP_WAVE; //not quite true, but good enough for now AJJ 4/23/07                   
137                case NT_FP64:
138                        dp= WaveData(p->waveHandle);
139                        p->result = HayterPenfoldMSA(dp,q);
140                        return 0;
141                default:                                                                // We can't handle this wave data type.
142                        SetNaN64(&p->result);
143                        return REQUIRES_SP_OR_DP_WAVE;
144        }
145       
146        return 0;
147}
148
149
150// called as DiamCylX(hcyl,rcyl)
151int
152DiamCylX(DiamParamsPtr p)
153{
154        double hcyl,rcyl;
155       
156        hcyl = p->p1;
157        rcyl = p->p2;
158   
159        p->result = DiamCyl(hcyl,rcyl);
160       
161        return(0);
162}
163
164//prolate OR oblate ellipsoids
165//aa is the axis of rotation
166//if aa>bb, then PROLATE
167//if aa<bb, then OBLATE
168// A. Isihara, J. Chem. Phys. 18, 1446 (1950)
169//returns DIAMETER
170// called as DiamEllipX(aa,bb)
171int
172DiamEllipX(DiamParamsPtr p)
173{
174       
175        double aa,bb;
176       
177        aa = p->p1;
178        bb = p->p2;
179       
180        p->result = DiamEllip(aa,bb);
181       
182        return(0);
183}
184
185
186#pragma XOP_RESET_STRUCT_PACKING                        // All structures are 2-byte-aligned.
187
188///////////end of XOP
189
190
Note: See TracBrowser for help on using the repository browser.