Diff for /imach/src/imach.c between versions 1.110 and 1.111

version 1.110, 2006/01/25 00:51:50 version 1.111, 2006/01/25 20:38:18
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.111  2006/01/25 20:38:18  brouard
     (Module): Lots of cleaning and bugs added (Gompertz)
     (Module): Comments can be added in data file. Missing date values
     can be a simple dot '.'.
   
   Revision 1.110  2006/01/25 00:51:50  brouard    Revision 1.110  2006/01/25 00:51:50  brouard
   (Module): Lots of cleaning and bugs added (Gompertz)    (Module): Lots of cleaning and bugs added (Gompertz)
   
Line 287  extern int errno; Line 292  extern int errno;
 /* $Id$ */  /* $Id$ */
 /* $State$ */  /* $State$ */
   
 char version[]="Imach version 0.98a, January 2006, INED-EUROREVES ";  char version[]="Imach version 0.98b, January 2006, INED-EUROREVES ";
 char fullversion[]="$Revision$ $Date$";   char fullversion[]="$Revision$ $Date$"; 
 int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings  */  int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings  */
 int nvar;  int nvar;
Line 332  FILE  *ficresvpl; Line 337  FILE  *ficresvpl;
 char fileresvpl[FILENAMELENGTH];  char fileresvpl[FILENAMELENGTH];
 char title[MAXLINE];  char title[MAXLINE];
 char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH];  char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH];
 char optionfilext[10], optionfilefiname[FILENAMELENGTH], plotcmd[FILENAMELENGTH];  char optionfilext[10], optionfilefiname[FILENAMELENGTH], plotcmd[FILENAMELENGTH], pplotcmd[FILENAMELENGTH];
 char tmpout[FILENAMELENGTH],  tmpout2[FILENAMELENGTH];   char tmpout[FILENAMELENGTH],  tmpout2[FILENAMELENGTH]; 
 char command[FILENAMELENGTH];  char command[FILENAMELENGTH];
 int  outcmd=0;  int  outcmd=0;
Line 2205  void  concatwav(int wav[], int **dh, int Line 2210  void  concatwav(int wav[], int **dh, int
     if(mi==0){      if(mi==0){
       nbwarn++;        nbwarn++;
       if(first==0){        if(first==0){
         printf("Warning! None valid information for:%ld line=%d (skipped) and may be others, see log file\n",num[i],i);          printf("Warning! No valid information for individual %ld line=%d (skipped) and may be others, see log file\n",num[i],i);
         first=1;          first=1;
       }        }
       if(first==1){        if(first==1){
         fprintf(ficlog,"Warning! None valid information for:%ld line=%d (skipped)\n",num[i],i);          fprintf(ficlog,"Warning! No valid information for individual %ld line=%d (skipped)\n",num[i],i);
       }        }
     } /* end mi==0 */      } /* end mi==0 */
   } /* End individuals */    } /* End individuals */
Line 4109  int main(int argc, char *argv[]) Line 4114  int main(int argc, char *argv[])
   int NDIM=2;    int NDIM=2;
   
   char ca[32], cb[32], cc[32];    char ca[32], cb[32], cc[32];
     char dummy[]="                         ";
   /*  FILE *fichtm; *//* Html File */    /*  FILE *fichtm; *//* Html File */
   /* FILE *ficgp;*/ /*Gnuplot File */    /* FILE *ficgp;*/ /*Gnuplot File */
   struct stat info;    struct stat info;
