Diff for /imach/src/imach.c between versions 1.254 and 1.263

version 1.254, 2017/03/08 07:13:00 version 1.263, 2017/04/24 15:23:15
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.263  2017/04/24 15:23:15  brouard
     Summary: to save
   
     Revision 1.262  2017/04/18 16:48:12  brouard
     *** empty log message ***
   
     Revision 1.261  2017/04/05 10:14:09  brouard
     Summary: Bug in E_ as well as in T_ fixed nres-1 vs k1-1
   
     Revision 1.260  2017/04/04 17:46:59  brouard
     Summary: Gnuplot indexations fixed (humm)
   
     Revision 1.259  2017/04/04 13:01:16  brouard
     Summary: Some errors to warnings only if date of death is unknown but status is death we could set to pi3
   
     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
   
     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    Revision 1.254  2017/03/08 07:13:00  brouard
   Summary: Fixing data parameter line    Summary: Fixing data parameter line
   
Line 1168  int *TvarsQind; Line 1197  int *TvarsQind;
   
 #define MAXRESULTLINES 10  #define MAXRESULTLINES 10
 int nresult=0;  int nresult=0;
   int parameterline=0; /* # of the parameter (type) line */
 int TKresult[MAXRESULTLINES];  int TKresult[MAXRESULTLINES];
 int Tresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */  int Tresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */
 int Tinvresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */  int Tinvresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */
Line 2400  void powell(double p[], double **xi, int Line 2430  void powell(double p[], double **xi, int
             flatd++;              flatd++;
         }          }
         if(flatd >0){          if(flatd >0){
           printf("%d flat directions\n",flatd);            printf("%d flat directions: ",flatd);
           fprintf(ficlog,"%d flat directions\n",flatd);            fprintf(ficlog,"%d flat directions :",flatd);
           for (j=1;j<=n;j++) {             for (j=1;j<=n;j++) { 
             if(flatdir[j]>0){              if(flatdir[j]>0){
               printf("%d ",j);                printf("%d ",j);
Line 4129  void ludcmp(double **a, int n, int *indx Line 4159  void ludcmp(double **a, int n, int *indx
     big=0.0;       big=0.0; 
     for (j=1;j<=n;j++)       for (j=1;j<=n;j++) 
       if ((temp=fabs(a[i][j])) > big) big=temp;         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;       vv[i]=1.0/big; 
   }     } 
   for (j=1;j<=n;j++) {     for (j=1;j<=n;j++) { 
Line 4632  Title=%s <br>Datafile=%s Firstpass=%d La Line 4671  Title=%s <br>Datafile=%s Firstpass=%d La
       if(posproptt < 1.e-5){        if(posproptt < 1.e-5){
         fprintf(ficresphtm,"\n <p><b> This combination (%d) is not valid and no result will be produced</b></p>",j1);          fprintf(ficresphtm,"\n <p><b> This combination (%d) is not valid and no result will be produced</b></p>",j1);
         fprintf(ficresphtmfr,"\n <p><b> This combination (%d) is not valid and no result will be produced</b></p>",j1);          fprintf(ficresphtmfr,"\n <p><b> This combination (%d) is not valid and no result will be produced</b></p>",j1);
         fprintf(ficres,"\n  This combination (%d) is not valid and no result will be produced\n\n",j1);          fprintf(ficlog,"#  This combination (%d) is not valid and no result will be produced\n",j1);
           printf("#  This combination (%d) is not valid and no result will be produced\n",j1);
         invalidvarcomb[j1]=1;          invalidvarcomb[j1]=1;
       }else{        }else{
         fprintf(ficresphtm,"\n <p> This combination (%d) is valid and result will be produced.</p>",j1);          fprintf(ficresphtm,"\n <p> This combination (%d) is valid and result will be produced.</p>",j1);
Line 4914  void  concatwav(int wav[], int **dh, int Line 4954  void  concatwav(int wav[], int **dh, int
 #else  #else
         if(s[m][i]==-1 && (int) andc[i] == 9999 && (int)anint[m][i] != 9999){          if(s[m][i]==-1 && (int) andc[i] == 9999 && (int)anint[m][i] != 9999){
           if(firsthree == 0){            if(firsthree == 0){
             printf("Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as pi. .\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m);              printf("Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as 1-p%d%d .\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m, s[m][i], nlstate+ndeath);
             firsthree=1;              firsthree=1;
           }            }
           fprintf(ficlog,"Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as pi. .\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m);            fprintf(ficlog,"Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as 1-p%d%d .\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m, s[m][i], nlstate+ndeath);
           mw[++mi][i]=m;            mw[++mi][i]=m;
           mli=m;            mli=m;
         }          }
Line 4944  void  concatwav(int wav[], int **dh, int Line 4984  void  concatwav(int wav[], int **dh, int
       /* if(mi==0)  never been interviewed correctly before death */        /* if(mi==0)  never been interviewed correctly before death */
       /* Only death is a correct wave */        /* Only death is a correct wave */
       mw[mi][i]=m;        mw[mi][i]=m;
     }      } /* else not in a death state */
 #ifndef DISPATCHINGKNOWNDEATHAFTERLASTWAVE  #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 */      else if ((int) andc[i] != 9999) {  /* Date of death is known */
       /* m++; */  
       /* mi++; */  
       /* s[m][i]=nlstate+1;  /\* We are setting the status to the last of non live state *\/ */  
       /* mw[mi][i]=m; */  
       if ((int)anint[m][i]!= 9999) { /* date of last interview 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 */          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++;            nbwarn++;
Line 4963  void  concatwav(int wav[], int **dh, int Line 4999  void  concatwav(int wav[], int **dh, int
         }else{ /* Death occured afer last wave potential bias */          }else{ /* Death occured afer last wave potential bias */
           nberr++;            nberr++;
           if(firstwo==0){            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;              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 */          /* death is known but not confirmed by death status at any wave */
         if(firstfour==0){          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 );            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 );
Line 4999  void  concatwav(int wav[], int **dh, int Line 5035  void  concatwav(int wav[], int **dh, int
       if (stepm <=0)        if (stepm <=0)
         dh[mi][i]=1;          dh[mi][i]=1;
       else{        else{
         if (s[mw[mi+1][i]][i] > nlstate) { /* A death */          if (s[mw[mi+1][i]][i] > nlstate) { /* A death, but what if date is unknown? */
           if (agedc[i] < 2*AGESUP) {            if (agedc[i] < 2*AGESUP) {
             j= rint(agedc[i]*12-agev[mw[mi][i]][i]*12);               j= rint(agedc[i]*12-agev[mw[mi][i]][i]*12); 
             if(j==0) j=1;  /* Survives at least one month after exam */              if(j==0) j=1;  /* Survives at least one month after exam */
Line 6361  To be simple, these graphs help to under Line 6397  To be simple, these graphs help to under
 void printinghtml(char fileresu[], char title[], char datafile[], int firstpass, \  void printinghtml(char fileresu[], char title[], char datafile[], int firstpass, \
                   int lastpass, int stepm, int weightopt, char model[],\                    int lastpass, int stepm, int weightopt, char model[],\
                   int imx,int jmin, int jmax, double jmeanint,char rfileres[],\                    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 jprev1, double mprev1,double anprev1, double dateprev1, \
                   double jprev2, double mprev2,double anprev2, double dateprev2){                    double jprev2, double mprev2,double anprev2, double dateprev2){
   int jj1, k1, i1, cpt, k4, nres;    int jj1, k1, i1, cpt, k4, nres;
Line 6435  void printinghtml(char fileresu[], char Line 6471  void printinghtml(char fileresu[], char
        }         }
      }       }
      /* aij, bij */       /* aij, bij */
      fprintf(fichtm,"<br>- Logit model (yours is: 1+age+%s), for example: logit(pij)=log(pij/pii)= aij+ bij age + V1 age + etc. as a function of age: <a href=\"%s_%d-1-%d.svg\">%s_%d-1-%d.svg</a><br> \       fprintf(fichtm,"<br>- Logit model (yours is: logit(pij)=log(pij/pii)= aij+ bij age+%s) as a function of age: <a href=\"%s_%d-1-%d.svg\">%s_%d-1-%d.svg</a><br> \
 <img src=\"%s_%d-1-%d.svg\">",model,subdirf2(optionfilefiname,"PE_"),k1,nres,subdirf2(optionfilefiname,"PE_"),k1,nres,subdirf2(optionfilefiname,"PE_"),k1,nres);  <img src=\"%s_%d-1-%d.svg\">",model,subdirf2(optionfilefiname,"PE_"),k1,nres,subdirf2(optionfilefiname,"PE_"),k1,nres,subdirf2(optionfilefiname,"PE_"),k1,nres);
      /* Pij */       /* Pij */
      fprintf(fichtm,"<br>\n- P<sub>ij</sub> or conditional probabilities to be observed in state j being in state i, %d (stepm) months before: <a href=\"%s_%d-2-%d.svg\">%s_%d-2-%d.svg</a><br> \       fprintf(fichtm,"<br>\n- P<sub>ij</sub> or conditional probabilities to be observed in state j being in state i, %d (stepm) months before: <a href=\"%s_%d-2-%d.svg\">%s_%d-2-%d.svg</a><br> \
Line 6459  divided by h: <sub>h</sub>P<sub>ij</sub> Line 6495  divided by h: <sub>h</sub>P<sub>ij</sub>
      }       }
      /* Period (stable) prevalence in each health state */       /* Period (stable) prevalence in each health state */
      for(cpt=1; cpt<=nlstate;cpt++){       for(cpt=1; cpt<=nlstate;cpt++){
        fprintf(fichtm,"<br>\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. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \         fprintf(fichtm,"<br>\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. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \
 <img src=\"%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);  <img src=\"%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){       if(backcast==1){
        /* Period (stable) back prevalence in each health state */         /* Period (stable) back prevalence in each health state */
        for(cpt=1; cpt<=nlstate;cpt++){         for(cpt=1; cpt<=nlstate;cpt++){
          fprintf(fichtm,"<br>\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. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \           fprintf(fichtm,"<br>\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. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \
 <img src=\"%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);  <img src=\"%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);
        }         }
      }       }
      if(prevfcast==1){       if(prevfcast==1){
        /* Projection of prevalence up to period (stable) prevalence in each health state */         /* Projection of prevalence up to period (stable) prevalence in each health state */
        for(cpt=1; cpt<=nlstate;cpt++){         for(cpt=1; cpt<=nlstate;cpt++){
          fprintf(fichtm,"<br>\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. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \           fprintf(fichtm,"<br>\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. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \
 <img src=\"%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);  <img src=\"%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);
        }         }
      }       }
                     
Line 6561  See page 'Matrix of variance-covariance Line 6597  See page 'Matrix of variance-covariance
        }         }
      }       }
      for(cpt=1; cpt<=nlstate;cpt++) {       for(cpt=1; cpt<=nlstate;cpt++) {
        fprintf(fichtm,"\n<br>- Observed (cross-sectional) and period (incidence based) \         fprintf(fichtm,"\n<br>- Observed (cross-sectional with mov_average=%d) and period (incidence based) \
 prevalence (with 95%% confidence interval) in state (%d): <a href=\"%s_%d-%d-%d.svg\"> %s_%d-%d-%d.svg</a>\n <br>\  prevalence (with 95%% confidence interval) in state (%d): <a href=\"%s_%d-%d-%d.svg\"> %s_%d-%d-%d.svg</a>\n <br>\
 <img src=\"%s_%d-%d-%d.svg\">",cpt,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres);    <img src=\"%s_%d-%d-%d.svg\">",mobilav,cpt,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres,subdirf2(optionfilefiname,"V_"),cpt,k1,nres);  
      }       }
      fprintf(fichtm,"\n<br>- Total life expectancy by age and \       fprintf(fichtm,"\n<br>- Total life expectancy by age and \
 health expectancies in states (1) and (2). If popbased=1 the smooth (due to the model) \  health expectancies in states (1) and (2). If popbased=1 the smooth (due to the model) \
Line 6658  void printinggnuplot(char fileresu[], ch Line 6694  void printinggnuplot(char fileresu[], ch
         /* printf("\n#\n"); */          /* printf("\n#\n"); */
         fprintf(ficgp,"\n#\n");          fprintf(ficgp,"\n#\n");
         if(invalidvarcomb[k1]){          if(invalidvarcomb[k1]){
             /*k1=k1-1;*/ /* To be checked */
           fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);             fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1); 
           continue;            continue;
         }          }
               
         fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1,nres);          fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1,nres);
         fprintf(ficgp,"\n#set out \"V_%s_%d-%d-%d.svg\" \n",optionfilefiname,cpt,k1,nres);          fprintf(ficgp,"\n#set out \"V_%s_%d-%d-%d.svg\" \n",optionfilefiname,cpt,k1,nres);
         fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres);          fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);
                 /* fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres); */
         /* k1-1 error should be nres-1*/
         for (i=1; i<= nlstate ; i ++) {          for (i=1; i<= nlstate ; i ++) {
           if (i==cpt) fprintf(ficgp," %%lf (%%lf)");            if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
           else        fprintf(ficgp," %%*lf (%%*lf)");            else        fprintf(ficgp," %%*lf (%%*lf)");
         }          }
         fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres);          fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);
         for (i=1; i<= nlstate ; i ++) {          for (i=1; i<= nlstate ; i ++) {
           if (i==cpt) fprintf(ficgp," %%lf (%%lf)");            if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
           else fprintf(ficgp," %%*lf (%%*lf)");            else fprintf(ficgp," %%*lf (%%*lf)");
         }           } 
         fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2==%d ? $3-1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres);           fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2==%d ? $3-1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres); 
         for (i=1; i<= nlstate ; i ++) {          for (i=1; i<= nlstate ; i ++) {
           if (i==cpt) fprintf(ficgp," %%lf (%%lf)");            if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
           else fprintf(ficgp," %%*lf (%%*lf)");            else fprintf(ficgp," %%*lf (%%*lf)");
Line 6748  void printinggnuplot(char fileresu[], ch Line 6786  void printinggnuplot(char fileresu[], ch
           fprintf(ficgp,"\nreplot ");            fprintf(ficgp,"\nreplot ");
         for (i=1; i<= nlstate+1 ; i ++) {          for (i=1; i<= nlstate+1 ; i ++) {
           k=2*i;            k=2*i;
           fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ?$4 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1, vpopbased);            fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ?$4 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),nres-1,nres-1, vpopbased);
           for (j=1; j<= nlstate+1 ; j ++) {            for (j=1; j<= nlstate+1 ; j ++) {
             if (j==i) fprintf(ficgp," %%lf (%%lf)");              if (j==i) fprintf(ficgp," %%lf (%%lf)");
             else fprintf(ficgp," %%*lf (%%*lf)");              else fprintf(ficgp," %%*lf (%%*lf)");
           }               }   
           if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l lt %d, \\\n",i);            if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l lt %d, \\\n",i);
           else fprintf(ficgp,"\" t\"LE in state (%d)\" w l lt %d, \\\n",i-1,i+1);            else fprintf(ficgp,"\" t\"LE in state (%d)\" w l lt %d, \\\n",i-1,i+1);
           fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4-$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);            fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4-$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),nres-1,nres-1,vpopbased);
           for (j=1; j<= nlstate+1 ; j ++) {            for (j=1; j<= nlstate+1 ; j ++) {
             if (j==i) fprintf(ficgp," %%lf (%%lf)");              if (j==i) fprintf(ficgp," %%lf (%%lf)");
             else fprintf(ficgp," %%*lf (%%*lf)");              else fprintf(ficgp," %%*lf (%%*lf)");
           }               }   
           fprintf(ficgp,"\" t\"\" w l lt 0,");            fprintf(ficgp,"\" t\"\" w l lt 0,");
           fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4+$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);            fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4+$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),nres-1,nres-1,vpopbased);
           for (j=1; j<= nlstate+1 ; j ++) {            for (j=1; j<= nlstate+1 ; j ++) {
             if (j==i) fprintf(ficgp," %%lf (%%lf)");              if (j==i) fprintf(ficgp," %%lf (%%lf)");
             else fprintf(ficgp," %%*lf (%%*lf)");              else fprintf(ficgp," %%*lf (%%*lf)");
Line 6782  void printinggnuplot(char fileresu[], ch Line 6820  void printinggnuplot(char fileresu[], ch
         continue;          continue;
   
       for (cpt=1; cpt<= nlstate ; cpt ++) {        for (cpt=1; cpt<= nlstate ; cpt ++) {
         fprintf(ficgp,"\n# 3d: Life expectancy with EXP_ files:  combination=%d state=%d",k1, cpt);          fprintf(ficgp,"\n\n# 3d: Life expectancy with EXP_ files:  combination=%d state=%d",k1, cpt);
         for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */          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 */            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 */            /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */
Line 6804  void printinggnuplot(char fileresu[], ch Line 6842  void printinggnuplot(char fileresu[], ch
         k=2+(nlstate+1)*(cpt-1);          k=2+(nlstate+1)*(cpt-1);
         fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres);          fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres);
         fprintf(ficgp,"set ter svg size 640, 480\n\          fprintf(ficgp,"set ter svg size 640, 480\n\
 plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subdirf2(fileresu,"E_"),k1-1,k1-1,k,cpt);  plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subdirf2(fileresu,"E_"),nres-1,nres-1,k,cpt);
         /*fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d-2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);          /*fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d-2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);
           for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");            for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");
           fprintf(ficgp,"\" t \"e%d1\" w l",cpt);            fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
Line 6814  plot [%.f:%.f] \"%s\" every :::%d::%d u Line 6852  plot [%.f:%.f] \"%s\" every :::%d::%d u
                                                                   
         */          */
         for (i=1; i< nlstate ; i ++) {          for (i=1; i< nlstate ; i ++) {
           fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+i,cpt,i+1);            fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileresu,"E_"),nres-1,nres-1,k+i,cpt,i+1);
           /*    fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+2*i,cpt,i+1);*/            /*    fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+2*i,cpt,i+1);*/
                                                                   
         }           } 
         fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d.\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+nlstate,cpt);          fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d.\" w l",subdirf2(fileresu,"E_"),nres-1,nres-1,k+nlstate,cpt);
       }        }
     } /* end nres */      } /* end nres */
   } /* end kl 3eme */    } /* end kl 3eme */
Line 6929  set ter svg size 640, 480\nunset log y\n Line 6967  set ter svg size 640, 480\nunset log y\n
   for(nres=1; nres <= nresult; nres++){ /* For each resultline */    for(nres=1; nres <= nresult; nres++){ /* For each resultline */
     if(m != 1 && TKresult[nres]!= k1)      if(m != 1 && TKresult[nres]!= k1)
       continue;        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);        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 */        for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */
Line 6953  set ter svg size 640, 480\nunset log y\n Line 6991  set ter svg size 640, 480\nunset log y\n
       fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\        fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
 set ter svg size 640, 480\nunset log y\nplot [%.f:%.f]  ", ageminpar, agemaxpar);  set ter svg size 640, 480\nunset log y\nplot [%.f:%.f]  ", ageminpar, agemaxpar);
       k=3; /* Offset */        k=3; /* Offset */
       for (i=1; i<= nlstate ; i ++){        for (i=1; i<= nlstate ; i ++){ /* State of origin */
         if(i==1)          if(i==1)
           fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));            fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
         else          else
           fprintf(ficgp,", '' ");            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);          fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);
         for (j=2; j<= nlstate ; j ++)          for (j=2; j<= nlstate ; j ++)
           fprintf(ficgp,"+$%d",k+l+j-1);            fprintf(ficgp,"+$%d",k+l+j-1);
