--- imach/src/imach.c 2006/01/19 13:24:36 1.106 +++ imach/src/imach.c 2006/01/19 16:20:37 1.107 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.106 2006/01/19 13:24:36 brouard Exp $ +/* $Id: imach.c,v 1.107 2006/01/19 16:20:37 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.107 2006/01/19 16:20:37 brouard + Test existence of gnuplot in imach path + Revision 1.106 2006/01/19 13:24:36 brouard Some cleaning and links added in html output @@ -227,6 +230,11 @@ #include #include +#include +#include +#include +extern int errno; + /* #include */ #include #include "timeval.h" @@ -257,17 +265,19 @@ #define AGEGOMP 10. /* Minimal age for Gompertz adjustment */ #ifdef UNIX #define DIRSEPARATOR '/' +#define CHARSEPARATOR "/" #define ODIRSEPARATOR '\\' #else #define DIRSEPARATOR '\\' +#define CHARSEPARATOR "\\" #define ODIRSEPARATOR '/' #endif -/* $Id: imach.c,v 1.106 2006/01/19 13:24:36 brouard Exp $ */ +/* $Id: imach.c,v 1.107 2006/01/19 16:20:37 brouard Exp $ */ /* $State: Exp $ */ char version[]="Imach version 0.98a, January 2006, INED-EUROREVES "; -char fullversion[]="$Revision: 1.106 $ $Date: 2006/01/19 13:24:36 $"; +char fullversion[]="$Revision: 1.107 $ $Date: 2006/01/19 16:20:37 $"; int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ int nvar; int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; @@ -388,7 +398,7 @@ double ftolhess; /* Tolerance for comput /**************** split *************************/ static int split( char *path, char *dirc, char *name, char *ext, char *finame ) { - /* From a file name with full path (either Unix or Windows) we extract the directory (dirc) + /* From a file name with (full) path (either Unix or Windows) we extract the directory (dirc) the name of the file (name), its extension only (ext) and its first part of the name (finame) */ char *ss; /* pointer */ @@ -397,7 +407,8 @@ static int split( char *path, char *dirc l1 = strlen(path ); /* length of path */ if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH ); ss= strrchr( path, DIRSEPARATOR ); /* find last / */ - if ( ss == NULL ) { /* no directory, so use current */ + if ( ss == NULL ) { /* no directory, so determine current directory */ + strcpy( name, path ); /* we got the fullname name because no directory */ /*if(strrchr(path, ODIRSEPARATOR )==NULL) printf("Warning you should use %s as a separator\n",DIRSEPARATOR);*/ /* get current working directory */ @@ -405,7 +416,8 @@ static int split( char *path, char *dirc if ( getcwd( dirc, FILENAME_MAX ) == NULL ) { return( GLOCK_ERROR_GETCWD ); } - strcpy( name, path ); /* we've got it */ + /* got dirc from getcwd*/ + printf(" DIRC = %s \n",dirc); } else { /* strip direcotry from path */ ss++; /* after this, the filename */ l2 = strlen( ss ); /* length of filename */ @@ -413,14 +425,15 @@ static int split( char *path, char *dirc strcpy( name, ss ); /* save file name */ strncpy( dirc, path, l1 - l2 ); /* now the directory */ dirc[l1-l2] = 0; /* add zero */ + printf(" DIRC2 = %s \n",dirc); } + /* We add a separator at the end of dirc if not exists */ l1 = strlen( dirc ); /* length of directory */ - /*#ifdef windows - if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; } -#else - if ( dirc[l1-1] != '/' ) { dirc[l1] = '/'; dirc[l1+1] = 0; } -#endif - */ + if( dirc[l1-1] != DIRSEPARATOR ){ + dirc[l1] = DIRSEPARATOR; + dirc[l1+1] = 0; + printf(" DIRC3 = %s \n",dirc); + } ss = strrchr( name, '.' ); /* find last / */ if (ss >0){ ss++; @@ -430,6 +443,7 @@ static int split( char *path, char *dirc strncpy( finame, name, l1-l2); finame[l1-l2]= 0; } + return( 0 ); /* we're done */ } @@ -3203,10 +3217,10 @@ void printinghtml(char fileres[], char t double jprev2, double mprev2,double anprev2){ int jj1, k1, i1, cpt; - fprintf(fichtm,"
  • href="#firstorder">Result files (first order: no variance)\n \ -
  • href="#secondorder">Result files (second order (variance)\n \ + fprintf(fichtm,""); - fprintf(fichtm,"
    • Result files (first order: no variance)

      \n \ + fprintf(fichtm,"
      • Result files (first order: no variance)

        \n \ - Observed prevalence in each state (during the period defined between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf): %s
        \n ", jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,subdirf2(fileres,"p"),subdirf2(fileres,"p")); fprintf(fichtm,"\ @@ -3257,7 +3271,7 @@ fprintf(fichtm," \n
        • Graphs fprintf(fichtm,"\ -\n
        • Result files (second order: variances)

          \n\ +\n
        • Result files (second order: variances)

          \n\ - Parameter file with estimated parameters and covariance matrix: %s
          \n", rfileres,rfileres); fprintf(fichtm," - Variance of one-step probabilities: %s
          \n", @@ -4067,6 +4081,7 @@ int main(int argc, char *argv[]) char ca[32], cb[32], cc[32]; /* FILE *fichtm; *//* Html File */ /* FILE *ficgp;*/ /*Gnuplot File */ + struct stat info; double agedeb, agefin,hf; double ageminpar=1.e20,agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20; @@ -4167,10 +4182,14 @@ int main(int argc, char *argv[]) printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/ /* cutv(path,optionfile,pathtot,'\\');*/ + /* Split argv[0], imach program to get pathimach */ + printf("\nargv[0]=%s argv[1]=%s, \n",argv[0],argv[1]); split(argv[0],pathimach,optionfile,optionfilext,optionfilefiname); + printf("\nargv[0]=%s pathimach=%s, \noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",argv[0],pathimach,optionfile,optionfilext,optionfilefiname); /* strcpy(pathimach,argv[0]); */ + /* Split argv[1]=pathtot, parameter file name to get path, optionfile, extension and name */ split(pathtot,path,optionfile,optionfilext,optionfilefiname); - printf("pathimach=%s, pathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathimach,pathtot,path,optionfile,optionfilext,optionfilefiname); + printf("\npathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); chdir(path); strcpy(command,"mkdir "); strcat(command,optionfilefiname); @@ -5530,13 +5549,22 @@ lsurv=vector(1,AGESUP); /*------ End -----------*/ chdir(path); +#ifndef UNIX strcpy(plotcmd,"\""); +#endif strcat(plotcmd,pathimach); + /*strcat(plotcmd,CHARSEPARATOR);*/ strcat(plotcmd,GNUPLOTPROGRAM); +#ifndef UNIX strcat(plotcmd,"\""); +#endif + if(stat(plotcmd,&info)){ + printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout); + } strcat(plotcmd," "); strcat(plotcmd,optionfilegnuplot); printf("Starting graphs with: %s",plotcmd);fflush(stdout); + if((outcmd=system(plotcmd)) != 0){ printf(" Problem with gnuplot\n"); }