Diff for /imach/src/imach.c between versions 1.41.2.1 and 1.46

version 1.41.2.1, 2003/06/12 10:43:20 version 1.46, 2002/05/30 17:44:35
Line 56 Line 56
 #include <unistd.h>  #include <unistd.h>
   
 #define MAXLINE 256  #define MAXLINE 256
 #define GNUPLOTPROGRAM "wgnuplot"  #define GNUPLOTPROGRAM "gnuplot"
 /*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/  /*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/
 #define FILENAMELENGTH 80  #define FILENAMELENGTH 80
 /*#define DEBUG*/  /*#define DEBUG*/
   #define windows
 /*#define windows*/  
 #define GLOCK_ERROR_NOPATH              -1      /* empty path */  #define GLOCK_ERROR_NOPATH              -1      /* empty path */
 #define GLOCK_ERROR_GETCWD              -2      /* cannot get cwd */  #define GLOCK_ERROR_GETCWD              -2      /* cannot get cwd */
   
Line 97  double jmean; /* Mean space between 2 wa Line 96  double jmean; /* Mean space between 2 wa
 double **oldm, **newm, **savm; /* Working pointers to matrices */  double **oldm, **newm, **savm; /* Working pointers to matrices */
 double **oldms, **newms, **savms; /* Fixed working pointers to matrices */  double **oldms, **newms, **savms; /* Fixed working pointers to matrices */
 FILE *fic,*ficpar, *ficparo,*ficres,  *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop;  FILE *fic,*ficpar, *ficparo,*ficres,  *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop;
 FILE *ficgp,*ficresprob,*ficpop;  FILE *ficgp,*ficresprob,*ficpop, *ficresprobcov, *ficresprobcor;
 FILE *ficreseij;  FILE *ficreseij;
   char filerese[FILENAMELENGTH];    char filerese[FILENAMELENGTH];
  FILE  *ficresvij;   FILE  *ficresvij;
Line 1331  void prevalence(int agemin, float agemax Line 1330  void prevalence(int agemin, float agemax
   j=cptcoveff;    j=cptcoveff;
   if (cptcovn<1) {j=1;ncodemax[1]=1;}    if (cptcovn<1) {j=1;ncodemax[1]=1;}
     
  for(k1=1; k1<=j;k1++){    for(k1=1; k1<=j;k1++){
     for(i1=1; i1<=ncodemax[k1];i1++){      for(i1=1; i1<=ncodemax[k1];i1++){
       j1++;        j1++;
         
       for (i=-1; i<=nlstate+ndeath; i++)          for (i=-1; i<=nlstate+ndeath; i++)  
         for (jk=-1; jk<=nlstate+ndeath; jk++)            for (jk=-1; jk<=nlstate+ndeath; jk++)  
           for(m=agemin; m <= agemax+3; m++)            for(m=agemin; m <= agemax+3; m++)
Line 1353  void prevalence(int agemin, float agemax Line 1352  void prevalence(int agemin, float agemax
             if ((k2>=dateprev1) && (k2<=dateprev2)) {              if ((k2>=dateprev1) && (k2<=dateprev2)) {
               if(agev[m][i]==0) agev[m][i]=agemax+1;                if(agev[m][i]==0) agev[m][i]=agemax+1;
               if(agev[m][i]==1) agev[m][i]=agemax+2;                if(agev[m][i]==1) agev[m][i]=agemax+2;
               if (m<lastpass)                if (m<lastpass) {
                 if (calagedate>0) freq[s[m][i]][s[m+1][i]][(int)(agev[m][i]+1-((int)calagedate %12)/12.)] += weight[i];                  if (calagedate>0)
               else                    freq[s[m][i]][s[m+1][i]][(int)(agev[m][i]+1-((int)calagedate %12)/12.)] += weight[i];
                freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];                  else
                freq[s[m][i]][s[m+1][i]][(int)(agemax+3)] += weight[i];                    freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];
                   freq[s[m][i]][s[m+1][i]][(int)(agemax+3)] += weight[i];
                 }
             }              }
           }            }
         }          }
       }        }
         for(i=(int)agemin; i <= (int)agemax+3; i++){        for(i=(int)agemin; i <= (int)agemax+3; i++){
           for(jk=1; jk <=nlstate ; jk++){          for(jk=1; jk <=nlstate ; jk++){
             for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)            for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)
               pp[jk] += freq[jk][m][i];              pp[jk] += freq[jk][m][i];
           }          }
           for(jk=1; jk <=nlstate ; jk++){          for(jk=1; jk <=nlstate ; jk++){
             for(m=-1, pos=0; m <=0 ; m++)            for(m=-1, pos=0; m <=0 ; m++)
             pos += freq[jk][m][i];              pos += freq[jk][m][i];
         }          }
                 
          for(jk=1; jk <=nlstate ; jk++){          for(jk=1; jk <=nlstate ; jk++){
            for(m=0, pp[jk]=0; m <=nlstate+ndeath; m++)            for(m=0, pp[jk]=0; m <=nlstate+ndeath; m++)
              pp[jk] += freq[jk][m][i];              pp[jk] += freq[jk][m][i];
          }  
            
          for(jk=1,pos=0; jk <=nlstate ; jk++) pos += pp[jk];  
   
          for(jk=1; jk <=nlstate ; jk++){            
            if( i <= (int) agemax){  
              if(pos>=1.e-5){  
                probs[i][jk][j1]= pp[jk]/pos;  
              }  
            }  
          }  
            
         }          }
          
           for(jk=1,pos=0; jk <=nlstate ; jk++) pos += pp[jk];
          
           for(jk=1; jk <=nlstate ; jk++){    
             if( i <= (int) agemax){
               if(pos>=1.e-5){
                 probs[i][jk][j1]= pp[jk]/pos;
               }
             }
           }
          
         }
     }      }
   }    }
   