Line 6976  set ter svg size 640, 480\nunset log y\n Line 7014  set ter svg size 640, 480\nunset log y\n
     for(nres=1; nres <= nresult; nres++){ /* For each resultline */      for(nres=1; nres <= nresult; nres++){ /* For each resultline */
       if(m != 1 && TKresult[nres]!= k1)        if(m != 1 && TKresult[nres]!= k1)
         continue;          continue;
       for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */        for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life ending state */
         fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt);          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 */          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 */            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 */            /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */
Line 6999  set ter svg size 640, 480\nunset log y\n Line 7037  set ter svg size 640, 480\nunset log y\n
         fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\          fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
 set ter svg size 640, 480\nunset log y\nplot [%.f:%.f]  ", ageminpar, agemaxpar);  set ter svg size 640, 480\nunset log y\nplot [%.f:%.f]  ", ageminpar, agemaxpar);
         k=3; /* Offset */          k=3; /* Offset */
         for (i=1; i<= nlstate ; i ++){          for (i=1; i<= nlstate ; i ++){ /* State of origin */
           if(i==1)            if(i==1)
             fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJB_"));              fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJB_"));
           else            else
             fprintf(ficgp,", '' ");              fprintf(ficgp,", '' ");
           /* l=(nlstate+ndeath)*(i-1)+1; */            /* 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); /\* 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/($%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 ++) */            /* for (j=2; j<= nlstate ; j ++) */
           /*    fprintf(ficgp,"+$%d",k+l+j-1); */            /*    fprintf(ficgp,"+$%d",k+l+j-1); */
           /*    /\* fprintf(ficgp,"+$%d",k+l+j-1); *\/ */            /*    /\* fprintf(ficgp,"+$%d",k+l+j-1); *\/ */
