Diff for /imach/src/imach.c between versions 1.139 and 1.142

version 1.139, 2010/06/14 07:50:17 version 1.142, 2014/01/26 03:57:36
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.142  2014/01/26 03:57:36  brouard
     Summary: gnuplot changed plot w l 1 has to be changed to plot w l lt 2
   
     * imach.c (Module): Trying to merge old staffs together while being at Tokyo. Not tested...
   
     Revision 1.141  2014/01/26 02:42:01  brouard
     * imach.c (Module): Trying to merge old staffs together while being at Tokyo. Not tested...
   
     Revision 1.140  2011/09/02 10:37:54  brouard
     Summary: times.h is ok with mingw32 now.
   
   Revision 1.139  2010/06/14 07:50:17  brouard    Revision 1.139  2010/06/14 07:50:17  brouard
   After the theft of my laptop, I probably lost some lines of codes which were not uploaded to the CVS tree.    After the theft of my laptop, I probably lost some lines of codes which were not uploaded to the CVS tree.
   I remember having already fixed agemin agemax which are pointers now but not cvs saved.    I remember having already fixed agemin agemax which are pointers now but not cvs saved.
Line 388 Line 399
 #include <errno.h>  #include <errno.h>
 extern int errno;  extern int errno;
   
 /* #include <sys/time.h> */  #ifdef LINUX
 #include <time.h>  #include <time.h>
 #include "timeval.h"  #include "timeval.h"
   #else
   #include <sys/time.h>
   #endif
   
 #ifdef GSL  #ifdef GSL
 #include <gsl/gsl_errno.h>  #include <gsl/gsl_errno.h>
Line 400  extern int errno; Line 414  extern int errno;
 /* #include <libintl.h> */  /* #include <libintl.h> */
 /* #define _(String) gettext (String) */  /* #define _(String) gettext (String) */
   
 #define MAXLINE 256  #define MAXLINE 1024 /* Was 256. Overflow with 312 with 2 states and 4 covariates. Should be ok */
   
 #define GNUPLOTPROGRAM "gnuplot"  #define GNUPLOTPROGRAM "gnuplot"
 /*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/  /*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/
Line 434  extern int errno; Line 448  extern int errno;
 /* $Id$ */  /* $Id$ */
 /* $State$ */  /* $State$ */
   
 char version[]="Imach version 0.98m, April 2010, INED-EUROREVES-Institut de longevite ";  char version[]="Imach version 0.98nR, January 2014,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121)";
 char fullversion[]="$Revision$ $Date$";   char fullversion[]="$Revision$ $Date$"; 
 char strstart[80];  char strstart[80];
 char optionfilext[10], optionfilefiname[FILENAMELENGTH];  char optionfilext[10], optionfilefiname[FILENAMELENGTH];
Line 558  double dateintmean=0; Line 572  double dateintmean=0;
   
 double *weight;  double *weight;
 int **s; /* Status */  int **s; /* Status */
 double *agedc, **covar, idx;  double *agedc;
 int **nbcode, *Tvar, **codtab, **Tvard, *Tprod, cptcovprod, *Tvaraff;  double  **covar; /**< covar[i,j], value of jth covariate for individual i,
                     * covar=matrix(0,NCOVMAX,1,n); 
                     * cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2]; */
   double  idx; 
   int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */
   int **codtab; /**< codtab=imatrix(1,100,1,10); */
   int **Tvard, *Tprod, cptcovprod, *Tvaraff;
 double *lsurv, *lpop, *tpop;  double *lsurv, *lpop, *tpop;
   
 double ftol=FTOL; /* Tolerance for computing Max Likelihood */  double ftol=FTOL; /* Tolerance for computing Max Likelihood */