Line 1640  void evsij(char fileres[], double ***eij Line 1641  void evsij(char fileres[], double ***eij
           }            }
         }          }
       }        }
        
      
   
       for(j=1; j<= nlstate*2; j++)        for(j=1; j<= nlstate*2; j++)
         for(h=0; h<=nhstepm-1; h++){          for(h=0; h<=nhstepm-1; h++){
           gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];            gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];
         }          }
   
      }       }
         
 /* End theta */  /* End theta */
Line 1657  void evsij(char fileres[], double ***eij Line 1654  void evsij(char fileres[], double ***eij
      for(h=0; h<=nhstepm-1; h++)       for(h=0; h<=nhstepm-1; h++)
       for(j=1; j<=nlstate*2;j++)        for(j=1; j<=nlstate*2;j++)
         for(theta=1; theta <=npar; theta++)          for(theta=1; theta <=npar; theta++)
         trgradg[h][j][theta]=gradg[h][theta][j];            trgradg[h][j][theta]=gradg[h][theta][j];
        
   
      for(i=1;i<=nlstate*2;i++)       for(i=1;i<=nlstate*2;i++)
       for(j=1;j<=nlstate*2;j++)        for(j=1;j<=nlstate*2;j++)
         varhe[i][j][(int)age] =0.;          varhe[i][j][(int)age] =0.;
   
     for(h=0;h<=nhstepm-1;h++){       printf("%d|",(int)age);fflush(stdout);
        for(h=0;h<=nhstepm-1;h++){
       for(k=0;k<=nhstepm-1;k++){        for(k=0;k<=nhstepm-1;k++){
         matprod2(dnewm,trgradg[h],1,nlstate*2,1,npar,1,npar,matcov);          matprod2(dnewm,trgradg[h],1,nlstate*2,1,npar,1,npar,matcov);
         matprod2(doldm,dnewm,1,nlstate*2,1,npar,1,nlstate*2,gradg[k]);          matprod2(doldm,dnewm,1,nlstate*2,1,npar,1,nlstate*2,gradg[k]);
Line 1722  void varevsij(char fileres[], double *** Line 1720  void varevsij(char fileres[], double ***
   double age,agelim, hf;    double age,agelim, hf;
   int theta;    int theta;
   
    fprintf(ficresvij,"# Covariances of life expectancies\n");    fprintf(ficresvij,"# Variance and covariance of health expectancies e.j \n#  (weighted average of eij where weights are the stable prevalence in health states i\n");
   fprintf(ficresvij,"# Age");    fprintf(ficresvij,"# Age");
   for(i=1; i<=nlstate;i++)    for(i=1; i<=nlstate;i++)
     for(j=1; j<=nlstate;j++)      for(j=1; j<=nlstate;j++)
Line 1857  void varprevlim(char fileres[], double * Line 1855  void varprevlim(char fileres[], double *
   double age,agelim;    double age,agelim;
   int theta;    int theta;
         
   fprintf(ficresvpl,"# Standard deviation of prevalences limit\n");    fprintf(ficresvpl,"# Standard deviation of prevalence's limit\n");
   fprintf(ficresvpl,"# Age");    fprintf(ficresvpl,"# Age");
   for(i=1; i<=nlstate;i++)    for(i=1; i<=nlstate;i++)
       fprintf(ficresvpl," %1d-%1d",i,i);        fprintf(ficresvpl," %1d-%1d",i,i);
Line 1929  void varprevlim(char fileres[], double * Line 1927  void varprevlim(char fileres[], double *
 void varprob(char fileres[], double **matcov, double x[], double delti[], int nlstate, double bage, double fage, int ij, int *Tvar, int **nbcode, int *ncodemax)  void varprob(char fileres[], double **matcov, double x[], double delti[], int nlstate, double bage, double fage, int ij, int *Tvar, int **nbcode, int *ncodemax)
 {  {
   int i, j, i1, k1, j1, z1;    int i, j, i1, k1, j1, z1;
   int k=0, cptcode;    int k=0,l, cptcode;
   double **dnewm,**doldm;    double **dnewm,**doldm;
   double *xp;    double *xp;
   double *gp, *gm;    double *gp, *gm;
Line 1937  void varprob(char fileres[], double **ma Line 1935  void varprob(char fileres[], double **ma
   double age,agelim, cov[NCOVMAX];    double age,agelim, cov[NCOVMAX];
   int theta;    int theta;
   char fileresprob[FILENAMELENGTH];    char fileresprob[FILENAMELENGTH];
     char fileresprobcov[FILENAMELENGTH];
     char fileresprobcor[FILENAMELENGTH];
   
   strcpy(fileresprob,"prob");    strcpy(fileresprob,"prob");
   strcat(fileresprob,fileres);    strcat(fileresprob,fileres);
   if((ficresprob=fopen(fileresprob,"w"))==NULL) {    if((ficresprob=fopen(fileresprob,"w"))==NULL) {
     printf("Problem with resultfile: %s\n", fileresprob);      printf("Problem with resultfile: %s\n", fileresprob);
   }    }
     strcpy(fileresprobcov,"probcov");
     strcat(fileresprobcov,fileres);
     if((ficresprobcov=fopen(fileresprobcov,"w"))==NULL) {
       printf("Problem with resultfile: %s\n", fileresprobcov);
     }
     strcpy(fileresprobcor,"probcor");
     strcat(fileresprobcor,fileres);
     if((ficresprobcor=fopen(fileresprobcor,"w"))==NULL) {
       printf("Problem with resultfile: %s\n", fileresprobcor);
     }
   printf("Computing standard deviation of one-step probabilities: result on file '%s' \n",fileresprob);    printf("Computing standard deviation of one-step probabilities: result on file '%s' \n",fileresprob);
     printf("Computing matrix of variance covariance of one-step probabilities: result on file '%s' \n",fileresprobcov);
     printf("and correlation matrix of one-step probabilities: result on file '%s' \n",fileresprobcor);
     
 fprintf(ficresprob,"#One-step probabilities and standard deviation in parentheses\n");    fprintf(ficresprob,"#One-step probabilities and stand. devi in ()\n");
   fprintf(ficresprob,"# Age");    fprintf(ficresprob,"# Age");
     fprintf(ficresprobcov,"#One-step probabilities and covariance matrix\n");
     fprintf(ficresprobcov,"# Age");
     fprintf(ficresprobcor,"#One-step probabilities and correlation matrix\n");
     fprintf(ficresprobcov,"# Age");
   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(ficresprob," p%1d-%1d (SE)",i,j);        fprintf(ficresprob," p%1d-%1d (SE)",i,j);
         fprintf(ficresprobcov," p%1d-%1d ",i,j);
         fprintf(ficresprobcor," p%1d-%1d ",i,j);
       }  
   fprintf(ficresprob,"\n");    fprintf(ficresprob,"\n");
     fprintf(ficresprobcov,"\n");
     fprintf(ficresprobcor,"\n");
   xp=vector(1,npar);    xp=vector(1,npar);
   dnewm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);    dnewm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
   doldm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,(nlstate+ndeath)*(nlstate+ndeath));    doldm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,(nlstate+ndeath)*(nlstate+ndeath));
Line 1969  fprintf(ficresprob,"#One-step probabilit Line 1986  fprintf(ficresprob,"#One-step probabilit
   
     if  (cptcovn>0) {      if  (cptcovn>0) {
       fprintf(ficresprob, "\n#********** Variable ");        fprintf(ficresprob, "\n#********** Variable ");
         fprintf(ficresprobcov, "\n#********** Variable ");
         fprintf(ficresprobcor, "\n#********** Variable ");
       for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);        for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
       fprintf(ficresprob, "**********\n#");        fprintf(ficresprob, "**********\n#");
         for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcov, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
         fprintf(ficresprobcov, "**********\n#");
         for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
         fprintf(ficresprobcor, "**********\n#");
     }      }
         
       for (age=bage; age<=fage; age ++){        for (age=bage; age<=fage; age ++){
         cov[2]=age;          cov[2]=age;
         for (k=1; k<=cptcovn;k++) {          for (k=1; k<=cptcovn;k++) {
           cov[2+k]=nbcode[Tvar[k]][codtab[j1][Tvar[k]]];            cov[2+k]=nbcode[Tvar[k]][codtab[j1][Tvar[k]]];
            
         }          }
         for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2];          for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2];
         for (k=1; k<=cptcovprod;k++)          for (k=1; k<=cptcovprod;k++)
Line 2035  fprintf(ficresprob,"#One-step probabilit Line 2057  fprintf(ficresprob,"#One-step probabilit
           }            }
         }          }
             
      /*printf("\n%d ",(int)age);          /*printf("\n%d ",(int)age);
      for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++){       for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++){
        printf("%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));         printf("%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));
      }*/       }*/
   
         fprintf(ficresprob,"\n%d ",(int)age);          fprintf(ficresprob,"\n%d ",(int)age);
           fprintf(ficresprobcov,"\n%d ",(int)age);
           fprintf(ficresprobcor,"\n%d ",(int)age);
   
         for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++)          for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++)
           fprintf(ficresprob,"%.3e (%.3e) ",gm[i],sqrt(doldm[i][i]));            fprintf(ficresprob,"%12.3e (%12.3e) ",gm[i],sqrt(doldm[i][j]));
            for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){
             fprintf(ficresprobcov,"%12.3e ",gm[i]);
             fprintf(ficresprobcor,"%12.3e ",gm[i]);
           }
           i=0;
           for (k=1; k<=(nlstate);k++){
             for (l=1; l<=(nlstate+ndeath);l++){
               i=i++;
               fprintf(ficresprobcov,"\n%d %d-%d",(int)age,k,l);
               fprintf(ficresprobcor,"\n%d %d-%d",(int)age,k,l);
               for (j=1; j<=i;j++){
                 fprintf(ficresprobcov," %12.3e",doldm[i][j]);
                 fprintf(ficresprobcor," %12.3e",doldm[i][j]/sqrt(doldm[i][i])/sqrt(doldm[j][j]));
               }
             }
           }
       }        }
     }      }
     free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));      free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));
