]> henry.ined.fr Git - .git/commitdiff
(Module): Change position of html and gnuplot routines and added
authorN. Brouard <brouard@ined.fr>
Tue, 17 Jun 2003 20:04:08 +0000 (20:04 +0000)
committerN. Brouard <brouard@ined.fr>
Tue, 17 Jun 2003 20:04:08 +0000 (20:04 +0000)
routine fileappend.

src/imach.c

index f9efc1381456f28d466c5fccd0572b72c561d31a..139ab73d776aee27661ddec2b1cf345660646fc3 100644 (file)
@@ -1,12 +1,25 @@
 /* $Id$
   $State$
   $Log$
+  Revision 1.85  2003/06/17 13:12:43  brouard
+  * imach.c (Repository): Check when date of death was earlier that
+  current date of interview. It may happen when the death was just
+  prior to the death. In this case, dh was negative and likelihood
+  was wrong (infinity). We still send an "Error" but patch by
+  assuming that the date of death was just one stepm after the
+  interview.
+  (Repository): Because some people have very long ID (first column)
+  we changed int to long in num[] and we added a new lvector for
+  memory allocation. But we also truncated to 8 characters (left
+  truncation)
+  (Repository): No more line truncation errors.
+
   Revision 1.84  2003/06/13 21:44:43  brouard
   * imach.c (Repository): Replace "freqsummary" at a correct
   place. It differs from routine "prevalence" which may be called
   many times. Probs is memory consuming and must be used with
   parcimony.
-  Version 0.95a2 (should output exactly the same maximization than 0.8a2)
+  Version 0.95a3 (should output exactly the same maximization than 0.8a2)
 
   Revision 1.83  2003/06/10 13:39:11  lievre
   *** empty log message ***
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <sys/time.h>
+#include <time.h>
+#include "timeval.h"
+
 #define MAXLINE 256
 #define GNUPLOTPROGRAM "gnuplot"
 /*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/
@@ -1329,8 +1346,10 @@ double funcone( double *x)
       ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
 /*       printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */
       if(globpr){
-       fprintf(ficresilk,"%6d %1d %1d %1d %1d %3d %10.6f %6.4f %10.6f %10.6f %10.6f ", \
-               i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],2*weight[i]*lli,out[s1][s2],savm[s1][s2]);
+       fprintf(ficresilk,"%ld %6d %1d %1d %1d %1d %3d %10.6f %6.4f\
+ %10.6f %10.6f %10.6f ", \
+               num[i],i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],
+               2*weight[i]*lli,out[s1][s2],savm[s1][s2]);
        for(k=1,l=0.; k<=nlstate; k++) 
          fprintf(ficresilk," %10.6f",ll[k]);
        fprintf(ficresilk,"\n");
@@ -1358,8 +1377,8 @@ void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpr, long
       printf("Problem with resultfile: %s\n", fileresilk);
       fprintf(ficlog,"Problem with resultfile: %s\n", fileresilk);
     }
-    fprintf(ficresilk, "# individual(line's record) s1 s2 wave# effective_wave# number_of_product_matrix pij weight 2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state");
-    fprintf(ficresilk, "# i s1 s2 mi mw dh likeli weight out sav ");
+    fprintf(ficresilk, "#individual(line's record) s1 s2 wave# effective_wave# number_of_product_matrix pij weight 2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state\n");
+    fprintf(ficresilk, "#num_i i s1 s2 mi mw dh likeli weight out sav ");
     /*         i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],2*weight[i]*lli,out[s1][s2],savm[s1][s2]); */
     for(k=1; k<=nlstate; k++) 
       fprintf(ficresilk," ll[%d]",k);
@@ -1367,8 +1386,18 @@ void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpr, long
   }
 
   *fretone=(*funcone)(p);
-  if(globpr !=0)
+  if(globpr !=0){
     fclose(ficresilk);
+    if((fichtm=fopen(optionfilehtm,"a"))==NULL) {
+      printf("Problem with html file: %s\n", optionfilehtm);
+      fprintf(ficlog,"Problem with html file: %s\n", optionfilehtm);
+      exit(0);
+    }
+    else{
+      fprintf(fichtm,"\n<br>File of contributions to the likelihood: <a href=\"%s\">%s</a><br>\n",fileresilk);
+      fclose(fichtm);
+    }
+  }
   return;
 }
 
