--- imach/src/imach.c 2014/08/25 20:10:10 1.156 +++ imach/src/imach.c 2014/08/27 16:26:55 1.157 @@ -1,6 +1,16 @@ -/* $Id: imach.c,v 1.156 2014/08/25 20:10:10 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 *** @@ -473,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 @@ -510,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.156 2014/08/25 20:10:10 brouard Exp $ */ +/* $Id: imach.c,v 1.157 2014/08/27 16:26:55 brouard Exp $ */ /* $State: Exp $ */ -char version[]="Imach version 0.98nV, 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.156 $ $Date: 2014/08/25 20:10:10 $"; +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 */ @@ -597,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; @@ -1246,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]); @@ -1264,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++) { @@ -5311,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); @@ -5408,7 +5430,7 @@ int main(int argc, char *argv[]) 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"); @@ -6640,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); @@ -6669,7 +6692,7 @@ 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)){ @@ -6678,7 +6701,7 @@ Interval (in months) between two waves: 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); @@ -6705,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