Line 2054  fprintf(ficresprob,"#One-step probabilit Line 2093  fprintf(ficresprob,"#One-step probabilit
   }    }
   free_vector(xp,1,npar);    free_vector(xp,1,npar);
   fclose(ficresprob);    fclose(ficresprob);
      fclose(ficresprobcov);
     fclose(ficresprobcor);
 }  }
   
   
 /******************* Printing html file ***********/  /******************* Printing html file ***********/
 void printinghtml(char fileres[], char title[], char datafile[], int firstpass, \  void printinghtml(char fileres[], 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 optionfile[], \                    int imx,int jmin, int jmax, double jmeanint,char optionfile[], \
  char optionfilehtm[],char rfileres[], char optionfilegnuplot[],\                    char optionfilehtm[],char rfileres[], char optionfilegnuplot[],\
  char version[], int popforecast, int estepm ){                    char version[], int popforecast, int estepm ,\
                     double jprev1, double mprev1,double anprev1, \
                     double jprev2, double mprev2,double anprev2){
   int jj1, k1, i1, cpt;    int jj1, k1, i1, cpt;
   FILE *fichtm;    FILE *fichtm;
   /*char optionfilehtm[FILENAMELENGTH];*/    /*char optionfilehtm[FILENAMELENGTH];*/
Line 2073  void printinghtml(char fileres[], char t Line 2116  void printinghtml(char fileres[], char t
     printf("Problem with %s \n",optionfilehtm), exit(0);      printf("Problem with %s \n",optionfilehtm), exit(0);
   }    }
   
  fprintf(fichtm,"<body> <font size=\"2\">%s </font> <hr size=\"2\" color=\"#EC5E5E\"> \n    fprintf(fichtm,"<body> <font size=\"2\">%s </font> <hr size=\"2\" color=\"#EC5E5E\"> \n
 Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n  Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n
 \n  \n
 Total number of observations=%d <br>\n  Total number of observations=%d <br>\n
 Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n  Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n
 <hr  size=\"2\" color=\"#EC5E5E\">  <hr  size=\"2\" color=\"#EC5E5E\">
  <ul><li>Outputs files<br>\n   <ul><li>Parameter files<br>\n
  - Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\n   - Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\n
  - Gnuplot file name: <a href=\"%s\">%s</a><br>\n   - Gnuplot file name: <a href=\"%s\">%s</a><br></ul>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,optionfilegnuplot,optionfilegnuplot);
  - Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n  
  - Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>\n     fprintf(fichtm,"<ul><li>Result files (first order: no variance)<br>\n
  - Transition probabilities: <a href=\"pij%s\">pij%s</a><br>\n   - Observed prevalence in each state (during the period defined between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf): <a href=\"p%s\">p%s</a> <br>\n
  - Life expectancies by age and initial health status (estepm=%2d months): <a href=\"e%s\">e%s</a> <br>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,optionfilegnuplot,optionfilegnuplot,fileres,fileres,fileres,fileres,fileres,fileres,estepm,fileres,fileres);   - Estimated transition probabilities over %d (stepm) months: <a href=\"pij%s\">pij%s</a><br>\n
    - Stable prevalence in each health state: <a href=\"pl%s\">pl%s</a> <br>\n
  fprintf(fichtm,"\n   - Life expectancies by age and initial health status (estepm=%2d months):
  - Parameter file with estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>\n     <a href=\"e%s\">e%s</a> <br>\n</li>", \
   - Variance of one-step probabilities: <a href=\"prob%s\">prob%s</a> <br>\n    jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,fileres,fileres,stepm,fileres,fileres,fileres,fileres,estepm,fileres,fileres);
  - Variances of life expectancies by age and initial health status (estepm=%d months): <a href=\"v%s\">v%s</a><br>\n  
  - Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br>\n   fprintf(fichtm,"\n<li> Result files (second order: variances)<br>\n
  - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\n",rfileres,rfileres,fileres,fileres, estepm, fileres,fileres,fileres,fileres,fileres,fileres);   - Parameter file with estimated parameters and covariance matrix: <a href=\"%s\">%s</a> <br>\n
    - Variance of one-step probabilities: <a href=\"prob%s\">prob%s</a> <br>\n
    - Variance-covariance of one-step probabilities: <a href=\"probcov%s\">probcov%s</a> <br>\n
    - Correlation matrix of one-step probabilities: <a href=\"probcor%s\">probcor%s</a> <br>\n
    - Variances and covariances of life expectancies by age and initial health status (estepm=%d months): <a href=\"v%s\">v%s</a><br>\n
    - Health expectancies with their variances (no covariance): <a href=\"t%s\">t%s</a> <br>\n
    - Standard deviation of stable prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\n",rfileres,rfileres,fileres,fileres,fileres,fileres,fileres,fileres, estepm, fileres,fileres,fileres,fileres,fileres,fileres);
   
  if(popforecast==1) fprintf(fichtm,"\n   if(popforecast==1) fprintf(fichtm,"\n
  - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\n   - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\n
Line 2108  fprintf(fichtm," <li>Graphs</li><p>"); Line 2157  fprintf(fichtm," <li>Graphs</li><p>");
  jj1=0;   jj1=0;
  for(k1=1; k1<=m;k1++){   for(k1=1; k1<=m;k1++){
    for(i1=1; i1<=ncodemax[k1];i1++){     for(i1=1; i1<=ncodemax[k1];i1++){
        jj1++;       jj1++;
        if (cptcovn > 0) {       if (cptcovn > 0) {
          fprintf(fichtm,"<hr  size=\"2\" color=\"#EC5E5E\">************ Results for covariates");         fprintf(fichtm,"<hr  size=\"2\" color=\"#EC5E5E\">************ Results for covariates");
          for (cpt=1; cpt<=cptcoveff;cpt++)         for (cpt=1; cpt<=cptcoveff;cpt++)
            fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtab[jj1][cpt]]);           fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtab[jj1][cpt]]);
          fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");         fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");
        }       }
        fprintf(fichtm,"<br>- Probabilities: pe%s%d.gif<br>       /* Pij */
 <img src=\"pe%s%d.gif\">",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);           fprintf(fichtm,"<br>- Pij or Conditional probabilities to be observed in state j being in state i %d (stepm) months before: pe%s%d1.png<br>
   <img src=\"pe%s%d1.png\">",stepm,strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);    
        /* Quasi-incidences */
        fprintf(fichtm,"<br>- Pij or Conditional probabilities to be observed in state j being in state i %d (stepm) months before but expressed in per year i.e. quasi incidences if stepm is small and probabilities too: pe%s%d2.png<br>
   <img src=\"pe%s%d2.png\">",stepm,strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);
          /* Stable prevalence in each health state */
        for(cpt=1; cpt<nlstate;cpt++){         for(cpt=1; cpt<nlstate;cpt++){
          fprintf(fichtm,"<br>- Prevalence of disability : p%s%d%d.gif<br>           fprintf(fichtm,"<br>- Stable prevalence in each health state : p%s%d%d.png<br>
 <img src=\"p%s%d%d.gif\">",strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);  <img src=\"p%s%d%d.png\">",strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);
        }         }
     for(cpt=1; cpt<=nlstate;cpt++) {      for(cpt=1; cpt<=nlstate;cpt++) {
        fprintf(fichtm,"<br>- Observed and stationary prevalence (with confident         fprintf(fichtm,"<br>- Observed and stationary prevalence (with confident
 interval) in state (%d): v%s%d%d.gif <br>  interval) in state (%d): v%s%d%d.png <br>
 <img src=\"v%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);    <img src=\"v%s%d%d.png\">",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);  
      }       }
      for(cpt=1; cpt<=nlstate;cpt++) {       for(cpt=1; cpt<=nlstate;cpt++) {
         fprintf(fichtm,"\n<br>- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif <br>          fprintf(fichtm,"\n<br>- Health life expectancies by age and initial health state (%d): exp%s%d%d.png <br>
 <img src=\"exp%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);  <img src=\"exp%s%d%d.png\">",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);
      }       }
      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): e%s%d.gif<br>  health expectancies in states (1) and (2): e%s%d.png<br>
 <img src=\"e%s%d.gif\">",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);  <img src=\"e%s%d.png\">",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);
 fprintf(fichtm,"\n</body>");  fprintf(fichtm,"\n</body>");
    }     }
    }   }
 fclose(fichtm);  fclose(fichtm);
 }  }
   