Line 9088  int calandcheckages(int imx, int maxwav, Line 9126  int calandcheckages(int imx, int maxwav,
         *nberr = *nberr + 1;          *nberr = *nberr + 1;
         if(firstone == 0){          if(firstone == 0){
           firstone=1;            firstone=1;
         printf("Error! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown, you must set an arbitrary year of death or he/she is skipped and results can be biased (%d) because status is a death state %d at wave %d. Wave dropped.\nOther similar cases in log file\n",(int)moisdc[i],(int)andc[i],num[i],i, *nberr,s[m][i],m);          printf("Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\nOther similar cases in log file\n", *nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m);
         }          }
         fprintf(ficlog,"Error! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown, you must set an arbitrary year of death or he/she is skipped and results can be biased (%d) because status is a death state %d at wave %d. Wave dropped.\n",(int)moisdc[i],(int)andc[i],num[i],i, *nberr,s[m][i],m);          fprintf(ficlog,"Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\n", *nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m);
         s[m][i]=-1;          s[m][i]=-1;  /* Droping the death status */
       }        }
       if((int)moisdc[i]==99 && (int)andc[i]!=9999 && s[m][i]>nlstate){        if((int)moisdc[i]==99 && (int)andc[i]!=9999 && s[m][i]>nlstate){
         (*nberr)++;          (*nberr)++;
         printf("Error! Month of death of individual %ld on line %d was unknown %2d, you should set it otherwise the information on the death is skipped and results are biased.\n",num[i],i,(int)moisdc[i]);           printf("Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\nOther similar cases in log file\n", *nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m);
         fprintf(ficlog,"Error! Month of death of individual %ld on line %d was unknown %f, you should set it otherwise the information on the death is skipped and results are biased.\n",num[i],i,moisdc[i]);           fprintf(ficlog,"Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\n", *nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m);
         s[m][i]=-1; /* We prefer to skip it (and to skip it in version 0.8a1 too */          s[m][i]=-2; /* We prefer to skip it (and to skip it in version 0.8a1 too */
       }        }
     }      }
   }    }