@@ -1971,7 +2000,7 @@ void  concatwav(int wav[], int **dh, int **bh,  int **mw, int **s, double *agedc
            else if(j<0){
              printf("Error! Negative delay (%d to death) between waves %d and %d of individual %ld at line %d who is aged %.1f with statuses from %d to %d\n ",j,mw[mi][i],mw[mi+1][i],num[i], i,agev[mw[mi][i]][i],s[mw[mi][i]][i] ,s[mw[mi+1][i]][i]);
              j=1; /* Careful Patch */
-             printf("   We assumed that the date of interview was correct (and not the date of death) and postponed the death %d month(s) (one stepm) after the interview.\n  You MUST fixe the contradiction between dates.\n",stepm);
+             printf("   We assumed that the date of interview was correct (and not the date of death) and postponed the death %d month(s) (one stepm) after the interview.\n  You MUST fix the contradiction between dates.\n",stepm);
              printf("Error! Negative delay (%d to death) between waves %d and %d of individual %ld at line %d who is aged %.1f with statuses from %d to %d\n ",j,mw[mi][i],mw[mi+1][i],num[i], i,agev[mw[mi][i]][i],s[mw[mi][i]][i] ,s[mw[mi+1][i]][i]);
              fprintf(ficlog,"   We assumed that the date of interview was correct (and not the date of death) and postponed the death %d month(s) (one stepm) after the interview.\n  You MUST fix the contradiction between dates.\n",stepm);
            }
@@ -3578,6 +3607,15 @@ populforecast(char fileres[], double anpyram,double mpyram,double jpyram,double
   fclose(ficrespop);
 } /* End of popforecast */
 
+int fileappend(FILE *fichier, char *optionfile)
+{
+  if((fichier=fopen(optionfile,"a"))==NULL) {
+    printf("Problem with file: %s\n", optionfile);
+    fprintf(ficlog,"Problem with file: %s\n", optionfile);
+    return (1);
+  }
+
+}
 /***********************************************/
 /**************** Main Program *****************/
 /***********************************************/
@@ -3631,8 +3669,7 @@ int main(int argc, char *argv[])
 
 
   char z[1]="c", occ;
-#include <sys/time.h>
-#include <time.h>
+
   char stra[80], strb[80], strc[80], strd[80],stre[80],modelsav[80];
   char *strt, *strtend;
   char *stratrunc;
@@ -3651,6 +3688,7 @@ int main(int argc, char *argv[])
   tm = *localtime(&start_time.tv_sec);
   tmg = *gmtime(&start_time.tv_sec);
   strt=asctime(&tm);
+
 /*  printf("Localtime (at start)=%s",strt); */
 /*  tp.tv_sec = tp.tv_sec +86400; */
 /*  tm = *localtime(&start_time.tv_sec); */
@@ -3700,8 +3738,9 @@ int main(int argc, char *argv[])
   fprintf(ficlog,"\n%s\n%s",version,fullversion);
   fprintf(ficlog,"\nEnter the parameter file name: ");
   fprintf(ficlog,"pathtot=%s, path=%s, optionfile=%s optionfilext=%s optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
-  printf("Localtime (at start)=%s",strt); 
-  fprintf(ficlog,"Localtime (at start)=%s",strt); 
+
+  printf("Localtime (at start)=%s",strt);
+  fprintf(ficlog,"Localtime (at start)=%s",strt);
   fflush(ficlog);
 
   /* */
@@ -4211,10 +4250,52 @@ int main(int argc, char *argv[])
      }
      scanf("%d",i);*/
     
+  /*------------ gnuplot -------------*/
+  strcpy(optionfilegnuplot,optionfilefiname);
+  strcat(optionfilegnuplot,".gp");
+  if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
+    printf("Problem with file %s",optionfilegnuplot);
+  }
+  else{
+    fprintf(ficgp,"\n# %s\n", version); 
+    fprintf(ficgp,"# %s\n", optionfilegnuplot); 
+    fprintf(ficgp,"set missing 'NaNq'\n");
+  }
+  fclose(ficgp);
+  /*--------- index.htm --------*/
+
+  strcpy(optionfilehtm,optionfile);
+  strcat(optionfilehtm,".htm");
+  if((fichtm=fopen(optionfilehtm,"w"))==NULL)    {
+    printf("Problem with %s \n",optionfilehtm), exit(0);
+  }
+
+  fprintf(fichtm,"<body> <font size=\"2\">%s <br> %s</font> \
+<hr size=\"2\" color=\"#EC5E5E\"> \n\
+Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n\
+\n\
+<hr  size=\"2\" color=\"#EC5E5E\">\
+ <ul><li><h4>Parameter files</h4>\n\
+ - Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\n\
+ - Log file of the run: <a href=\"%s\">%s</a><br>\n\
+ - Gnuplot file name: <a href=\"%s\">%s</a>\n\
+ - Date and time at start: %s</ul>\n",\
+         version,fullversion,title,datafile,firstpass,lastpass,stepm, weightopt,\
+         model,fileres,fileres,\
+         filelog,filelog,optionfilegnuplot,optionfilegnuplot,strt);
+  fclose(fichtm);
+
   /* Calculates basic frequencies. Computes observed prevalence at single age
      and prints on file fileres'p'. */
   freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint);
 
