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

version 1.46, 2002/05/30 17:44:35 version 1.47, 2002/06/10 13:12:01
Line 75 Line 75
 #define YEARM 12. /* Number of months per year */  #define YEARM 12. /* Number of months per year */
 #define AGESUP 130  #define AGESUP 130
 #define AGEBASE 40  #define AGEBASE 40
   #ifdef windows
   #define DIRSEPARATOR '\\'
   #else
   #define DIRSEPARATOR '/'
   #endif
   
   char version[80]="Imach version 0.8g, May 2002, INED-EUROREVES ";
 int erreur; /* Error number */  int erreur; /* Error number */
 int nvar;  int nvar;
 int cptcovn, cptcovage=0, cptcoveff=0,cptcov;  int cptcovn, cptcovage=0, cptcoveff=0,cptcov;
Line 97  double **oldm, **newm, **savm; /* Workin Line 102  double **oldm, **newm, **savm; /* Workin
 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, *ficresprobcov, *ficresprobcor;  FILE *ficgp,*ficresprob,*ficpop, *ficresprobcov, *ficresprobcor;
   FILE *fichtm; /* Html File */
 FILE *ficreseij;  FILE *ficreseij;
   char filerese[FILENAMELENGTH];  char filerese[FILENAMELENGTH];
  FILE  *ficresvij;  FILE  *ficresvij;
   char fileresv[FILENAMELENGTH];  char fileresv[FILENAMELENGTH];
  FILE  *ficresvpl;  FILE  *ficresvpl;
   char fileresvpl[FILENAMELENGTH];  char fileresvpl[FILENAMELENGTH];
   char title[MAXLINE];
   char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH];
   char optionfilext[10], optionfilefiname[FILENAMELENGTH], plotcmd[FILENAMELENGTH];
   
   char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH];
   
   char filerest[FILENAMELENGTH];
   char fileregp[FILENAMELENGTH];
   char popfile[FILENAMELENGTH];
   
   char optionfilegnuplot[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];
   
 #define NR_END 1  #define NR_END 1
 #define FREE_ARG char*  #define FREE_ARG char*
Line 161  static int split( char *path, char *dirc Line 178  static int split( char *path, char *dirc
   
    l1 = strlen( path );                 /* length of path */     l1 = strlen( path );                 /* length of path */
    if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );     if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );
 #ifdef windows     s = strrchr( path,  DIRSEPARATOR );          /* find last / */
    s = strrchr( path, '\\' );           /* find last / */  
 #else  
    s = strrchr( path, '/' );            /* find last / */  
 #endif  
    if ( s == NULL ) {                   /* no directory, so use current */     if ( s == NULL ) {                   /* no directory, so use current */
 #if     defined(__bsd__)                /* get current working directory */  #if     defined(__bsd__)                /* get current working directory */
       extern char       *getwd( );        extern char       *getwd( );
Line 1671  void evsij(char fileres[], double ***eij Line 1684  void evsij(char fileres[], double ***eij
             varhe[i][j][(int)age] += doldm[i][j]*hf*hf;              varhe[i][j][(int)age] += doldm[i][j]*hf*hf;
       }        }
     }      }
   
        
     /* Computing expectancies */      /* Computing expectancies */
     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 1698  void evsij(char fileres[], double ***eij Line 1709  void evsij(char fileres[], double ***eij
     free_ma3x(trgradg,0,nhstepm,1,nlstate*2,1,npar);      free_ma3x(trgradg,0,nhstepm,1,nlstate*2,1,npar);
     free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);      free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
   }    }
     printf("\n");
   
   free_vector(xp,1,npar);    free_vector(xp,1,npar);
   free_matrix(dnewm,1,nlstate*2,1,npar);    free_matrix(dnewm,1,nlstate*2,1,npar);
   free_matrix(doldm,1,nlstate*2,1,nlstate*2);    free_matrix(doldm,1,nlstate*2,1,nlstate*2);
