| /***************************************************************************************/ |
| /* specfit.c based on FunctionTemplate.c */ |
| /***************************************************************************************/ |
| |
| #include "proFit_interface.h" |
| #include <math.h> |
| |
| #define Pi 3.1415926535 |
| #define max_ind 10000 |
| #define nr_of_spins 1000 |
| |
| double bins[max_ind]; /*The bins can't be local since the locally available memory is |
| restricted to 32kB*/ |
| |
| /***************************************************************************************/ |
| |
| void SetUp ( ... ) |
| /* SetUp is called once when the external module is linked to proFit */ |
| { |
| *moduleKind=isFunction; /* we define a function */ |
SetPascalStr(name,"
pSpecFit 3/2",255); /* write its name here */ |
| ... |
| } |
| |
| /***************************************************************************************/ |
| |
| void InitializeFunc( ... ) |
| /* InitializeFunc is called once (after SetUp has been called) when the external module |
| is linked to proFit. Used to set all the information needed to describe a function |
| and to set up the parameter window. */ |
| { |
SetPascalStr(descr1stLine,"
pSpectrum for spin 3/2 atoms",255); |
SetPascalStr(descr2ndLine,"
puse with care... very experimental version (drau, 13.8.99)",255); |
| *numberOfParams = 7; |
| |
SetPascalStr((*a0->name)[0],"
pnu_L0",maxParamNameLength); |
| (*a0->mode)[0] = active; |
| (*a0->value)[0] = 70965; |
| |
| ...
} |
| |
| /***************************************************************************************/ |
| |
| void First ( ParamArray a, /* the new parameters */ |
| ExtModulesParamBlock* pb) /*the complete parameter block passed by pro Fit*/ |
| /* Called whenever the parameters are changed. Can be used to accelerate */ |
| /* some calculations. See manual for more info */ |
| { |
| double nu_L0, nu_Q, nusq_Q, fstep; |
| double theta; |
| double musq, nu_m, factor2nd; |
| double factor1st; |
| int index; |
| double sinttau, ftausq, ftausq2, nu, nu_off, tau, width; |
| double weight; |
| |
| nu_L0 = a[0]; |
| nu_Q = a[1]; |
| fstep = a[3]; |
| tau = a[2]; |
| width = a[5]; |
| weight = a[6]; |
| |
| nusq_Q = nu_Q * nu_Q; |
| factor2nd = (-3) * nusq_Q / ( 16 * nu_L0 ) * 3; |
| |
| ftausq = 4 * tau * tau * 4 * Pi * Pi; |
| |
| for(index=0;index<max_ind;index++) bins[index] = 0; |
| |
| /* calculate the second order perturbation of the central line */ |
| |
| for(theta = 0; theta < Pi; theta += Pi/nr_of_spins ){ |
| |
| musq = cos(theta); musq *= musq; |
| nu_m = factor2nd * (1 - musq ) * ( 9 * musq - 1 ); |
| |
| sinttau = sin(theta) * 2 * tau; |
| |
| for(nu=-width;nu<width;nu+=fstep){ |
| index = int( nu / fstep ) + max_ind / 2; |
| nu_off = nu_m - nu; |
| if(index>=0 && index < max_ind) bins[index] += sinttau / ( 1 + ftausq * nu_off * nu_off ); |
| } |
| } |
| for( index = 0; index < 10000; index ++) bins[index] *= weight; |
| |
| /* calculate the first order perturbation of the wings*/ |
| |
| ... |
| |
| for( index = 0; index < 10000; index ++) bins[index]*=a[4]; |
| } |
| |
| /***************************************************************************************/ |
| |
| void Func ( double x, /* the x-value */ |
| ParamArray a, /* the parameters */ |
| double* const y, /* the y-value to be returned */ |
| ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit */ |
| /* called to calculate the y-value of the function for a given x and a given set of |
| parameters */ |
| { |
| int index; |
| double nu_off; |
| nu_off = ( x - a[0] ) / a[3] + max_ind / 2; |
| index = int( nu_off ); |
| *y = 0; |
| if( 0 <= index && index < max_ind ) *y = bins[index]; |
| } |
| |
| /***************************************************************************************/ |
| |
| void Derivatives( ... ) |
| /* called to calculate the partial derivatives of the function with respect to */ |
| /* its parameters. The elements of the array "dyda[i]" must be set to the derivatives of*/ |
| /* the function with respect to parameter number "i". If any dyda[i] is not set by */ |
| /* this function, then the derivatives will be calculated numerically by pro Fit.*/ |
| /* If you set hasDerivatives to false in FuncInitialize, then ALL derivatives will always */ |
| /* be calcuated numerically by pro Fit, no matter what you do in the function "Derivatives" */ |
| /* If a derivative is too complicated to be calculated analytically, then don't set the */ |
| /* corresponding "dyda". pro Fit will notice this and calculate that derivative numerically. */ |
| /* If you are able to calculate the dyda analytically, do so! By doing this you will make */ |
| /* fitting much, much faster. */ |
| { |
| |
| } |
| |
| ... |