--- imach/src/imach.c 2014/12/16 10:30:11 1.163 +++ imach/src/imach.c 2014/12/22 11:40:47 1.166 @@ -1,6 +1,19 @@ -/* $Id: imach.c,v 1.163 2014/12/16 10:30:11 brouard Exp $ +/* $Id: imach.c,v 1.166 2014/12/22 11:40:47 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.166 2014/12/22 11:40:47 brouard + *** empty log message *** + + Revision 1.165 2014/12/16 11:20:36 brouard + Summary: After compiling on Visual C + + * imach.c (Module): Merging 1.61 to 1.162 + + Revision 1.164 2014/12/16 10:52:11 brouard + Summary: Merging with Visual C after suppressing some warnings for unused variables. Also fixing Saito's bug 0.98Xn + + * imach.c (Module): Merging 1.61 to 1.162 + Revision 1.163 2014/12/16 10:30:11 brouard * imach.c (Module): Merging 1.61 to 1.162 @@ -492,9 +505,8 @@ end */ +#define POWELL /* Instead of NLOPT */ - - #include #include #include @@ -557,7 +569,7 @@ typedef struct { #define YEARM 12. /**< Number of months per year */ #define AGESUP 130 #define AGEBASE 40 -#define AGEGOMP 10. /**< Minimal age for Gompertz adjustment */ +#define AGEGOMP 10 /**< Minimal age for Gompertz adjustment */ #ifdef _WIN32 #define DIRSEPARATOR '\\' #define CHARSEPARATOR "\\" @@ -568,11 +580,11 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.163 2014/12/16 10:30:11 brouard Exp $ */ +/* $Id: imach.c,v 1.166 2014/12/22 11:40:47 brouard Exp $ */ /* $State: Exp $ */ char version[]="Imach version 0.99, September 2014,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121)"; -char fullversion[]="$Revision: 1.163 $ $Date: 2014/12/16 10:30:11 $"; +char fullversion[]="$Revision: 1.166 $ $Date: 2014/12/22 11:40:47 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -686,7 +698,12 @@ static double maxarg1,maxarg2; #define SIGN(a,b) ((b)>0.0 ? fabs(a) : -fabs(a)) #define rint(a) floor(a+0.5) - +/* http://www.thphys.uni-heidelberg.de/~robbers/cmbeasy/doc/html/myutils_8h-source.html */ +/* #define mytinydouble 1.0e-16 */ +/* #define DEQUAL(a,b) (fabs((a)-(b))khi/nkhif) || (k2 >khi/nkhif)){ /* Keeps lastvalue before 3.84/2 KHI2 5% 1d.f. */ - k=kmax; l=lmax*10.; + k=kmax; l=lmax*10; } else if((k1 >khi/nkhi) || (k2 >khi/nkhi)){ delts=delt; @@ -2365,7 +2384,7 @@ double hessii(double x[], double delta, double hessij( double x[], double delti[], int thetai,int thetaj,double (*func)(double []),int npar) { int i; - int l=1, l1, lmax=20; + int l=1, lmax=20; double k1,k2,k3,k4,res,fx; double p2[MAXPARM+1]; int k; @@ -2480,7 +2499,7 @@ void pstamp(FILE *fichier) void freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **agev, int nlstate, int imx, int *Tvaraff, int **nbcode, int *ncodemax,double **mint,double **anint, char strstart[]) { /* Some frequencies */ - int i, m, jk, k1,i1, j1, bool, z1,j; + int i, m, jk, j1, bool, z1,j; int first; double ***freq; /* Frequencies */ double *pp, **prop; @@ -2661,10 +2680,10 @@ void prevalence(double ***probs, double We still use firstpass and lastpass as another selection. */ - int i, m, jk, k1, i1, j1, bool, z1,j; - double ***freq; /* Frequencies */ - double *pp, **prop; - double pos,posprop; + int i, m, jk, j1, bool, z1,j; + + double **prop; + double posprop; double y2; /* in fractional years */ int iagemin, iagemax; int first; /** to stop verbosity which is redirected to log file */ @@ -2755,7 +2774,7 @@ void concatwav(int wav[], int **dh, int int j, k=0,jk, ju, jl; double sum=0.; first=0; - jmin=1e+5; + jmin=100000; jmax=-1; jmean=0.; for(i=1; i<=imx; i++){ @@ -2995,7 +3014,7 @@ void evsij(double ***eij, double x[], in { /* Health expectancies, no variances */ - int i, j, nhstepm, hstepm, h, nstepm, k, cptj, cptj2, i2, j2; + int i, j, nhstepm, hstepm, h, nstepm; int nhstepma, nstepma; /* Decreasing with age */ double age, agelim, hf; double ***p3mat; @@ -3317,7 +3336,7 @@ void varevsij(char optionfilefiname[], d double **dnewm,**doldm; double **dnewmp,**doldmp; int i, j, nhstepm, hstepm, h, nstepm ; - int k, cptcode; + int k; double *xp; double **gp, **gm; /* for var eij */ double ***gradg, ***trgradg; /*for var eij */ @@ -3617,10 +3636,9 @@ void varprevlim(char fileres[], double * { /* Variance of prevalence limit */ /* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double **savm,double ftolpl);*/ - double **newm; + double **dnewm,**doldm; int i, j, nhstepm, hstepm; - int k, cptcode; double *xp; double *gp, *gm; double **gradg, **trgradg; @@ -3699,9 +3717,9 @@ void varprevlim(char fileres[], double * /************ Variance of one-step probabilities ******************/ void varprob(char optionfilefiname[], double **matcov, double x[], double delti[], int nlstate, double bage, double fage, int ij, int *Tvar, int **nbcode, int *ncodemax, char strstart[]) { - int i, j=0, i1, k1, l1, t, tj; + int i, j=0, k1, l1, tj; int k2, l2, j1, z1; - int k=0,l, cptcode; + int k=0, l; int first=1, first1, first2; double cv12, mu1, mu2, lc1, lc2, v12, v21, v11, v22,v1,v2, c12, tnalp; double **dnewm,**doldm; @@ -3709,7 +3727,7 @@ void varprob(char optionfilefiname[], do double *gp, *gm; double **gradg, **trgradg; double **mu; - double age,agelim, cov[NCOVMAX+1]; + double age, cov[NCOVMAX+1]; double std=2.0; /* Number of standard deviation wide of confidence ellipsoids */ int theta; char fileresprob[FILENAMELENGTH]; @@ -4081,8 +4099,8 @@ fprintf(fichtm," \n
  • Graphs ",stepm,subdirf2(optionfilefiname,"pe"),jj1,subdirf2(optionfilefiname,"pe"),jj1,subdirf2(optionfilefiname,"pe"),jj1); /* Period (stable) prevalence in each health state */ for(cpt=1; cpt<=nlstate;cpt++){ - fprintf(fichtm,"
    - Convergence from each state (1 to %d) to period (stable) prevalence in state %d %s%d_%d.png
    \ -",nlstate, cpt, subdirf2(optionfilefiname,"p"),cpt,jj1,subdirf2(optionfilefiname,"p"),cpt,jj1,subdirf2(optionfilefiname,"p"),cpt,jj1); + fprintf(fichtm,"
    - Convergence to period (stable) prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. %s%d_%d.png
    \ +", cpt, cpt, nlstate, subdirf2(optionfilefiname,"p"),cpt,jj1,subdirf2(optionfilefiname,"p"),cpt,jj1,subdirf2(optionfilefiname,"p"),cpt,jj1); } for(cpt=1; cpt<=nlstate;cpt++) { fprintf(fichtm,"\n
    - Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) : %s%d%d.png
    \ @@ -4167,7 +4185,7 @@ true period expectancies (those weighted void printinggnuplot(char fileres[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){ char dirfileres[132],optfileres[132]; - int m0,cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,ij=0,l=0; + int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,ij=0,l=0; int ng=0; /* if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */ /* printf("Problem with file %s",optionfilegnuplot); */ @@ -4353,7 +4371,7 @@ plot [%.f:%.f] ", ageminpar, agemaxpar) } /* end k2 */ } /* end jk */ } /* end ng */ - avoid: + /* avoid: */ fflush(ficgp); } /* end gnuplot */ @@ -4407,8 +4425,7 @@ prevforecast(char fileres[], double anpr dateprev1 dateprev2 range of dates during which prevalence is computed anproj2 year of en of projection (same day and month as proj1). */ - int yearp, stepsize, hstepm, nhstepm, j, k, c, cptcod, i, h, i1; - int *popage; + int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1; double agec; /* generic age */ double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean; double *popeffectif,*popcount; @@ -4702,8 +4719,8 @@ void prwizard(int ncovmodel, int nlstate /* Wizard to print covariance matrix template */ - char ca[32], cb[32], cc[32]; - int i,j, k, l, li, lj, lk, ll, jj, npar, itimes; + char ca[32], cb[32]; + int i,j, k, li, lj, lk, ll, jj, npar, itimes; int numlinepar; printf("# Parameters nlstate*nlstate*ncov a12*1 + b12 * age + ...\n"); @@ -4924,7 +4941,7 @@ fprintf(fichtm,"
    • Life table=1;j--){ @@ -5121,7 +5136,7 @@ int readdata(char datafile[], int firsto fclose(fic); return (0); - endread: + /* endread: */ printf("Exiting readdata: "); fclose(fic); return (1); @@ -5152,7 +5167,7 @@ int decodemodel ( char model[], int last */ { int i, j, k, ks; - int i1, j1, k1, k2; + int j1, k1, k2; char modelsav[80]; char stra[80], strb[80], strc[80], strd[80],stre[80]; @@ -5301,7 +5316,7 @@ int decodemodel ( char model[], int last return (0); /* with covar[new additional covariate if product] and Tage if age */ - endread: + /*endread:*/ printf("Exiting decodemodel: "); return (1); } @@ -5398,7 +5413,7 @@ calandcheckages(int imx, int maxwav, dou fprintf(ficlog,"Total number of individuals= %d, Agemin = %.2f, Agemax= %.2f\n\n", imx, *agemin, *agemax); return (0); - endread: + /* endread:*/ printf("Exiting calandcheckages: "); return (1); } @@ -5418,38 +5433,35 @@ int main(int argc, char *argv[]) double ssval; #endif int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav); - int i,j, k, n=MAXN,iter,m,size=100,cptcode, cptcod; - int linei, month, year,iout; - int jj, ll, li, lj, lk, imk; + int i,j, k, n=MAXN,iter=0,m,size=100, cptcod; + + int jj, ll, li, lj, lk; int numlinepar=0; /* Current linenumber of parameter file */ int itimes; int NDIM=2; int vpopbased=0; - char ca[32], cb[32], cc[32]; + char ca[32], cb[32]; /* FILE *fichtm; *//* Html File */ /* FILE *ficgp;*/ /*Gnuplot File */ struct stat info; - double agedeb, agefin,hf; + double agedeb; double ageminpar=1.e20,agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20; double fret; - double **xi,tmp,delta; - double dum; /* Dummy variable */ double ***p3mat; double ***mobaverage; - int *indx; - char line[MAXLINE], linepar[MAXLINE]; + + char line[MAXLINE]; char path[MAXLINE],pathc[MAXLINE],pathcd[MAXLINE],pathtot[MAXLINE],model[MAXLINE]; char pathr[MAXLINE], pathimach[MAXLINE]; - char **bp, *tok, *val; /* pathtot */ + char *tok, *val; /* pathtot */ int firstobs=1, lastobs=10; - int sdeb, sfin; /* Status at beginning and end */ - int c, h , cpt,l; - int ju,jl, mi; - int i1,j1, jk,aa,bb, stepsize, ij; - int jnais,jdc,jint4,jint1,jint2,jint3,*tab; + int c, h , cpt; + int jl; + int i1, j1, jk, stepsize; + int *tab; int mobilavproj=0 , prevfcast=0 ; /* moving average of prev, If prevfcast=1 prevalence projection */ int mobilav=0,popforecast=0; int hstepm, nhstepm; @@ -5458,7 +5470,7 @@ int main(int argc, char *argv[]) double jprev1=1, mprev1=1,anprev1=2000,jprev2=1, mprev2=1,anprev2=2000; double jpyram=1, mpyram=1,anpyram=2000,jpyram1=1, mpyram1=1,anpyram1=2000; - double bage, fage, age, agelim, agebase; + double bage=0, fage=110, age, agelim, agebase; double ftolpl=FTOL; double **prlim; double ***param; /* Matrix of parameters */ @@ -5469,19 +5481,18 @@ int main(int argc, char *argv[]) double ***eij, ***vareij; double **varpl; /* Variances of prevalence limits by age */ double *epj, vepp; - double kk1, kk2; + double dateprev1, dateprev2,jproj1=1,mproj1=1,anproj1=2000,jproj2=1,mproj2=1,anproj2=2000; double **ximort; char *alph[]={"a","a","b","c","d","e"}, str[4]="1234"; int *dcwave; - char z[1]="c", occ; + char z[1]="c"; /*char *strt;*/ char strtend[80]; - long total_usecs; - + /* setlocale (LC_ALL, ""); */ /* bindtextdomain (PACKAGE, LOCALEDIR); */ /* textdomain (PACKAGE); */ @@ -5752,7 +5763,7 @@ run imach with mle=-1 to get a correct t for(i=1; i <=nlstate; i++){ for(j=1; j <=nlstate+ndeath-1; j++){ fscanf(ficpar,"%1d%1d",&i1,&j1); - if ((i1-i)*(j1-j)!=0){ + if ( (i1-i) * (j1-j) != 0){ printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n",numlinepar, i,j, i1, j1); exit(1); } @@ -6787,7 +6798,7 @@ Interval (in months) between two waves: if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); free_ma3x(probs,1,AGESUP,1,NCOVMAX, 1,NCOVMAX); } /* mle==-3 arrives here for freeing */ - endfree: + /* endfree:*/ free_matrix(prlim,1,nlstate,1,nlstate); /*here or after loop ? */ free_matrix(pmmij,1,nlstate+ndeath,1,nlstate+ndeath); free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);