Line 1090  char *asc_diff_time(long time_sec, char Line 1110  char *asc_diff_time(long time_sec, char
   sec_left = (sec_left) %(60*60);    sec_left = (sec_left) %(60*60);
   minutes = (sec_left) /60;    minutes = (sec_left) /60;
   sec_left = (sec_left) % (60);    sec_left = (sec_left) % (60);
   sprintf(ascdiff,"%d day(s) %d hour(s) %d minute(s) %d second(s)",days, hours, minutes, sec_left);      sprintf(ascdiff,"%ld day(s) %ld hour(s) %ld minute(s) %ld second(s)",days, hours, minutes, sec_left);  
   return ascdiff;    return ascdiff;
 }  }
   
Line 1280  double **prevalim(double **prlim, int nl Line 1300  double **prevalim(double **prlim, int nl
     /*printf("ij=%d cptcovprod=%d tvar=%d ", ij, cptcovprod, Tvar[1]);*/      /*printf("ij=%d cptcovprod=%d tvar=%d ", ij, cptcovprod, Tvar[1]);*/
     /*printf("ij=%d cov[3]=%lf cov[4]=%lf \n",ij, cov[3],cov[4]);*/      /*printf("ij=%d cov[3]=%lf cov[4]=%lf \n",ij, cov[3],cov[4]);*/
     /*printf("ij=%d cov[3]=%lf \n",ij, cov[3]);*/      /*printf("ij=%d cov[3]=%lf \n",ij, cov[3]);*/
     out=matprod2(newm, pmij(pmmij,cov,ncovmodel,x,nlstate),1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm);      out=matprod2(newm, pmij(pmmij,cov,ncovmodel,x,nlstate),1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm); /* Bug Valgrind */
           
     savm=oldm;      savm=oldm;
     oldm=newm;      oldm=newm;
Line 1796  double funcone( double *x) Line 1816  double funcone( double *x)
       ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;        ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
       /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */        /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */
       if(globpr){        if(globpr){
         fprintf(ficresilk,"%9d %6d %2d %2d %1d %1d %3d %11.6f %8.4f\          fprintf(ficresilk,"%9ld %6d %2d %2d %1d %1d %3d %11.6f %8.4f\
  %11.6f %11.6f %11.6f ", \   %11.6f %11.6f %11.6f ", \
                 num[i],i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],                  num[i],i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],
                 2*weight[i]*lli,out[s1][s2],savm[s1][s2]);                  2*weight[i]*lli,out[s1][s2],savm[s1][s2]);
Line 2538  void  concatwav(int wav[], int **dh, int Line 2558  void  concatwav(int wav[], int **dh, int
   }    }
   jmean=sum/k;    jmean=sum/k;
   printf("Delay (in months) between two waves Min=%d (for indiviudal %ld) Max=%d (%ld) Mean=%f\n\n ",jmin, num[ijmin], jmax, num[ijmax], jmean);    printf("Delay (in months) between two waves Min=%d (for indiviudal %ld) Max=%d (%ld) Mean=%f\n\n ",jmin, num[ijmin], jmax, num[ijmax], jmean);
   fprintf(ficlog,"Delay (in months) between two waves Min=%d (for indiviudal %ld) Max=%d (%ld) Mean=%f\n\n ",jmin, ijmin, jmax, ijmax, jmean);    fprintf(ficlog,"Delay (in months) between two waves Min=%d (for indiviudal %d) Max=%d (%d) Mean=%f\n\n ",jmin, ijmin, jmax, ijmax, jmean);
  }   }
   
 /*********** Tricode ****************************/  /*********** Tricode ****************************/