Line 4510  int main(int argc, char *argv[]) Line 4516  int main(int argc, char *argv[])
   
   i=1;    i=1;
   linei=0;    linei=0;
   while ((fgets(line, MAXLINE, fic) != NULL) &&((i >= firstobs) && (i <=lastobs)))    {    while ((fgets(line, MAXLINE, fic) != NULL) &&((i >= firstobs) && (i <=lastobs))) {
     linei=linei+1;      linei=linei+1;
     for(j=strlen(line); j>=0;j--){  /* Untabifies line */      for(j=strlen(line); j>=0;j--){  /* Untabifies line */
         if(line[j] == '\t')        if(line[j] == '\t')
           line[j] = ' ';          line[j] = ' ';
       }      }
       for(j=strlen(line)-1; (line[j]==' ')||(line[j]==10)||(line[j]==13);j--){      for(j=strlen(line)-1; (line[j]==' ')||(line[j]==10)||(line[j]==13);j--){
         ;        ;
       };      };
       line[j+1]=0;  /* Trims blanks at end of line */      line[j+1]=0;  /* Trims blanks at end of line */
       if(line[0]=='#'){      if(line[0]=='#'){
         fprintf(ficlog,"Comment line\n%s\n",line);        fprintf(ficlog,"Comment line\n%s\n",line);
         printf("Comment line\n%s\n",line);        printf("Comment line\n%s\n",line);
         continue;        continue;
       }      }
       for (j=maxwav;j>=1;j--){  
         cutv(stra, strb,line,' ');   
         errno=0;  
         lval=strtol(strb,&endptr,10);   
         /*      if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/  
         if( strb[0]=='\0' || (*endptr != '\0')){  
           printf("Error reading data around '%d' at line number %d %s for individual %d\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n",lval, i,line,linei,j,maxwav);  
           exit(1);  
         }  
         s[j][i]=lval;  
   
         strcpy(line,stra);      for (j=maxwav;j>=1;j--){
         cutv(stra, strb,line,' ');  
         if(iout=sscanf(strb,"%d/%d",&month, &year) != 0){  
         }  
         else  if(iout=sscanf(strb,".") != 0){  
           month=99;  
           year=9999;  
         }else{  
           printf("Error reading data around '%s'.at line number %ld %s for individual %d\nShould be a year of exam at wave %d.  Exiting.\n",strb, i,line,linei,j);  
           exit(1);  
         }  
         anint[j][i]= (double) year;   
         mint[j][i]= (double)month;   
         strcpy(line,stra);  
       } /* ENd Waves */  
           
       cutv(stra, strb,line,' ');         cutv(stra, strb,line,' '); 
       if(iout=sscanf(strb,"%d/%d",&month, &year) != 0){        errno=0;
       }        lval=strtol(strb,&endptr,10); 
       else  if(iout=sscanf(strb,".") != 0){        /*        if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/
         month=99;        if( strb[0]=='\0' || (*endptr != '\0')){
         year=9999;          printf("Error reading data around '%d' at line number %d %s 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);
       }else{  
         printf("Error reading data around '%s'.at line number %ld %s for individual %d\nShould be a year of exam at wave %d.  Exiting.\n",strb, i,line,linei,j);  
         exit(1);          exit(1);
       }        }
       andc[i]=(double) year;         s[j][i]=lval;
       moisdc[i]=(double) month;         
       strcpy(line,stra);        strcpy(line,stra);
         cutv(stra, strb,line,' ');
       cutv(stra, strb,line,' ');   
       if(iout=sscanf(strb,"%d/%d",&month, &year) != 0){        if(iout=sscanf(strb,"%d/%d",&month, &year) != 0){
       }        }
       else  if(iout=sscanf(strb,".") != 0){        else  if(iout=sscanf(strb,"%s.") != 0){
         month=99;          month=99;
         year=9999;          year=9999;
       }else{        }else{
         printf("Error reading data around '%s'.at line number %ld %s for individual %d\nShould be a year of exam at wave %d.  Exiting.\n",strb, i,line,linei,j);          printf("Error reading data around '%s' at line number %ld %s for individual %d, '%s'\nShould be a date of interview (mm/yyyy or .) at wave %d.  Exiting.\n",strb, linei,i, line,j);
         exit(1);          exit(1);
       }        }
       annais[i]=(double)(year);        anint[j][i]= (double) year; 
       moisnais[i]=(double)(month);         mint[j][i]= (double)month; 
       strcpy(line,stra);        strcpy(line,stra);
       } /* ENd Waves */
       
       cutv(stra, strb,line,' '); 
       if(iout=sscanf(strb,"%d/%d",&month, &year) != 0){
       }
       else  if(iout=sscanf(strb,"%s.",dummy) != 0){
         month=99;
         year=9999;
       }else{
         printf("Error reading data around '%s' at line number %ld %s for individual %d, '%s'\nShould be a date of death (mm/yyyy or .).  Exiting.\n",strb, linei,i,line);
         exit(1);
       }
       andc[i]=(double) year; 
       moisdc[i]=(double) month; 
       strcpy(line,stra);
       
       cutv(stra, strb,line,' '); 
       if(iout=sscanf(strb,"%d/%d",&month, &year) != 0){
       }
       else  if(iout=sscanf(strb,"%s.") != 0){
         month=99;
         year=9999;
       }else{
         printf("Error reading data around '%s' at line number %ld %s for individual %d, '%s'\nShould be a date of birth (mm/yyyy or .).  Exiting.\n",strb, linei,i,line,j);
         exit(1);
       }
       annais[i]=(double)(year);
       moisnais[i]=(double)(month); 
       strcpy(line,stra);
       
       cutv(stra, strb,line,' '); 
       errno=0;
       lval=strtol(strb,&endptr,10); 
       if( strb[0]=='\0' || (*endptr != '\0')){
         printf("Error reading data around '%d' at line number %ld %s for individual %d\nShould be a weight.  Exiting.\n",lval, i,line,linei);
         exit(1);
       }
       weight[i]=(double)(lval); 
       strcpy(line,stra);
       
       for (j=ncovcol;j>=1;j--){
       cutv(stra, strb,line,' ');         cutv(stra, strb,line,' '); 
       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 %s for individual %d\nShould be a weight.  Exiting.\n",lval, i,line,linei);          printf("Error reading data around '%d' at line number %ld %s for individual %d, '%s'\nShould be a covar (meaning 0 for the reference or 1).  Exiting.\n",lval, linei,i, line);
         exit(1);          exit(1);
       }        }
       weight[i]=(double)(lval);         if(lval <-1 || lval >1){
       strcpy(line,stra);          printf("Error reading data around '%d' at line number %ld %s for individual %d, '%s'\nShould be a value of the %d covar (meaning 0 for the reference or 1. IMaCh does not build design variables, do it your self).  Exiting.\n",lval,linei, i,line,j);
           exit(1);
       for (j=ncovcol;j>=1;j--){  
         cutv(stra, strb,line,' ');   
         errno=0;  
         lval=strtol(strb,&endptr,10);   
         if( strb[0]=='\0' || (*endptr != '\0')){  
           printf("Error reading data around '%d' at line number %ld %s for individual %d\nShould be a covar (meaning 0 for the reference or 1).  Exiting.\n",lval, i,line,linei);  
           exit(1);  
         }  
         if(lval <-1 || lval >1){  
           printf("Error reading data around '%d' at line number %ld %s for individual %d\nShould be a value of the %d covar (meaning 0 for the reference or 1. IMaCh does not build design variables, do it your self).  Exiting.\n",lval,i,line,linei,j);  
           exit(1);  
         }  
         covar[j][i]=(double)(lval);  
         strcpy(line,stra);  
       }   
       lstra=strlen(stra);  
   
       if(lstra > 9){ /* More than 2**32 or max of what printf can write with %ld */  
         stratrunc = &(stra[lstra-9]);  
         num[i]=atol(stratrunc);  
       }        }
       else        covar[j][i]=(double)(lval);
         num[i]=atol(stra);        strcpy(line,stra);
       /*if((s[2][i]==2) && (s[3][i]==-1)&&(s[4][i]==9)){      } 
         printf("%ld %.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])); ij=ij+1;}*/      lstra=strlen(stra);
       
       i=i+1;      if(lstra > 9){ /* More than 2**32 or max of what printf can write with %ld */
         stratrunc = &(stra[lstra-9]);
         num[i]=atol(stratrunc);
       }
       else
         num[i]=atol(stra);
       /*if((s[2][i]==2) && (s[3][i]==-1)&&(s[4][i]==9)){
         printf("%ld %.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])); ij=ij+1;}*/
       
       i=i+1;
   } /* End loop reading  data */    } /* End loop reading  data */
   /* printf("ii=%d", ij);    /* printf("ii=%d", ij);
      scanf("%d",i);*/       scanf("%d",i);*/
Line 4981  Interval (in months) between two waves: Line 4988  Interval (in months) between two waves:
         ximort[i][j]=(i == j ? 1.0 : 0.0);          ximort[i][j]=(i == j ? 1.0 : 0.0);
     }      }
           
     p[1]=0.1; p[NDIM]=0.1;      p[1]=0.0268; p[NDIM]=0.083;
     /*printf("%lf %lf", p[1], p[2]);*/      /*printf("%lf %lf", p[1], p[2]);*/
           
           
