double pos, k2, dateintsum=0,k2cpt=0;\r
FILE *ficresp;\r
char fileresp[FILENAMELENGTH];\r
-\r
+ \r
pp=vector(1,nlstate);\r
probs= ma3x(1,AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
strcpy(fileresp,"p");\r
}\r
\r
/************ Prevalence ********************/\r
-void prevalence(int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2, double calagedate)\r
+void prevalence(int agemin, float agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2, double calagedate)\r
{ /* Some frequencies */\r
\r
int i, m, jk, k1, i1, j1, bool, z1,z2,j;\r
for (jk=-1; jk<=nlstate+ndeath; jk++) \r
for(m=agemin; m <= agemax+3; m++)\r
freq[i][jk][m]=0;\r
- \r
+ \r
for (i=1; i<=imx; i++) {\r
bool=1;\r
if (cptcovn>0) {\r
for (z1=1; z1<=cptcoveff; z1++) \r
if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) \r
bool=0;\r
- }\r
+ } \r
if (bool==1) { \r
for(m=firstpass; m<=lastpass; m++){\r
k2=anint[m][i]+(mint[m][i]/12.);\r
if(agev[m][i]==0) agev[m][i]=agemax+1;\r
if(agev[m][i]==1) agev[m][i]=agemax+2;\r
freq[s[m][i]][s[m+1][i]][(int)(agev[m][i]+1-((int)calagedate %12)/12.)] += weight[i];\r
- freq[s[m][i]][s[m+1][i]][(int)(agemax+3+1)] += weight[i]; \r
+ /* freq[s[m][i]][s[m+1][i]][(int)(agemax+3+1)] += weight[i]; */ \r
}\r
}\r
}\r
}\r
- \r
for(i=(int)agemin; i <= (int)agemax+3; i++){ \r
for(jk=1; jk <=nlstate ; jk++){\r
for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)\r
- Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br>\r
- Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br>\r
- Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\r
- - Prevalences and population forecasting: <a href=\"f%s\">f%s</a> <br>\r
- <br>",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
+ - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\r
+ - Population forecasting (if popforecast=1): <a href=\"pop%s\">pop%s</a> <br>\r
+ <br>",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
\r
fprintf(fichtm," <li>Graphs</li><p>");\r
\r
}\r
\r
/******************* Gnuplot file **************/\r
-void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double agemin, double agemax, double fage , char pathc[], double p[]){\r
+void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double agemin, double agemaxpar, double fage , char pathc[], double p[]){\r
\r
int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;\r
\r
for (k1=1; k1<= m ; k1 ++) { \r
for (cpt=1; cpt<nlstate ; cpt ++) {\r
k=3;\r
- fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",agemin,agemax,fileres,k1,k+cpt+1,k+1);\r
+ fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",agemin,agemaxpar,fileres,k1,k+cpt+1,k+1);\r
\r
for (i=1; i< nlstate ; i ++)\r
fprintf(ficgp,"+$%d",k+i+1);\r
}\r
\r
for(jk=1; jk <=m; jk++) {\r
- fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot [%.f:%.f] ",agemin,agemax);\r
+ fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot [%.f:%.f] ",agemin,agemaxpar);\r
i=1;\r
for(k2=1; k2<=nlstate; k2++) {\r
k3=i;\r
\r
agelim=AGESUP;\r
calagedate=(anproj1+mproj1/12.+jproj1/365.-dateintmean)*YEARM;\r
- \r
- prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2, calagedate);\r
\r
+ prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2, calagedate);\r
+ \r
\r
strcpy(fileresf,"f"); \r
strcat(fileresf,fileres);\r
for (cpt=0; cpt<=(anproj2-anproj1);cpt++) { \r
fprintf(ficresf,"\n");\r
fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+cpt); \r
- \r
+\r
for (agedeb=(fage-((int)calagedate %12/12.)); agedeb>=(agemin-((int)calagedate %12)/12.); agedeb--){ \r
nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm); \r
nhstepm = nhstepm/hstepm; \r
fclose(ficresf);\r
}\r
/************** Forecasting ******************/\r
-populforecast(char fileres[], double anproj1,double mproj1,double jproj1,double agemin, double agemax,double dateprev1, double dateprev2, int mobilav, double agedeb, double fage, int popforecast, char popfile[], double anproj2,double p[], int i2){\r
+populforecast(char fileres[], double anpyram,double mpyram,double jpyram,double agemin, double agemax,double dateprev1, double dateprev2, int mobilav, double agedeb, double fage, int popforecast, char popfile[], double anpyram1,double p[], int i2){\r
\r
int cpt, stepsize, hstepm, nhstepm, j,k,c, cptcod, i,h;\r
int *popage;\r
double ***p3mat,***tabpop,***tabpopprev;\r
char filerespop[FILENAMELENGTH];\r
\r
-tabpop= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
-tabpopprev= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
- agelim=AGESUP;\r
-calagedate=(anproj1+mproj1/12.+jproj1/365.-dateintmean)*YEARM;\r
+ tabpop= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
+ tabpopprev= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
+ agelim=AGESUP;\r
+ calagedate=(anpyram+mpyram/12.+jpyram/365.-dateintmean)*YEARM;\r
\r
prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2, calagedate);\r
-\r
- \r
+ \r
+ \r
strcpy(filerespop,"pop"); \r
strcat(filerespop,fileres);\r
if((ficrespop=fopen(filerespop,"w"))==NULL) {\r
fprintf(ficrespop," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]);\r
}\r
fprintf(ficrespop,"******\n");\r
- fprintf(ficrespop,"# StartingAge FinalAge");\r
+ fprintf(ficrespop,"# Age");\r
for(j=1; j<=nlstate+ndeath;j++) fprintf(ficrespop," P.%d",j);\r
if (popforecast==1) fprintf(ficrespop," [Population]");\r
\r
for (cpt=0; cpt<=0;cpt++) { \r
- fprintf(ficrespop,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+cpt); \r
+ fprintf(ficrespop,"\n\n# Forecasting at date %.lf/%.lf/%.lf ",jpyram,mpyram,anpyram+cpt); \r
\r
for (agedeb=(fage-((int)calagedate %12/12.)); agedeb>=(agemin-((int)calagedate %12)/12.); agedeb--){ \r
nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm); \r
\r
for (h=0; h<=nhstepm; h++){\r
if (h==(int) (calagedate+YEARM*cpt)) {\r
- fprintf(ficrespop,"\n %.f ",agedeb+h*hstepm/YEARM*stepm);\r
+ fprintf(ficrespop,"\n %3.f ",agedeb+h*hstepm/YEARM*stepm);\r
} \r
for(j=1; j<=nlstate+ndeath;j++) {\r
kk1=0.;kk2=0;\r
for(i=1; i<=nlstate;i++){\r
kk1=0.;\r
for(j=1; j<=nlstate;j++){\r
- kk1= kk1+Tabpop[(int)(agedeb)][j][cptcod]; \r
+ kk1= kk1+tabpop[(int)(agedeb)][j][cptcod]; \r
}\r
tabpopprev[(int)(agedeb)][i][cptcod]=tabpop[(int)(agedeb)][i][cptcod]/kk1*popeffectif[(int)(agedeb+(calagedate+12*cpt)*hstepm/YEARM*stepm-1)];\r
}\r
\r
-if (h==(int)(calagedate+12*cpt)) for(j=1; j<=nlstate;j++) fprintf(ficrespop," %.3f",tabpopprev[(int)(agedeb+1)][j][cptcod]);\r
+ if (h==(int)(calagedate+12*cpt)) for(j=1; j<=nlstate;j++) \r
+ fprintf(ficrespop," %15.2f",tabpopprev[(int)(agedeb+1)][j][cptcod]);\r
}\r
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
}\r
\r
/******/\r
\r
- for (cpt=1; cpt<=4;cpt++) { \r
- fprintf(ficrespop,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+cpt); \r
+ for (cpt=1; cpt<=(anpyram1-anpyram);cpt++) { \r
+ fprintf(ficrespop,"\n\n# Forecasting at date %.lf/%.lf/%.lf ",jpyram,mpyram,anpyram+cpt); \r
for (agedeb=(fage-((int)calagedate %12/12.)); agedeb>=(agemin-((int)calagedate %12)/12.); agedeb--){ \r
nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm); \r
nhstepm = nhstepm/hstepm; \r
hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); \r
for (h=0; h<=nhstepm; h++){\r
if (h==(int) (calagedate+YEARM*cpt)) {\r
- fprintf(ficresf,"\n %.f ",agedeb+h*hstepm/YEARM*stepm);\r
+ fprintf(ficresf,"\n %3.f ",agedeb+h*hstepm/YEARM*stepm);\r
} \r
for(j=1; j<=nlstate+ndeath;j++) {\r
kk1=0.;kk2=0;\r
for(i=1; i<=nlstate;i++) { \r
kk1=kk1+p3mat[i][j][h]*tabpopprev[(int)agedeb+1][i][cptcod]; \r
}\r
- if (h==(int)(calagedate+12*cpt)) fprintf(ficresf," %.3f", kk1); \r
+ if (h==(int)(calagedate+12*cpt)) fprintf(ficresf," %15.2f", kk1); \r
}\r
}\r
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
\r
int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;\r
double agedeb, agefin,hf;\r
- double agemin=1.e20, agemax=-1.e20;\r
+ double agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20;\r
\r
double fret;\r
double **xi,tmp,delta;\r
int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab; \r
int mobilav=0,popforecast=0;\r
int hstepm, nhstepm;\r
- double jprev1, mprev1,anprev1,jprev2, mprev2,anprev2;\r
+ double jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,jpyram, mpyram,anpyram,jpyram1, mpyram1,anpyram1;\r
\r
double bage, fage, age, agelim, agebase;\r
double ftolpl=FTOL;\r
}\r
ungetc(c,ficpar);\r
\r
- fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);\r
+ fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemaxpar, &bage, &fage);\r
\r
if (fage <= 2) {\r
bage = agemin;\r
- fage = agemax;\r
+ fage = agemaxpar;\r
}\r
\r
fprintf(ficres,"# agemin agemax for life expectancy, bage fage (if mle==0 ie no data nor Max likelihood).\n");\r
- fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);\r
- fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);\r
+ fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemaxpar,bage,fage);\r
+ fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemaxpar,bage,fage);\r
\r
while((c=getc(ficpar))=='#' && c!= EOF){\r
ungetc(c,ficpar);\r
dateprev2=anprev2+mprev2/12.+jprev2/365.;\r
\r
fscanf(ficpar,"pop_based=%d\n",&popbased);\r
- fprintf(ficparo,"pop_based=%d\n",popbased); \r
- fprintf(ficres,"pop_based=%d\n",popbased); \r
-\r
+ fprintf(ficparo,"pop_based=%d\n",popbased); \r
+ fprintf(ficres,"pop_based=%d\n",popbased); \r
+ \r
while((c=getc(ficpar))=='#' && c!= EOF){\r
ungetc(c,ficpar);\r
fgets(line, MAXLINE, ficpar);\r
fputs(line,ficparo);\r
}\r
ungetc(c,ficpar);\r
- fscanf(ficpar,"popforecast=%d popfile=%s starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf mov_average=%d\n",&popforecast,popfile,&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2,&mobilav);\r
-fprintf(ficparo,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mov_average=%d\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);\r
-fprintf(ficres,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mov_average=%d\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);\r
+\r
+ fscanf(ficpar,"starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf mov_average=%d\n",&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2,&mobilav);\r
+fprintf(ficparo,"starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mov_average=%d\n",jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);\r
+fprintf(ficres,"starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mov_average=%d\n",jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);\r
+\r
+\r
+while((c=getc(ficpar))=='#' && c!= EOF){\r
+ ungetc(c,ficpar);\r
+ fgets(line, MAXLINE, ficpar);\r
+ puts(line);\r
+ fputs(line,ficparo);\r
+ }\r
+ ungetc(c,ficpar);\r
+\r
+ fscanf(ficpar,"popforecast=%d popfile=%s popfiledate=%lf/%lf/%lf last-popfiledate=%lf/%lf/%lf\n",&popforecast,popfile,&jpyram,&mpyram,&anpyram,&jpyram1,&mpyram1,&anpyram1);\r
+ fprintf(ficparo,"popforecast=%d popfile=%s popfiledate=%.lf/%.lf/%.lf last-popfiledate=%.lf/%.lf/%.lf\n",popforecast,popfile,jpyram,mpyram,anpyram,jpyram1,mpyram1,anpyram1);\r
+ fprintf(ficres,"popforecast=%d popfile=%s popfiledate=%.lf/%.lf/%.lf last-popfiledate=%.lf/%.lf/%.lf\n",popforecast,popfile,jpyram,mpyram,anpyram,jpyram1,mpyram1,anpyram1);\r
\r
freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);\r
\r
/*------------ gnuplot -------------*/\r
- printinggnuplot(fileres,optionfilefiname,optionfile,optionfilegnuplot, agemin,agemax,fage, pathc,p);\r
+ printinggnuplot(fileres,optionfilefiname,optionfile,optionfilegnuplot, agemin,agemaxpar,fage, pathc,p);\r
\r
/*------------ free_vector -------------*/\r
chdir(path);\r
/*free_matrix(covar,1,NCOVMAX,1,n);*/\r
fclose(ficparo);\r
fclose(ficres);\r
- \r
- /* Reads comments: lines beginning with '#' */\r
- while((c=getc(ficpar))=='#' && c!= EOF){\r
- ungetc(c,ficpar);\r
- fgets(line, MAXLINE, ficpar);\r
- puts(line);\r
- fputs(line,ficparo);\r
- }\r
- ungetc(c,ficpar);\r
- \r
- fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);\r
- printf("agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax, bage, fage);\r
- fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);\r
+\r
/*--------- index.htm --------*/\r
\r
printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm);\r
oldm=oldms; newm=newms; savm=savms; /* Keeps fixed addresses to free */\r
k=0;\r
agebase=agemin;\r
- agelim=agemax;\r
+ agelim=agemaxpar;\r
ftolpl=1.e-10;\r
i1=cptcoveff;\r
if (cptcovn < 1){i1=1;}\r
/*---------- Forecasting ------------------*/\r
if(stepm == 1) {\r
prevforecast(fileres, anproj1,mproj1,jproj1, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anproj2,p, i1);\r
-populforecast(fileres, anproj1,mproj1,jproj1, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anproj2,p, i1);\r
+if (popforecast==1) populforecast(fileres, anpyram,mpyram,jpyram, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anpyram1,p, i1);\r
free_matrix(mint,1,maxwav,1,n);\r
free_matrix(anint,1,maxwav,1,n); free_imatrix(s,1,maxwav+1,1,n);\r
free_vector(weight,1,n);}\r