=================================================================== RCS file: /home/cvs/OpenXM/src/hgm/mh/src/rk.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -p -r1.3 -r1.4 --- OpenXM/src/hgm/mh/src/rk.c 2013/02/20 01:06:38 1.3 +++ OpenXM/src/hgm/mh/src/rk.c 2013/02/20 05:20:49 1.4 @@ -1,12 +1,13 @@ /* License: LGPL Ref: Copied from this11/misc-2011/A1/wishart/Prog -$OpenXM: OpenXM/src/hgm/mh/src/rk.c,v 1.2 2013/02/19 08:03:14 takayama Exp $ +$OpenXM: OpenXM/src/hgm/mh/src/rk.c,v 1.3 2013/02/20 01:06:38 takayama Exp $ */ #include #include #include #include +#include "sfile.h" extern int MH_RANK; extern int MH_M; @@ -17,8 +18,8 @@ extern int MH_Mg; extern double *MH_Beta; extern double *MH_Ng; extern double MH_X0g; extern int MH_RawName; double MH_Hg = 0.001; -static FILE *Gf=NULL; -static FILE *Df =NULL; +static struct SFILE *Gf =NULL; +static struct SFILE *Df =NULL; int MH_P95=0; int MH_Verbose=0; static mypower(int x,int n) { @@ -31,6 +32,7 @@ mh_gopen_file() { FILE *fp; char fname[1024]; int i; + extern int MH_byFile; Gf=NULL; Df=NULL; if (MH_Verbose) { @@ -46,29 +48,31 @@ mh_gopen_file() { if (!MH_RawName) { sprintf(&(MH_Dfname[strlen(MH_Dfname)]),"-m%d-n%lf-x0%lf-b",MH_Mg,*MH_Ng,MH_X0g); for (i=0; i0?(xxn)); x += h) { if (Df) show_v(x,y, MH_RANK); - if (Gf) fprintf(Gf,"%lf %le\n",x,y[0]); + if (Gf) { + sprintf(swork,"%lf %le\n",x,y[0]); + mh_fputs(swork,Gf); + } /* Output 95% point */ if (MH_P95) { if ((MH_P95==1) && (y[0] >= 0.95)) { @@ -172,7 +182,13 @@ double mh_rkmain(double x0,double y0[],double xn) y[i] = y[i] + 1.0/6.0 * k1[i] + 1.0/3.0 * k2[i] + 1.0/3.0 * k3[i] + 1.0/6.0 * k4[i]; } printf("x=%lf, y[0]=%lg\n",x,y[0]); - if (Df) fclose(Df); - if (Gf) fclose(Gf); - return x; + result.x = x; + result.rank = MH_RANK; + result.y = (double *)mh_malloc(sizeof(double)*MH_RANK); /* todo, how to free it */ + for (i=0; i