Diff for /imach064/src/imach.c between versions 1.3 and 1.5

version 1.3, 2001/05/02 17:21:42 version 1.5, 2001/05/02 17:42:45
Line 51 Line 51
 #define FILENAMELENGTH 80  #define FILENAMELENGTH 80
 /*#define DEBUG*/  /*#define DEBUG*/
 #define windows  #define windows
   #define GLOCK_ERROR_NOPATH              -1      /* empty path */
   #define GLOCK_ERROR_GETCWD              -2      /* cannot get cwd */
   
   
   
 #define MAXPARM 30 /* Maximum number of parameters for the optimization */  #define MAXPARM 30 /* Maximum number of parameters for the optimization */
 #define NPARMAX 64 /* (nlstate+ndeath-1)*nlstate*ncovmodel */  #define NPARMAX 64 /* (nlstate+ndeath-1)*nlstate*ncovmodel */
Line 138  double ftol=FTOL; /* Tolerance for compu Line 142  double ftol=FTOL; /* Tolerance for compu
 double ftolhess; /* Tolerance for computing hessian */  double ftolhess; /* Tolerance for computing hessian */
   
   
   static  int split( char *path, char *dirc, char *name )
   {
      char *s;                             /* pointer */
      int  l1, l2;                         /* length counters */
   
      l1 = strlen( path );                 /* length of path */
      if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );
      s = strrchr( path, '\\' );           /* find last / */
      if ( s == NULL ) {                   /* no directory, so use current */
   #if     defined(__bsd__)                /* get current working directory */
         extern char       *getwd( );
   
         if ( getwd( dirc ) == NULL ) {
   #else
         extern char       *getcwd( );
   
         if ( getcwd( dirc, FILENAME_MAX ) == NULL ) {
   #endif
            return( GLOCK_ERROR_GETCWD );
         }
         strcpy( name, path );             /* we've got it */
      } else {                             /* strip direcotry from path */
         s++;                              /* after this, the filename */
         l2 = strlen( s );                 /* length of filename */
         if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH );
         strcpy( name, s );                /* save file name */
         strncpy( dirc, path, l1 - l2 );   /* now the directory */
         dirc[l1-l2] = 0;                  /* add zero */
      }
      l1 = strlen( dirc );                 /* length of directory */
      if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; }
      return( 0 );                         /* we're done */
   }
   
   
 /******************************************/  /******************************************/
   
 void replace(char *s, char*t)  void replace(char *s, char*t)
Line 1573  int main() Line 1612  int main()
   int sdeb, sfin; /* Status at beginning and end */    int sdeb, sfin; /* Status at beginning and end */
   int c,  h , cpt,l;    int c,  h , cpt,l;
   int ju,jl, mi;    int ju,jl, mi;
   int i1,j1, k1,jk,aa,bb, stepsize;    int i1,j1, k1,k2,k3,jk,aa,bb, stepsize;
   int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;    int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;
     
   int hstepm, nhstepm;    int hstepm, nhstepm;
Line 1591  int main() Line 1630  int main()
   double *epj, vepp;    double *epj, vepp;
   char version[80]="Imach version 62c, May 1999, INED-EUROREVES ";    char version[80]="Imach version 62c, May 1999, INED-EUROREVES ";
   char *alph[]={"a","a","b","c","d","e"}, str[4];    char *alph[]={"a","a","b","c","d","e"}, str[4];
   
   char z[1]="c", occ;    char z[1]="c", occ;
 #include <sys/time.h>  #include <sys/time.h>
 #include <time.h>  #include <time.h>
Line 1601  int main() Line 1641  int main()
   gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */    gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */
   
   
   printf("\nIMACH, Version 0.63");    printf("\nIMACH, Version 0.64a");
   printf("\nEnter the parameter file name: ");    printf("\nEnter the parameter file name: ");
   
 #ifdef windows  #ifdef windows
   scanf("%s",pathtot);    scanf("%s",pathtot);
   getcwd(pathcd, size);    getcwd(pathcd, size);
   cutv(path,optionfile,pathtot,'\\');    /*cygwin_split_path(pathtot,path,optionfile);
       printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/
     /* cutv(path,optionfile,pathtot,'\\');*/
   
   split(pathtot, path,optionfile);
   chdir(path);    chdir(path);
   replace(pathc,path);    replace(pathc,path);
 #endif  #endif
Line 1797  int main() Line 1841  int main()
         }          }
         num[i]=atol(stra);          num[i]=atol(stra);
   
         /*printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]),  (mint[2][i]), (anint[2][i]), (s[2][i]),  (mint[3][i]), (anint[3][i]), (s[3][i]),  (mint[4][i]), (anint[4][i]), (s[4][i]),  (mint[5][i]), (anint[5][i]), (s[5][i]),  (mint[6][i]), (anint[6][i]), (s[6][i]));*/          /*printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]),  (mint[2][i]), (anint[2][i]), (s[2][i]),  (mint[3][i]), (anint[3][i]), (s[3][i]),  (mint[4][i]), (anint[4][i]), (s[4][i]));*/
   
         i=i+1;          i=i+1;
       }        }
Line 1946  Tcode=ivector(1,100); Line 1990  Tcode=ivector(1,100);
        and prints on file fileres'p'. */         and prints on file fileres'p'. */
   freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax);    freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax);
   
   
   /*scanf("%d ",i);*/  
   
   
     pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */      pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
     oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */      oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
     newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */      newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
Line 2118  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2158  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
     
   /*3eme*/    /*3eme*/
   
    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*(cpt-1);        k=2+nlstate*(cpt-1);
       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",agemin,fage,fileres,k1-1,k1-1,k,cpt);        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",agemin,fage,fileres,k1-1,k1-1,k,cpt);