Line 1924  void varprevlim(char fileres[], double * Line 1937  void varprevlim(char fileres[], double *
 }  }
   
 /************ Variance of one-step probabilities  ******************/  /************ Variance of one-step probabilities  ******************/
 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 optionfilefiname[], 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, l1;
     int k2, l2, j1,  z1;
   int k=0,l, cptcode;    int k=0,l, cptcode;
     int first=1;
     double cv12, mu1, mu2, lc1, lc2, v12, v21, v11, v22,v1,v2;
   double **dnewm,**doldm;    double **dnewm,**doldm;
   double *xp;    double *xp;
   double *gp, *gm;    double *gp, *gm;
   double **gradg, **trgradg;    double **gradg, **trgradg;
     double **mu;
   double age,agelim, cov[NCOVMAX];    double age,agelim, cov[NCOVMAX];
     double std=2.0; /* Number of standard deviation wide of confidence ellipsoids */
   int theta;    int theta;
   char fileresprob[FILENAMELENGTH];    char fileresprob[FILENAMELENGTH];
   char fileresprobcov[FILENAMELENGTH];    char fileresprobcov[FILENAMELENGTH];
   char fileresprobcor[FILENAMELENGTH];    char fileresprobcor[FILENAMELENGTH];
   
     double ***varpij;
   
   strcpy(fileresprob,"prob");    strcpy(fileresprob,"prob");
   strcat(fileresprob,fileres);    strcat(fileresprob,fileres);
   if((ficresprob=fopen(fileresprob,"w"))==NULL) {    if((ficresprob=fopen(fileresprob,"w"))==NULL) {
Line 1963  void varprob(char fileres[], double **ma Line 1983  void varprob(char fileres[], double **ma
   fprintf(ficresprobcov,"# Age");    fprintf(ficresprobcov,"# Age");
   fprintf(ficresprobcor,"#One-step probabilities and correlation matrix\n");    fprintf(ficresprobcor,"#One-step probabilities and correlation matrix\n");
   fprintf(ficresprobcov,"# Age");    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);
Line 1973  void varprob(char fileres[], double **ma Line 1995  void varprob(char fileres[], double **ma
   fprintf(ficresprobcov,"\n");    fprintf(ficresprobcov,"\n");
   fprintf(ficresprobcor,"\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)*(nlstate+ndeath),1,npar);
   doldm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,(nlstate+ndeath)*(nlstate+ndeath));    doldm=matrix(1,(nlstate)*(nlstate+ndeath),1,(nlstate)*(nlstate+ndeath));
      mu=matrix(1,(nlstate)*(nlstate+ndeath), (int) bage, (int)fage);
     varpij=ma3x(1,nlstate*(nlstate+ndeath),1,nlstate*(nlstate+ndeath),(int) bage, (int) fage);
     first=1;
     if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) {
       printf("Problem with gnuplot file: %s\n", optionfilegnuplot);
       exit(0);
     }
     else{
       fprintf(ficgp,"\n# Routine varprob");
     }
     if((fichtm=fopen(optionfilehtm,"a"))==NULL) {
       printf("Problem with html file: %s\n", optionfilehtm);
       exit(0);
     }
     else{
       fprintf(fichtm,"\n<H2> Computing matrix of variance-covariance of step probabilities</h2>\n");
       fprintf(fichtm,"\n<br> We have drawn ellipsoids of confidence around the p<inf>ij</inf>, p<inf>kl</inf> to understand the covariance between two incidences. They are expressed in year<sup>-1</sup> in order to be less dependent of stepm.<br>\n");
       fprintf(fichtm,"\n<br> We have drawn x'cov<sup>-1</sup>x = 4 where x is the column vector (pij,pkl). It means that if pij and pkl where uncorrelated the (2X2) matrix would have been (1/(var pij), 0 , 0, 1/(var pkl)), and the confidence interval would be 2 standard deviations wide on each axis. <br> When both incidences are correlated we diagonalised the inverse of the covariance matrix and made the appropriate rotation.<br> \n");
   
     }
   cov[1]=1;    cov[1]=1;
   j=cptcoveff;    j=cptcoveff;
   if (cptcovn<1) {j=1;ncodemax[1]=1;}    if (cptcovn<1) {j=1;ncodemax[1]=1;}
Line 1987  void varprob(char fileres[], double **ma Line 2028  void varprob(char fileres[], double **ma
     if  (cptcovn>0) {      if  (cptcovn>0) {
       fprintf(ficresprob, "\n#********** Variable ");        fprintf(ficresprob, "\n#********** Variable ");
       fprintf(ficresprobcov, "\n#********** Variable ");        fprintf(ficresprobcov, "\n#********** Variable ");
         fprintf(ficgp, "\n#********** Variable ");
         fprintf(fichtm, "\n<h4>********** Variable</h4>\n ");
       fprintf(ficresprobcor, "\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]]);        for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcov, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
       fprintf(ficresprobcov, "**********\n#");        fprintf(ficresprobcov, "**********\n#");
       for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);        for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
       fprintf(ficresprobcor, "**********\n#");        fprintf(ficgp, "**********\n#");
         for (z1=1; z1<=cptcoveff; z1++) fprintf(ficgp, "# V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
         fprintf(ficgp, "**********\n#");
         for (z1=1; z1<=cptcoveff; z1++) fprintf(fichtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
         fprintf(fichtm, "**********\n#");
     }      }
         
       for (age=bage; age<=fage; age ++){        for (age=bage; age<=fage; age ++){
Line 2005  void varprob(char fileres[], double **ma Line 2052  void varprob(char fileres[], double **ma
         for (k=1; k<=cptcovprod;k++)          for (k=1; k<=cptcovprod;k++)
           cov[2+Tprod[k]]=nbcode[Tvard[k][1]][codtab[ij][Tvard[k][1]]]*nbcode[Tvard[k][2]][codtab[ij][Tvard[k][2]]];            cov[2+Tprod[k]]=nbcode[Tvard[k][1]][codtab[ij][Tvard[k][1]]]*nbcode[Tvard[k][2]][codtab[ij][Tvard[k][2]]];
                 
         gradg=matrix(1,npar,1,9);          gradg=matrix(1,npar,1,(nlstate)*(nlstate+ndeath));
         trgradg=matrix(1,9,1,npar);          trgradg=matrix(1,(nlstate)*(nlstate+ndeath),1,npar);
         gp=vector(1,(nlstate+ndeath)*(nlstate+ndeath));          gp=vector(1,(nlstate)*(nlstate+ndeath));
         gm=vector(1,(nlstate+ndeath)*(nlstate+ndeath));          gm=vector(1,(nlstate)*(nlstate+ndeath));
         
         for(theta=1; theta <=npar; theta++){          for(theta=1; theta <=npar; theta++){
           for(i=1; i<=npar; i++)            for(i=1; i<=npar; i++)
Line 2017  void varprob(char fileres[], double **ma Line 2064  void varprob(char fileres[], double **ma
           pmij(pmmij,cov,ncovmodel,xp,nlstate);            pmij(pmmij,cov,ncovmodel,xp,nlstate);
                     
           k=0;            k=0;
           for(i=1; i<= (nlstate+ndeath); i++){            for(i=1; i<= (nlstate); i++){
             for(j=1; j<=(nlstate+ndeath);j++){              for(j=1; j<=(nlstate+ndeath);j++){
               k=k+1;                k=k+1;
               gp[k]=pmmij[i][j];                gp[k]=pmmij[i][j];
Line 2029  void varprob(char fileres[], double **ma Line 2076  void varprob(char fileres[], double **ma
         
           pmij(pmmij,cov,ncovmodel,xp,nlstate);            pmij(pmmij,cov,ncovmodel,xp,nlstate);
           k=0;            k=0;
           for(i=1; i<=(nlstate+ndeath); i++){            for(i=1; i<=(nlstate); i++){
             for(j=1; j<=(nlstate+ndeath);j++){              for(j=1; j<=(nlstate+ndeath);j++){
               k=k+1;                k=k+1;
               gm[k]=pmmij[i][j];                gm[k]=pmmij[i][j];
             }              }
           }            }
             
           for(i=1; i<= (nlstate+ndeath)*(nlstate+ndeath); i++)            for(i=1; i<= (nlstate)*(nlstate+ndeath); i++)
             gradg[theta][i]=(gp[i]-gm[i])/2./delti[theta];                gradg[theta][i]=(gp[i]-gm[i])/2./delti[theta];  
         }          }
   
         for(j=1; j<=(nlstate+ndeath)*(nlstate+ndeath);j++)          for(j=1; j<=(nlstate)*(nlstate+ndeath);j++)
           for(theta=1; theta <=npar; theta++)            for(theta=1; theta <=npar; theta++)
             trgradg[j][theta]=gradg[theta][j];              trgradg[j][theta]=gradg[theta][j];
                 
         matprod2(dnewm,trgradg,1,9,1,npar,1,npar,matcov);          matprod2(dnewm,trgradg,1,(nlstate)*(nlstate+ndeath),1,npar,1,npar,matcov);
         matprod2(doldm,dnewm,1,9,1,npar,1,9,gradg);          matprod2(doldm,dnewm,1,(nlstate)*(nlstate+ndeath),1,npar,1,(nlstate)*(nlstate+ndeath),gradg);
                 
         pmij(pmmij,cov,ncovmodel,x,nlstate);          pmij(pmmij,cov,ncovmodel,x,nlstate);
                 
         k=0;          k=0;
         for(i=1; i<=(nlstate+ndeath); i++){          for(i=1; i<=(nlstate); i++){
           for(j=1; j<=(nlstate+ndeath);j++){            for(j=1; j<=(nlstate+ndeath);j++){
             k=k+1;              k=k+1;
             gm[k]=pmmij[i][j];              mu[k][(int) age]=pmmij[i][j];
           }            }
         }          }
                for(i=1;i<=(nlstate)*(nlstate+ndeath);i++)
             for(j=1;j<=(nlstate)*(nlstate+ndeath);j++)
               varpij[i][j][(int)age] = doldm[i][j];
   
         /*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)*(nlstate+ndeath);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]));
      }*/       }*/
   
Line 2066  void varprob(char fileres[], double **ma Line 2116  void varprob(char fileres[], double **ma
         fprintf(ficresprobcov,"\n%d ",(int)age);          fprintf(ficresprobcov,"\n%d ",(int)age);
         fprintf(ficresprobcor,"\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)*(nlstate+ndeath);i++)
           fprintf(ficresprob,"%12.3e (%12.3e) ",gm[i],sqrt(doldm[i][j]));            fprintf(ficresprob,"%11.3e (%11.3e) ",mu[i][(int) age],sqrt(varpij[i][i][(int)age]));
         for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){          for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){
           fprintf(ficresprobcov,"%12.3e ",gm[i]);            fprintf(ficresprobcov,"%11.3e ",mu[i][(int) age]);
           fprintf(ficresprobcor,"%12.3e ",gm[i]);            fprintf(ficresprobcor,"%11.3e ",mu[i][(int) age]);
         }          }
         i=0;          i=0;
         for (k=1; k<=(nlstate);k++){          for (k=1; k<=(nlstate);k++){
Line 2079  void varprob(char fileres[], double **ma Line 2129  void varprob(char fileres[], double **ma
             fprintf(ficresprobcov,"\n%d %d-%d",(int)age,k,l);              fprintf(ficresprobcov,"\n%d %d-%d",(int)age,k,l);
             fprintf(ficresprobcor,"\n%d %d-%d",(int)age,k,l);              fprintf(ficresprobcor,"\n%d %d-%d",(int)age,k,l);
             for (j=1; j<=i;j++){              for (j=1; j<=i;j++){
               fprintf(ficresprobcov," %12.3e",doldm[i][j]);                fprintf(ficresprobcov," %11.3e",varpij[i][j][(int)age]);
               fprintf(ficresprobcor," %12.3e",doldm[i][j]/sqrt(doldm[i][i])/sqrt(doldm[j][j]));                fprintf(ficresprobcor," %11.3e",varpij[i][j][(int) age]/sqrt(varpij[i][i][(int) age])/sqrt(varpij[j][j][(int)age]));
             }              }
           }            }
         }          }/* end of loop for state */
       }        } /* end of loop for age */
     }          /* Drawing ellipsoids of confidence of two variables p(k1-l1,k2-l2)*/
         for (k1=1; k1<=(nlstate);k1++){
           for (l1=1; l1<=(nlstate+ndeath);l1++){
             if(l1==k1) continue;
             i=(k1-1)*(nlstate+ndeath)+l1;
             for (k2=1; k2<=(nlstate);k2++){
               for (l2=1; l2<=(nlstate+ndeath);l2++){
                 if(l2==k2) continue;
                 j=(k2-1)*(nlstate+ndeath)+l2;
                 if(j<=i) continue;
                 for (age=bage; age<=fage; age ++){
                   if ((int)age %5==0){
                     v1=varpij[i][i][(int)age]/stepm*YEARM/stepm*YEARM;
                     v2=varpij[j][j][(int)age]/stepm*YEARM/stepm*YEARM;
                     cv12=varpij[i][j][(int)age]/stepm*YEARM/stepm*YEARM;
                     mu1=mu[i][(int) age]/stepm*YEARM ;
                     mu2=mu[j][(int) age]/stepm*YEARM;
                     /* Computing eigen value of matrix of covariance */
                     lc1=(v1+v2)+sqrt((v1+v2)*(v1+v2) - 4*(v1*v2-cv12*cv12));
                     lc2=(v1+v2)-sqrt((v1+v2)*(v1+v2) - 4*(v1*v2-cv12*cv12));
                     printf("Var %.4e %.4e cov %.4e Eigen %.3e %.3e\n",v1,v2,cv12,lc1,lc2);
                     /* Eigen vectors */
                     v11=(1./sqrt(1+(v1-lc1)*(v1-lc1)/cv12/cv12));
                     v21=sqrt(1.-v11*v11);
                     v12=-v21;
                     v22=v11;
                     /*printf(fignu*/
                     /* mu1+ v11*lc1*cost + v12*lc2*sin(t) */
                     /* mu2+ v21*lc1*cost + v21*lc2*sin(t) */
                     if(first==1){
                       first=0;
                       fprintf(ficgp,"\nset parametric;set nolabel");
                       fprintf(ficgp,"\nset log y;set log x; set xlabel \"p%1d%1d (year-1)\";set ylabel \"p%1d%1d (year-1)\"",k2,l2,k1,l1);
                       fprintf(ficgp,"\nset ter png small\nset size 0.65,0.65");
                       fprintf(fichtm,"\n<br>Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year<sup>-1</sup> :<a href=\"varpijgr%s%1d%1d-%1d%1d.png\">varpijgr%s%1d%1d-%1d%1d.png</A>, ",k2,l2,k1,l1,optionfilefiname,k2,l2,k1,l1,optionfilefiname,k2,l2,k1,l1);
                       fprintf(fichtm,"\n<br><img src=\"varpijgr%s%1d%1d-%1d%1d.png\">, ",optionfilefiname,k2,l2,k1,l1);
                       fprintf(ficgp,"\nset out \"varpijgr%s%1d%1d-%1d%1d.png\"",optionfilefiname,k2,l2,k1,l1);
                       fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu2,mu1);
                       fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k2,l2,k1,l1);
                       fprintf(ficgp,"\nplot [-pi:pi] %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(-%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) t \"%d\"",\
                               mu2,std,v21,sqrt(lc1),v21,sqrt(lc2), \
                               mu1,std,v11,sqrt(lc1),v12,sqrt(lc2),(int) age);
                     }else{
                       first=0;
                       fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k2,l2,k1,l1);
                       fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu2,mu1);
                       fprintf(ficgp,"\nreplot %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(-%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) t \"%d\"",\
                               mu2,std,v21,sqrt(lc1),v21,sqrt(lc2), \
                               mu1,std,v11,sqrt(lc1),v12,sqrt(lc2),(int) age);
                     }/* if first */
                   } /* age mod 5 */
                 } /* end loop age */
                 fprintf(ficgp,"\nset out \"varpijgr%s%1d%1d-%1d%1d.png\";replot;",optionfilefiname,k2,l2,k1,l1);
                 first=1;
               } /*l12 */
             } /* k12 */
           } /*l1 */
         }/* k1 */
       } /* loop covariates */
       free_ma3x(varpij,1,nlstate,1,nlstate+ndeath,(int) bage, (int)fage);
     free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));      free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));
     free_vector(gm,1,(nlstate+ndeath)*(nlstate+ndeath));      free_vector(gm,1,(nlstate+ndeath)*(nlstate+ndeath));
       free_matrix(mu,1,(nlstate+ndeath)*(nlstate+ndeath),(int) bage, (int)fage);
     free_matrix(trgradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);      free_matrix(trgradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
     free_matrix(gradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);      free_matrix(gradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
   }    }
Line 2095  void varprob(char fileres[], double **ma Line 2205  void varprob(char fileres[], double **ma
   fclose(ficresprob);    fclose(ficresprob);
   fclose(ficresprobcov);    fclose(ficresprobcov);
   fclose(ficresprobcor);    fclose(ficresprobcor);
     fclose(ficgp);
     fclose(fichtm);
 }  }
   
   
 /******************* 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 rfileres[],\
                   char optionfilehtm[],char rfileres[], char optionfilegnuplot[],\                    int popforecast, int estepm ,\
                   char version[], int popforecast, int estepm ,\  
                   double jprev1, double mprev1,double anprev1, \                    double jprev1, double mprev1,double anprev1, \
                   double jprev2, double mprev2,double anprev2){                    double jprev2, double mprev2,double anprev2){
   int jj1, k1, i1, cpt;    int jj1, k1, i1, cpt;
   FILE *fichtm;  
   /*char optionfilehtm[FILENAMELENGTH];*/    /*char optionfilehtm[FILENAMELENGTH];*/
     if((fichtm=fopen(optionfilehtm,"a"))==NULL)    {
   strcpy(optionfilehtm,optionfile);  
   strcat(optionfilehtm,".htm");  
   if((fichtm=fopen(optionfilehtm,"w"))==NULL)    {  
     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  
 Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n  
 \n  
 Total number of observations=%d <br>\n  
 Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n  
 <hr  size=\"2\" color=\"#EC5E5E\">  
  <ul><li>Parameter files<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></ul>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,optionfilegnuplot,optionfilegnuplot);  
   
    fprintf(fichtm,"<ul><li>Result files (first order: no variance)<br>\n     fprintf(fichtm,"<ul><li>Result files (first order: no variance)<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   - 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
  - Estimated transition probabilities over %d (stepm) months: <a href=\"pij%s\">pij%s</a><br>\n   - Estimated transition probabilities over %d (stepm) months: <a href=\"pij%s\">pij%s</a><br>\n
Line 2187  interval) in state (%d): v%s%d%d.png <br Line 2284  interval) in state (%d): v%s%d%d.png <br
      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.png<br>  health expectancies in states (1) and (2): e%s%d.png<br>
 <img src=\"e%s%d.png\">",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);  <img src=\"e%s%d.png\">",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);
 fprintf(fichtm,"\n</body>");  
    }     }
  }   }
 fclose(fichtm);  fclose(fichtm);
 }  }
   
 /******************* Gnuplot file **************/  /******************* Gnuplot file **************/
 void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){  void printinggnuplot(char fileres[], 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;    int ng;
   strcpy(optionfilegnuplot,optionfilefiname);    if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) {
   strcat(optionfilegnuplot,".gp");  
   if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {  
     printf("Problem with file %s",optionfilegnuplot);      printf("Problem with file %s",optionfilegnuplot);
   }    }
   
Line 2379  fprintf(ficgp,"\" t \"e%d1\" w l",cpt); Line 2473  fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
        }         }
      }       }
    }     }
    fclose(ficgp);     fclose(ficgp);
 }  /* end gnuplot */  }  /* end gnuplot */
   
   
