Diff for /imach/src/imach.c between versions 1.156 and 1.157

version 1.156, 2014/08/25 20:10:10 version 1.157, 2014/08/27 16:26:55
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     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    Revision 1.156  2014/08/25 20:10:10  brouard
   *** empty log message ***    *** empty log message ***
   
Line 473 Line 483
 #include <errno.h>  #include <errno.h>
 extern int errno;  extern int errno;
   
 #ifdef LINUX  /* #ifdef LINUX */
   /* #include <time.h> */
   /* #include "timeval.h" */
   /* #else */
   /* #include <sys/time.h> */
   /* #endif */
   
 #include <time.h>  #include <time.h>
 #include "timeval.h"  
 #else  
 #include <sys/time.h>  
 #endif  
   
 #ifdef GSL  #ifdef GSL
 #include <gsl/gsl_errno.h>  #include <gsl/gsl_errno.h>
Line 510  extern int errno; Line 522  extern int errno;
 #define AGESUP 130  #define AGESUP 130
 #define AGEBASE 40  #define AGEBASE 40
 #define AGEGOMP 10. /**< Minimal age for Gompertz adjustment */  #define AGEGOMP 10. /**< Minimal age for Gompertz adjustment */
 #ifdef UNIX  #ifdef _WIN32
 #define DIRSEPARATOR '/'  
 #define CHARSEPARATOR "/"  
 #define ODIRSEPARATOR '\\'  
 #else  
 #define DIRSEPARATOR '\\'  #define DIRSEPARATOR '\\'
 #define CHARSEPARATOR "\\"  #define CHARSEPARATOR "\\"
 #define ODIRSEPARATOR '/'  #define ODIRSEPARATOR '/'
   #else
   #define DIRSEPARATOR '/'
   #define CHARSEPARATOR "/"
   #define ODIRSEPARATOR '\\'
 #endif  #endif
   
 /* $Id$ */  /* $Id$ */
 /* $State$ */  /* $State$ */
   
 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 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$ $Date$";   char fullversion[]="$Revision$ $Date$"; 
 char strstart[80];  char strstart[80];
 char optionfilext[10], optionfilefiname[FILENAMELENGTH];  char optionfilext[10], optionfilefiname[FILENAMELENGTH];
Line 597  char popfile[FILENAMELENGTH]; Line 609  char popfile[FILENAMELENGTH];
   
 char optionfilegnuplot[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH], optionfilehtmcov[FILENAMELENGTH] ;  char optionfilegnuplot[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH], optionfilehtmcov[FILENAMELENGTH] ;
   
 struct timeval start_time, end_time, curr_time, last_time, forecast_time;  /* struct timeval start_time, end_time, curr_time, last_time, forecast_time; */
 struct timezone tzp;  /* struct timezone tzp; */
 extern int gettimeofday();  /* extern int gettimeofday(); */
 struct tm tmg, tm, tmf, *gmtime(), *localtime();  struct tm tml, *gmtime(), *localtime();
 long time_value;  
 extern long time();  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 strcurr[80], strfor[80];
   
 char *endptr;  char *endptr;
