#include #include #include #include #include "phsplan.h" /* this is also X free ! */ #define GEAR 5 #define RKQS 8 #define STIFF 9 #define CVODE 10 #define DP5 11 #define DP83 12 #define RB23 13 #define MAX_LEN_SBOX 25 #define MAX(a,b) ((a)>(b)?(a):(b)) extern double constants[]; extern double last_ic[MAXODE]; double atof(); typedef struct { char file[25]; char varlist[25],collist[25]; char parlist1[25],parlist2[25]; int dim,npars,nvars,npts,maxiter; int icols[50],ipar[50],ivar[50]; double tol,eps; } FITINFO; extern double DELAY; extern int DelayFlag; FITINFO fin; char *get_first(); char *get_next(); int (*solver)(); init_fit_info() { fin.tol=.001; fin.eps=1e-5; fin.dim=0; fin.npars=0; fin.nvars=0; fin.varlist[0]=0; fin.collist[0]=0; fin.parlist1[0]=0; fin.parlist2[0]=0; fin.npts=0; fin.maxiter=20; fin.file[0]=0; } get_fit_info(y,a,t0,flag,eps,yfit,yderv,npts,npars,nvars,ivar,ipar) int *flag,*ivar,*ipar,npts,npars,nvars; double *y,*a,eps,**yderv,*yfit,*t0; /* y initial condition a initial guesses for the parameters t0 vector of output times flag 1 for success 0 for failure eps derivative step yfit has y[i1](t0),...,y[im](t0), ..., y[i1](tn),...,y[im](tn) which are the values of the test functions at the npts times. yfit is (npts)*nvars int yderv[npar][nvars*(npts)] is the derivative of yfit with rrspect to the parameter npts is the number of times to be fitted npars the number of parameters nvars the number of variables ipar the vector of parameters negative are constants positive are initial data ivar the vector of variables */ { int i,iv,ip,istart=1,j,k,l,k0,ok; double yold[MAXODE],dp; double par,t=t0[0]; *flag=0; /* set up all initial data and parameter guesses */ for(l=0;lt1)||(dt>0&&t=0) { if(fin.ipar[i]>=NODE){ err_msg(" Cant vary auxiliary/markov variables! "); return; } } for(i=0;i= 2"); return; } if(fin.ivar[i]<0||fin.ivar[i]>=NODE){ err_msg(" Fit only to variables! "); return; } } yfit=(double *)malloc(fin.npts*fin.nvars*sizeof(double)); for(i=0;i=maxiter))break; if(ochisq>chisq){ if(((ochisq-chisq)=maxiter){ err_msg("Max iterations exceeded..."); free(work); for(i=0;i0){ ipars[i+*n]=v-1; i++; } else { v=get_param_index(item); if(v<=0)return; ipars[i+*n]=-v; i++; } while((item=get_next(" ,"))!=NULL) { find_variable(item,&v); if(v>0){ ipars[i+*n]=v-1; i++; } else { v=get_param_index(item); if(v<=0)return; ipars[i+*n]=-v; i++; } } *n=*n+i; }