version 1.27, 2016/02/04 06:56:05 |
version 1.28, 2016/02/13 02:19:00 |
|
|
/* |
/* |
$OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.26 2016/02/01 11:37:14 takayama Exp $ |
$OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.27 2016/02/04 06:56:05 takayama Exp $ |
License: LGPL |
License: LGPL |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
|
|
#include "mh.h" |
#include "mh.h" |
#define SMAX 4096 |
#define SMAX 4096 |
#define inci(i) { i++; if (i >= argc) { oxprintfe("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; |
int MH_deallocate=0; |
|
|
/* |
/* |
changelog |
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.04 MH_Ef_type exponential or scalar factor |
2016.02.01 C_2F1 |
2016.02.01 C_2F1 |
2014.03.15 --strategy 1 is default. A new parser in setParam() |
2014.03.15 --strategy 1 is default. A new parser in setParam() |
Line 51 double MH_coeff_max; |
|
Line 53 double MH_coeff_max; |
|
*/ |
*/ |
double MH_estimated_start_step; |
double MH_estimated_start_step; |
|
|
#ifdef C_2F1 |
|
int MH_P_pFq=2; |
|
int MH_Q_pFq=1; |
|
double MH_A_pFq[2]; |
|
double MH_B_pFq[1]; |
|
int MH_Ef_type=2; |
|
#else |
|
int MH_P_pFq=1; |
int MH_P_pFq=1; |
int MH_Q_pFq=1; |
int MH_Q_pFq=1; |
double MH_A_pFq[1]; |
double *MH_A_pFq=NULL; |
double MH_B_pFq[1]; |
double *MH_B_pFq=NULL; |
int MH_Ef_type=1; |
int MH_Ef_type=1; |
#endif |
MH_RF mh_rf=NULL; /* function pointer to mh_rf */ |
|
|
extern int MH_Verbose; |
extern int MH_Verbose; |
extern int MH_strategy; |
extern int MH_strategy; |
extern double MH_abserr; |
extern double MH_abserr; |
Line 78 static int showParam(void); |
|
Line 74 static int showParam(void); |
|
static int next(struct SFILE *fp,char *s, char *msg); |
static int next(struct SFILE *fp,char *s, char *msg); |
static double estimateHg(int m, double beta[],double x0); |
static double estimateHg(int m, double beta[],double x0); |
|
|
#ifdef C_2F1 |
|
void mh_setabc(double a,double b,double c); |
|
#endif |
|
/* #define DEBUG */ |
/* #define DEBUG */ |
#ifdef DEBUG |
#ifdef DEBUG |
char *MH_Dfname; char *MH_Gfname; double MH_Hg; |
char *MH_Dfname; char *MH_Gfname; double MH_Hg; |
Line 94 void mh_freeWorkArea(void) { |
|
Line 88 void mh_freeWorkArea(void) { |
|
mh_main(0,NULL); |
mh_main(0,NULL); |
setParam(NULL); |
setParam(NULL); |
mh_rkmain(0.0, NULL, 0.0); |
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. */ |
MH_deallocate=0; /* switch to the normal mode. */ |
} |
} |
static int mypower(int x,int n) { |
static int mypower(int x,int n) { |
Line 124 struct MH_RESULT *mh_main(int argc,char *argv[]) { |
|
Line 118 struct MH_RESULT *mh_main(int argc,char *argv[]) { |
|
struct MH_RESULT *rp=NULL; |
struct MH_RESULT *rp=NULL; |
extern int MH_deallocate; |
extern int MH_deallocate; |
extern int MH_byFile; |
extern int MH_byFile; |
|
extern double Ef; |
|
Ef = 1; |
MH_byFile=1; |
MH_byFile=1; |
if (MH_deallocate) { if (y0) mh_free(y0); return(rp); } |
if (MH_deallocate) { if (y0) mh_free(y0); return(rp); } |
setParam(NULL); MH_Gfname = MH_Dfname = NULL; MH_Verbose=1; |
setParam(NULL); MH_Gfname = MH_Dfname = NULL; MH_Verbose=1; |
Line 194 struct MH_RESULT *mh_main(int argc,char *argv[]) { |
|
Line 190 struct MH_RESULT *mh_main(int argc,char *argv[]) { |
|
if (MH_Verbose) showParam(); |
if (MH_Verbose) showParam(); |
if (MH_Verbose) {for (i=0; i<rank; i++) oxprintf("%lf\n",y0[i]); } |
if (MH_Verbose) {for (i=0; i<rank; i++) oxprintf("%lf\n",y0[i]); } |
|
|
#ifdef C_2F1 |
|
mh_setabc(MH_A_pFq[0],MH_A_pFq[1],MH_B_pFq[0]); |
|
#endif |
|
*rp=mh_rkmain(x0,y0,xn); |
*rp=mh_rkmain(x0,y0,xn); |
return(rp); |
return(rp); |
} |
} |
|
|
int mh_usage() { |
int mh_usage() { |
oxprintfe("Usages:\n"); |
|
#ifdef C_2F1 |
#include "usage-w-n.h" |
oxprintfe("hgm_w-n-2f1 "); |
|
#else |
|
oxprintfe("hgm_w-n "); |
|
#endif |
|
oxprintfe(" [--idata input_data_file --gnuplotf gnuplot_file_name\n"); |
|
oxprintfe(" --dataf output_data_file --raw --xmax xmax --test m --step h]\n"); |
|
oxprintfe("[ --95 --verbose] \n"); |
|
oxprintfe("[ --strategy s --abserr ae --relerr re] \n"); |
|
oxprintfe("s:0 rk, s:1 adaptive, s:2 adaptive&multiply, see rk.c for the default value of ae and re.\n"); |
|
oxprintfe("strategy default = %d\n",MH_strategy); |
|
oxprintfe("--raw does not add data parameters to the output_data_file.\n"); |
|
oxprintfe("\nThe command hgm_w-n [options] evaluates Pr({y | y<xmax}), which is the cumulative distribution function of the largest root of the m by m Wishart matrix with n degrees of freedom and the covariantce matrix sigma.\n"); |
|
oxprintfe("All the eigenvalues of sigma must be simple.\n"); |
|
oxprintfe("Parameters are specified by the input_data_file.\n"); |
|
oxprintfe("Parameters are redefined when they appear more than once in the idata file and the command line options.\n"); |
|
oxprintfe("The format of the input_data_file, which should be generated by the command hgm_jack-n.\n"); |
|
oxprintfe(" MH_Mg: m, MH_Beta: beta=sigma^(-1)/2 (diagonized), MH_Ng: n, MH_X0g: starting value of x,\n"); |
|
oxprintfe(" Iv: initial values at MH_X0g*MH_Beta (see our paper how to order them), \n"); |
|
oxprintfe(" Ef: a scalar factor to the initial value. It may set to 1.\n"); |
|
oxprintfe(" MH_Hg: h (step size),\n"); |
|
oxprintfe(" MH_Dp: output data is stored in every MH_Dp steps when output_data_file is specified.\n"); |
|
oxprintfe(" Xng: terminating value of x.\n\n"); |
|
oxprintfe("--95: output the 95%% point. --verbose: verbose mode.\n"); |
|
oxprintfe("The line started with %%%% or # is a comment line.\n"); |
|
oxprintfe("An example format of the input_data_file can be obtained by executing hgm_jack-n with no option.\n"); |
|
oxprintfe("When --idata option is used, this command is quiet. Use --verbose option if you want to see some messages.\n"); |
|
oxprintfe("\nExamples:\n"); |
|
oxprintfe("[1] ./hgm_w-n \n"); |
|
oxprintfe("[2] ./hgm_w-n --xmax 20\n"); |
|
oxprintfe("[3] ./hgm_w-n --test 6\n"); |
|
oxprintfe(" A test run in Mg=6.\n"); |
|
oxprintfe("[4] ./hgm_jack-n --idata Testdata/tmp-idata3.txt >t.txt\n"); |
|
oxprintfe(" ./hgm_w-n --idata t.txt --gnuplotf test-g --verbose\n"); |
|
oxprintfe(" gnuplot -persist <test-g-gp.txt\n"); |
|
oxprintfe(" tmp-idata3.txt is a sample input data distributed with this file.\n"); |
|
oxprintfe(" test-g-gp.txt is an input file of the gnuplot\n"); |
|
oxprintfe(" test-g is the table of x and the values of Pr({y | y<x}).\n"); return(0); |
|
} |
} |
|
|
static int setParamTest() { |
static int setParamTest() { |
Line 265 static int setParamTest() { |
|
Line 222 static int setParamTest() { |
|
} |
} |
static int setParamDefault() { |
static int setParamDefault() { |
int rank; |
int rank; |
|
double a[1]; |
|
double b[1]; |
MH_M=MH_Mg = 2 ; |
MH_M=MH_Mg = 2 ; |
MH_RANK=rank = mypower(2,MH_Mg); |
MH_RANK=rank = mypower(2,MH_Mg); |
MH_Beta = (double *)mh_malloc(sizeof(double)*MH_Mg); |
MH_Beta = (double *)mh_malloc(sizeof(double)*MH_Mg); |
MH_Beta[0] = 1.0; MH_Beta[1] = 2.0; |
MH_Beta[0] = 1.0; MH_Beta[1] = 2.0; |
MH_Ng = (double *)mh_malloc(sizeof(double)); *MH_Ng = 3.0; |
MH_Ng = (double *)mh_malloc(sizeof(double)); *MH_Ng = 3.0; |
|
a[0] = (MH_M+1.0)/2.0; |
|
b[0] = a[0]+(*MH_Ng)/2.0; |
|
mh_setA(a,1); mh_setB(b,1); |
|
mh_rf = & mh_rf_ef_type_1; |
Iv = (double *)mh_malloc(sizeof(double)*rank); |
Iv = (double *)mh_malloc(sizeof(double)*rank); |
Iv[0] = 1.58693; |
Iv[0] = 1.58693; |
Iv[1] = 0.811369; |
Iv[1] = 0.811369; |
Line 282 static int setParamDefault() { |
|
Line 245 static int setParamDefault() { |
|
Xng = 10.0; return(0); |
Xng = 10.0; return(0); |
} |
} |
|
|
static int next(struct SFILE *sfp,char *s,char *msg) { |
static int next_old1(struct SFILE *sfp,char *s,char *msg) { |
s[0] = '%'; |
s[0] = '%'; |
while (s[0] == '%') { |
while (s[0] == '%') { |
if (!mh_fgets(s,SMAX,sfp)) { |
if (!mh_fgets(s,SMAX,sfp)) { |
Line 292 static int next(struct SFILE *sfp,char *s,char *msg) { |
|
Line 255 static int next(struct SFILE *sfp,char *s,char *msg) { |
|
if (s[0] != '%') return(0); |
if (s[0] != '%') return(0); |
} return(0); |
} return(0); |
} |
} |
|
static int next(struct SFILE *sfp,char *s,char *msg) { |
|
static int check=1; |
|
char *ng="%%Ng="; |
|
// int i; |
|
s[0] = '%'; |
|
while ((s[0] == '%') || (s[0] == '#')) { |
|
if (!mh_fgets(s,SMAX,sfp)) { |
|
oxprintfe("Data format error at %s\n",msg); |
|
oxprintfe("Is it version 2.0 format? If so, add\n%s\nat the top.\n",VSTRING); |
|
mh_exit(-1); |
|
} |
|
if ((s[0] == '%') && (s[1] == '%')) continue; |
|
if (s[0] == '#') continue; |
|
if (strncmp(s,VSTRING,strlen(VSTRING)) == 0) { |
|
return(2); |
|
} |
|
if (check && (strncmp(msg,ng,4)==0)) { |
|
if (strncmp(s,ng,5) != 0) { |
|
oxprintfe("Warning, there is no %%Ng= at the border of Beta's and Ng, s=%s\n",s); |
|
} |
|
/* check=0; */ |
|
} |
|
if (s[0] != '%') return(0); |
|
} |
|
return(0); |
|
} |
|
|
static int setParam(char *fname) { |
static int setParam(char *fname) { |
int rank; |
int rank; |
char s[SMAX]; |
char s[SMAX]; |
struct SFILE *fp; |
struct SFILE *fp; |
int i; |
int i; |
|
int version; |
|
double a[1]; double b[1]; /* for old inputs */ |
struct mh_token tk; |
struct mh_token tk; |
extern int MH_deallocate; |
extern int MH_deallocate; |
extern int MH_byFile; |
extern int MH_byFile; |
if (MH_deallocate) { |
if (MH_deallocate) { |
if (MH_Beta) mh_free(MH_Beta); |
if (MH_Beta) {mh_free(MH_Beta); MH_Beta=NULL;} |
if (MH_Ng) mh_free(MH_Ng); |
if (MH_Ng) {mh_free(MH_Ng); MH_Ng=NULL;} |
if (Iv) mh_free(Iv); |
if (Iv) {mh_free(Iv); Iv = NULL;} |
|
if (MH_A_pFq) {mh_free(MH_A_pFq); MH_A_pFq=NULL; MH_P_pFq = 0;} |
|
if (MH_B_pFq) {mh_free(MH_B_pFq); MH_B_pFq=NULL; MH_Q_pFq = 0;} |
return(0); |
return(0); |
} |
} |
if (fname == NULL) return(setParamDefault()); |
if (fname == NULL) return(setParamDefault()); |
Line 312 static int setParam(char *fname) { |
|
Line 306 static int setParam(char *fname) { |
|
oxprintfe("File %s is not found.\n",fname); |
oxprintfe("File %s is not found.\n",fname); |
mh_exit(-1); |
mh_exit(-1); |
} |
} |
next(fp,s,"MH_Mg(m)"); |
/* set default initial values */ |
|
MH_Mg=MH_M=-1; /* number of variables */ |
|
MH_Ng=(double *) mh_malloc(sizeof(double)); *MH_Ng=-1; /* *Ng is the degree of freedom 1F1 */ |
|
MH_X0g=0.1; /* evaluation point */ |
|
Ef=1.0; /* exponential factor */ |
|
MH_Ef_type=1; |
|
MH_Hg=0.01; /* step size for RK */ |
|
MH_Dp = 1; /* sampling rate */ |
|
Xng = 10.0; /* terminal point for RK */ |
|
|
|
/* Parser for the old style (version <2.0) input */ |
|
version=next(fp,s,"Mg(m)"); |
|
if (version == 2) goto mh_myparse; |
sscanf(s,"%d",&MH_Mg); MH_M=MH_Mg; |
sscanf(s,"%d",&MH_Mg); MH_M=MH_Mg; |
MH_RANK=rank = mypower(2,MH_Mg); |
MH_RANK=rank = mypower(2,MH_Mg); |
|
|
Line 322 static int setParam(char *fname) { |
|
Line 328 static int setParam(char *fname) { |
|
sscanf(s,"%lf",&(MH_Beta[i])); |
sscanf(s,"%lf",&(MH_Beta[i])); |
} |
} |
|
|
MH_Ng = (double *)mh_malloc(sizeof(double)); |
|
next(fp,s,"MH_Ng(freedom parameter n)"); |
next(fp,s,"MH_Ng(freedom parameter n)"); |
sscanf(s,"%lf",MH_Ng); |
sscanf(s,"%lf",MH_Ng); |
|
/* for old style input only for 1F1 ef_type==1. */ |
|
MH_P_pFq = 1; MH_Q_pFq = 1; |
|
a[0] = (MH_M+1.0)/2.0; |
|
b[0] = a[0]+(*MH_Ng)/2.0; |
|
mh_setA(a,1); mh_setB(b,1); |
|
mh_rf = & mh_rf_ef_type_1; |
|
|
|
|
next(fp,s,"MH_X0g(initial point)"); |
next(fp,s,"MH_X0g(initial point)"); |
sscanf(s,"%lf",&MH_X0g); |
sscanf(s,"%lf",&MH_X0g); |
|
|
Line 348 static int setParam(char *fname) { |
|
Line 360 static int setParam(char *fname) { |
|
sscanf(s,"%lf",&Xng); |
sscanf(s,"%lf",&Xng); |
|
|
/* Reading the optional parameters */ |
/* Reading the optional parameters */ |
|
mh_myparse: |
while ((tk = mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_EOF) { |
while ((tk = mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_EOF) { |
/* expect ID */ |
/* expect ID */ |
if (tk.type != MH_TOKEN_ID) { |
if (tk.type != MH_TOKEN_ID) { |
Line 383 static int setParam(char *fname) { |
|
Line 396 static int setParam(char *fname) { |
|
MH_strategy = tk.ival; |
MH_strategy = tk.ival; |
continue; |
continue; |
} |
} |
// Format: #p_pFq=2 1.5 3.2 |
// Format: #p_pFq=2 1.5 3.2 override by new input format. |
if (strcmp(s,"p_pFq")==0) { |
if (strcmp(s,"p_pFq")==0) { |
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
Line 392 static int setParam(char *fname) { |
|
Line 405 static int setParam(char *fname) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
} |
} |
MH_P_pFq = tk.ival; |
MH_P_pFq = tk.ival; |
|
mh_setA(NULL,tk.ival); /* allocate mem */ |
for (i=0; i<MH_P_pFq; i++) { |
for (i=0; i<MH_P_pFq; i++) { |
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
MH_A_pFq[i] = tk.dval; |
MH_A_pFq[i] = tk.dval; |
Line 411 static int setParam(char *fname) { |
|
Line 425 static int setParam(char *fname) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
} |
} |
MH_Q_pFq = tk.ival; |
MH_Q_pFq = tk.ival; |
|
mh_setB(NULL,tk.ival); /* allocate mem */ |
for (i=0; i<MH_Q_pFq; i++) { |
for (i=0; i<MH_Q_pFq; i++) { |
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
MH_B_pFq[i] = tk.dval; |
MH_B_pFq[i] = tk.dval; |
Line 432 static int setParam(char *fname) { |
|
Line 447 static int setParam(char *fname) { |
|
MH_Ef_type = tk.ival; |
MH_Ef_type = tk.ival; |
continue; |
continue; |
} |
} |
|
|
|
if (strcmp(s,"Mg")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
MH_Mg = tk.ival; MH_M = MH_Mg; |
|
MH_RANK = rank = mypower(2,MH_Mg); |
|
continue; |
|
} |
|
if (strcmp(s,"Beta")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if (MH_Mg <= 0) { |
|
oxprintfe("Mg should be set before reading Beta.\n"); mh_exit(-1); |
|
} |
|
MH_Beta = (double *)mh_malloc(sizeof(double)*MH_Mg); |
|
for (i=0; i<MH_Mg; i++) { |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
MH_Beta[i] = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
MH_Beta[i] = tk.ival; |
|
}else { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
} |
|
Iv = (double *)mh_malloc(sizeof(double)*rank); |
|
for (i=0; i<rank; i++) { |
|
Iv[i] = 0.0; |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"Ng")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
|
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type== MH_TOKEN_DOUBLE) { |
|
*MH_Ng = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
*MH_Ng = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"X0g")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
MH_X0g = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
MH_X0g = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"Iv")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
for (i=0; i<rank; i++) { |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
Iv[i] = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
Iv[i] = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"Ef")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
Ef = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
Ef = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"Hg")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
MH_Hg = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
MH_Hg = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"Dp")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
MH_Dp = tk.dval; |
|
continue; |
|
} |
|
if (strcmp(s,"Xng")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
Xng = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
Xng = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
continue; |
|
} |
|
|
oxprintfe("Unknown ID for wmain.c (old...) at %s.\n",s); mh_exit(-1); |
oxprintfe("Unknown ID for wmain.c (old...) at %s.\n",s); mh_exit(-1); |
} |
} |
|
if (MH_Ef_type == 1) { |
|
mh_rf = &mh_rf_ef_type_1; |
|
}else if (MH_Ef_type == 2) { |
|
mh_rf = &mh_rf_ef_type_2; |
|
}else{ |
|
oxprintfe("Ef_type = %d is not implemented.\n",MH_Ef_type); mh_exit(-1); |
|
} |
|
if ((MH_M < 0) || (MH_A_pFq==NULL)) { |
|
oxprintfe("MH_M and p_pFq, q_pFq are compulsory parameters.\n"); mh_exit(-1); |
|
} |
|
|
mh_fclose(fp); return(0); |
mh_fclose(fp); return(0); |
} |
} |
Line 463 static int showParam() { |
|
Line 615 static int showParam() { |
|
oxprintf("#MH_coeff_max=%lg\n",MH_coeff_max); |
oxprintf("#MH_coeff_max=%lg\n",MH_coeff_max); |
oxprintf("#MH_estimated_start_step=%lg\n",MH_estimated_start_step); |
oxprintf("#MH_estimated_start_step=%lg\n",MH_estimated_start_step); |
oxprintf("%%ef_type=%d\n",MH_Ef_type); |
oxprintf("%%ef_type=%d\n",MH_Ef_type); |
#ifdef C_2F1 |
|
oxprintf("%%q_pFq=%d, ",MH_P_pFq); |
oxprintf("%%q_pFq=%d, ",MH_P_pFq); |
for (i=0; i<MH_P_pFq; i++) { |
for (i=0; i<MH_P_pFq; i++) { |
if (i != MH_P_pFq-1) oxprintf(" %lg,",MH_A_pFq[i]); |
if (i != MH_P_pFq-1) oxprintf(" %lg,",MH_A_pFq[i]); |
Line 474 static int showParam() { |
|
Line 625 static int showParam() { |
|
if (i != MH_Q_pFq-1) oxprintf(" %lg,",MH_B_pFq[i]); |
if (i != MH_Q_pFq-1) oxprintf(" %lg,",MH_B_pFq[i]); |
else oxprintf(" %lg\n",MH_B_pFq[i]); |
else oxprintf(" %lg\n",MH_B_pFq[i]); |
} |
} |
#endif |
|
return(0); |
return(0); |
} |
} |
|
|
Line 499 static double estimateHg(int m, double beta[],double x |
|
Line 649 static double estimateHg(int m, double beta[],double x |
|
h = exp(log(MH_abserr/cmax)/5.0); |
h = exp(log(MH_abserr/cmax)/5.0); |
MH_estimated_start_step = h; |
MH_estimated_start_step = h; |
return h; |
return h; |
|
} |
|
|
|
void mh_setA(double a[],int alen) { |
|
int i; |
|
if (alen < 0) { |
|
if (MH_A_pFq != NULL) mh_free(MH_A_pFq); |
|
MH_A_pFq=NULL; MH_P_pFq=-1; |
|
return; |
|
} |
|
if (alen == 0) { |
|
MH_P_pFq=0; return; |
|
} |
|
MH_P_pFq=alen; |
|
MH_A_pFq = (double *)mh_malloc(MH_P_pFq*sizeof(double)); |
|
if (a != NULL) { |
|
for (i=0; i<alen; i++) MH_A_pFq[i] = a[i]; |
|
}else{ |
|
for (i=0; i<alen; i++) MH_A_pFq[i] = 0.0; |
|
} |
|
return; |
|
} |
|
void mh_setB(double b[],int blen) { |
|
int i; |
|
if (blen < 0) { |
|
if (MH_B_pFq != NULL) mh_free(MH_B_pFq); |
|
MH_B_pFq=NULL; MH_Q_pFq=-1; |
|
return; |
|
} |
|
if (blen == 0) { |
|
MH_Q_pFq=0; return; |
|
} |
|
MH_Q_pFq=blen; |
|
MH_B_pFq = (double *)mh_malloc(MH_Q_pFq*sizeof(double)); |
|
if (b != NULL) { |
|
for (i=0; i<blen; i++) MH_B_pFq[i] = b[i]; |
|
}else{ |
|
for (i=0; i<blen; i++) MH_B_pFq[i] = 0.0; |
|
} |
|
return; |
} |
} |