=================================================================== RCS file: /home/cvs/OpenXM/src/hgm/mh/src/jack-n.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -p -r1.28 -r1.29 --- OpenXM/src/hgm/mh/src/jack-n.c 2014/03/20 10:58:37 1.28 +++ OpenXM/src/hgm/mh/src/jack-n.c 2015/03/24 05:59:43 1.29 @@ -5,7 +5,7 @@ #include #include "sfile.h" /* - $OpenXM: OpenXM/src/hgm/mh/src/jack-n.c,v 1.27 2014/03/20 09:37:16 takayama Exp $ + $OpenXM: OpenXM/src/hgm/mh/src/jack-n.c,v 1.28 2014/03/20 10:58:37 takayama Exp $ Ref: copied from this11/misc-2011/A1/wishart/Prog jack-n.c, translated from mh.rr or tk_jack.rr in the asir-contrib. License: LGPL Koev-Edelman for higher order derivatives. @@ -242,7 +242,7 @@ int jk_freeWorkArea() { if (M_beta_1) {myfree(M_beta_1); M_beta_1=NULL;} if (M_jack) { for (i=0; M_jack[i] != NULL; i++) { - if (Debug) printf("Free M_jack[%d]\n",i); + if (Debug) oxprintf("Free M_jack[%d]\n",i); myfree(M_jack[i]); M_jack[i] = NULL; } myfree(M_jack); M_jack=NULL; @@ -286,19 +286,19 @@ int jk_initializeWorkArea() { static void *mymalloc(int size) { void *p; - if (Debug) printf("mymalloc(%d)\n",size); + if (Debug) oxprintf("mymalloc(%d)\n",size); p = (void *)mh_malloc(size); if (p == NULL) { - fprintf(stderr,"No more memory.\n"); + oxprintfe("No more memory.\n"); mh_exit(-1); } return(p); } static int myfree(void *p) { - if (Debug) printf("myFree at %p\n",p); + if (Debug) oxprintf("myFree at %p\n",p); return(mh_free(p)); } -static int myerror(char *s) { fprintf(stderr,"%s: type in control-C\n",s); getchar(); getchar(); return(0);} +static int myerror(char *s) { oxprintfe("%s: type in control-C\n",s); getchar(); getchar(); return(0);} static double jack1(int K) { double F; @@ -349,7 +349,7 @@ static double xval(int ii,int p) { /* x_i^p */ if (p > M_m_MAX-2) myerror("xval, p is too large."); if (p < 0) { myerror("xval, p is negative."); - printf("ii=%d, p=%d\n",ii,p); + oxprintf("ii=%d, p=%d\n",ii,p); mh_exit(-1); } return(Xarray[ii-1][p]); @@ -405,7 +405,7 @@ static int test_ptrans() { int i; M_m = 10; ptrans(p,pt); - if (Debug) {for (i=0; i<10; i++) printf("%d,",pt[i]); printf("\n");} + if (Debug) {for (i=0; i<10; i++) oxprintf("%d,",pt[i]); oxprintf("\n");} return(0); } @@ -419,7 +419,7 @@ static int huk(int K[],int I,int J) { int Kp[M_m_MAX]; int A,H; A=Alpha; - /*printf("h^k(%a,%a,%a,%a)\n",K,I,J,A);*/ + /*oxprintf("h^k(%a,%a,%a,%a)\n",K,I,J,A);*/ ptrans(K,Kp); H=Kp[J-1]-I+A*(K[I-1]-J+1); return(H); @@ -434,7 +434,7 @@ static int hdk(int K[],int I,int J) { int Kp[M_m_MAX]; int A,H; A = Alpha; - /*printf("h_k(%a,%a,%a,%a)\n",K,I,J,A);*/ + /*oxprintf("h_k(%a,%a,%a,%a)\n",K,I,J,A);*/ ptrans(K,Kp); H=Kp[J-1]-I+1+A*(K[I-1]-J); return(H); @@ -454,7 +454,7 @@ static double jjk(int K[]) { V *= huk(K,I+1,J+1)*hdk(K,I+1,J+1); } } - if (Debug) {printp(K); printf("<--K, jjk=%lg\n",V);} + if (Debug) {printp(K); oxprintf("<--K, jjk=%lg\n",V);} return(V); } /* @@ -528,8 +528,8 @@ static int bb(int N[],int K[],int M[],int I,int J) { ptrans(M,Mp); /* - printp(K); printf("K<--, "); printp2(Kp); printf("<--Kp\n"); - printp(M); printf("M<--, "); printp2(Mp); printf("<--Mp\n"); + printp(K); oxprintf("K<--, "); printp2(Kp); oxprintf("<--Kp\n"); + printp(M); oxprintf("M<--, "); printp2(Mp); oxprintf("<--Mp\n"); */ if ((plength_t(Kp) < J) || (plength_t(Mp) < J)) return(hdk(N,I,J)); @@ -550,7 +550,7 @@ static double beta(int K[],int M[]) { for (J=0; J= M_n) { - if (Debug) {fprintf(stderr,"Ksize >= M_n\n");} + if (Debug) {oxprintfe("Ksize >= M_n\n");} continue; } for (i=0; 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); }} static int imypower(int x,int n) { int i; @@ -1458,7 +1458,7 @@ static int imypower(int x,int n) { main(int argc,char *argv[]) { mh_exit(MH_RESET_EXIT); /* jk_main(argc,argv); - printf("second run.\n"); */ + oxprintf("second run.\n"); */ jk_main(argc,argv); return(0); } @@ -1522,7 +1522,7 @@ struct MH_RESULT *jk_main2(int argc,char *argv[],int a }else if (strcmp(argv[i],"--help")==0) { usage(); return(0); }else if (strcmp(argv[i],"--bystring")==0) { - if (idata) {fprintf(stderr,"--bystring must come before --idata option.\n"); mh_exit(-1);} + if (idata) {oxprintfe("--bystring must come before --idata option.\n"); mh_exit(-1);} JK_byFile = 0; }else if (strcmp(argv[i],"--automatic")==0) { inci(i); /* ignore, in this function */ @@ -1533,7 +1533,7 @@ struct MH_RESULT *jk_main2(int argc,char *argv[],int a inci(i); sscanf(argv[i],"%lg",&M_x0value_min); }else { - fprintf(stderr,"Unknown option %s\n",argv[i]); + oxprintfe("Unknown option %s\n",argv[i]); usage(); return(NULL); } @@ -1560,7 +1560,7 @@ struct MH_RESULT *jk_main2(int argc,char *argv[],int a if (M_n > Mapprox) Mapprox=M_n; } /* Output by a file=stdout */ - ofp = mh_fopen("stdout","w",JK_byFile); + ofp = mh_fopen("oxstdout","w",JK_byFile); sprintf(swork,"%%%%Use --help option to see the help.\n"); mh_fputs(swork,ofp); sprintf(swork,"%%%%Mapprox=%d\n",Mapprox); mh_fputs(swork,ofp); @@ -1585,7 +1585,7 @@ struct MH_RESULT *jk_main2(int argc,char *argv[],int a a[0] = ((double)Mg+1.0)/2.0; b[0] = ((double)Mg+1.0)/2.0 + ((double) (*Ng))/2.0; /* bug, double check */ - if (Debug) printf("Calling mh_t with ([%lf],[%lf],%d,%d)\n",a[0],b[0],M_n,Mapprox); + if (Debug) oxprintf("Calling mh_t with ([%lf],[%lf],%d,%d)\n",a[0],b[0],M_n,Mapprox); mh_t(a,b,M_n,Mapprox); if ((!M_mh_t_success) && M_automatic) { jk_freeWorkArea(); @@ -1616,44 +1616,44 @@ struct MH_RESULT *jk_main2(int argc,char *argv[],int a ans->series_error = M_series_error; ans->recommended_abserr = M_recommended_abserr; } - if (Debug) printf("jk_freeWorkArea() starts\n"); + if (Debug) oxprintf("jk_freeWorkArea() starts\n"); jk_freeWorkArea(); - if (Debug) printf("jk_freeWorkArea() has finished.\n"); + if (Debug) oxprintf("jk_freeWorkArea() has finished.\n"); return(ans); } static int usage() { - fprintf(stderr,"Usages:\n"); - fprintf(stderr,"hgm_jack-n [--idata input_data_file --x0 x0 --degree approxm]\n"); - fprintf(stderr," [--automatic n --assigned_series_error e --x0value_min e2]\n"); - fprintf(stderr,"\nThe command hgm_jack-n [options] generates an input for hgm_w-n, Pr({y | ytest2.txt\n"); - fprintf(stderr," ./hgm_w-n --idata test2.txt --gnuplotf test-g\n"); - fprintf(stderr," gnuplot -persist test2.txt\n"); + oxprintfe(" ./hgm_w-n --idata test2.txt --gnuplotf test-g\n"); + oxprintfe(" gnuplot -persist s); + if (JK_byFile) oxprintfe("File %s is not found.\n",fp->s); mh_exit(-1); } next(fp,s,"Mg(m)"); @@ -1760,69 +1760,69 @@ static int setParam(char *fname) { while ((tk = mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_EOF) { /* expect ID */ if (tk.type != MH_TOKEN_ID) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } if (strcmp(s,"automatic")==0) { if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } M_automatic = tk.ival; continue; } if (strcmp(s,"assigned_series_error")==0) { if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_DOUBLE) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } M_assigned_series_error = tk.dval; continue; } if (strcmp(s,"x0value_min")==0) { if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_DOUBLE) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } M_x0value_min = tk.dval; continue; } if ((strcmp(s,"Mapprox")==0) || (strcmp(s,"degree")==0)) { if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } Mapprox = tk.ival; continue; } if (strcmp(s,"X0g_bound")==0) { if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_DOUBLE) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } M_X0g_bound = tk.dval; continue; } if (strcmp(s,"show_autosteps")==0) { if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { - fprintf(stderr,"Syntax error at %s\n",s); mh_exit(-1); + oxprintfe("Syntax error at %s\n",s); mh_exit(-1); } M_show_autosteps = tk.ival; continue; } - fprintf(stderr,"Unknown ID at %s\n",s); mh_exit(-1); + oxprintfe("Unknown ID at %s\n",s); mh_exit(-1); } mh_fclose(fp); return(0); @@ -1832,7 +1832,7 @@ static int showParam(struct SFILE *fp,int fd) { int rank,i; char swork[1024]; if (fd) { - fp = mh_fopen("stdout","w",1); + fp = mh_fopen("oxstdout","w",1); } rank = imypower(2,Mg); sprintf(swork,"%%Mg=\n%d\n",Mg); mh_fputs(swork,fp); @@ -1876,7 +1876,7 @@ static double gammam(double a,int n) { for (i=1; i<=n; i++) { v2 += lgamma(a-((double)(i-1))/2.0); /* not for big n */ } - if (Debug) printf("gammam(%lg,%d)=%lg\n",a,n,v*exp(v2)); + if (Debug) oxprintf("gammam(%lg,%d)=%lg\n",a,n,v*exp(v2)); return(v*exp(v2)); }