Line 5654  Interval (in months) between two waves: Line 5661  Interval (in months) between two waves:
   /*------ End -----------*/    /*------ End -----------*/
   
   chdir(path);    chdir(path);
 #ifndef UNIX  
   /*  strcpy(plotcmd,"\""); */  
 #endif  
   strcpy(plotcmd,pathimach);  
   /*strcat(plotcmd,CHARSEPARATOR);*/    /*strcat(plotcmd,CHARSEPARATOR);*/
   strcat(plotcmd,GNUPLOTPROGRAM);    sprintf(plotcmd,"gnuplot");
 #ifndef UNIX  #ifndef UNIX
   strcat(plotcmd,".exe");    sprintf(plotcmd,"\"%swgnuplot.exe\"",pathimach);
   /*  strcat(plotcmd,"\"");*/  
 #endif  #endif
   if(stat(plotcmd,&info)){    if(!stat(plotcmd,&info)){
     printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout);      printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout);
   }      if(!stat(getenv("GNUPLOTBIN"),&info)){
         printf("Error gnuplot program not found: %s Environment GNUPLOTBIN not set.\n",plotcmd);fflush(stdout);
 #ifndef UNIX      }else
   strcpy(plotcmd,"\"");        strcpy(pplotcmd,plotcmd);
 #endif  #ifdef UNIX
   strcat(plotcmd,pathimach);      strcpy(plotcmd,GNUPLOTPROGRAM);
   strcat(plotcmd,GNUPLOTPROGRAM);      if(!stat(plotcmd,&info)){
 #ifndef UNIX        printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout);
   strcat(plotcmd,".exe");      }else
   strcat(plotcmd,"\"");        strcpy(pplotcmd,plotcmd);
 #endif  #endif
   strcat(plotcmd," ");    }else
   strcat(plotcmd,optionfilegnuplot);      strcpy(pplotcmd,plotcmd);
   printf("Starting graphs with: %s",plotcmd);fflush(stdout);    
     sprintf(plotcmd,"%s %s",pplotcmd, optionfilegnuplot);
     printf("Starting graphs with: %s\n",plotcmd);fflush(stdout);
   
   if((outcmd=system(plotcmd)) != 0){    if((outcmd=system(plotcmd)) != 0){
     printf("\n Problem with gnuplot\n");      printf("\n Problem with gnuplot\n");

Removed from v.1.110  
changed lines
  Added in v.1.111


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