--- imach/src/imach.c 2017/05/23 08:39:25 1.269 +++ imach/src/imach.c 2017/05/24 05:45:29 1.270 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.269 2017/05/23 08:39:25 brouard Exp $ +/* $Id: imach.c,v 1.270 2017/05/24 05:45:29 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.270 2017/05/24 05:45:29 brouard + *** empty log message *** + Revision 1.269 2017/05/23 08:39:25 brouard Summary: Code into subroutine, cleanings @@ -1010,12 +1013,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.269 2017/05/23 08:39:25 brouard Exp $ */ +/* $Id: imach.c,v 1.270 2017/05/24 05:45:29 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="February 2016,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.269 $ $Date: 2017/05/23 08:39:25 $"; +char fullversion[]="$Revision: 1.270 $ $Date: 2017/05/24 05:45:29 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -5464,7 +5467,7 @@ void concatwav(int wav[], int **dh, int /* hstepm beeing the number of stepms, if hstepm=1 the length of hstepm is stepm. nhstepm is the number of hstepm from age to agelim nstepm is the number of stepm from age to agelin. - Look at hpijx to understand the reason of that which relies in memory size + Look at hpijx to understand the reason which relies in memory size consideration and note for a fixed period like estepm months */ /* We decided (b) to get a life expectancy respecting the most precise curvature of the survival function given by stepm (the optimization length). Unfortunately it @@ -6924,7 +6927,7 @@ true period expectancies (those weighted } /******************* Gnuplot file **************/ -void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , int prevfcast, int backcast, char pathc[], double p[], int offyear, int offbyear){ +void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double bage, double fage , int prevfcast, int backcast, char pathc[], double p[], int offyear, int offbyear){ char dirfileres[132],optfileres[132]; char gplotcondition[132], gplotlabel[132]; @@ -6933,6 +6936,8 @@ void printinggnuplot(char fileresu[], ch int ng=0; int vpopbased; int ioffset; /* variable offset for columns */ + int iyearc=1; /* variable column for year of projection */ + int iagec=1; /* variable column for age of projection */ int nres=0; /* Index of resultline */ int istart=1; /* For starting graphs in projections */ @@ -7506,24 +7511,22 @@ set ter svg size 640, 480\nunset log y\n /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */ fprintf(ficgp," u %d:(", ioffset); if(i==nlstate+1){ - fprintf(ficgp," $%d/(1.-$%d)):5 t 'pw.%d' with line lc variable ", \ + fprintf(ficgp," $%d/(1.-$%d)):1 t 'pw.%d' with line lc variable ", \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt ); fprintf(ficgp,",\\\n '' "); fprintf(ficgp," u %d:(",ioffset); - fprintf(ficgp," (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", \ + fprintf(ficgp," (($1-$2) == %d ) ? $%d/(1.-$%d) : 1/0):1 with labels center not ", \ offyear, \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate ); }else fprintf(ficgp," $%d/(1.-$%d)) t 'p%d%d' with line ", \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,i,cpt ); }else{ /* more than 2 covariates */ - if(cptcoveff ==1){ - ioffset=4; /* Age is in 4 */ - }else{ - ioffset=6; /* Age is in 6 */ - /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/ - /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ - } + ioffset=2*cptcoveff+2; /* Age is in 4 or 6 or etc.*/ + /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/ + /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ + iyearc=ioffset-1; + iagec=ioffset; fprintf(ficgp," u %d:(",ioffset); kl=0; strcpy(gplotcondition,"("); @@ -7545,13 +7548,13 @@ set ter svg size 640, 480\nunset log y\n /*6+1+(i-1)+(nlstate+1)*nlstate; 6+1+(1-1) +(2+1)*2=13 */ /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0)? $9/(1.-$15) : 1/0):($5==2000? 3:2) t 'p.1' with line lc variable*/ if(i==nlstate+1){ - fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0):5 t 'p.%d' with line lc variable", gplotcondition, \ - ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt ); + fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0):%d t 'p.%d' with line lc variable", gplotcondition, \ + ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,iyearc, cpt ); fprintf(ficgp,",\\\n '' "); - fprintf(ficgp," u %d:(",ioffset); - fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", gplotcondition, \ - offyear, \ - ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate ); + fprintf(ficgp," u %d:(",iagec); + fprintf(ficgp,"%s && (($%d-$%d) == %d ) ? $%d/(1.-$%d) : 1/0):%d with labels center not ", gplotcondition, \ + iyearc, iagec, offyear, \ + ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate, iyearc ); /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0) && (($5-$6) == 1947) ? $10/(1.-$22) : 1/0):5 with labels center boxed not*/ }else{ fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ", gplotcondition, \ @@ -7621,24 +7624,22 @@ set ter svg size 640, 480\nunset log y\n /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */ fprintf(ficgp," u %d:(", ioffset); if(i==nlstate+1){ - fprintf(ficgp," $%d/(1.-$%d)):5 t 'bw%d' with line lc variable ", \ + fprintf(ficgp," $%d/(1.-$%d)):1 t 'bw%d' with line lc variable ", \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt ); fprintf(ficgp,",\\\n '' "); fprintf(ficgp," u %d:(",ioffset); - fprintf(ficgp," (($5-$6) == %d ) ? $%d : 1/0):5 with labels center not ", \ + fprintf(ficgp," (($1-$2) == %d ) ? $%d : 1/0):1 with labels center not ", \ offbyear, \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1) ); }else fprintf(ficgp," $%d/(1.-$%d)) t 'b%d%d' with line ", \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt,i ); }else{ /* more than 2 covariates */ - if(cptcoveff ==1){ - ioffset=4; /* Age is in 4 */ - }else{ - ioffset=6; /* Age is in 6 */ - /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/ - /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ - } + ioffset=2*cptcoveff+2; /* Age is in 4 or 6 or etc.*/ + /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/ + /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ + iyearc=ioffset-1; + iagec=ioffset; fprintf(ficgp," u %d:(",ioffset); kl=0; strcpy(gplotcondition,"("); @@ -7660,14 +7661,14 @@ set ter svg size 640, 480\nunset log y\n /*6+1+(i-1)+(nlstate+1)*nlstate; 6+1+(1-1) +(2+1)*2=13 */ /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0)? $9/(1.-$15) : 1/0):($5==2000? 3:2) t 'p.1' with line lc variable*/ if(i==nlstate+1){ - fprintf(ficgp,"%s ? $%d : 1/0):5 t 'bw%d' with line lc variable", gplotcondition, \ - ioffset+(cpt-1)*(nlstate+1)+1+(i-1),cpt ); + fprintf(ficgp,"%s ? $%d : 1/0):%d t 'bw%d' with line lc variable", gplotcondition, \ + ioffset+(cpt-1)*(nlstate+1)+1+(i-1),iyearc,cpt ); fprintf(ficgp,",\\\n '' "); - fprintf(ficgp," u %d:(",ioffset); + fprintf(ficgp," u %d:(",iagec); /* fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", gplotcondition, \ */ - fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d : 1/0):5 with labels center not ", gplotcondition, \ - offbyear, \ - ioffset+(cpt-1)*(nlstate+1)+1+(i-1) ); + fprintf(ficgp,"%s && (($%d-$%d) == %d ) ? $%d : 1/0):%d with labels center not ", gplotcondition, \ + iyearc,iagec,offbyear, \ + ioffset+(cpt-1)*(nlstate+1)+1+(i-1), iyearc ); /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0) && (($5-$6) == 1947) ? $10/(1.-$22) : 1/0):5 with labels center boxed not*/ }else{ /* fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ", gplotcondition, \ */ @@ -8154,7 +8155,12 @@ set ter svg size 640, 480\nunset log y\n if(estepm < stepm){ printf ("Problem %d lower than %d\n",estepm, stepm); } - else hstepm=estepm; + else{ + hstepm=estepm; + } + if(estepm > stepm){ /* Yes every two year */ + stepsize=2; + } hstepm=hstepm/stepm; yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and @@ -8199,7 +8205,8 @@ set ter svg size 640, 480\nunset log y\n for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) { fprintf(ficresf,"\n"); fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+yearp); - for (agec=fage; agec>=(ageminpar-1); agec--){ + /* for (agec=fage; agec>=(ageminpar-1); agec--){ */ + for (agec=fage; agec>=(bage); agec--){ nhstepm=(int) rint((agelim-agec)*YEARM/stepm); nhstepm = nhstepm/hstepm; p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); @@ -8287,7 +8294,12 @@ set ter svg size 640, 480\nunset log y\n if(estepm < stepm){ printf ("Problem %d lower than %d\n",estepm, stepm); } - else hstepm=estepm; + else{ + hstepm=estepm; + } + if(estepm >= stepm){ /* Yes every two year */ + stepsize=2; + } hstepm=hstepm/stepm; yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and @@ -8334,7 +8346,8 @@ set ter svg size 640, 480\nunset log y\n fprintf(ficresfb,"\n"); fprintf(ficresfb,"\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp); /* printf("\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp); */ - for (agec=bage; agec<=agemax-1; agec++){ /* testing */ + /* for (agec=bage; agec<=agemax-1; agec++){ /\* testing *\/ */ + for (agec=bage; agec<=fage; agec++){ /* testing */ /* We compute bij at age agec over nhstepm, nhstepm decreases when agec increases because of agemax;*/ nhstepm=(int) rint((agec-agelim)*YEARM/stepm); nhstepm = nhstepm/hstepm; @@ -12071,7 +12084,8 @@ Please run with mle=-1 to get a correct This is probably because your parameter file doesn't \n contain the exact number of lines (or columns) corresponding to your model line.\n\ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar); }else{ - printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p, (int)anproj1-(int)agemin, (int)anback1-(int)agemax+1); + /* printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p, (int)anproj1-(int)agemin, (int)anback1-(int)agemax+1); */ + printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,bage, fage, prevfcast, backcast, pathc,p, (int)anproj1-bage, (int)anback1-fage); } printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \ model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,backcast, estepm, \