Line 3210  void varevsij(char optionfilefiname[], d Line 3230  void varevsij(char optionfilefiname[], d
 /*   fprintf(ficgp,"\n plot \"%s\"  u 1:($3*%6.3f) not w l 1 ",fileresprobmorprev,YEARM/estepm); */  /*   fprintf(ficgp,"\n plot \"%s\"  u 1:($3*%6.3f) not w l 1 ",fileresprobmorprev,YEARM/estepm); */
 /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)*%6.3f) t \"95\%% interval\" w l 2 ",fileresprobmorprev,YEARM/estepm); */  /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)*%6.3f) t \"95\%% interval\" w l 2 ",fileresprobmorprev,YEARM/estepm); */
 /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)*%6.3f) not w l 2 ",fileresprobmorprev,YEARM/estepm); */  /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)*%6.3f) not w l 2 ",fileresprobmorprev,YEARM/estepm); */
   fprintf(ficgp,"\n plot \"%s\"  u 1:($3) not w l 1 ",subdirf(fileresprobmorprev));    fprintf(ficgp,"\n plot \"%s\"  u 1:($3) not w l lt 2 ",subdirf(fileresprobmorprev));
   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)) t \"95\%% interval\" w l 2 ",subdirf(fileresprobmorprev));    fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)) t \"95\%% interval\" w l lt 3 ",subdirf(fileresprobmorprev));
   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)) not w l 2 ",subdirf(fileresprobmorprev));    fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)) not w l lt 3 ",subdirf(fileresprobmorprev));
   fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",subdirf(fileresprobmorprev),subdirf(fileresprobmorprev));    fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",subdirf(fileresprobmorprev),subdirf(fileresprobmorprev));
   fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"%s%s.png\"> <br>\n", estepm,subdirf3(optionfilefiname,"varmuptjgr",digitp),digit);    fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"%s%s.png\"> <br>\n", estepm,subdirf3(optionfilefiname,"varmuptjgr",digitp),digit);
   /*  fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months and then divided by estepm and multiplied by %.0f in order to have the probability to die over a year <br> <img src=\"varmuptjgr%s%s.png\"> <br>\n", stepm,YEARM,digitp,digit);    /*  fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months and then divided by estepm and multiplied by %.0f in order to have the probability to die over a year <br> <img src=\"varmuptjgr%s%s.png\"> <br>\n", stepm,YEARM,digitp,digit);
Line 3807  plot [%.f:%.f] \"%s\" every :::%d::%d u Line 3827  plot [%.f:%.f] \"%s\" every :::%d::%d u
        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 0,\"%s\" every :::%d::%d u 1:($2+1.96*$3) \"\%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1);       fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 1,\"%s\" every :::%d::%d u 1:($2+1.96*$3) \"\%%lf",subdirf2(fileres,"vpl"),k1-1,k1-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\"95\%% CI\" w l 1,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"\%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1);        fprintf(ficgp,"\" t\"95\%% CI\" w l lt 2,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"\%%lf",subdirf2(fileres,"vpl"),k1-1,k1-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\"\" w l 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l 2",subdirf2(fileres,"p"),k1-1,k1-1,2+4*(cpt-1));       fprintf(ficgp,"\" t\"\" w l lt 2,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l lt 3",subdirf2(fileres,"p"),k1-1,k1-1,2+4*(cpt-1));
    }     }
   }    }
   /*2 eme*/    /*2 eme*/
Line 3840  plot [%.f:%.f] \"%s\" every :::%d::%d u Line 3860  plot [%.f:%.f] \"%s\" every :::%d::%d u
         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 0,");        fprintf(ficgp,"\" t\"\" w l lt 1,");
       fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2+$3*2) \"\%%lf",subdirf2(fileres,"t"),k1-1,k1-1);        fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2+$3*2) \"\%%lf",subdirf2(fileres,"t"),k1-1,k1-1);
       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== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l 0");        if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l lt 1");
       else fprintf(ficgp,"\" t\"\" w l 0,");        else fprintf(ficgp,"\" t\"\" w l lt 1,");
     }      }
   }    }
       