Line 9566  int back_prevalence_limit(double *p, dou Line 9604  int back_prevalence_limit(double *p, dou
         fprintf(ficresplb," %.3f %d\n", tot, *ncvyearp);          fprintf(ficresplb," %.3f %d\n", tot, *ncvyearp);
       } /* Age */        } /* Age */
       /* was end of cptcod */        /* 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 any combination */
   } /* end of nres */      } /* end of nres */  
   /* hBijx(p, bage, fage); */    /* hBijx(p, bage, fage); */
Line 9682  int hPijx(double *p, int bage, int fage) Line 9721  int hPijx(double *p, int bage, int fage)
       
   /* hstepm=1;   aff par mois*/    /* hstepm=1;   aff par mois*/
   pstamp(ficrespijb);    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);    i1= pow(2,cptcoveff);
   /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */    /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */
   /*    /\*for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*\/ */    /*    /\*for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*\/ */
Line 9716  int hPijx(double *p, int bage, int fage) Line 9755  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,nlstate,stepm,oldm,savm, k);   */
         hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, 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); */          /* 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(i=1; i<=nlstate;i++)
           for(j=1; j<=nlstate+ndeath;j++)            for(j=1; j<=nlstate+ndeath;j++)
             fprintf(ficrespijb," %1d-%1d",i,j);              fprintf(ficrespijb," %1d-%1d",i,j);
Line 9762  int main(int argc, char *argv[]) Line 9801  int main(int argc, char *argv[])
   int NDIM=2;    int NDIM=2;
   int vpopbased=0;    int vpopbased=0;
   int nres=0;    int nres=0;
     int endishere=0;
   
   char ca[32], cb[32];    char ca[32], cb[32];
   /*  FILE *fichtm; *//* Html File */    /*  FILE *fichtm; *//* Html File */
Line 10043  int main(int argc, char *argv[]) Line 10083  int main(int argc, char *argv[])
       break;        break;
   }    }
   if((num_filled=sscanf(line,"model=1+age%[^.\n]", model)) !=EOF){    if((num_filled=sscanf(line,"model=1+age%[^.\n]", model)) !=EOF){
     if (num_filled == 0)      if (num_filled == 0){
             model[0]='\0';        printf("ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);
     else if (num_filled != 1){        fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);
         model[0]='\0';
         goto end;
       } else if (num_filled != 1){
       printf("ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);        printf("ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);
       fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);        fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);
       model[0]='\0';        model[0]='\0';
Line 11136  Please run with mle=-1 to get a correct Line 11179  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);          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;          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);        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(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);        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);        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);
     }      }
   
Line 11172  Please run with mle=-1 to get a correct Line 11213  Please run with mle=-1 to get a correct
       fprintf(ficres,"pop_based=%d\n",popbased);           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 */      /* Results */
     nresult=0;      nresult=0;
     while(fgets(line, MAXLINE, ficpar)) {      do{
       /* If line starts with a # it is a comment */        if(!fgets(line, MAXLINE, ficpar)){
       if (line[0] == '#') {          endishere=1;
           parameterline=14;
         }else if (line[0] == '#') {
           /* If line starts with a # it is a comment */
         numlinepar++;          numlinepar++;
         fputs(line,stdout);          fputs(line,stdout);
         fputs(line,ficparo);          fputs(line,ficparo);
         fputs(line,ficlog);          fputs(line,ficlog);
         fputs(line,ficres);  
         continue;          continue;
       }else        }else if(sscanf(line,"prevforecast=%[^\n]\n",modeltemp))
         break;          parameterline=11;
     }        else if(sscanf(line,"backcast=%[^\n]\n",modeltemp))
     if (!feof(ficpar))          parameterline=12;
     while((num_filled=sscanf(line,"result:%[^\n]\n",resultline)) !=EOF){        else if(sscanf(line,"result:%[^\n]\n",modeltemp))
       if (num_filled == 0){          parameterline=13;
         resultline[0]='\0';        else{
         printf("Warning %d: no result line should be at minimum 'result: V2=0 V1=1 or result:.\n%s\n", num_filled, line);          parameterline=14;
       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;  
       }        }
       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;          break;
       else{ /* Processess output results for this combination of covariate values */        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);*/
     } /* end while */          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 final-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 final-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 && nresult==0 ){
               printf("ERROR: no result lines! It should be at minimum 'result: V2=0 V1=1 or result:.' %s\n",line);
               goto end;
             }
             break;
           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); */      /* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint); */
     /* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */      /* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */
Line 11307  Please run with mle=-1 to get a correct Line 11316  Please run with mle=-1 to get a correct
       printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p);        printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p);
     }      }
     printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \      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);                   jprev1,mprev1,anprev1,dateprev1,jprev2,mprev2,anprev2,dateprev2);
                                   
     /*------------ free_vector  -------------*/      /*------------ free_vector  -------------*/
Line 11360  Please run with mle=-1 to get a correct Line 11369  Please run with mle=-1 to get a correct
       mobaverage=mobaverages;        mobaverage=mobaverages;
       if (mobilav!=0) {        if (mobilav!=0) {
         printf("Movingaveraging observed prevalence\n");          printf("Movingaveraging observed prevalence\n");
           fprintf(ficlog,"Movingaveraging observed prevalence\n");
         if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilav)!=0){          if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilav)!=0){
           fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav);            fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav);
           printf(" Error in movingaverage mobilav=%d\n",mobilav);            printf(" Error in movingaverage mobilav=%d\n",mobilav);
Line 11369  Please run with mle=-1 to get a correct Line 11379  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); */        /* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
       else if (mobilavproj !=0) {        else if (mobilavproj !=0) {
         printf("Movingaveraging projected observed prevalence\n");          printf("Movingaveraging projected observed prevalence\n");
           fprintf(ficlog,"Movingaveraging projected observed prevalence\n");
         if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilavproj)!=0){          if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilavproj)!=0){
           fprintf(ficlog," Error in movingaverage mobilavproj=%d\n",mobilavproj);            fprintf(ficlog," Error in movingaverage mobilavproj=%d\n",mobilavproj);
           printf(" Error in movingaverage mobilavproj=%d\n",mobilavproj);            printf(" Error in movingaverage mobilavproj=%d\n",mobilavproj);

Removed from v.1.254  
changed lines
  Added in v.1.263


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>