--- imach/src/imach.c 2019/05/20 13:03:18 1.296 +++ imach/src/imach.c 2019/05/22 17:56:10 1.297 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.296 2019/05/20 13:03:18 brouard Exp $ +/* $Id: imach.c,v 1.297 2019/05/22 17:56:10 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.297 2019/05/22 17:56:10 brouard + Summary: Fix bug by moving date2dmy and nhstepm which gaefin=-1 + Revision 1.296 2019/05/20 13:03:18 brouard Summary: Projection syntax simplified @@ -1107,12 +1110,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.296 2019/05/20 13:03:18 brouard Exp $ */ +/* $Id: imach.c,v 1.297 2019/05/22 17:56:10 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="April 2018,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018"; -char fullversion[]="$Revision: 1.296 $ $Date: 2019/05/20 13:03:18 $"; +char fullversion[]="$Revision: 1.297 $ $Date: 2019/05/22 17:56:10 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -3046,7 +3049,7 @@ double **pmij(double **ps, double *cov, sumnew=0.; /*for (ii=1;ii<=nlstate+ndeath;ii++){*/ for (ii=1;ii<=nlstate;ii++){ /* Only on live states */ - /* printf(" agefin=%d, ii=%d, ij=%d, prev=%f\n",(int)agefin,ii, ij, prevacurrent[(int)agefin][ii][ij]); */ + /* printf(" agefin=%d, ii=%d, ij=%d, prev=%f\n",(int)agefin,ii, ij, prevacurrent[(int)agefin][ii][ij]); */ sumnew+=prevacurrent[(int)agefin][ii][ij]; } if(sumnew >0.01){ /* At least some value in the prevalence */ @@ -4421,6 +4424,20 @@ void pstamp(FILE *fichier) fprintf(fichier,"# %s.%s\n#IMaCh version %s, %s\n#%s\n# %s", optionfilefiname,optionfilext,version,copyright, fullversion, strstart); } +void date2dmy(double date,double *day, double *month, double *year){ + double yp=0., yp1=0., yp2=0.; + + yp1=modf(date,&yp);/* extracts integral of date in yp and + fractional in yp1 */ + *year=yp; + yp2=modf((yp1*12),&yp); + *month=yp; + yp1=modf((yp2*30.5),&yp); + *day=yp; + if(*day==0) *day=1; + if(*month==0) *month=1; +} + /************ Frequencies ********************/ @@ -8321,20 +8338,6 @@ set ter svg size 640, 480\nunset log y\n }/* End movingaverage */ - int date2dmy(double date,double *day, double *month, double *year){ - double yp=0., yp1=0., yp2=0.; - - yp1=modf(date,&yp);/* extracts integral of date in yp and - fractional in yp1 */ - *year=yp; - yp2=modf((yp1*12),&yp); - *month=yp; - yp1=modf((yp2*30.5),&yp); - *day=yp; - if(*day==0) *day=1; - if(*month==0) *month=1; - return; - } /************** Forecasting ******************/ /* void prevforecast(char fileres[], double dateintmean, double anprojd, double mprojd, double jprojd, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double ***prev, double bage, double fage, int firstpass, int lastpass, double anprojf, double p[], int cptcoveff)*/ @@ -10748,8 +10751,8 @@ int hPijx(double *p, int bage, int fage) /* for (agedeb=fage; agedeb>=bage; agedeb--){ /\* If stepm=6 months *\/ */ for (agedeb=bage; agedeb<=fage; agedeb++){ /* If stepm=6 months and estepm=24 (2 years) */ /* nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm); /\* Typically 20 years = 20*12/6=40 *\/ */ - nhstepm=(int) rint((agedeb-ageminl)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */ - nhstepm = nhstepm/hstepm; /* Typically 40/4=10, because estepm=24 stepm=6 => hstepm=24/6=4 */ + nhstepm=(int) rint((agedeb-ageminl)*YEARM/stepm+0.1)-1; /* Typically 20 years = 20*12/6=40 or 55*12/24=27.5-1.1=>27 */ + nhstepm = nhstepm/hstepm; /* Typically 40/4=10, because estepm=24 stepm=6 => hstepm=24/6=4 or 28*/ /* nhstepm=nhstepm*YEARM; aff par mois*/