--- imach/src/imach.c 2014/06/20 17:32:08 1.154 +++ imach/src/imach.c 2014/08/27 16:26:55 1.157 @@ -1,6 +1,23 @@ -/* $Id: imach.c,v 1.154 2014/06/20 17:32:08 brouard Exp $ +/* $Id: imach.c,v 1.157 2014/08/27 16:26:55 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.157 2014/08/27 16:26:55 brouard + Summary: Preparing windows Visual studio version + Author: Brouard + + In order to compile on Visual studio, time.h is now correct and time_t + and tm struct should be used. difftime should be used but sometimes I + just make the differences in raw time format (time(&now). + Trying to suppress #ifdef LINUX + Add xdg-open for __linux in order to open default browser. + + Revision 1.156 2014/08/25 20:10:10 brouard + *** empty log message *** + + Revision 1.155 2014/08/25 18:32:34 brouard + Summary: New compile, minor changes + Author: Brouard + Revision 1.154 2014/06/20 17:32:08 brouard Summary: Outputs now all graphs of convergence to period prevalence @@ -466,12 +483,14 @@ #include extern int errno; -#ifdef LINUX +/* #ifdef LINUX */ +/* #include */ +/* #include "timeval.h" */ +/* #else */ +/* #include */ +/* #endif */ + #include -#include "timeval.h" -#else -#include -#endif #ifdef GSL #include @@ -503,21 +522,21 @@ extern int errno; #define AGESUP 130 #define AGEBASE 40 #define AGEGOMP 10. /**< Minimal age for Gompertz adjustment */ -#ifdef UNIX -#define DIRSEPARATOR '/' -#define CHARSEPARATOR "/" -#define ODIRSEPARATOR '\\' -#else +#ifdef _WIN32 #define DIRSEPARATOR '\\' #define CHARSEPARATOR "\\" #define ODIRSEPARATOR '/' +#else +#define DIRSEPARATOR '/' +#define CHARSEPARATOR "/" +#define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.154 2014/06/20 17:32:08 brouard Exp $ */ +/* $Id: imach.c,v 1.157 2014/08/27 16:26:55 brouard Exp $ */ /* $State: Exp $ */ -char version[]="Imach version 0.98nU, January 2014,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121)"; -char fullversion[]="$Revision: 1.154 $ $Date: 2014/06/20 17:32:08 $"; +char version[]="Imach version 0.98nX, August 2014,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121)"; +char fullversion[]="$Revision: 1.157 $ $Date: 2014/08/27 16:26:55 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -590,12 +609,17 @@ char popfile[FILENAMELENGTH]; char optionfilegnuplot[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH], optionfilehtmcov[FILENAMELENGTH] ; -struct timeval start_time, end_time, curr_time, last_time, forecast_time; -struct timezone tzp; -extern int gettimeofday(); -struct tm tmg, tm, tmf, *gmtime(), *localtime(); -long time_value; -extern long time(); +/* struct timeval start_time, end_time, curr_time, last_time, forecast_time; */ +/* struct timezone tzp; */ +/* extern int gettimeofday(); */ +struct tm tml, *gmtime(), *localtime(); + +extern time_t time(); + +struct tm start_time, end_time, curr_time, last_time, forecast_time; +time_t rstart_time, rend_time, rcurr_time, rlast_time, rforecast_time; /* raw time */ +struct tm tm; + char strcurr[80], strfor[80]; char *endptr; @@ -1239,15 +1263,18 @@ void powell(double p[], double **xi, int xits=vector(1,n); *fret=(*func)(p); for (j=1;j<=n;j++) pt[j]=p[j]; + rcurr_time = time(NULL); for (*iter=1;;++(*iter)) { fp=(*fret); ibig=0; del=0.0; - last_time=curr_time; - (void) gettimeofday(&curr_time,&tzp); - printf("\nPowell iter=%d -2*LL=%.12f %ld sec. %ld sec.",*iter,*fret, curr_time.tv_sec-last_time.tv_sec, curr_time.tv_sec-start_time.tv_sec);fflush(stdout); - fprintf(ficlog,"\nPowell iter=%d -2*LL=%.12f %ld sec. %ld sec.",*iter,*fret, curr_time.tv_sec-last_time.tv_sec, curr_time.tv_sec-start_time.tv_sec); fflush(ficlog); -/* fprintf(ficrespow,"%d %.12f %ld",*iter,*fret,curr_time.tv_sec-start_time.tv_sec); */ + rlast_time=rcurr_time; + /* (void) gettimeofday(&curr_time,&tzp); */ + rcurr_time = time(NULL); + curr_time = *localtime(&rcurr_time); + printf("\nPowell iter=%d -2*LL=%.12f %ld sec. %ld sec.",*iter,*fret, rcurr_time-rlast_time, rcurr_time-rstart_time);fflush(stdout); + fprintf(ficlog,"\nPowell iter=%d -2*LL=%.12f %ld sec. %ld sec.",*iter,*fret,rcurr_time-rlast_time, rcurr_time-rstart_time); fflush(ficlog); +/* fprintf(ficrespow,"%d %.12f %ld",*iter,*fret,curr_time.tm_sec-start_time.tm_sec); */ for (i=1;i<=n;i++) { printf(" %d %.12f",i, p[i]); fprintf(ficlog," %d %.12lf",i, p[i]); @@ -1257,25 +1284,25 @@ void powell(double p[], double **xi, int fprintf(ficlog,"\n"); fprintf(ficrespow,"\n");fflush(ficrespow); if(*iter <=3){ - tm = *localtime(&curr_time.tv_sec); - strcpy(strcurr,asctime(&tm)); + tml = *localtime(&rcurr_time); + strcpy(strcurr,asctime(&tml)); /* asctime_r(&tm,strcurr); */ - forecast_time=curr_time; + rforecast_time=rcurr_time; itmp = strlen(strcurr); if(strcurr[itmp-1]=='\n') /* Windows outputs with a new line */ strcurr[itmp-1]='\0'; - printf("\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,curr_time.tv_sec-last_time.tv_sec); - fprintf(ficlog,"\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,curr_time.tv_sec-last_time.tv_sec); + printf("\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,rcurr_time-rlast_time); + fprintf(ficlog,"\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,rcurr_time-rlast_time); for(niterf=10;niterf<=30;niterf+=10){ - forecast_time.tv_sec=curr_time.tv_sec+(niterf-*iter)*(curr_time.tv_sec-last_time.tv_sec); - tmf = *localtime(&forecast_time.tv_sec); + rforecast_time=rcurr_time+(niterf-*iter)*(rcurr_time-rlast_time); + forecast_time = *localtime(&rforecast_time); /* asctime_r(&tmf,strfor); */ - strcpy(strfor,asctime(&tmf)); + strcpy(strfor,asctime(&forecast_time)); itmp = strlen(strfor); if(strfor[itmp-1]=='\n') strfor[itmp-1]='\0'; - printf(" - if your program needs %d iterations to converge, convergence will be \n reached in %s i.e.\n on %s (current time is %s);\n",niterf, asc_diff_time(forecast_time.tv_sec-curr_time.tv_sec,tmpout),strfor,strcurr); - fprintf(ficlog," - if your program needs %d iterations to converge, convergence will be \n reached in %s i.e.\n on %s (current time is %s);\n",niterf, asc_diff_time(forecast_time.tv_sec-curr_time.tv_sec,tmpout),strfor,strcurr); + printf(" - if your program needs %d iterations to converge, convergence will be \n reached in %s i.e.\n on %s (current time is %s);\n",niterf, asc_diff_time(rforecast_time-rcurr_time,tmpout),strfor,strcurr); + fprintf(ficlog," - if your program needs %d iterations to converge, convergence will be \n reached in %s i.e.\n on %s (current time is %s);\n",niterf, asc_diff_time(rforecast_time-rcurr_time,tmpout),strfor,strcurr); } } for (i=1;i<=n;i++) { @@ -5175,7 +5202,7 @@ calandcheckages(int imx, int maxwav, dou } else if(agev[m][i] >*agemax){ *agemax=agev[m][i]; - printf(" Max anint[%d][%d]=%.0f annais[%d]=%.0f, agemax=%.2f\n",m,i,anint[m][i], i,annais[i], *agemax); + /* printf(" Max anint[%d][%d]=%.0f annais[%d]=%.0f, agemax=%.2f\n",m,i,anint[m][i], i,annais[i], *agemax);*/ } /*agev[m][i]=anint[m][i]-annais[i];*/ /* agev[m][i] = age[i]+2*m;*/ @@ -5304,19 +5331,21 @@ int main(int argc, char *argv[]) /* setlocale (LC_MESSAGES, ""); */ /* gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */ - (void) gettimeofday(&start_time,&tzp); + rstart_time = time(NULL); + /* (void) gettimeofday(&start_time,&tzp);*/ + start_time = *localtime(&rstart_time); curr_time=start_time; - tm = *localtime(&start_time.tv_sec); - tmg = *gmtime(&start_time.tv_sec); - strcpy(strstart,asctime(&tm)); + /*tml = *localtime(&start_time.tm_sec);*/ + /* strcpy(strstart,asctime(&tml)); */ + strcpy(strstart,asctime(&start_time)); /* printf("Localtime (at start)=%s",strstart); */ -/* tp.tv_sec = tp.tv_sec +86400; */ -/* tm = *localtime(&start_time.tv_sec); */ +/* tp.tm_sec = tp.tm_sec +86400; */ +/* tm = *localtime(&start_time.tm_sec); */ /* tmg.tm_year=tmg.tm_year +dsign*dyear; */ /* tmg.tm_mon=tmg.tm_mon +dsign*dmonth; */ /* tmg.tm_hour=tmg.tm_hour + 1; */ -/* tp.tv_sec = mktime(&tmg); */ +/* tp.tm_sec = mktime(&tmg); */ /* strt=asctime(&tmg); */ /* printf("Time(after) =%s",strstart); */ /* (void) time (&time_value); @@ -5337,6 +5366,9 @@ int main(int argc, char *argv[]) i=strlen(pathr); if(pathr[i-1]=='\n') pathr[i-1]='\0'; + i=strlen(pathr); + if(pathr[i-1]==' ') /* This may happen when dragging on oS/X! */ + pathr[i-1]='\0'; for (tok = pathr; tok != NULL; ){ printf("Pathr |%s|\n",pathr); while ((val = strsep(&tok, "\"" )) != NULL && *val == '\0'); @@ -5392,13 +5424,13 @@ int main(int argc, char *argv[]) path=%s \n\ optionfile=%s\n\ optionfilext=%s\n\ - optionfilefiname=%s\n",pathimach,pathtot,path,optionfile,optionfilext,optionfilefiname); + optionfilefiname='%s'\n",pathimach,pathtot,path,optionfile,optionfilext,optionfilefiname); printf("Local time (at start):%s",strstart); fprintf(ficlog,"Local time (at start): %s",strstart); fflush(ficlog); /* (void) gettimeofday(&curr_time,&tzp); */ -/* printf("Elapsed time %d\n", asc_diff_time(curr_time.tv_sec-start_time.tv_sec,tmpout)); */ +/* printf("Elapsed time %d\n", asc_diff_time(curr_time.tm_sec-start_time.tm_sec,tmpout)); */ /* */ strcpy(fileres,"r"); @@ -5408,8 +5440,8 @@ int main(int argc, char *argv[]) /*---------arguments file --------*/ if((ficpar=fopen(optionfile,"r"))==NULL) { - printf("Problem with optionfile %s with errno=%s\n",optionfile,strerror(errno)); - fprintf(ficlog,"Problem with optionfile %s with errno=%s\n",optionfile,strerror(errno)); + printf("Problem with optionfile '%s' with errno='%s'\n",optionfile,strerror(errno)); + fprintf(ficlog,"Problem with optionfile '%s' with errno='%s'\n",optionfile,strerror(errno)); fflush(ficlog); /* goto end; */ exit(70); @@ -6630,17 +6662,18 @@ Interval (in months) between two waves: } printf("See log file on %s\n",filelog); /* gettimeofday(&end_time, (struct timezone*)0);*/ /* after time */ - (void) gettimeofday(&end_time,&tzp); - tm = *localtime(&end_time.tv_sec); - tmg = *gmtime(&end_time.tv_sec); - strcpy(strtend,asctime(&tm)); + /*(void) gettimeofday(&end_time,&tzp);*/ + rend_time = time(NULL); + end_time = *localtime(&rend_time); + /* tml = *localtime(&end_time.tm_sec); */ + strcpy(strtend,asctime(&end_time)); printf("Local time at start %s\nLocal time at end %s",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(rend_time -rstart_time,tmpout)); - 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 was %ld Sec.\n", end_time.tv_sec -start_time.tv_sec); + printf("Total time was %.0lf Sec.\n", difftime(rend_time,rstart_time)); + fprintf(ficlog,"Total time used %s\n", asc_diff_time(rend_time -rstart_time,tmpout)); + fprintf(ficlog,"Total time was %.0lf Sec.\n", difftime(rend_time,rstart_time)); /* printf("Total time was %d uSec.\n", total_usecs);*/ /* if(fileappend(fichtm,optionfilehtm)){ */ fprintf(fichtm,"
Local time at start %s
Local time at end %s
\n",strstart, strtend); @@ -6659,16 +6692,16 @@ Interval (in months) between two waves: printf("Current directory %s!\n",pathcd); /*strcat(plotcmd,CHARSEPARATOR);*/ sprintf(plotcmd,"gnuplot"); -#ifndef UNIX +#ifdef _WIN32 sprintf(plotcmd,"\"%sgnuplot.exe\"",pathimach); #endif if(!stat(plotcmd,&info)){ - printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout); + printf("Error or 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); + printf("Error or gnuplot program not found: %s Environment GNUPLOTBIN not set.\n",plotcmd);fflush(stdout); }else strcpy(pplotcmd,plotcmd); -#ifdef UNIX +#ifdef __unix strcpy(plotcmd,GNUPLOTPROGRAM); if(!stat(plotcmd,&info)){ printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout); @@ -6695,8 +6728,10 @@ Interval (in months) between two waves: scanf("%s",z); /* if (z[0] == 'c') system("./imach"); */ if (z[0] == 'e') { -#ifdef OSX +#ifdef _APPLE_ sprintf(pplotcmd, "open %s", optionfilehtm); +#elif __linux + sprintf(pplotcmd, "xdg-open %s", optionfilehtm); #else sprintf(pplotcmd, "%s", optionfilehtm); #endif