--- imach/src/imach.c 2016/12/15 11:59:41 1.253 +++ imach/src/imach.c 2017/03/29 16:53:30 1.257 @@ -1,6 +1,18 @@ -/* $Id: imach.c,v 1.253 2016/12/15 11:59:41 brouard Exp $ +/* $Id: imach.c,v 1.257 2017/03/29 16:53:30 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.257 2017/03/29 16:53:30 brouard + Summary: Temp + + Revision 1.256 2017/03/27 05:50:23 brouard + Summary: Temporary + + Revision 1.255 2017/03/08 16:02:28 brouard + Summary: IMaCh version 0.99r10 bugs in gnuplot fixed + + Revision 1.254 2017/03/08 07:13:00 brouard + Summary: Fixing data parameter line + Revision 1.253 2016/12/15 11:59:41 brouard Summary: 0.99 in progress @@ -959,12 +971,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.253 2016/12/15 11:59:41 brouard Exp $ */ +/* $Id: imach.c,v 1.257 2017/03/29 16:53:30 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.253 $ $Date: 2016/12/15 11:59:41 $"; +char fullversion[]="$Revision: 1.257 $ $Date: 2017/03/29 16:53:30 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -2397,8 +2409,8 @@ void powell(double p[], double **xi, int flatd++; } if(flatd >0){ - printf("%d flat directions\n",flatd); - fprintf(ficlog,"%d flat directions\n",flatd); + printf("%d flat directions: ",flatd); + fprintf(ficlog,"%d flat directions :",flatd); for (j=1;j<=n;j++) { if(flatdir[j]>0){ printf("%d ",j); @@ -4126,7 +4138,16 @@ void ludcmp(double **a, int n, int *indx big=0.0; for (j=1;j<=n;j++) if ((temp=fabs(a[i][j])) > big) big=temp; - if (big == 0.0) nrerror("Singular matrix in routine ludcmp"); + if (big == 0.0){ + printf(" Singular Hessian matrix at row %d:\n",i); + for (j=1;j<=n;j++) { + printf(" a[%d][%d]=%f,",i,j,a[i][j]); + fprintf(ficlog," a[%d][%d]=%f,",i,j,a[i][j]); + } + fflush(ficlog); + fclose(ficlog); + nrerror("Singular matrix in routine ludcmp"); + } vv[i]=1.0/big; } for (j=1;j<=n;j++) { @@ -4941,13 +4962,9 @@ void concatwav(int wav[], int **dh, int /* if(mi==0) never been interviewed correctly before death */ /* Only death is a correct wave */ mw[mi][i]=m; - } + } /* else not in a death state */ #ifndef DISPATCHINGKNOWNDEATHAFTERLASTWAVE - else if ((int) andc[i] != 9999) { /* Status is negative. A death occured after lastpass, we can't take it into account because of potential bias */ - /* m++; */ - /* mi++; */ - /* s[m][i]=nlstate+1; /\* We are setting the status to the last of non live state *\/ */ - /* mw[mi][i]=m; */ + else if ((int) andc[i] != 9999) { /* Date of death is known */ if ((int)anint[m][i]!= 9999) { /* date of last interview is known */ if((andc[i]+moisdc[i]/12.) <=(anint[m][i]+mint[m][i]/12.)){ /* death occured before last wave and status should have been death instead of -1 */ nbwarn++; @@ -4960,12 +4977,12 @@ void concatwav(int wav[], int **dh, int }else{ /* Death occured afer last wave potential bias */ nberr++; if(firstwo==0){ - printf("Error! Death for individual %ld line=%d occurred at %d/%d after last wave %d interviewed at %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\nOthers in log file only\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m ); + printf("Error! Death for individual %ld line=%d occurred at %d/%d after last wave %d interviewed at %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood. Please add a new fictive wave at the date of last vital status scan, with a dead status or alive but unknown state status (-1). See documentation\nOthers in log file only\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m ); firstwo=1; } - fprintf(ficlog,"Error! Death for individual %ld line=%d occurred at %d/%d after last wave %d interviewed at %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m ); + fprintf(ficlog,"Error! Death for individual %ld line=%d occurred at %d/%d after last wave %d interviewed at %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood. Please add a new fictive wave at the date of last vital status scan, with a dead status or alive but unknown state status (-1). See documentation\n\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m ); } - }else{ /* end date of interview is known */ + }else{ /* if date of interview is unknown */ /* death is known but not confirmed by death status at any wave */ if(firstfour==0){ printf("Error! Death for individual %ld line=%d occurred %d/%d but not confirmed by any death status for any wave, including last wave %d at unknown date %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\nOthers in log file only\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m ); @@ -6456,13 +6473,13 @@ divided by h: hPij } /* Period (stable) prevalence in each health state */ for(cpt=1; cpt<=nlstate;cpt++){ - fprintf(fichtm,"
\n- Convergence 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
\ + fprintf(fichtm,"
\n- Convergence to period (stable) prevalence in state %d. Or probability to be in state %d some years earlier, knowing that we will be in state (1 to %d) at different ages. %s_%d-%d-%d.svg
\ ", cpt, cpt, nlstate, subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres); } if(backcast==1){ /* Period (stable) back prevalence in each health state */ for(cpt=1; cpt<=nlstate;cpt++){ - fprintf(fichtm,"
\n- Convergence to period (stable) back 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
\ + fprintf(fichtm,"
\n- Convergence to mixed (stable) back prevalence in state %d. Or probability to be in state %d at a younger age, knowing that we will be in state (1 to %d) at different older ages. %s_%d-%d-%d.svg
\ ", cpt, cpt, nlstate, subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres); } } @@ -6926,7 +6943,7 @@ set ter svg size 640, 480\nunset log y\n for(nres=1; nres <= nresult; nres++){ /* For each resultline */ if(m != 1 && TKresult[nres]!= k1) continue; - for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */ + for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state of arrival */ fprintf(ficgp,"\n#\n#\n#CV preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt); for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */ @@ -6950,12 +6967,12 @@ set ter svg size 640, 480\nunset log y\n fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar); k=3; /* Offset */ - for (i=1; i<= nlstate ; i ++){ + for (i=1; i<= nlstate ; i ++){ /* State of origin */ if(i==1) fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_")); else fprintf(ficgp,", '' "); - l=(nlstate+ndeath)*(i-1)+1; + l=(nlstate+ndeath)*(i-1)+1; /* 1, 1+ nlstate+ndeath, 1+2*(nlstate+ndeath) */ fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l); for (j=2; j<= nlstate ; j ++) fprintf(ficgp,"+$%d",k+l+j-1); @@ -6973,8 +6990,8 @@ set ter svg size 640, 480\nunset log y\n for(nres=1; nres <= nresult; nres++){ /* For each resultline */ if(m != 1 && TKresult[nres]!= k1) continue; - for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */ - fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt); + for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life ending state */ + fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pijb' files, covariatecombination#=%d state=%d",k1, cpt); for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */ lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */ /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */ @@ -6996,16 +7013,16 @@ set ter svg size 640, 480\nunset log y\n fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar); k=3; /* Offset */ - for (i=1; i<= nlstate ; i ++){ + for (i=1; i<= nlstate ; i ++){ /* State of origin */ if(i==1) fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJB_")); else fprintf(ficgp,", '' "); /* l=(nlstate+ndeath)*(i-1)+1; */ - l=(nlstate+ndeath)*(cpt-1)+1; + l=(nlstate+ndeath)*(cpt-1)+1; /* fixed for i; cpt=1 1, cpt=2 1+ nlstate+ndeath, 1+2*(nlstate+ndeath) */ /* fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l); /\* a vérifier *\/ */ /* fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l+(cpt-1)+i-1); /\* a vérifier *\/ */ - fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d",k1,k+l+(cpt-1)+i-1); /* a vérifier */ + fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d",k1,k+l+i-1); /* To be verified */ /* for (j=2; j<= nlstate ; j ++) */ /* fprintf(ficgp,"+$%d",k+l+j-1); */ /* /\* fprintf(ficgp,"+$%d",k+l+j-1); *\/ */ @@ -9563,6 +9580,7 @@ int back_prevalence_limit(double *p, dou fprintf(ficresplb," %.3f %d\n", tot, *ncvyearp); } /* Age */ /* was end of cptcod */ + /*fprintf(ficresplb,"\n");*/ /* Seems to be necessary for gnuplot only if two result lines and no covariate. */ } /* end of any combination */ } /* end of nres */ /* hBijx(p, bage, fage); */ @@ -9679,7 +9697,7 @@ int hPijx(double *p, int bage, int fage) /* hstepm=1; aff par mois*/ pstamp(ficrespijb); - fprintf(ficrespijb,"#****** h Pij x Back Probability to be in state i at age x-h being in j at x "); + fprintf(ficrespijb,"#****** h Bij x Back probability to be in state i at age x-h being in j at x: B1j+B2j+...=1 "); i1= pow(2,cptcoveff); /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */ /* /\*for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*\/ */ @@ -9713,7 +9731,7 @@ int hPijx(double *p, int bage, int fage) /* hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); */ hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, k); /* hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm, dnewm, doldm, dsavm, k); */ - fprintf(ficrespijb,"# Cov Agex agex-h hpijx with i,j="); + fprintf(ficrespijb,"# Cov Agex agex-h hbijx with i,j="); for(i=1; i<=nlstate;i++) for(j=1; j<=nlstate+ndeath;j++) fprintf(ficrespijb," %1d-%1d",i,j); @@ -11114,68 +11132,127 @@ Please run with mle=-1 to get a correct fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d, ftolpl=%e\n",ageminpar,agemaxpar,bage,fage, estepm, ftolpl); /* Other stuffs, more or less useful */ - while((c=getc(ficpar))=='#' && c!= EOF){ - ungetc(c,ficpar); - fgets(line, MAXLINE, ficpar); - fputs(line,stdout); - fputs(line,ficparo); + 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; } - ungetc(c,ficpar); - - 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); - 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); - - while((c=getc(ficpar))=='#' && c!= EOF){ - ungetc(c,ficpar); - fgets(line, MAXLINE, ficpar); - fputs(line,stdout); - fputs(line,ficparo); + + if((num_filled=sscanf(line,"begin-prev-date=%lf/%lf/%lf end-prev-date=%lf/%lf/%lf mov_average=%d\n",&jprev1, &mprev1,&anprev1,&jprev2, &mprev2,&anprev2,&mobilav)) !=EOF){ + + if (num_filled != 7) { + printf("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); + 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); + } + + 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; } - ungetc(c,ficpar); dateprev1=anprev1+(mprev1-1)/12.+(jprev1-1)/365.; dateprev2=anprev2+(mprev2-1)/12.+(jprev2-1)/365.; - fscanf(ficpar,"pop_based=%d\n",&popbased); - fprintf(ficlog,"pop_based=%d\n",popbased); - fprintf(ficparo,"pop_based=%d\n",popbased); - fprintf(ficres,"pop_based=%d\n",popbased); - - while((c=getc(ficpar))=='#' && c!= EOF){ - ungetc(c,ficpar); - fgets(line, MAXLINE, ficpar); - fputs(line,stdout); - fputs(line,ficres); - fputs(line,ficparo); + if((num_filled=sscanf(line,"pop_based=%d\n",&popbased)) !=EOF){ + if (num_filled != 1) { + printf("Error: Not 1 (data)parameters in line but %d, for example:pop_based=0\n, your line=%s . Probably you are running an older format.\n",num_filled,line); + fprintf(ficlog,"Error: Not 1 (data)parameters in line but %d, for example: pop_based=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line); + goto end; + } + printf("pop_based=%d\n",popbased); + fprintf(ficlog,"pop_based=%d\n",popbased); + fprintf(ficparo,"pop_based=%d\n",popbased); + fprintf(ficres,"pop_based=%d\n",popbased); } - 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); - 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); + + 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((c=getc(ficpar))=='#' && c!= EOF){ - ungetc(c,ficpar); - fgets(line, MAXLINE, ficpar); - fputs(line,stdout); - fputs(line,ficparo); - fputs(line,ficres); } - ungetc(c,ficpar); + 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); - 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); + 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)) {