Line 1246  void powell(double p[], double **xi, int Line 1263  void powell(double p[], double **xi, int
   xits=vector(1,n);     xits=vector(1,n); 
   *fret=(*func)(p);     *fret=(*func)(p); 
   for (j=1;j<=n;j++) pt[j]=p[j];     for (j=1;j<=n;j++) pt[j]=p[j]; 
       rcurr_time = time(NULL);  
   for (*iter=1;;++(*iter)) {     for (*iter=1;;++(*iter)) { 
     fp=(*fret);       fp=(*fret); 
     ibig=0;       ibig=0; 
     del=0.0;       del=0.0; 
     last_time=curr_time;      rlast_time=rcurr_time;
     (void) gettimeofday(&curr_time,&tzp);      /* (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);      rcurr_time = time(NULL);  
     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);      curr_time = *localtime(&rcurr_time);
 /*     fprintf(ficrespow,"%d %.12f %ld",*iter,*fret,curr_time.tv_sec-start_time.tv_sec); */      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++) {     for (i=1;i<=n;i++) {
       printf(" %d %.12f",i, p[i]);        printf(" %d %.12f",i, p[i]);
       fprintf(ficlog," %d %.12lf",i, p[i]);        fprintf(ficlog," %d %.12lf",i, p[i]);
Line 1264  void powell(double p[], double **xi, int Line 1284  void powell(double p[], double **xi, int
     fprintf(ficlog,"\n");      fprintf(ficlog,"\n");
     fprintf(ficrespow,"\n");fflush(ficrespow);      fprintf(ficrespow,"\n");fflush(ficrespow);
     if(*iter <=3){      if(*iter <=3){
       tm = *localtime(&curr_time.tv_sec);        tml = *localtime(&rcurr_time);
       strcpy(strcurr,asctime(&tm));        strcpy(strcurr,asctime(&tml));
 /*       asctime_r(&tm,strcurr); */  /*       asctime_r(&tm,strcurr); */
       forecast_time=curr_time;         rforecast_time=rcurr_time; 
       itmp = strlen(strcurr);        itmp = strlen(strcurr);
       if(strcurr[itmp-1]=='\n')  /* Windows outputs with a new line */        if(strcurr[itmp-1]=='\n')  /* Windows outputs with a new line */
         strcurr[itmp-1]='\0';          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);        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,curr_time.tv_sec-last_time.tv_sec);        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){        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);          rforecast_time=rcurr_time+(niterf-*iter)*(rcurr_time-rlast_time);
         tmf = *localtime(&forecast_time.tv_sec);          forecast_time = *localtime(&rforecast_time);
 /*      asctime_r(&tmf,strfor); */  /*      asctime_r(&tmf,strfor); */
         strcpy(strfor,asctime(&tmf));          strcpy(strfor,asctime(&forecast_time));
         itmp = strlen(strfor);          itmp = strlen(strfor);
         if(strfor[itmp-1]=='\n')          if(strfor[itmp-1]=='\n')
         strfor[itmp-1]='\0';          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);          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(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(rforecast_time-rcurr_time,tmpout),strfor,strcurr);
       }        }
     }      }
     for (i=1;i<=n;i++) {       for (i=1;i<=n;i++) { 
Line 5311  int main(int argc, char *argv[]) Line 5331  int main(int argc, char *argv[])
 /*   setlocale (LC_MESSAGES, ""); */  /*   setlocale (LC_MESSAGES, ""); */
   
   /*   gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */    /*   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;    curr_time=start_time;
   tm = *localtime(&start_time.tv_sec);    /*tml = *localtime(&start_time.tm_sec);*/
   tmg = *gmtime(&start_time.tv_sec);    /* strcpy(strstart,asctime(&tml)); */
   strcpy(strstart,asctime(&tm));    strcpy(strstart,asctime(&start_time));
   
 /*  printf("Localtime (at start)=%s",strstart); */  /*  printf("Localtime (at start)=%s",strstart); */
 /*  tp.tv_sec = tp.tv_sec +86400; */  /*  tp.tm_sec = tp.tm_sec +86400; */
 /*  tm = *localtime(&start_time.tv_sec); */  /*  tm = *localtime(&start_time.tm_sec); */
 /*   tmg.tm_year=tmg.tm_year +dsign*dyear; */  /*   tmg.tm_year=tmg.tm_year +dsign*dyear; */
 /*   tmg.tm_mon=tmg.tm_mon +dsign*dmonth; */  /*   tmg.tm_mon=tmg.tm_mon +dsign*dmonth; */
 /*   tmg.tm_hour=tmg.tm_hour + 1; */  /*   tmg.tm_hour=tmg.tm_hour + 1; */
 /*   tp.tv_sec = mktime(&tmg); */  /*   tp.tm_sec = mktime(&tmg); */
 /*   strt=asctime(&tmg); */  /*   strt=asctime(&tmg); */
 /*   printf("Time(after) =%s",strstart);  */  /*   printf("Time(after) =%s",strstart);  */
 /*  (void) time (&time_value);  /*  (void) time (&time_value);
Line 5408  int main(int argc, char *argv[]) Line 5430  int main(int argc, char *argv[])
   fprintf(ficlog,"Local time (at start): %s",strstart);    fprintf(ficlog,"Local time (at start): %s",strstart);
   fflush(ficlog);    fflush(ficlog);
 /*   (void) gettimeofday(&curr_time,&tzp); */  /*   (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");    strcpy(fileres,"r");
Line 6640  Interval (in months) between two waves: Line 6662  Interval (in months) between two waves:
   }    }
   printf("See log file on %s\n",filelog);    printf("See log file on %s\n",filelog);
   /*  gettimeofday(&end_time, (struct timezone*)0);*/  /* after time */    /*  gettimeofday(&end_time, (struct timezone*)0);*/  /* after time */
   (void) gettimeofday(&end_time,&tzp);    /*(void) gettimeofday(&end_time,&tzp);*/
   tm = *localtime(&end_time.tv_sec);    rend_time = time(NULL);  
   tmg = *gmtime(&end_time.tv_sec);    end_time = *localtime(&rend_time);
   strcpy(strtend,asctime(&tm));    /* tml = *localtime(&end_time.tm_sec); */
     strcpy(strtend,asctime(&end_time));
   printf("Local time at start %s\nLocal time at end   %s",strstart, strtend);     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);     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);    printf("Total time was %.0lf Sec.\n", difftime(rend_time,rstart_time));
   fprintf(ficlog,"Total time used %s\n", asc_diff_time(end_time.tv_sec -start_time.tv_sec,tmpout));    fprintf(ficlog,"Total time used %s\n", asc_diff_time(rend_time -rstart_time,tmpout));
   fprintf(ficlog,"Total time was %ld Sec.\n", end_time.tv_sec -start_time.tv_sec);    fprintf(ficlog,"Total time was %.0lf Sec.\n", difftime(rend_time,rstart_time));
   /*  printf("Total time was %d uSec.\n", total_usecs);*/    /*  printf("Total time was %d uSec.\n", total_usecs);*/
 /*   if(fileappend(fichtm,optionfilehtm)){ */  /*   if(fileappend(fichtm,optionfilehtm)){ */
   fprintf(fichtm,"<br>Local time at start %s<br>Local time at end   %s<br>\n</body></html>",strstart, strtend);    fprintf(fichtm,"<br>Local time at start %s<br>Local time at end   %s<br>\n</body></html>",strstart, strtend);
Line 6669  Interval (in months) between two waves: Line 6692  Interval (in months) between two waves:
     printf("Current directory %s!\n",pathcd);      printf("Current directory %s!\n",pathcd);
   /*strcat(plotcmd,CHARSEPARATOR);*/    /*strcat(plotcmd,CHARSEPARATOR);*/
   sprintf(plotcmd,"gnuplot");    sprintf(plotcmd,"gnuplot");
 #ifndef UNIX  #ifdef _WIN32
   sprintf(plotcmd,"\"%sgnuplot.exe\"",pathimach);    sprintf(plotcmd,"\"%sgnuplot.exe\"",pathimach);
 #endif  #endif
   if(!stat(plotcmd,&info)){    if(!stat(plotcmd,&info)){
Line 6678  Interval (in months) between two waves: Line 6701  Interval (in months) between two waves:
       printf("Error or 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      }else
       strcpy(pplotcmd,plotcmd);        strcpy(pplotcmd,plotcmd);
 #ifdef UNIX  #ifdef __unix
     strcpy(plotcmd,GNUPLOTPROGRAM);      strcpy(plotcmd,GNUPLOTPROGRAM);
     if(!stat(plotcmd,&info)){      if(!stat(plotcmd,&info)){
       printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout);        printf("Error gnuplot program not found: %s\n",plotcmd);fflush(stdout);
Line 6705  Interval (in months) between two waves: Line 6728  Interval (in months) between two waves:
     scanf("%s",z);      scanf("%s",z);
 /*     if (z[0] == 'c') system("./imach"); */  /*     if (z[0] == 'c') system("./imach"); */
     if (z[0] == 'e') {      if (z[0] == 'e') {
 #ifdef OSX  #ifdef _APPLE_
       sprintf(pplotcmd, "open %s", optionfilehtm);        sprintf(pplotcmd, "open %s", optionfilehtm);
   #elif __linux
         sprintf(pplotcmd, "xdg-open %s", optionfilehtm);
 #else  #else
       sprintf(pplotcmd, "%s", optionfilehtm);        sprintf(pplotcmd, "%s", optionfilehtm);
 #endif  #endif

Removed from v.1.156  
changed lines
  Added in v.1.157


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>