} \r
\r
/************ Frequencies ********************/\r
-void freqsummary(char fileres[], 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)\r
+void freqsummary(char fileres[], 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 jprev1, double mprev1,double anprev1,double jprev2, double mprev2,double anprev2)\r
{ /* Some frequencies */\r
\r
int i, m, jk, k1,i1, j1, bool, z1,z2,j;\r
}\r
}\r
}\r
+ \r
+ fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);\r
+\r
if (cptcovn>0) {\r
fprintf(ficresp, "\n#********** Variable "); \r
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);\r
for(i=1; i<=nlstate;i++)\r
prlim[i][i]=probs[(int)age][i][ij];\r
}\r
- \r
+ \r
for(j=1; j<= nlstate; j++){\r
for(h=0; h<=nhstepm; h++){\r
for(i=1, gp[h][j]=0.;i<=nlstate;i++)\r
xp[i] = x[i] - (i==theta ?delti[theta]:0);\r
hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij); \r
prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ij);\r
-\r
+ \r
if (popbased==1) {\r
for(i=1; i<=nlstate;i++)\r
prlim[i][i]=probs[(int)age][i][ij];\r
free_ma3x(trgradg,0,nhstepm,1,nlstate,1,npar);\r
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
} /* End age */\r
- \r
+ \r
free_vector(xp,1,npar);\r
free_matrix(doldm,1,nlstate,1,npar);\r
free_matrix(dnewm,1,nlstate,1,nlstate);\r
}\r
free_vector(xp,1,npar);\r
fclose(ficresprob);\r
- exit(0);\r
+\r
}\r
\r
/******************* Printing html file ***********/\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 mob_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 mob_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 mob_average=%d\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);\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
- freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2);\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
/*---------- Forecasting ------------------*/\r
calagedate=(anproj1+mproj1/12.+jproj1/365.-dateintmean)*YEARM;\r
\r
- /*printf("calage= %f", calagedate);*/\r
+ \r
\r
prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2, calagedate);\r
\r
-\r
+ \r
strcpy(fileresf,"f"); \r
strcat(fileresf,fileres);\r
if((ficresf=fopen(fileresf,"w"))==NULL) {\r
printf("Problem with forecast resultfile: %s\n", fileresf);goto end;\r
}\r
printf("Computing forecasting: result on file '%s' \n", fileresf);\r
-\r
+ \r
free_matrix(mint,1,maxwav,1,n);\r
free_matrix(anint,1,maxwav,1,n);\r
- free_matrix(agev,1,maxwav,1,imx);\r
-\r
- /* Mobile average */\r
\r
if (cptcoveff==0) ncodemax[cptcoveff]=1;\r
\r
\r
stepsize=(int) (stepm+YEARM-1)/YEARM;\r
if (stepm<=12) stepsize=1;\r
-\r
+ \r
agelim=AGESUP;\r
- /*hstepm=stepsize*YEARM; *//* Every year of age */\r
+ \r
hstepm=1;\r
- hstepm=hstepm/stepm; /* Typically 2 years, = 2 years/6 months = 4 */ \r
+ hstepm=hstepm/stepm; \r
yp1=modf(dateintmean,&yp);\r
anprojmean=yp;\r
yp2=modf((yp1*12),&yp);\r
jprojmean=yp;\r
if(jprojmean==0) jprojmean=1;\r
if(mprojmean==0) jprojmean=1;\r
-\r
+ \r
fprintf(ficresf,"# Estimated date of observed prevalence: %.lf/%.lf/%.lf ",jprojmean,mprojmean,anprojmean); \r
-\r
+ \r
if (popforecast==1) {\r
if((ficpop=fopen(popfile,"r"))==NULL) {\r
printf("Problem with population file : %s\n",popfile);goto end;\r
popage=ivector(0,AGESUP);\r
popeffectif=vector(0,AGESUP);\r
popcount=vector(0,AGESUP);\r
-\r
+ \r
i=1; \r
while ((c=fscanf(ficpop,"%d %lf\n",&popage[i],&popcount[i])) != EOF)\r
{\r
\r
for (i=1; i<imx;i++) popeffectif[popage[i]]=popcount[i];\r
}\r
-\r
+ \r
for(cptcov=1;cptcov<=i1;cptcov++){\r
for(cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){\r
k=k+1;\r
for(j=1; j<=nlstate+ndeath;j++) fprintf(ficresf," P.%d",j);\r
if (popforecast==1) fprintf(ficresf," [Population]");\r
\r
- for (cpt=0; cpt<=(anproj2-anproj1);cpt++) { \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
- 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
\r
- p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
- oldm=oldms;savm=savms;\r
- hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); \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
+ \r
+ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
+ oldm=oldms;savm=savms;\r
+ hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); \r
\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
- } \r
- for(j=1; j<=nlstate+ndeath;j++) {\r
- kk1=0.;kk2=0;\r
- for(i=1; i<=nlstate;i++) { \r
- if (mobilav==1) \r
- kk1=kk1+p3mat[i][j][h]*mobaverage[(int)agedeb+1][i][cptcod];\r
- else {\r
- kk1=kk1+p3mat[i][j][h]*probs[(int)(agedeb+1)][i][cptcod];\r
- \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
+ } \r
+ for(j=1; j<=nlstate+ndeath;j++) {\r
+ kk1=0.;kk2=0;\r
+ for(i=1; i<=nlstate;i++) { \r
+ if (mobilav==1) \r
+ kk1=kk1+p3mat[i][j][h]*mobaverage[(int)agedeb+1][i][cptcod];\r
+ else {\r
+ kk1=kk1+p3mat[i][j][h]*probs[(int)(agedeb+1)][i][cptcod];\r
+ }\r
+ if (popforecast==1) kk2=kk1*popeffectif[(int)agedeb];\r
}\r
-\r
- if (popforecast==1) kk2=kk1*popeffectif[(int)agedeb];\r
- }\r
- \r
- if (h==(int)(calagedate+12*cpt)){\r
- fprintf(ficresf," %.3f", kk1);\r
+ if (h==(int)(calagedate+12*cpt)){\r
+ fprintf(ficresf," %.3f", kk1);\r
\r
- if (popforecast==1) fprintf(ficresf," [%.f]", kk2);\r
+ if (popforecast==1) fprintf(ficresf," [%.f]", kk2);\r
+ }\r
}\r
}\r
+ free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
}\r
- free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
- }\r
- }\r
+ }\r
}\r
}\r
+ \r
if (mobilav==1) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
\r
if (popforecast==1) {\r
free_vector(popeffectif,0,AGESUP);\r
free_vector(popcount,0,AGESUP);\r
}\r
+ \r
free_imatrix(s,1,maxwav+1,1,n);\r
free_vector(weight,1,n);\r
fclose(ficresf);\r
- }/* End forecasting */\r
+ }\r
+\r
+ /* End forecasting */\r
else{\r
erreur=108;\r
printf("Error %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d\n", erreur, stepm);\r
-\r
}\r
-\r
+ \r
\r
/*---------- Health expectancies and variances ------------*/\r
\r
evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k); \r
vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);\r
oldm=oldms;savm=savms;\r
- varevsij(fileres, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl,k);\r
- \r
+ varevsij(fileres, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl,k);\r
+ \r
+\r
+ \r
fprintf(ficrest,"#Total LEs with variances: e.. (std) ");\r
for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i);\r
fprintf(ficrest,"\n");\r
- \r
+\r
hf=1;\r
if (stepm >= YEARM) hf=stepm/YEARM;\r
epj=vector(1,nlstate+1);\r
fclose(ficpar);\r
free_vector(epj,1,nlstate+1);\r
/* scanf("%d ",i); */\r
-\r
+ \r
/*------- Variance limit prevalence------*/ \r
\r
strcpy(fileresvpl,"vpl");\r
\r
free_matrix(matcov,1,npar,1,npar);\r
free_vector(delti,1,npar);\r
- \r
+ free_matrix(agev,1,maxwav,1,imx);\r
free_ma3x(param,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel);\r
\r
if(erreur >0)\r