Line 3932  plot [%.f:%.f] \"%s\" u ($1==%d ? ($3):1 Line 3952  plot [%.f:%.f] \"%s\" u ($1==%d ? ($3):1
                fprintf(ficgp," %f*exp(p%d+p%d*x",YEARM/stepm,i,i+1);                 fprintf(ficgp," %f*exp(p%d+p%d*x",YEARM/stepm,i,i+1);
              else               else
                fprintf(ficgp," exp(p%d+p%d*x",i,i+1);                 fprintf(ficgp," exp(p%d+p%d*x",i,i+1);
              ij=1;               ij=1;/* To be checked else nbcode[0][0] wrong */
              for(j=3; j <=ncovmodel; j++) {               for(j=3; j <=ncovmodel; j++) {
                if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {                 if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) { /* Bug valgrind */
                  fprintf(ficgp,"+p%d*%d*x",i+j-1,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);                   fprintf(ficgp,"+p%d*%d*x",i+j-1,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);
                  ij++;                   ij++;
                }                 }
Line 4604  int readdata(char datafile[], int firsto Line 4624  int readdata(char datafile[], int firsto
         lval=strtol(strb,&endptr,10);           lval=strtol(strb,&endptr,10); 
       /*        if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/        /*        if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/
         if( strb[0]=='\0' || (*endptr != '\0')){          if( strb[0]=='\0' || (*endptr != '\0')){
           printf("Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);            printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);
           fprintf(ficlog,"Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);fflush(ficlog);            fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);fflush(ficlog);
           return 1;            return 1;
         }          }
       }        }
Line 4619  int readdata(char datafile[], int firsto Line 4639  int readdata(char datafile[], int firsto
         month=99;          month=99;
         year=9999;          year=9999;
       }else{        }else{
         printf("Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of interview (mm/yyyy or .) at wave %d.  Exiting.\n",strb, linei,i, line,j);          printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of interview (mm/yyyy or .) at wave %d.  Exiting.\n",strb, linei,i, line,j);
         fprintf(ficlog,"Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of interview (mm/yyyy or .) at wave %d.  Exiting.\n",strb, linei,i, line,j);fflush(ficlog);          fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of interview (mm/yyyy or .) at wave %d.  Exiting.\n",strb, linei,i, line,j);fflush(ficlog);
         return 1;          return 1;
       }        }
       anint[j][i]= (double) year;         anint[j][i]= (double) year; 
Line 4635  int readdata(char datafile[], int firsto Line 4655  int readdata(char datafile[], int firsto
       month=99;        month=99;
       year=9999;        year=9999;
     }else{      }else{
       printf("Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of death (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);        printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of death (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);
         fprintf(ficlog,"Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of death (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);fflush(ficlog);          fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of death (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);fflush(ficlog);
         return 1;          return 1;
     }      }
     andc[i]=(double) year;       andc[i]=(double) year; 
Line 4650  int readdata(char datafile[], int firsto Line 4670  int readdata(char datafile[], int firsto
       month=99;        month=99;
       year=9999;        year=9999;
     }else{      }else{
       printf("Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of birth (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);        printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of birth (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);
       fprintf(ficlog,"Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of birth (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);fflush(ficlog);        fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of birth (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);fflush(ficlog);
         return 1;          return 1;
     }      }
     if (year==9999) {      if (year==9999) {
       printf("Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of birth (mm/yyyy) but at least the year of birth should be given.  Exiting.\n",strb, linei,i,line);        printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of birth (mm/yyyy) but at least the year of birth should be given.  Exiting.\n",strb, linei,i,line);
       fprintf(ficlog,"Error reading data around '%s' at line number %ld for individual %d, '%s'\nShould be a date of birth (mm/yyyy) but at least the year of birth should be given. Exiting.\n",strb, linei,i,line);fflush(ficlog);        fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of birth (mm/yyyy) but at least the year of birth should be given. Exiting.\n",strb, linei,i,line);fflush(ficlog);
         return 1;          return 1;
   
     }      }
Line 4668  int readdata(char datafile[], int firsto Line 4688  int readdata(char datafile[], int firsto
     errno=0;      errno=0;
     dval=strtod(strb,&endptr);       dval=strtod(strb,&endptr); 
     if( strb[0]=='\0' || (*endptr != '\0')){      if( strb[0]=='\0' || (*endptr != '\0')){
       printf("Error reading data around '%f' at line number %ld, \"%s\" for individual %d\nShould be a weight.  Exiting.\n",dval, i,line,linei);        printf("Error reading data around '%f' at line number %d, \"%s\" for individual %d\nShould be a weight.  Exiting.\n",dval, i,line,linei);
       fprintf(ficlog,"Error reading data around '%f' at line number %ld, \"%s\" for individual %d\nShould be a weight.  Exiting.\n",dval, i,line,linei);        fprintf(ficlog,"Error reading data around '%f' at line number %d, \"%s\" for individual %d\nShould be a weight.  Exiting.\n",dval, i,line,linei);
       fflush(ficlog);        fflush(ficlog);
       return 1;        return 1;
     }      }
Line 4684  int readdata(char datafile[], int firsto Line 4704  int readdata(char datafile[], int firsto
         errno=0;          errno=0;
         lval=strtol(strb,&endptr,10);           lval=strtol(strb,&endptr,10); 
         if( strb[0]=='\0' || (*endptr != '\0')){          if( strb[0]=='\0' || (*endptr != '\0')){
           printf("Error reading data around '%d' at line number %ld for individual %d, '%s'\nShould be a covariate value (=0 for the reference or 1 for alternative).  Exiting.\n",lval, linei,i, line);            printf("Error reading data around '%ld' at line number %d for individual %d, '%s'\nShould be a covariate value (=0 for the reference or 1 for alternative).  Exiting.\n",lval, linei,i, line);
           fprintf(ficlog,"Error reading data around '%d' at line number %ld for individual %d, '%s'\nShould be a covariate value (=0 for the reference or 1 for alternative).  Exiting.\n",lval, linei,i, line);fflush(ficlog);            fprintf(ficlog,"Error reading data around '%ld' at line number %d for individual %d, '%s'\nShould be a covariate value (=0 for the reference or 1 for alternative).  Exiting.\n",lval, linei,i, line);fflush(ficlog);
           return 1;            return 1;
         }          }
       }        }
       if(lval <-1 || lval >1){        if(lval <-1 || lval >1){
         printf("Error reading data around '%d' at line number %ld for individual %d, '%s'\n \          printf("Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
  Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \   Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \
  for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \   for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \
  For example, for multinomial values like 1, 2 and 3,\n \   For example, for multinomial values like 1, 2 and 3,\n \
Line 4699  int readdata(char datafile[], int firsto Line 4719  int readdata(char datafile[], int firsto
  and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \   and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \
  output of IMaCh is often meaningless.\n \   output of IMaCh is often meaningless.\n \
  Exiting.\n",lval,linei, i,line,j);   Exiting.\n",lval,linei, i,line,j);
         fprintf(ficlog,"Error reading data around '%d' at line number %ld for individual %d, '%s'\n \          fprintf(ficlog,"Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
  Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \   Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \
  for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \   for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \
  For example, for multinomial values like 1, 2 and 3,\n \   For example, for multinomial values like 1, 2 and 3,\n \
Line 4761  int decodemodel ( char model[], int last Line 4781  int decodemodel ( char model[], int last
       fprintf(ficlog,"Error. AGE must be in lower case model=%s ",model);fflush(ficlog);        fprintf(ficlog,"Error. AGE must be in lower case model=%s ",model);fflush(ficlog);
       return 1;        return 1;
     }      }
       if (strstr(model,"v") !=0){
         printf("Error. 'v' must be in upper case 'V' model=%s ",model);
         fprintf(ficlog,"Error. 'v' must be in upper case model=%s ",model);fflush(ficlog);
         return 1;
       }
           
     /* This loop fills the array Tvar from the string 'model'.*/      /* This loop fills the array Tvar from the string 'model'.*/
     /* j is the number of + signs in the model V1+V2+V3 j=2 i=3 to 1 */      /* j is the number of + signs in the model V1+V2+V3 j=2 i=3 to 1 */
Line 5157  int main(int argc, char *argv[]) Line 5182  int main(int argc, char *argv[])
     ungetc(c,ficpar);      ungetc(c,ficpar);
     fgets(line, MAXLINE, ficpar);      fgets(line, MAXLINE, ficpar);
     numlinepar++;      numlinepar++;
     puts(line);      fputs(line,stdout);
     fputs(line,ficparo);      fputs(line,ficparo);
     fputs(line,ficlog);      fputs(line,ficlog);
   }    }
Line 5173  int main(int argc, char *argv[]) Line 5198  int main(int argc, char *argv[])
     ungetc(c,ficpar);      ungetc(c,ficpar);
     fgets(line, MAXLINE, ficpar);      fgets(line, MAXLINE, ficpar);
     numlinepar++;      numlinepar++;
     puts(line);      fputs(line, stdout);
       //puts(line);
     fputs(line,ficparo);      fputs(line,ficparo);
     fputs(line,ficlog);      fputs(line,ficlog);
   }    }