+  if(fileappend(fichtm, optionfilehtm)){
+    fprintf(fichtm,"<br>Total number of observations=%d <br>\n\
+Youngest age at first (selected) pass %.2f, oldest age %.2f<br>\n\
+Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n",\
+       imx,agemin,agemax,jmin,jmax,jmean);
+    fclose(fichtm);
+  }
     pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
     oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
     newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
@@ -4226,7 +4307,7 @@ int main(int argc, char *argv[])
      so we point p on param[1][1] so that p[1] maps on param[1][1][1] */
   p=param[1][1]; /* *(*(*(param +1)+1)+0) */
 
-  globpr=0; /* To get ipmx number of contributions and sum of weights*/
+  globpr=0; /* To get the number ipmx of contributions and the sum of weights*/
   likelione(ficres, p, npar, nlstate, &globpr, &ipmx, &sw, &fretone, funcone); /* Prints the contributions to the likelihood */
   printf("First Likeli=%12.6f ipmx=%ld sw=%12.6f",fretone,ipmx,sw);
   for (k=1; k<=npar;k++)
@@ -4400,45 +4481,10 @@ int main(int argc, char *argv[])
   fprintf(ficparo,"popforecast=%d popfile=%s popfiledate=%.lf/%.lf/%.lf last-popfiledate=%.lf/%.lf/%.lf\n",popforecast,popfile,jpyram,mpyram,anpyram,jpyram1,mpyram1,anpyram1);
   fprintf(ficres,"popforecast=%d popfile=%s popfiledate=%.lf/%.lf/%.lf last-popfiledate=%.lf/%.lf/%.lf\n",popforecast,popfile,jpyram,mpyram,anpyram,jpyram1,mpyram1,anpyram1);
 
-  freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint);
+  /*  freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint);*/
   /*,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);*/
 
-  /*------------ gnuplot -------------*/
-  strcpy(optionfilegnuplot,optionfilefiname);
-  strcat(optionfilegnuplot,".gp");
-  if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
-    printf("Problem with file %s",optionfilegnuplot);
-  }
-  else{
-    fprintf(ficgp,"\n# %s\n", version); 
-    fprintf(ficgp,"# %s\n", optionfilegnuplot); 
-    fprintf(ficgp,"set missing 'NaNq'\n");
-  }
-  fclose(ficgp);
   printinggnuplot(fileres, ageminpar,agemaxpar,fage, pathc,p);
-  /*--------- index.htm --------*/
-
-  strcpy(optionfilehtm,optionfile);
-  strcat(optionfilehtm,".htm");
-  if((fichtm=fopen(optionfilehtm,"w"))==NULL)    {
-    printf("Problem with %s \n",optionfilehtm), exit(0);
-  }
-
-  fprintf(fichtm,"<body> <font size=\"2\">%s </font> <hr size=\"2\" color=\"#EC5E5E\"> \n\
-Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n\
-\n\
-Total number of observations=%d <br>\n\
-Youngest age at first (selected) pass %.2f, oldest age %.2f<br>\n\
-Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n\
-<hr  size=\"2\" color=\"#EC5E5E\">\
- <ul><li><h4>Parameter files</h4>\n\
- - Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\n\
- - Log file of the run: <a href=\"%s\">%s</a><br>\n\
- - Gnuplot file name: <a href=\"%s\">%s</a></ul>\n",\
-         version,title,datafile,firstpass,lastpass,stepm, weightopt,\
-         model,imx,agemin,agemax,jmin,jmax,jmean,fileres,fileres,\
-         filelog,filelog,optionfilegnuplot,optionfilegnuplot);
-  fclose(fichtm);
 
   printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,\
               model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,\
@@ -4787,6 +4833,10 @@ ageminpar, agemax, s[lastpass][imx], agev[lastpass][imx], nlstate, imx, mint[las
   printf("Total time was %d Sec. %d uSec.\n", end_time.tv_sec -start_time.tv_sec, end_time.tv_usec -start_time.tv_usec);
   fprintf(ficlog,"Total time was %d Sec. %d uSec.\n", end_time.tv_sec -start_time.tv_sec, end_time.tv_usec -start_time.tv_usec);
   /*  printf("Total time was %d uSec.\n", total_usecs);*/
+  if(fileappend(fichtm,optionfilehtm)){
+    fprintf(fichtm,"<br>Localtime at start %s and at end=%s<br>",strt, strtend);
+    fclose(fichtm);
+  }
   /*------ End -----------*/
 
   end: