--- imach/src/imach.c 2006/01/19 16:20:37 1.107 +++ imach/src/imach.c 2006/01/24 19:37:15 1.109 @@ -1,6 +1,13 @@ -/* $Id: imach.c,v 1.107 2006/01/19 16:20:37 brouard Exp $ +/* $Id: imach.c,v 1.109 2006/01/24 19:37:15 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.109 2006/01/24 19:37:15 brouard + (Module): Comments (lines starting with a #) are allowed in data. + + Revision 1.108 2006/01/19 18:05:42 lievre + Gnuplot problem appeared... + To be fixed + Revision 1.107 2006/01/19 16:20:37 brouard Test existence of gnuplot in imach path @@ -230,6 +237,7 @@ #include #include +#include #include #include #include @@ -243,11 +251,11 @@ extern int errno; /* #define _(String) gettext (String) */ #define MAXLINE 256 + #define GNUPLOTPROGRAM "gnuplot" /*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/ #define FILENAMELENGTH 132 -/*#define DEBUG*/ -/*#define windows*/ + #define GLOCK_ERROR_NOPATH -1 /* empty path */ #define GLOCK_ERROR_GETCWD -2 /* cannot get cwd */ @@ -273,11 +281,11 @@ extern int errno; #define ODIRSEPARATOR '/' #endif -/* $Id: imach.c,v 1.107 2006/01/19 16:20:37 brouard Exp $ */ +/* $Id: imach.c,v 1.109 2006/01/24 19:37:15 brouard Exp $ */ /* $State: Exp $ */ char version[]="Imach version 0.98a, January 2006, INED-EUROREVES "; -char fullversion[]="$Revision: 1.107 $ $Date: 2006/01/19 16:20:37 $"; +char fullversion[]="$Revision: 1.109 $ $Date: 2006/01/24 19:37:15 $"; int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ int nvar; int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; @@ -342,6 +350,9 @@ long time_value; extern long time(); char strcurr[80], strfor[80]; +char *endptr; +long lval; + #define NR_END 1 #define FREE_ARG char* #define FTOL 1.0e-10 @@ -4073,6 +4084,7 @@ int main(int argc, char *argv[]) { int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav); int i,j, k, n=MAXN,iter,m,size=100,cptcode, cptcod; + int linei; int jj, ll, li, lj, lk, imk; int numlinepar=0; /* Current linenumber of parameter file */ int itimes; @@ -4356,7 +4368,6 @@ int main(int argc, char *argv[]) } fflush(ficlog); - p=param[1][1]; /* Reads comments: lines beginning with '#' */ @@ -4480,43 +4491,132 @@ int main(int argc, char *argv[]) ncodemax=ivector(1,8); i=1; - while (fgets(line, MAXLINE, fic) != NULL) { - if ((i >= firstobs) && (i <=lastobs)) { - for(j=0; line[j] != '\n';j++){ /* Untabifies line */ + linei=0; + while ((fgets(line, MAXLINE, fic) != NULL) ||((i >= firstobs) && (i <=lastobs))) { + linei=linei+1; + printf("IIIII= %d linei=%d\n",i,linei); + 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);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,' '); s[j][i]=atoi(strb); + 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); + 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 year of exam at wave %d. Exiting.\n",lval, i,line,linei,j); + exit(1); + } + anint[j][i]=(double)(lval); + + 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 month of exam at wave %d. Exiting.\n",lval, i,line, linei,j); + exit(1); + } + mint[j][i]=(double)(lval); strcpy(line,stra); - cutv(stra, strb,line,'/'); anint[j][i]=(double)(atoi(strb)); strcpy(line,stra); - cutv(stra, strb,line,' '); mint[j][i]=(double)(atoi(strb)); strcpy(line,stra); } - cutv(stra, strb,line,'/'); andc[i]=(double)(atoi(strb)); strcpy(line,stra); - cutv(stra, strb,line,' '); moisdc[i]=(double)(atoi(strb)); strcpy(line,stra); - - cutv(stra, strb,line,'/'); annais[i]=(double)(atoi(strb)); strcpy(line,stra); - cutv(stra, strb,line,' '); moisnais[i]=(double)(atoi(strb)); 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 year of death. Exiting.\n",lval, i,line,linei); + exit(1); + } + andc[i]=(double)(lval); + 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 month of death. Exiting.\n",lval,i,line, linei); + exit(1); + } + moisdc[i]=(double)(lval); + + 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 year of birth. Exiting.\n",lval, i,line, linei); + exit(1); + } + annais[i]=(double)(lval); + + 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 month of birth. Exiting.\n",lval,i,line,linei); + exit(1); + } + moisnais[i]=(double)(lval); + 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); - cutv(stra, strb,line,' '); weight[i]=(double)(atoi(strb)); strcpy(line,stra); for (j=ncovcol;j>=1;j--){ - cutv(stra, strb,line,' '); covar[j][i]=(double)(atoi(strb)); 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 covar (meaning 0 for the reference or 1). Exiting.\n",lval, i,line,linei); + exit(1); + } + if(lval <0 || 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 num[i]=atol(stra); - + printf ("num [i] %ld %d\n",i, num[i]);fflush(stdout); /*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);*/ imx=i-1; /* Number of individuals */ @@ -4664,8 +4764,7 @@ int main(int argc, char *argv[]) } } else if(s[m][i] !=9){ /* Standard case, age in fractional - years but with the precision of a - month */ + years but with the precision of a month */ agev[m][i]=(mint[m][i]/12.+1./24.+anint[m][i])-(moisnais[i]/12.+1./24.+annais[i]); if((int)mint[m][i]==99 || (int)anint[m][i]==9999) agev[m][i]=1; @@ -5550,23 +5649,34 @@ lsurv=vector(1,AGESUP); chdir(path); #ifndef UNIX - strcpy(plotcmd,"\""); + /* strcpy(plotcmd,"\""); */ #endif - strcat(plotcmd,pathimach); + strcpy(plotcmd,pathimach); /*strcat(plotcmd,CHARSEPARATOR);*/ strcat(plotcmd,GNUPLOTPROGRAM); #ifndef UNIX - strcat(plotcmd,"\""); + strcat(plotcmd,".exe"); + /* strcat(plotcmd,"\"");*/ #endif 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,"\""); +#endif strcat(plotcmd," "); strcat(plotcmd,optionfilegnuplot); printf("Starting graphs with: %s",plotcmd);fflush(stdout); if((outcmd=system(plotcmd)) != 0){ - printf(" Problem with gnuplot\n"); + printf("\n Problem with gnuplot\n"); } printf(" Wait..."); while (z[0] != 'q') {