Line 5226  int main(int argc, char *argv[]) Line 5252  int main(int argc, char *argv[])
       ungetc(c,ficpar);        ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);        fgets(line, MAXLINE, ficpar);
       numlinepar++;        numlinepar++;
       puts(line);        fputs(line,stdout);
       fputs(line,ficparo);        fputs(line,ficparo);
       fputs(line,ficlog);        fputs(line,ficlog);
     }      }
Line 5276  run imach with mle=-1 to get a correct t Line 5302  run imach with mle=-1 to get a correct t
       ungetc(c,ficpar);        ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);        fgets(line, MAXLINE, ficpar);
       numlinepar++;        numlinepar++;
       puts(line);        fputs(line,stdout);
       fputs(line,ficparo);        fputs(line,ficparo);
       fputs(line,ficlog);        fputs(line,ficlog);
     }      }
Line 5317  run imach with mle=-1 to get a correct t Line 5343  run imach with mle=-1 to get a correct t
       ungetc(c,ficpar);        ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);        fgets(line, MAXLINE, ficpar);
       numlinepar++;        numlinepar++;
       puts(line);        fputs(line,stdout);
       fputs(line,ficparo);        fputs(line,ficparo);
       fputs(line,ficlog);        fputs(line,ficlog);
     }      }
Line 5408  run imach with mle=-1 to get a correct t Line 5434  run imach with mle=-1 to get a correct t
     ncovcol + k1      ncovcol + k1
     If already ncovcol=4 and model=V2+V1+V1*V4+age*V3      If already ncovcol=4 and model=V2+V1+V1*V4+age*V3
     Tvar[3=V1*V4]=4+1 etc */      Tvar[3=V1*V4]=4+1 etc */
   Tprod=ivector(1,15);     Tprod=ivector(1,15); /* Gives the position of a product */
   /* Tprod[k1=1]=3(=V1*V4) for V2+V1+V1*V4+age*V3    /* Tprod[k1=1]=3(=V1*V4) for V2+V1+V1*V4+age*V3
      if  V2+V1+V1*V4+age*V3+V3*V2   TProd[k1=2]=5 (V3*V2)       if  V2+V1+V1*V4+age*V3+V3*V2   TProd[k1=2]=5 (V3*V2)
   */    */
   Tvaraff=ivector(1,15);     Tvaraff=ivector(1,15); 
   Tvard=imatrix(1,15,1,2); /* For V3*V2 Tvard[k1=2][1]=3 (V3) Tvard[k1=2][2]=2(V2) */    Tvard=imatrix(1,15,1,2); /* n=Tvard[k1][1]  and m=Tvard[k1][2] gives the couple n,m of the k1 th product Vn*Vm
                               * For V3*V2 (in V2+V1+V1*V4+age*V3+V3*V2), V3*V2 position is 2nd. 
                               * Tvard[k1=2][1]=3 (V3) Tvard[k1=2][2]=2(V2) */
   Tage=ivector(1,15); /* Gives the covariate id of covariates associated with age: V2 + V1 + age*V4 + V3*age    Tage=ivector(1,15); /* Gives the covariate id of covariates associated with age: V2 + V1 + age*V4 + V3*age
                          4 covariates (3 plus signs)                           4 covariates (3 plus signs)
                          Tage[1=V3*age]= 4; Tage[2=age*V4] = 3                           Tage[1=V3*age]= 4; Tage[2=age*V4] = 3
Line 5472  run imach with mle=-1 to get a correct t Line 5500  run imach with mle=-1 to get a correct t
       for(j=1; j <= ncodemax[k]; j++){ /* For each modality of this covariate */        for(j=1; j <= ncodemax[k]; j++){ /* For each modality of this covariate */
         for(cpt=1; cpt <=(m/pow(2,cptcoveff+1-k)); cpt++){  /* cpt=1 to 8/2**(3+1-1 or 3+1-3) =1 or 4 */           for(cpt=1; cpt <=(m/pow(2,cptcoveff+1-k)); cpt++){  /* cpt=1 to 8/2**(3+1-1 or 3+1-3) =1 or 4 */ 
           h++;            h++;
           if (h>m) {            if (h>m) 
             h=1;              h=1;
             codtab[h][k]=j;            codtab[h][k]=j;
             codtab[h][Tvar[k]]=j;            codtab[h][Tvar[k]]=j;
           }  
           printf("h=%d k=%d j=%d codtab[h][k]=%d Tvar[k]=%d codtab[h][Tvar[k]]=%d \n",h, k,j,codtab[h][k],Tvar[k],codtab[h][Tvar[k]]);            printf("h=%d k=%d j=%d codtab[h][k]=%d Tvar[k]=%d codtab[h][Tvar[k]]=%d \n",h, k,j,codtab[h][k],Tvar[k],codtab[h][Tvar[k]]);
         }           } 
       }        }