Line 2143  fclose(fichtm); Line 2197  fclose(fichtm);
 void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){  void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){
   
   int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;    int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;
     int ng;
   strcpy(optionfilegnuplot,optionfilefiname);    strcpy(optionfilegnuplot,optionfilefiname);
   strcat(optionfilegnuplot,".gp.txt");    strcat(optionfilegnuplot,".gp");
   if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {    if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
     printf("Problem with file %s",optionfilegnuplot);      printf("Problem with file %s",optionfilegnuplot);
   }    }
Line 2159  m=pow(2,cptcoveff); Line 2213  m=pow(2,cptcoveff);
   for (cpt=1; cpt<= nlstate ; cpt ++) {    for (cpt=1; cpt<= nlstate ; cpt ++) {
    for (k1=1; k1<= m ; k1 ++) {     for (k1=1; k1<= m ; k1 ++) {
   
      fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"vpl%s\" every :::%d::%d u 1:2 \"\%%lf",ageminpar,fage,fileres,k1-1,k1-1);  #ifdef windows
        fprintf(ficgp,"\nset out \"v%s%d%d.png\" \n",strtok(optionfile, "."),cpt,k1);
        fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter png small\nset size 0.65,0.65\nplot [%.f:%.f] \"vpl%s\" every :::%d::%d u 1:2 \"\%%lf",ageminpar,fage,fileres,k1-1,k1-1);
   #endif
   #ifdef unix
   fprintf(ficgp,"\nset out \"v%s%d%d.png\" \n",strtok(optionfile, "."),cpt,k1);
   fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nplot [%.f:%.f] \"vpl%s\" u 1:2 \"\%%lf",ageminpar,fage,fileres);
   #endif
   
 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)");