Line 2127  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2167  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
       }        }
       fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);        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",agemin,agemax,fileres,k1,k+cpt+1,k+1);        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",agemin,agemax,fileres,k1,k+cpt+1,k+1);
Line 2148  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2188  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
       fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);        fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);
     }      }
   }    }
    
   /* proba elementaires */    /* proba elementaires */
   for(i=1,jk=1; i <=nlstate; i++){     for(i=1,jk=1; i <=nlstate; i++){
     for(k=1; k <=(nlstate+ndeath); k++){      for(k=1; k <=(nlstate+ndeath); k++){
       if (k != i) {        if (k != i) {
         /*  fprintf(ficgp,"%1d%1d ",i,k);*/  
         for(j=1; j <=ncovmodel; j++){          for(j=1; j <=ncovmodel; j++){
           fprintf(ficgp,"%s%1d%1d=%f ",alph[j],i,k,p[jk]);            /*fprintf(ficgp,"%s%1d%1d=%f ",alph[j],i,k,p[jk]);*/
             /*fprintf(ficgp,"%s",alph[1]);*/
             fprintf(ficgp,"p%d=%f ",jk,p[jk]);
           jk++;            jk++;
           fprintf(ficgp,"\n");            fprintf(ficgp,"\n");
         }          }
       }        }
     }      }
   }      }
   
   for(jk=1; jk <=m; jk++) {    for(jk=1; jk <=m; jk++) {
   fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot  [%.f:%.f] ",agemin,agemax);    fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot  [%.f:%.f] ",agemin,agemax);
   for(i=1; i <=nlstate; i++) {     i=1;
     for(k=1; k <=(nlstate+ndeath); k++){     for(k2=1; k2<=nlstate; k2++) {
       if (k != i) {       k3=i;
         fprintf(ficgp," exp(a%d%d+b%d%d*x",i,k,i,k);       for(k=1; k<=(nlstate+ndeath); k++) {
          if (k != k2){
           fprintf(ficgp," exp(p%d+p%d*x",i,i+1);
   
         for(j=3; j <=ncovmodel; j++)          for(j=3; j <=ncovmodel; j++)
           fprintf(ficgp,"+%s%d%d*%d",alph[j],i,k,nbcode[Tvar[j-2]][codtab[jk][j-2]]);            fprintf(ficgp,"+p%d*%d",k2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);
         fprintf(ficgp,")/(1");          fprintf(ficgp,")/(1");
         for(k1=1; k1 <=(nlstate+ndeath); k1++)  
           if (k1 != i) {          for(k1=1; k1 <=nlstate+1; k1=k1+2){  
             fprintf(ficgp,"+exp(a%d%d+b%d%d*x",i,k1,i,k1);              fprintf(ficgp,"+exp(p%d+p%d*x",k1+k3-1,k1+k3);
   
             for(j=3; j <=ncovmodel; j++)              for(j=3; j <=ncovmodel; j++)
               fprintf(ficgp,"+%s%d%d*%d",alph[j],i,k,nbcode[Tvar[j-2]][codtab[jk][j-2]]);                fprintf(ficgp,"+p%d*%d",k2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);
             fprintf(ficgp,")");              fprintf(ficgp,")");
           }          }
         fprintf(ficgp,") t \"p%d%d\" ", i,k);          fprintf(ficgp,") t \"p%d%d\" ", k2,k);
       if ((i+k)!= (nlstate*2+ndeath)) fprintf(ficgp,",");          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);       }
   }    fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk);
       }
  fclose(ficgp);     
     fclose(ficgp);
     chdir(path);     
   chdir(path);
     free_matrix(agev,1,maxwav,1,imx);      free_matrix(agev,1,maxwav,1,imx);
     free_ivector(wav,1,imx);      free_ivector(wav,1,imx);
     free_imatrix(dh,1,lastpass-firstpass+1,1,imx);      free_imatrix(dh,1,lastpass-firstpass+1,1,imx);
Line 2219  fprintf(ficgp,"\nset out \"pe%s%d.gif\" Line 2266  fprintf(ficgp,"\nset out \"pe%s%d.gif\"
   }    }
   ungetc(c,ficpar);    ungetc(c,ficpar);
     
   
   fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);    fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);
   printf("agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax, bage, fage);    printf("agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax, bage, fage);
   fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);    fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);
Line 2229  fprintf(ficgp,"\nset out \"pe%s%d.gif\" Line 2275  fprintf(ficgp,"\nset out \"pe%s%d.gif\"
     printf("Problem with index.htm \n");goto end;      printf("Problem with index.htm \n");goto end;
   }    }
   
  fprintf(fichtm,"<body><ul> Imach, Version 0.63<hr> <li>Outputs files<br><br>\n   fprintf(fichtm,"<body><ul> Imach, Version 0.64a<hr> <li>Outputs files<br><br>\n
         - Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n          - Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n
 - Estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>  - Estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>
         - Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>          - Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>
Line 2268  interval) in state (%d): v%s%d%d.gif <br Line 2314  interval) in state (%d): v%s%d%d.gif <br
      }       }
      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.gif <br>
 <img src=\"ex%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);  <img src=\"exp%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);
      }       }
      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.gif<br>
Line 2456  fclose(fichtm); Line 2502  fclose(fichtm);
   fclose(ficrest);    fclose(ficrest);
   fclose(ficpar);    fclose(ficpar);
   free_vector(epj,1,nlstate+1);    free_vector(epj,1,nlstate+1);
   /*scanf("%d ",i); */    /*  scanf("%d ",i); */
   
   /*------- Variance limit prevalence------*/      /*------- Variance limit prevalence------*/  
   

Removed from v.1.3  
changed lines
  Added in v.1.5


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