--- imach/src/imach.c 2017/03/29 16:53:30 1.257
+++ imach/src/imach.c 2017/04/03 10:17:47 1.258
@@ -1,6 +1,11 @@
-/* $Id: imach.c,v 1.257 2017/03/29 16:53:30 brouard Exp $
+/* $Id: imach.c,v 1.258 2017/04/03 10:17:47 brouard Exp $
$State: Exp $
$Log: imach.c,v $
+ Revision 1.258 2017/04/03 10:17:47 brouard
+ Summary: Version 0.99r12
+
+ Some cleanings, conformed with updated documentation.
+
Revision 1.257 2017/03/29 16:53:30 brouard
Summary: Temp
@@ -971,12 +976,12 @@ typedef struct {
#define ODIRSEPARATOR '\\'
#endif
-/* $Id: imach.c,v 1.257 2017/03/29 16:53:30 brouard Exp $ */
+/* $Id: imach.c,v 1.258 2017/04/03 10:17:47 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.257 $ $Date: 2017/03/29 16:53:30 $";
+char fullversion[]="$Revision: 1.258 $ $Date: 2017/04/03 10:17:47 $";
char strstart[80];
char optionfilext[10], optionfilefiname[FILENAMELENGTH];
int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */
@@ -1177,6 +1182,7 @@ int *TvarsQind;
#define MAXRESULTLINES 10
int nresult=0;
+int parameterline=0; /* # of the parameter (type) line */
int TKresult[MAXRESULTLINES];
int Tresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */
int Tinvresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */
@@ -6375,7 +6381,7 @@ To be simple, these graphs help to under
void printinghtml(char fileresu[], char title[], char datafile[], int firstpass, \
int lastpass, int stepm, int weightopt, char model[],\
int imx,int jmin, int jmax, double jmeanint,char rfileres[],\
- int popforecast, int prevfcast, int backcast, int estepm , \
+ int popforecast, int mobilav, int prevfcast, int mobilavproj, int backcast, int estepm , \
double jprev1, double mprev1,double anprev1, double dateprev1, \
double jprev2, double mprev2,double anprev2, double dateprev2){
int jj1, k1, i1, cpt, k4, nres;
@@ -6486,8 +6492,8 @@ divided by h: hPij
if(prevfcast==1){
/* Projection of prevalence up to period (stable) prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f) up 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-%d.svg
\
-", dateprev1, dateprev2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
+ fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d) up 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-%d.svg
\
+", dateprev1, dateprev2, mobilavproj, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
}
}
@@ -6575,9 +6581,9 @@ See page 'Matrix of variance-covariance
}
}
for(cpt=1; cpt<=nlstate;cpt++) {
- fprintf(fichtm,"\n
- Observed (cross-sectional) and period (incidence based) \
+ fprintf(fichtm,"\n
- Observed (cross-sectional with mov_average=%d) and period (incidence based) \
prevalence (with 95%% confidence interval) in state (%d): %s_%d-%d-%d.svg\n
\
-",cpt,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres);
+",mobilav,cpt,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres);
}
fprintf(fichtm,"\n
- Total life expectancy by age and \
health expectancies in states (1) and (2). If popbased=1 the smooth (due to the model) \
@@ -9777,6 +9783,7 @@ int main(int argc, char *argv[])
int NDIM=2;
int vpopbased=0;
int nres=0;
+ int endishere=0;
char ca[32], cb[32];
/* FILE *fichtm; *//* Html File */
@@ -11151,11 +11158,9 @@ Please run with mle=-1 to get a correct
fprintf(ficlog,"Error: Not 7 (data)parameters in line but %d, for example:begin-prev-date=1/1/1990 end-prev-date=1/6/2004 mov_average=0\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
goto end;
}
- /* fscanf(ficpar,"begin-prev-date=%lf/%lf/%lf end-prev-date=%lf/%lf/%lf mov_average=%d\n",&jprev1, &mprev1,&anprev1,&jprev2, &mprev2,&anprev2,&mobilav); */
printf("begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mov_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);
fprintf(ficparo,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mov_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);
fprintf(ficres,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mov_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);
- printf("begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mov_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);
fprintf(ficlog,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mov_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);
}
@@ -11187,125 +11192,92 @@ Please run with mle=-1 to get a correct
fprintf(ficres,"pop_based=%d\n",popbased);
}
- while(fgets(line, MAXLINE, ficpar)) {
- /* If line starts with a # it is a comment */
- if (line[0] == '#') {
- numlinepar++;
- fputs(line,stdout);
- fputs(line,ficparo);
- fputs(line,ficlog);
- continue;
- }else
- break;
- }
- /* while((c=getc(ficpar))=='#' && c!= EOF){ */
- /* ungetc(c,ficpar); */
- /* fgets(line, MAXLINE, ficpar); */
- /* fputs(line,stdout); */
- /* fputs(line,ficres); */
- /* fputs(line,ficparo); */
- /* } */
- /* ungetc(c,ficpar); */
-
- /* fscanf(ficpar,"prevforecast=%d starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf mobil_average=%d\n",&prevfcast,&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2,&mobilavproj); */
- if((num_filled=sscanf(line,"prevforecast=%d starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf mobil_average=%d\n",&prevfcast,&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2,&mobilavproj)) !=EOF){
- if (num_filled != 8) {
- printf("Error: Not 8 (data)parameters in line but %d, for example:prevforecast=1 starting-proj-date=1/1/1990 final-proj-date=1/1/2000 mobil_average=0\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
- fprintf(ficlog,"Error: Not 8 (data)parameters in line but %d, for example:prevforecast=1 starting-proj-date=1/1/1990 final-proj-date=1/1/2000 mov_average=0\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
- goto end;
- }
- fprintf(ficparo,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
- printf("prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
- fprintf(ficlog,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
- fprintf(ficres,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
- /* day and month of proj2 are not used but only year anproj2.*/
- }
- while(fgets(line, MAXLINE, ficpar)) {
- /* If line starts with a # it is a comment */
- if (line[0] == '#') {
- numlinepar++;
- fputs(line,stdout);
- fputs(line,ficparo);
- fputs(line,ficlog);
- continue;
- }else
- break;
- }
- /* while((c=getc(ficpar))=='#' && c!= EOF){ */
- /* ungetc(c,ficpar); */
- /* fgets(line, MAXLINE, ficpar); */
- /* fputs(line,stdout); */
- /* fputs(line,ficparo); */
- /* fputs(line,ficres); */
- /* } */
- /* ungetc(c,ficpar); */
-
- fscanf(ficpar,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj);
- if((num_filled=sscanf(line,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj)) !=EOF){
- if (num_filled != 8) {
- printf("Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 finloal-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
- fprintf(ficlog,"Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 finloal-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
- goto end;
- }
- printf("backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
- fprintf(ficparo,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
- fprintf(ficlog,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
- fprintf(ficres,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
- /* day and month of proj2 are not used but only year anproj2.*/
- }
/* Results */
nresult=0;
- while(fgets(line, MAXLINE, ficpar)) {
- /* If line starts with a # it is a comment */
- if (line[0] == '#') {
+ do{
+ if(!fgets(line, MAXLINE, ficpar)){
+ endishere=1;
+ parameterline=14;
+ }else if (line[0] == '#') {
+ /* If line starts with a # it is a comment */
numlinepar++;
fputs(line,stdout);
fputs(line,ficparo);
fputs(line,ficlog);
- fputs(line,ficres);
continue;
- }else
- break;
- }
- if (!feof(ficpar))
- while((num_filled=sscanf(line,"result:%[^\n]\n",resultline)) !=EOF){
- if (num_filled == 0){
- resultline[0]='\0';
- printf("Warning %d: no result line should be at minimum 'result: V2=0 V1=1 or result:.\n%s\n", num_filled, line);
- break;
- } else if (num_filled != 1){
- printf("ERROR %d: result line should be at minimum 'result: V2=0 V1=1 or result:.' %s\n",num_filled, line);
- }
- nresult++; /* Sum of resultlines */
- printf("Result %d: result=%s\n",nresult, resultline);
- if(nresult > MAXRESULTLINES){
- printf("ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\n",MAXRESULTLINES,nresult);
- fprintf(ficlog,"ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\n",MAXRESULTLINES,nresult);
- goto end;
- }
- decoderesult(resultline, nresult); /* Fills TKresult[nresult] combination and Tresult[nresult][k4+1] combination values */
- fprintf(ficparo,"result: %s\n",resultline);
- fprintf(ficres,"result: %s\n",resultline);
- fprintf(ficlog,"result: %s\n",resultline);
- while(fgets(line, MAXLINE, ficpar)) {
- /* If line starts with a # it is a comment */
- if (line[0] == '#') {
- numlinepar++;
- fputs(line,stdout);
- fputs(line,ficparo);
- fputs(line,ficres);
- fputs(line,ficlog);
- continue;
- }else
- break;
+ }else if(sscanf(line,"prevforecast=%[^\n]\n",modeltemp))
+ parameterline=11;
+ else if(sscanf(line,"backcast=%[^\n]\n",modeltemp))
+ parameterline=12;
+ else if(sscanf(line,"result:%[^\n]\n",modeltemp))
+ parameterline=13;
+ else{
+ parameterline=14;
}
- if (feof(ficpar))
+ switch (parameterline){
+ case 11:
+ if((num_filled=sscanf(line,"prevforecast=%d starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf mobil_average=%d\n",&prevfcast,&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2,&mobilavproj)) !=EOF){
+ if (num_filled != 8) {
+ printf("Error: Not 8 (data)parameters in line but %d, for example:prevforecast=1 starting-proj-date=1/1/1990 final-proj-date=1/1/2000 mobil_average=0\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
+ fprintf(ficlog,"Error: Not 8 (data)parameters in line but %d, for example:prevforecast=1 starting-proj-date=1/1/1990 final-proj-date=1/1/2000 mov_average=0\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
+ goto end;
+ }
+ fprintf(ficparo,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
+ printf("prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
+ fprintf(ficlog,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
+ fprintf(ficres,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
+ /* day and month of proj2 are not used but only year anproj2.*/
+ }
break;
- else{ /* Processess output results for this combination of covariate values */
- }
- } /* end while */
-
-
+ case 12:
+ /*fscanf(ficpar,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj);*/
+ if((num_filled=sscanf(line,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj)) !=EOF){
+ if (num_filled != 8) {
+ printf("Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 finloal-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
+ fprintf(ficlog,"Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 finloal-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
+ goto end;
+ }
+ printf("backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
+ fprintf(ficparo,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
+ fprintf(ficlog,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
+ fprintf(ficres,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
+ /* day and month of proj2 are not used but only year anproj2.*/
+ }
+ break;
+ case 13:
+ if((num_filled=sscanf(line,"result:%[^\n]\n",resultline)) !=EOF){
+ if (num_filled == 0){
+ resultline[0]='\0';
+ printf("Warning %d: no result line! It should be at minimum 'result: V2=0 V1=1 or result:.\n%s\n", num_filled, line);
+ fprintf(ficlog,"Warning %d: no result line! It should be at minimum 'result: V2=0 V1=1 or result:.\n%s\n", num_filled, line);
+ break;
+ } else if (num_filled != 1){
+ printf("ERROR %d: result line! It should be at minimum 'result: V2=0 V1=1 or result:.' %s\n",num_filled, line);
+ fprintf(ficlog,"ERROR %d: result line! It should be at minimum 'result: V2=0 V1=1 or result:.' %s\n",num_filled, line);
+ }
+ nresult++; /* Sum of resultlines */
+ printf("Result %d: result=%s\n",nresult, resultline);
+ if(nresult > MAXRESULTLINES){
+ printf("ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\n",MAXRESULTLINES,nresult);
+ fprintf(ficlog,"ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\n",MAXRESULTLINES,nresult);
+ goto end;
+ }
+ decoderesult(resultline, nresult); /* Fills TKresult[nresult] combination and Tresult[nresult][k4+1] combination values */
+ fprintf(ficparo,"result: %s\n",resultline);
+ fprintf(ficres,"result: %s\n",resultline);
+ fprintf(ficlog,"result: %s\n",resultline);
+ break;
+ case 14:
+ if(ncovmodel >2){
+ printf("ERROR: no result line! It should be at minimum 'result: V2=0 V1=1 or result:.' %s\n",line);
+ goto end;
+ }
+ default:
+ nresult=1;
+ decoderesult(".",nresult ); /* No covariate */
+ }
+ } /* End switch parameterline */
+ }while(endishere==0); /* End do */
/* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint); */
/* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */
@@ -11322,7 +11294,7 @@ Please run with mle=-1 to get a correct
printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p);
}
printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \
- model,imx,jmin,jmax,jmean,rfileres,popforecast,prevfcast,backcast, estepm, \
+ model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,backcast, estepm, \
jprev1,mprev1,anprev1,dateprev1,jprev2,mprev2,anprev2,dateprev2);
/*------------ free_vector -------------*/
@@ -11375,6 +11347,7 @@ Please run with mle=-1 to get a correct
mobaverage=mobaverages;
if (mobilav!=0) {
printf("Movingaveraging observed prevalence\n");
+ fprintf(ficlog,"Movingaveraging observed prevalence\n");
if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilav)!=0){
fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav);
printf(" Error in movingaverage mobilav=%d\n",mobilav);
@@ -11384,6 +11357,7 @@ Please run with mle=-1 to get a correct
/* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
else if (mobilavproj !=0) {
printf("Movingaveraging projected observed prevalence\n");
+ fprintf(ficlog,"Movingaveraging projected observed prevalence\n");
if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilavproj)!=0){
fprintf(ficlog," Error in movingaverage mobilavproj=%d\n",mobilavproj);
printf(" Error in movingaverage mobilavproj=%d\n",mobilavproj);