Line 2176  for (i=1; i<= nlstate ; i ++) { Line 2237  for (i=1; i<= nlstate ; i ++) {
   else fprintf(ficgp," \%%*lf (\%%*lf)");    else fprintf(ficgp," \%%*lf (\%%*lf)");
 }    }  
      fprintf(ficgp,"\" t\"\" w l 1,\"p%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l 2",fileres,k1-1,k1-1,2+4*(cpt-1));       fprintf(ficgp,"\" t\"\" w l 1,\"p%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l 2",fileres,k1-1,k1-1,2+4*(cpt-1));
   #ifdef unix
 fprintf(ficgp,"\nset out \"v%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);  fprintf(ficgp,"\nset ter png small\nset size 0.65,0.65\n");
   #endif
    }     }
   }    }
   /*2 eme*/    /*2 eme*/
   
   for (k1=1; k1<= m ; k1 ++) {    for (k1=1; k1<= m ; k1 ++) {
     fprintf(ficgp,"set ylabel \"Years\" \nset ter gif small size 400,300\nplot [%.f:%.f] ",ageminpar,fage);      fprintf(ficgp,"\nset out \"e%s%d.png\" \n",strtok(optionfile, "."),k1);
       fprintf(ficgp,"set ylabel \"Years\" \nset ter png small\nset size 0.65,0.65\nplot [%.f:%.f] ",ageminpar,fage);
         
     for (i=1; i<= nlstate+1 ; i ++) {      for (i=1; i<= nlstate+1 ; i ++) {
       k=2*i;        k=2*i;
Line 2208  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2271  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
       if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l 0");        if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l 0");
       else fprintf(ficgp,"\" t\"\" w l 0,");        else fprintf(ficgp,"\" t\"\" w l 0,");
     }      }
     fprintf(ficgp,"\nset out \"e%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),k1);  
   }    }
     
   /*3eme*/    /*3eme*/