Line 5504  run imach with mle=-1 to get a correct t Line 5531  run imach with mle=-1 to get a correct t
   else{    else{
     fprintf(ficgp,"\n# %s\n", version);       fprintf(ficgp,"\n# %s\n", version); 
     fprintf(ficgp,"# %s\n", optionfilegnuplot);       fprintf(ficgp,"# %s\n", optionfilegnuplot); 
     fprintf(ficgp,"set missing 'NaNq'\n");      //fprintf(ficgp,"set missing 'NaNq'\n");
       fprintf(ficgp,"set datafile missing 'NaNq'\n");
   }    }
   /*  fclose(ficgp);*/    /*  fclose(ficgp);*/
   /*--------- index.htm --------*/    /*--------- index.htm --------*/
Line 5943  Interval (in months) between two waves: Line 5971  Interval (in months) between two waves:
     while((c=getc(ficpar))=='#' && c!= EOF){      while((c=getc(ficpar))=='#' && c!= EOF){
       ungetc(c,ficpar);        ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);        fgets(line, MAXLINE, ficpar);
       puts(line);        fputs(line,stdout);
       fputs(line,ficparo);        fputs(line,ficparo);
     }      }
     ungetc(c,ficpar);      ungetc(c,ficpar);
Line 5963  Interval (in months) between two waves: Line 5991  Interval (in months) between two waves:
     while((c=getc(ficpar))=='#' && c!= EOF){      while((c=getc(ficpar))=='#' && c!= EOF){
       ungetc(c,ficpar);        ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);        fgets(line, MAXLINE, ficpar);
       puts(line);        fputs(line,stdout);
       fputs(line,ficparo);        fputs(line,ficparo);
     }      }
     ungetc(c,ficpar);      ungetc(c,ficpar);
