=================================================================== RCS file: /home/cvs/OpenXM/src/hgm/mh/src/wmain.c,v retrieving revision 1.2 retrieving revision 1.7 diff -u -p -r1.2 -r1.7 --- OpenXM/src/hgm/mh/src/wmain.c 2013/02/19 08:03:14 1.2 +++ OpenXM/src/hgm/mh/src/wmain.c 2013/02/23 06:01:15 1.7 @@ -1,17 +1,21 @@ /* -$OpenXM$ +$OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.6 2013/02/21 07:30:56 takayama Exp $ License: LGPL */ #include #include #include #include +#include "sfile.h" #define SMAX 4096 -#define inci(i) { i++; if (i >= argc) { fprintf(stderr,"Option argument is not given.\n"); return(-1); }} +#define inci(i) { i++; if (i >= argc) { fprintf(stderr,"Option argument is not given.\n"); return(NULL); }} +int MH_deallocate=0; + extern char *MH_Gfname; extern char *MH_Dfname; /* global variables. They are set in setParam() */ +int MH_byFile=1; int MH_RANK; int MH_M; @@ -30,31 +34,28 @@ extern int MH_Verbose; extern int MH_P95; /* 95 % points */ int mh_gopen_file(void); -double mh_rkmain(double x0,double y0[],double xn); static int setParamTest(void); static int setParamDefault(void); static int setParam(char *fname); static int showParam(void); +static int next(struct SFILE *fp,char *s, char *msg); /* #define DEBUG */ #ifdef DEBUG char *MH_Dfname; char *MH_Gfname; double MH_Hg; int mh_gopen_file(void) { } -double mh_rkmain(double x0,double y0[],double xn) { } +struct MH_RESULT mh_rkmain(double x0,double y0[],double xn) { } #endif -void *mh_malloc(int s) { - void *p; - p = (void*)malloc(s); - if (p == NULL) { - fprintf(stderr,"No memory.\n"); mh_exit(-1); - } - return(p); +void mh_freeWorkArea(void) { + extern int MH_deallocate; + MH_deallocate=1; /* switch to deallocation mode. */ + mh_main(0,NULL); + setParam(NULL); + mh_rkmain(0.0, NULL, 0.0); + mh_rf(0.0, NULL, 0, NULL, 0); + MH_deallocate=0; /* switch to the normal mode. */ } -mh_free(void *p) { - free(p); - return(0); -} static mypower(int x,int n) { int a,i; a = 1; @@ -63,14 +64,22 @@ static mypower(int x,int n) { } #ifdef STANDALONE main(int argc,char *argv[]) { - return mh_main(argc,char *argv[]); + mh_exit(MH_RESET_EXIT); /* standalone mode */ +/* mh_main(argc,argv); + mh_freeWorkArea(); */ + mh_main(argc,argv); } #endif -mh_main(int argc,char *argv[]) { - double *y0; +struct MH_RESULT *mh_main(int argc,char *argv[]) { + static double *y0; double x0,xn; double ef; int i,rank; + struct MH_RESULT *rp=NULL; + extern int MH_deallocate; + extern int MH_byFile; + MH_byFile=1; + if (MH_deallocate) { if (y0) mh_free(y0); return(rp); } setParam(NULL); MH_Gfname = MH_Dfname = NULL; MH_Verbose=1; for (i=1; i