Line 2216  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2278  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
   for (k1=1; k1<= m ; k1 ++) {    for (k1=1; k1<= m ; k1 ++) {
     for (cpt=1; cpt<= nlstate ; cpt ++) {      for (cpt=1; cpt<= nlstate ; cpt ++) {
       k=2+nlstate*(2*cpt-2);        k=2+nlstate*(2*cpt-2);
       fprintf(ficgp,"set ter gif small size 400,300\nplot [%.f:%.f] \"e%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,fileres,k1-1,k1-1,k,cpt);        fprintf(ficgp,"\nset out \"exp%s%d%d.png\" \n",strtok(optionfile, "."),cpt,k1);
         fprintf(ficgp,"set ter png small\nset size 0.65,0.65\nplot [%.f:%.f] \"e%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,fileres,k1-1,k1-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 2229  fprintf(ficgp,"\" t \"e%d1\" w l",cpt); Line 2292  fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
         fprintf(ficgp," ,\"e%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",fileres,k1-1,k1-1,k+2*i,cpt,i+1);          fprintf(ficgp," ,\"e%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",fileres,k1-1,k1-1,k+2*i,cpt,i+1);
   
       }        }
       fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);  
     }  
     }      }
     }
     
   /* CV preval stat */    /* CV preval stat */
     for (k1=1; k1<= m ; k1 ++) {      for (k1=1; k1<= m ; k1 ++) {
     for (cpt=1; cpt<nlstate ; cpt ++) {      for (cpt=1; cpt<nlstate ; cpt ++) {
       k=3;        k=3;
       fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",ageminpar,agemaxpar,fileres,k1,k+cpt+1,k+1);        fprintf(ficgp,"\nset out \"p%s%d%d.png\" \n",strtok(optionfile, "."),cpt,k1);
         fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter png small\nset size 0.65,0.65\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",ageminpar,agemaxpar,fileres,k1,k+cpt+1,k+1);
   
       for (i=1; i< nlstate ; i ++)        for (i=1; i< nlstate ; i ++)
         fprintf(ficgp,"+$%d",k+i+1);          fprintf(ficgp,"+$%d",k+i+1);
Line 2250  fprintf(ficgp,"\" t \"e%d1\" w l",cpt); Line 2313  fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
         fprintf(ficgp,"+$%d",l+i+1);          fprintf(ficgp,"+$%d",l+i+1);
       }        }
       fprintf(ficgp,")) t\"prev(%d,%d)\" w l\n",cpt+1,cpt+1);          fprintf(ficgp,")) t\"prev(%d,%d)\" w l\n",cpt+1,cpt+1);  
       fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);  
     }      }
   }      }  
     