Line 5977  Interval (in months) between two waves: Line 6005  Interval (in months) between two waves:
     while((c=getc(ficpar))=='#' && c!= EOF){      while((c=getc(ficpar))=='#' && c!= EOF){
       ungetc(c,ficpar);        ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);        fgets(line, MAXLINE, ficpar);
       puts(line);        fputs(line,stdout);
       fputs(line,ficparo);        fputs(line,ficparo);
     }      }
     ungetc(c,ficpar);      ungetc(c,ficpar);
Line 5993  Interval (in months) between two waves: Line 6021  Interval (in months) between two waves:
     while((c=getc(ficpar))=='#' && c!= EOF){      while((c=getc(ficpar))=='#' && c!= EOF){
       ungetc(c,ficpar);        ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);        fgets(line, MAXLINE, ficpar);
       puts(line);        fputs(line,stdout);
       fputs(line,ficparo);        fputs(line,ficparo);
     }      }
     ungetc(c,ficpar);      ungetc(c,ficpar);
Line 6370  Interval (in months) between two waves: Line 6398  Interval (in months) between two waves:
     /*---------- End : free ----------------*/      /*---------- End : free ----------------*/
     if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);      if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
     free_ma3x(probs,1,AGESUP,1,NCOVMAX, 1,NCOVMAX);      free_ma3x(probs,1,AGESUP,1,NCOVMAX, 1,NCOVMAX);
   
   }  /* mle==-3 arrives here for freeing */    }  /* mle==-3 arrives here for freeing */
  endfree:   endfree:
   free_matrix(prlim,1,nlstate,1,nlstate);      free_matrix(prlim,1,nlstate,1,nlstate); /*here or after loop ? */
     free_matrix(pmmij,1,nlstate+ndeath,1,nlstate+ndeath);      free_matrix(pmmij,1,nlstate+ndeath,1,nlstate+ndeath);
     free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);      free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);
     free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath);      free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath);