Line 2679  int main(int argc, char *argv[]) Line 2773  int main(int argc, char *argv[])
   double ***p3mat;    double ***p3mat;
   int *indx;    int *indx;
   char line[MAXLINE], linepar[MAXLINE];    char line[MAXLINE], linepar[MAXLINE];
   char title[MAXLINE];  
   char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH];  
   char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH];  
    
   char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH];  
   
   char filerest[FILENAMELENGTH];  
   char fileregp[FILENAMELENGTH];  
   char popfile[FILENAMELENGTH];  
   char path[80],pathc[80],pathcd[80],pathtot[80],model[20];    char path[80],pathc[80],pathcd[80],pathtot[80],model[20];
   int firstobs=1, lastobs=10;    int firstobs=1, lastobs=10;
   int sdeb, sfin; /* Status at beginning and end */    int sdeb, sfin; /* Status at beginning and end */
Line 2715  int main(int argc, char *argv[]) Line 2800  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.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 3310  while((c=getc(ficpar))=='#' && c!= EOF){ Line 3394  while((c=getc(ficpar))=='#' && c!= EOF){
  freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);   freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);
   
 /*------------ gnuplot -------------*/  /*------------ gnuplot -------------*/
  printinggnuplot(fileres,optionfilefiname,optionfile,optionfilegnuplot, ageminpar,agemaxpar,fage, pathc,p);    strcpy(optionfilegnuplot,optionfilefiname);
     strcat(optionfilegnuplot,".gp");
     if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
       printf("Problem with file %s",optionfilegnuplot);
     }
     fclose(ficgp);
    printinggnuplot(fileres, ageminpar,agemaxpar,fage, pathc,p);
   /*--------- index.htm --------*/
   
     strcpy(optionfilehtm,optionfile);
     strcat(optionfilehtm,".htm");
     if((fichtm=fopen(optionfilehtm,"w"))==NULL)    {
       printf("Problem with %s \n",optionfilehtm), exit(0);
     }
   
     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
   \n
   Total number of observations=%d <br>\n
   Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n
   <hr  size=\"2\" color=\"#EC5E5E\">
    <ul><li>Parameter files<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></ul>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,optionfilegnuplot,optionfilegnuplot);
     fclose(fichtm);
   
    printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,jprev1,mprev1,anprev1,jprev2,mprev2,anprev2);
     
 /*------------ free_vector  -------------*/  /*------------ free_vector  -------------*/
  chdir(path);   chdir(path);
