=================================================================== RCS file: /home/cvs/OpenXM/src/hgm/mh/src/wmain.c,v retrieving revision 1.12 retrieving revision 1.36 diff -u -p -r1.12 -r1.36 --- OpenXM/src/hgm/mh/src/wmain.c 2013/03/08 04:54:01 1.12 +++ OpenXM/src/hgm/mh/src/wmain.c 2016/06/06 04:49:11 1.36 @@ -1,5 +1,5 @@ /* - $OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.11 2013/03/07 05:23:31 takayama Exp $ + $OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.35 2016/06/04 07:52:14 takayama Exp $ License: LGPL */ #include @@ -9,9 +9,17 @@ #include "sfile.h" #include "mh.h" #define SMAX 4096 -#define inci(i) { i++; if (i >= argc) { fprintf(stderr,"Option argument is not given.\n"); return(NULL); }} +#define inci(i) { i++; if (i >= argc) { oxprintfe("Option argument is not given.\n"); return(NULL); }} +#define VSTRING "%!version2.0" int MH_deallocate=0; +/* + changelog + 2016.02.13 code-n.c and code-n-2f1.c are linked together. New idata format. + 2016.02.04 MH_Ef_type exponential or scalar factor + 2016.02.01 C_2F1 + 2014.03.15 --strategy 1 is default. A new parser in setParam() + */ extern char *MH_Gfname; extern char *MH_Dfname; @@ -31,7 +39,31 @@ int MH_Dp; /* Data sampling period */ static double Xng=0.0; /* the last point */ int MH_RawName = 0; static int Testrank=0; +/* If MH_success is set to 1, then strategy, MH_abserr, MH_relerr seem to + be properly set. +*/ +int MH_success=0; +/* + Estimation of the maximal coeff of A in y'=Ay. + This might be too rough estimate. + */ +double MH_coeff_max; +/* + Estimation of h by MH_coeff_max; + */ +double MH_estimated_start_step; + +int MH_P_pFq=1; +int MH_Q_pFq=1; +double *MH_A_pFq=NULL; +double *MH_B_pFq=NULL; +int MH_Ef_type=1; +MH_RF mh_rf=NULL; /* function pointer to mh_rf */ + extern int MH_Verbose; +extern int MH_strategy; +extern double MH_abserr; +extern double MH_relerr; extern int MH_P95; /* 95 % points */ int mh_gopen_file(void); @@ -40,7 +72,9 @@ static int setParamDefault(void); static int setParam(char *fname); static int showParam(void); static int next(struct SFILE *fp,char *s, char *msg); +static double estimateHg(int m, double beta[],double x0); + /* #define DEBUG */ #ifdef DEBUG char *MH_Dfname; char *MH_Gfname; double MH_Hg; @@ -54,7 +88,7 @@ void mh_freeWorkArea(void) { mh_main(0,NULL); setParam(NULL); mh_rkmain(0.0, NULL, 0.0); - mh_rf(0.0, NULL, 0, NULL, 0); + if (mh_rf) (*mh_rf)(0.0, NULL, 0, NULL, 0); MH_deallocate=0; /* switch to the normal mode. */ } static int mypower(int x,int n) { @@ -64,35 +98,28 @@ static int mypower(int x,int n) { return(a); } #ifdef STANDALONE2 -main(int argc,char *argv[]) { +int main(int argc,char *argv[]) { int strategy=STRATEGY_DEFAULT; double err[2]={-1.0,-1.0}; int i; - for (i=1; i SIGDIGIT_DEFAULT*myabs(y0[0])) { + MH_success = 0; + oxprintfe("%%%%Warning, abserr seems not to be small enough, abserr=%lg, y[0]=%lg. Increasing the starting point (q0 or X0g(standalone case)) may or making abserr (err[1] or abserror(standalone case)) smaller will help, e.g., err=c(%lg,1e-10)\n",MH_abserr,y0[0],y0[0]*(1e-6)); + }else{ + MH_success = 1; + } + }else{ + MH_success = 0; + } + MH_estimated_start_step = estimateHg(MH_Mg,MH_Beta,MH_X0g); + if (MH_Verbose) showParam(); + if (MH_Verbose) {for (i=0; i1) dmin = myabs(beta[1]-beta[0]); + else dmin=myabs(beta[0]); + for (i=0; i