Line 6414  Interval (in months) between two waves: Line 6441  Interval (in months) between two waves:
   fprintf(ficlog,"Local time at start %s\nLocal time at end   %s\n",strstart, strtend);     fprintf(ficlog,"Local time at start %s\nLocal time at end   %s\n",strstart, strtend); 
   printf("Total time used %s\n", asc_diff_time(end_time.tv_sec -start_time.tv_sec,tmpout));    printf("Total time used %s\n", asc_diff_time(end_time.tv_sec -start_time.tv_sec,tmpout));
   
   printf("Total time was %d Sec.\n", end_time.tv_sec -start_time.tv_sec);    printf("Total time was %ld Sec.\n", end_time.tv_sec -start_time.tv_sec);
   fprintf(ficlog,"Total time used %s\n", asc_diff_time(end_time.tv_sec -start_time.tv_sec,tmpout));    fprintf(ficlog,"Total time used %s\n", asc_diff_time(end_time.tv_sec -start_time.tv_sec,tmpout));
   fprintf(ficlog,"Total time was %d Sec.\n", end_time.tv_sec -start_time.tv_sec);    fprintf(ficlog,"Total time was %ld Sec.\n", end_time.tv_sec -start_time.tv_sec);
   /*  printf("Total time was %d uSec.\n", total_usecs);*/    /*  printf("Total time was %d uSec.\n", total_usecs);*/
 /*   if(fileappend(fichtm,optionfilehtm)){ */  /*   if(fileappend(fichtm,optionfilehtm)){ */
   fprintf(fichtm,"<br>Local time at start %s<br>Local time at end   %s<br>\n</body></html>",strstart, strtend);    fprintf(fichtm,"<br>Local time at start %s<br>Local time at end   %s<br>\n</body></html>",strstart, strtend);

Removed from v.1.139  
changed lines
  Added in v.1.142


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