Changeset 756 for sans/XOP_Dev/SANSAnalysis/XOP/StructureFactor.c
 Timestamp:
 Oct 19, 2010 1:16:24 PM (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

sans/XOP_Dev/SANSAnalysis/XOP/StructureFactor.c
r188 r756 10 10 #include "libSANSAnalysis.h" 11 11 #include "StructureFactor.h" 12 #include "2Y_OneYukawa.h" 13 #include "2Y_TwoYukawa.h" 12 14 13 15 … … 187 189 188 190 191 // 192 // 193 int 194 OneYukawaX(FitParamsPtr_Yuk p) 195 { 196 double *sq; //pointer to sq wave 197 double *qw; //pointer to q wave 198 double *cw; //pointer to coef wave 199 long npnts,i; //number of points in waves 200 201 202 double a, b, c, d; 203 int debug = 0,check,ok; //always keep this to zero... 204 //default parameters 205 double Z,K,phi,radius; 206 char buf[256]; 207 208 /* check that wave handles are all valid */ 209 if (p>SQHandle == NIL) { 210 SetNaN64(&p>retVal); /* return NaN if wave is not valid */ 211 return(NON_EXISTENT_WAVE); 212 } 213 if (p>QHandle == NIL) { 214 SetNaN64(&p>retVal); /* return NaN if wave is not valid */ 215 return(NON_EXISTENT_WAVE); 216 } 217 if (p>CoefHandle == NIL) { 218 SetNaN64(&p>retVal); /* return NaN if wave is not valid */ 219 return(NON_EXISTENT_WAVE); 220 } 221 222 //get the wave data 223 sq = WaveData(p>SQHandle); 224 qw = WaveData(p>QHandle); 225 cw = WaveData(p>CoefHandle); 226 npnts = WavePoints(p>QHandle); // Number of points in q wave. 227 228 phi = cw[0]; 229 radius = cw[1]; 230 K = cw[2]; 231 Z = cw[3]; 232 233 if(fabs(Z) < 0.1) Z = 0.1; // values near zero are very bad for the calculation 234 235 // sprintf(buf, "Input OK, phi,radius,K,Z = %g %g %g %g\r",phi,radius,K,Z); 236 // XOPNotice(buf); 237 238 debug = 0; 239 ok = Y_SolveEquations( Z, K, phi, &a, &b, &c, &d, debug ); 240 241 if( ok ) 242 { 243 // sprintf(buf, "Y_SolveEquations OK\r"); 244 // XOPNotice(buf); 245 246 check = Y_CheckSolution( Z, K, phi, a, b, c, d ); 247 if(debug) { 248 sprintf(buf, "solution = (%g, %g, %g, %g) check = %d\r", a, b, c, d, check ); 249 XOPNotice(buf); 250 } 251 } 252 253 // sprintf(buf, "Y_CheckSolution OK\r"); 254 // XOPNotice(buf); 255 256 // loop through and calculate the S(q), or return 1 if the solution failed 257 // if(check) { //from the converted ccode 258 259 if(ok) { //less restrictive, if a solution found, return it, even if the equations aren't quite satisfied 260 261 for (i = 0; i < npnts; i++) { 262 sq[i] = SqOneYukawa(qw[i]*radius*2.0, Z, K, phi, a, b, c, d); 263 } 264 } else { 265 for (i = 0; i < npnts; i++) { 266 sq[i] = 1; 267 } 268 } 269 270 // mark the returned wave as updated so that the graph etc. automatically updates 271 WaveHandleModified(p>SQHandle); 272 273 p>retVal = 0; 274 275 return 0; 276 } 277 278 279 int 280 TwoYukawaX(FitParamsPtr_Yuk p) 281 { 282 double *sq; //pointer to sq wave 283 double *qw; //pointer to q wave 284 double *cw; //pointer to coef wave 285 long npnts,i; //number of points in waves 286 287 288 double a, b, c1, c2, d1, d2; 289 int debug = 0,check,ok; //always keep this to zero... 290 //default parameters 291 double Z1,K1,Z2,K2,phi,radius; 292 char buf[256]; 293 294 /* check that wave handles are all valid */ 295 if (p>SQHandle == NIL) { 296 SetNaN64(&p>retVal); /* return NaN if wave is not valid */ 297 return(NON_EXISTENT_WAVE); 298 } 299 if (p>QHandle == NIL) { 300 SetNaN64(&p>retVal); /* return NaN if wave is not valid */ 301 return(NON_EXISTENT_WAVE); 302 } 303 if (p>CoefHandle == NIL) { 304 SetNaN64(&p>retVal); /* return NaN if wave is not valid */ 305 return(NON_EXISTENT_WAVE); 306 } 307 308 //get the wave data 309 sq = WaveData(p>SQHandle); 310 qw = WaveData(p>QHandle); 311 cw = WaveData(p>CoefHandle); 312 npnts = WavePoints(p>QHandle); // Number of points in q wave. 313 314 phi = cw[0]; 315 radius = cw[1]; 316 K1 = cw[2]; 317 Z1 = cw[3]; 318 K2 = cw[4]; 319 Z2 = cw[5]; 320 321 if(fabs(Z1) < 0.001) Z1 = 0.001; // values near zero are very bad for the calculation 322 if(fabs(Z2) < 0.001) Z2 = 0.001; // values near zero are very bad for the calculation 323 if(fabs(K1) < 0.001) K1 = 0.001; // values near zero are very bad for the calculation 324 if(fabs(K2) < 0.001) K2 = 0.001; // values near zero are very bad for the calculation 325 326 327 // sprintf(buf, "Input OK, phi,radius,K1,Z1,K2,Z2 = %g %g %g %g %g %g\r",phi,radius,K1,Z1,K2,Z2); 328 // XOPNotice(buf); 329 330 debug = 0; 331 332 ok = TY_SolveEquations( Z1, Z2, K1, K2, phi, &a, &b, &c1, &c2, &d1, &d2, debug ); 333 if( ok ) 334 { 335 // sprintf(buf, "TY_SolveEquations OK \r"); 336 // XOPNotice(buf); 337 338 339 check = TY_CheckSolution( Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ); 340 if(debug) { 341 sprintf(buf, "solution = (%g, %g, %g, %g, %g, %g) check = %d\r", a, b, c1, c2, d1, d2, check ); 342 XOPNotice(buf); 343 } 344 } 345 // sprintf(buf, "TY_CheckSolution OK \r"); 346 // XOPNotice(buf); 347 348 // loop through and calculate the S(q), or return 1 if the solution failed 349 // if(check) { //from the converted ccode 350 351 if(ok) { //less restrictive, if a solution found, return it, even if the equations aren't quite satisfied 352 353 354 for (i = 0; i < npnts; i++) { 355 sq[i] = SqTwoYukawa(qw[i]*radius*2.0, Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2); 356 } 357 } else { 358 for (i = 0; i < npnts; i++) { 359 sq[i] = 1; 360 } 361 } 362 363 // mark the returned wave as updated so that the graph etc. automatically updates 364 WaveHandleModified(p>SQHandle); 365 366 p>retVal = 0; 367 368 return 0; 369 } 370 371 372 373 374 189 375 ///////////end of XOP 190 376
Note: See TracChangeset
for help on using the changeset viewer.