--- imach/src/imach.c 2006/01/25 00:51:50 1.110 +++ imach/src/imach.c 2006/01/25 20:38:18 1.111 @@ -1,6 +1,11 @@ -/* $Id: imach.c,v 1.110 2006/01/25 00:51:50 brouard Exp $ +/* $Id: imach.c,v 1.111 2006/01/25 20:38:18 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + 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 (Module): Lots of cleaning and bugs added (Gompertz) @@ -284,11 +289,11 @@ extern int errno; #define ODIRSEPARATOR '/' #endif -/* $Id: imach.c,v 1.110 2006/01/25 00:51:50 brouard Exp $ */ +/* $Id: imach.c,v 1.111 2006/01/25 20:38:18 brouard Exp $ */ /* $State: Exp $ */ -char version[]="Imach version 0.98a, January 2006, INED-EUROREVES "; -char fullversion[]="$Revision: 1.110 $ $Date: 2006/01/25 00:51:50 $"; +char version[]="Imach version 0.98b, January 2006, INED-EUROREVES "; +char fullversion[]="$Revision: 1.111 $ $Date: 2006/01/25 20:38:18 $"; int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ int nvar; int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; @@ -332,7 +337,7 @@ FILE *ficresvpl; char fileresvpl[FILENAMELENGTH]; char title[MAXLINE]; 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 command[FILENAMELENGTH]; int outcmd=0; @@ -2205,11 +2210,11 @@ void concatwav(int wav[], int **dh, int if(mi==0){ nbwarn++; 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; } 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 individuals */ @@ -4109,6 +4114,7 @@ int main(int argc, char *argv[]) int NDIM=2; char ca[32], cb[32], cc[32]; + char dummy[]=" "; /* FILE *fichtm; *//* Html File */ /* FILE *ficgp;*/ /*Gnuplot File */ struct stat info; @@ -4510,113 +4516,114 @@ int main(int argc, char *argv[]) i=1; 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; for(j=strlen(line); j>=0;j--){ /* Untabifies line */ - if(line[j] == '\t') - line[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 */ - if(line[0]=='#'){ - fprintf(ficlog,"Comment line\n%s\n",line); - printf("Comment line\n%s\n",line); - 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; + if(line[j] == '\t') + line[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 */ + if(line[0]=='#'){ + fprintf(ficlog,"Comment line\n%s\n",line); + printf("Comment line\n%s\n",line); + continue; + } - strcpy(line,stra); - 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 */ - + 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); + 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, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,j,maxwav); exit(1); } - andc[i]=(double) year; - moisdc[i]=(double) month; + s[j][i]=lval; + strcpy(line,stra); - - cutv(stra, strb,line,' '); + cutv(stra, strb,line,' '); if(iout=sscanf(strb,"%d/%d",&month, &year) != 0){ } - else if(iout=sscanf(strb,".") != 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\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); } - annais[i]=(double)(year); - moisnais[i]=(double)(month); + anint[j][i]= (double) year; + mint[j][i]= (double)month; 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,' '); 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); + 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); } - weight[i]=(double)(lval); - strcpy(line,stra); - - 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); + if(lval <-1 || lval >1){ + 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); } - 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; + 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 + 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 */ /* printf("ii=%d", ij); scanf("%d",i);*/ @@ -4981,7 +4988,7 @@ Interval (in months) between two waves: 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]);*/ @@ -5654,32 +5661,29 @@ Interval (in months) between two waves: /*------ End -----------*/ chdir(path); -#ifndef UNIX - /* strcpy(plotcmd,"\""); */ -#endif - strcpy(plotcmd,pathimach); /*strcat(plotcmd,CHARSEPARATOR);*/ - strcat(plotcmd,GNUPLOTPROGRAM); + sprintf(plotcmd,"gnuplot"); #ifndef UNIX - strcat(plotcmd,".exe"); - /* strcat(plotcmd,"\"");*/ + sprintf(plotcmd,"\"%swgnuplot.exe\"",pathimach); #endif - if(stat(plotcmd,&info)){ + if(!stat(plotcmd,&info)){ printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout); - } - -#ifndef UNIX - strcpy(plotcmd,"\""); -#endif - strcat(plotcmd,pathimach); - strcat(plotcmd,GNUPLOTPROGRAM); -#ifndef UNIX - strcat(plotcmd,".exe"); - strcat(plotcmd,"\""); + if(!stat(getenv("GNUPLOTBIN"),&info)){ + printf("Error gnuplot program not found: %s Environment GNUPLOTBIN not set.\n",plotcmd);fflush(stdout); + }else + strcpy(pplotcmd,plotcmd); +#ifdef UNIX + strcpy(plotcmd,GNUPLOTPROGRAM); + if(!stat(plotcmd,&info)){ + printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout); + }else + strcpy(pplotcmd,plotcmd); #endif - strcat(plotcmd," "); - strcat(plotcmd,optionfilegnuplot); - printf("Starting graphs with: %s",plotcmd);fflush(stdout); + }else + strcpy(pplotcmd,plotcmd); + + sprintf(plotcmd,"%s %s",pplotcmd, optionfilegnuplot); + printf("Starting graphs with: %s\n",plotcmd);fflush(stdout); if((outcmd=system(plotcmd)) != 0){ printf("\n Problem with gnuplot\n");