Line 2266  fprintf(ficgp,"\" t \"e%d1\" w l",cpt); Line 2328  fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
         }          }
       }        }
     }      }
     }     }
   
     for(jk=1; jk <=m; jk++) {     for(ng=1; ng<=2;ng++){ /* Number of graphics: first is probabilities second is incidence per year*/
   fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot  [%.f:%.f] ",ageminpar,agemaxpar);       for(jk=1; jk <=m; jk++) {
    i=1;         fprintf(ficgp,"\nset out \"pe%s%d%d.png\" \n",strtok(optionfile, "."),jk,ng);
    for(k2=1; k2<=nlstate; k2++) {         if (ng==2)
      k3=i;           fprintf(ficgp,"\nset ylabel \"Quasi-incidence per year\"\n");
      for(k=1; k<=(nlstate+ndeath); k++) {         else
        if (k != k2){           fprintf(ficgp,"\nset title \"Probability\"\n");
         fprintf(ficgp," exp(p%d+p%d*x",i,i+1);         fprintf(ficgp,"\nset ter png small\nset size 0.65,0.65\nset log y\nplot  [%.f:%.f] ",ageminpar,agemaxpar);
 ij=1;         i=1;
         for(j=3; j <=ncovmodel; j++) {         for(k2=1; k2<=nlstate; k2++) {
           if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {           k3=i;
             fprintf(ficgp,"+p%d*%d*x",i+j-1,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);           for(k=1; k<=(nlstate+ndeath); k++) {
             ij++;             if (k != k2){
           }               if(ng==2)
           else                 fprintf(ficgp," %f*exp(p%d+p%d*x",YEARM/stepm,i,i+1);
           fprintf(ficgp,"+p%d*%d",i+j-1,nbcode[Tvar[j-2]][codtab[jk][j-2]]);               else
         }                 fprintf(ficgp," exp(p%d+p%d*x",i,i+1);
           fprintf(ficgp,")/(1");               ij=1;
                       for(j=3; j <=ncovmodel; j++) {
         for(k1=1; k1 <=nlstate; k1++){                   if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {
           fprintf(ficgp,"+exp(p%d+p%d*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1);                   fprintf(ficgp,"+p%d*%d*x",i+j-1,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);
 ij=1;                   ij++;
           for(j=3; j <=ncovmodel; j++){                 }
           if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {                 else
             fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);                   fprintf(ficgp,"+p%d*%d",i+j-1,nbcode[Tvar[j-2]][codtab[jk][j-2]]);
             ij++;               }
           }               fprintf(ficgp,")/(1");
           else               
             fprintf(ficgp,"+p%d*%d",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);               for(k1=1; k1 <=nlstate; k1++){  
           }                 fprintf(ficgp,"+exp(p%d+p%d*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1);
           fprintf(ficgp,")");                 ij=1;
         }                 for(j=3; j <=ncovmodel; j++){
         fprintf(ficgp,") t \"p%d%d\" ", k2,k);                   if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {
         if ((k+k2)!= (nlstate*2+ndeath)) fprintf(ficgp,",");                     fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);
         i=i+ncovmodel;                     ij++;
                    }
                    else
                      fprintf(ficgp,"+p%d*%d",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);
                  }
                  fprintf(ficgp,")");
                }
                fprintf(ficgp,") t \"p%d%d\" ", k2,k);
                if ((k+k2)!= (nlstate*2+ndeath)) fprintf(ficgp,",");
                i=i+ncovmodel;
              }
            }
        }         }
      }       }
    }     }
    fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk);     fclose(ficgp);
    }  
      
   fclose(ficgp);  
 }  /* end gnuplot */  }  /* end gnuplot */
   
   