Line 3324  while((c=getc(ficpar))=='#' && c!= EOF){ Line 3434  while((c=getc(ficpar))=='#' && c!= EOF){
  fclose(ficparo);   fclose(ficparo);
  fclose(ficres);   fclose(ficres);
   
 /*--------- index.htm --------*/  
   
  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 --------------*/
     
   strcpy(filerespl,"pl");    strcpy(filerespl,"pl");
Line 3423  while((c=getc(ficpar))=='#' && c!= EOF){ Line 3529  while((c=getc(ficpar))=='#' && c!= EOF){
     }      }
   }    }
   
   varprob(fileres, matcov, p, delti, nlstate, (int) bage, (int) fage,k,Tvar,nbcode, ncodemax);    varprob(optionfilefiname, matcov, p, delti, nlstate, (int) bage, (int) fage,k,Tvar,nbcode, ncodemax);
   
   fclose(ficrespij);    fclose(ficrespij);
   
Line 3579  free_matrix(mint,1,maxwav,1,n); Line 3685  free_matrix(mint,1,maxwav,1,n);
   free_matrix(agev,1,maxwav,1,imx);    free_matrix(agev,1,maxwav,1,imx);
   free_ma3x(param,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel);    free_ma3x(param,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel);
   
     fprintf(fichtm,"\n</body>");
     fclose(fichtm);
     fclose(ficgp);
    
   
   if(erreur >0)    if(erreur >0)
     printf("End of Imach with error or warning %d\n",erreur);      printf("End of Imach with error or warning %d\n",erreur);
   else   printf("End of Imach\n");    else   printf("End of Imach\n");

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


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