]> henry.ined.fr Git - .git/commitdiff
Summary: Adding error when the covariance matrix doesn't contain the exact number...
authorN. Brouard <brouard@ined.fr>
Tue, 18 Aug 2015 13:32:00 +0000 (13:32 +0000)
committerN. Brouard <brouard@ined.fr>
Tue, 18 Aug 2015 13:32:00 +0000 (13:32 +0000)
src/imach.c

index c1d48662dd8b81dddce31d3e0df2c959981a38d6..1730b1862b10deaed3281b116fd264b78f5a5ea4 100644 (file)
@@ -1,6 +1,9 @@
 /* $Id$
   $State$
   $Log$
+  Revision 1.193  2015/08/04 07:17:42  brouard
+  Summary: 0.98q4
+
   Revision 1.192  2015/07/16 16:49:02  brouard
   Summary: Fixing some outputs
 
@@ -682,6 +685,7 @@ typedef struct {
 #define YEARM 12. /**< Number of months per year */
 #define AGESUP 130
 #define AGEBASE 40
+#define AGEOVERFLOW 1.e20
 #define AGEGOMP 10 /**< Minimal age for Gompertz adjustment */
 #ifdef _WIN32
 #define DIRSEPARATOR '\\'
@@ -696,7 +700,7 @@ typedef struct {
 /* $Id$ */
 /* $State$ */
 
-char version[]="Imach version 0.98q4, July 2015,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015";
+char version[]="Imach version 0.98q5, August 2015,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015";
 char fullversion[]="$Revision$ $Date$"; 
 char strstart[80];
 char optionfilext[10], optionfilefiname[FILENAMELENGTH];
@@ -6269,7 +6273,8 @@ int main(int argc, char *argv[])
   /* FILE *ficgp;*/ /*Gnuplot File */
   struct stat info;
   double agedeb=0.;
-  double ageminpar=1.e20,agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20;
+
+  double ageminpar=AGEOVERFLOW,agemin=AGEOVERFLOW, agemaxpar=-AGEOVERFLOW, agemax=-AGEOVERFLOW;
 
   double fret;
   double dum=0.; /* Dummy variable */
@@ -6284,6 +6289,8 @@ int main(int argc, char *argv[])
   int c,  h , cpt;
   int jl=0;
   int i1, j1, jk, stepsize=0;
+  int count=0;
+
   int *tab; 
   int mobilavproj=0 , prevfcast=0 ; /* moving average of prev, If prevfcast=1 prevalence projection */
   int mobilav=0,popforecast=0;
@@ -6474,7 +6481,7 @@ int main(int argc, char *argv[])
   ungetc(c,ficpar);
 
   fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d model=1+age+%s\n",title, datafile, &lastobs, &firstpass,&lastpass,&ftol, &stepm, &ncovcol, &nlstate,&ndeath, &maxwav, &mle, &weightopt,model);
-  numlinepar++;
+  numlinepar=numlinepar+3; /* In general */
   printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nlstate,ndeath, maxwav, mle, weightopt,model);
   if(model[strlen(model)-1]=='.') /* Suppressing leading dot in the model */
     model[strlen(model)-1]='\0';
@@ -6651,12 +6658,22 @@ run imach with mle=-1 to get a correct template of the parameter file.\n",numlin
     for(i=1; i <=npar; i++)
       for(j=1; j <=npar; j++) matcov[i][j]=0.;
       
+    /* Scans npar lines */
     for(i=1; i <=npar; i++){
-      fscanf(ficpar,"%s",str);
+      count=fscanf(ficpar,"%1d%1d%1d",&i1,&j1,&jk);
+      if(count != 3){
+       printf("Error! Error in parameter file %s at line %d after line starting with %1d%1d%1d\n\
+This is probably because your covariance matrix doesn't \n  contain exactly %d lines corresponding to your model line '1+age+%s'.\n\
+Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numlinepar, i1,j1,jk, npar, model);
+       fprintf(ficlog,"Error! Error in parameter file %s at line %d after line starting with %1d%1d%1d\n\
+This is probably because your covariance matrix doesn't \n  contain exactly %d lines corresponding to your model line '1+age+%s'.\n\
+Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numlinepar, i1,j1,jk, npar, model);
+       exit(1);
+      }else
       if(mle==1)
-       printf("%s",str);
-      fprintf(ficlog,"%s",str);
-      fprintf(ficparo,"%s",str);
+       printf("%1d%1d%1d",i1,j1,jk);
+      fprintf(ficlog,"%1d%1d%1d",i1,j1,jk);
+      fprintf(ficparo,"%1d%1d%1d",i1,j1,jk);
       for(j=1; j <=i; j++){
        fscanf(ficpar," %le",&matcov[i][j]);
        if(mle==1){
@@ -6672,6 +6689,7 @@ run imach with mle=-1 to get a correct template of the parameter file.\n",numlin
       fprintf(ficlog,"\n");
       fprintf(ficparo,"\n");
     }
+    /* End of read covariance matrix npar lines */
     for(i=1; i <=npar; i++)
       for(j=i+1;j<=npar;j++)
        matcov[i][j]=matcov[j][i];
@@ -7146,8 +7164,15 @@ Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n",\
     
     
     replace_back_to_slash(pathc,pathcd); /* Even gnuplot wants a / */
-    printinggnuplotmort(fileres, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);
-    
+    if(ageminpar == AGEOVERFLOW ||agemaxpar == AGEOVERFLOW){
+       printf("Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
+This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
+Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
+       fprintf(ficlog,"Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
+This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
+Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
+    }else
+      printinggnuplotmort(fileres, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);
     printinghtmlmort(fileres,title,datafile, firstpass, lastpass, \
                     stepm, weightopt,\
                     model,imx,p,matcov,agemortsup);
@@ -7410,7 +7435,15 @@ Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n",\
     /* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */
     
     replace_back_to_slash(pathc,pathcd); /* Even gnuplot wants a / */
-    printinggnuplot(fileres, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);
+    if(ageminpar == AGEOVERFLOW ||agemaxpar == -AGEOVERFLOW){
+       printf("Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
+This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
+Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
+       fprintf(ficlog,"Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
+This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
+Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
+    }else
+      printinggnuplot(fileres, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);
     
     printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,\
                 model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,\