Line 2645  int main(int argc, char *argv[]) Line 2715  int main(int argc, char *argv[])
   double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2;    double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2;
     
   
   char version[80]="Imach version 0.8a, May 2002, INED-EUROREVES ";    char version[80]="Imach version 0.8g, May 2002, INED-EUROREVES ";
   char *alph[]={"a","a","b","c","d","e"}, str[4];    char *alph[]={"a","a","b","c","d","e"}, str[4];
   
   
Line 3256  while((c=getc(ficpar))=='#' && c!= EOF){ Line 3326  while((c=getc(ficpar))=='#' && c!= EOF){
   
 /*--------- index.htm --------*/  /*--------- index.htm --------*/
   
   printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm,rfileres,optionfilegnuplot,version,popforecast,estepm);   printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm,rfileres,optionfilegnuplot,version,popforecast,estepm,jprev1,mprev1,anprev1,jprev2,mprev2,anprev2);
   
     
   /*--------------- Prevalence limit --------------*/    /*--------------- Prevalence limit --------------*/
Line 3520  free_matrix(mint,1,maxwav,1,n); Line 3590  free_matrix(mint,1,maxwav,1,n);
   
   
  end:   end:
   #ifdef windows
   /* chdir(pathcd);*/    /* chdir(pathcd);*/
   #endif
  /*system("wgnuplot graph.plt");*/   /*system("wgnuplot graph.plt");*/
  /*system("../gp37mgw/wgnuplot graph.plt");*/   /*system("../gp37mgw/wgnuplot graph.plt");*/
  /*system("cd ../gp37mgw");*/   /*system("cd ../gp37mgw");*/
Line 3530  free_matrix(mint,1,maxwav,1,n); Line 3602  free_matrix(mint,1,maxwav,1,n);
  strcat(plotcmd,optionfilegnuplot);   strcat(plotcmd,optionfilegnuplot);
  system(plotcmd);   system(plotcmd);
   
  /*#ifdef windows*/  #ifdef windows
   while (z[0] != 'q') {    while (z[0] != 'q') {
     /* chdir(path); */      /* chdir(path); */
     printf("\nType e to edit output files, g to graph again, c to start again, and q for exiting: ");      printf("\nType e to edit output files, g to graph again, c to start again, and q for exiting: ");
Line 3540  free_matrix(mint,1,maxwav,1,n); Line 3612  free_matrix(mint,1,maxwav,1,n);
     else if (z[0] == 'g') system(plotcmd);      else if (z[0] == 'g') system(plotcmd);
     else if (z[0] == 'q') exit(0);      else if (z[0] == 'q') exit(0);
   }    }
   /*#endif */  #endif
 }  }
   
   

Removed from v.1.41.2.1  
changed lines
  Added in v.1.46


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