--- imach/src/imach.c 2019/05/09 13:44:18 1.291 +++ imach/src/imach.c 2019/05/09 14:17:20 1.292 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.291 2019/05/09 13:44:18 brouard Exp $ +/* $Id: imach.c,v 1.292 2019/05/09 14:17:20 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.292 2019/05/09 14:17:20 brouard + Summary: Some updates + Revision 1.291 2019/05/09 13:44:18 brouard Summary: Before ncovmax @@ -1081,12 +1084,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.291 2019/05/09 13:44:18 brouard Exp $ */ +/* $Id: imach.c,v 1.292 2019/05/09 14:17:20 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="April 2018,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018"; -char fullversion[]="$Revision: 1.291 $ $Date: 2019/05/09 13:44:18 $"; +char fullversion[]="$Revision: 1.292 $ $Date: 2019/05/09 14:17:20 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -2992,7 +2995,7 @@ double **pmij(double **ps, double *cov, double **out, **pmij(); double sumnew=0.; double agefin; - double k3=0.; /* constant of the w_x diagonal matrixe (in order for B to sum to 1 even for death state) */ + double k3=0.; /* constant of the w_x diagonal matrix (in order for B to sum to 1 even for death state) */ double **dnewm, **dsavm, **doldm; double **bbmij; @@ -3011,7 +3014,7 @@ double **pmij(double **ps, double *cov, /* outputs pmmij which is a stochastic matrix in row */ /* Diag(w_x) */ - /* Problem with prevacurrent which can be zero */ + /* Rescaling the cross-sectional prevalence: Problem with prevacurrent which can be zero */ sumnew=0.; /*for (ii=1;ii<=nlstate+ndeath;ii++){*/ for (ii=1;ii<=nlstate;ii++){ /* Only on live states */ @@ -3038,10 +3041,10 @@ double **pmij(double **ps, double *cov, } /* End doldm, At the end doldm is diag[(w_i)] */ - /* left Product of this diag matrix by pmmij=Px (dnewm=dsavm*doldm) */ - bbmij=matprod2(dnewm, doldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, pmmij); /* Bug Valgrind */ + /* Left product of this diag matrix by pmmij=Px (dnewm=dsavm*doldm): diag[(w_i)*Px */ + bbmij=matprod2(dnewm, doldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, pmmij); /* was a Bug Valgrind */ - /* Diag(Sum_i w^i_x p^ij_x */ + /* Diag(Sum_i w^i_x p^ij_x, should be the prevalence at age x+stepm */ /* w1 p11 + w2 p21 only on live states N1./N..*N11/N1. + N2./N..*N21/N2.=(N11+N21)/N..=N.1/N.. */ for (j=1;j<=nlstate+ndeath;j++){ sumnew=0.; @@ -3059,7 +3062,7 @@ double **pmij(double **ps, double *cov, } /*End ii */ } /* End j, At the end dsavm is diag[1/(w_1p1i+w_2 p2i)] for ALL states even if the sum is only for live states */ - ps=matprod2(ps, dnewm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, dsavm); /* Bug Valgrind */ + ps=matprod2(ps, dnewm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, dsavm); /* was a Bug Valgrind */ /* ps is now diag[w_i] * Px * diag [1/(w_1p1i+w_2 p2i)] */ /* end bmij */ return ps; /*pointer is unchanged */ @@ -3891,7 +3894,7 @@ return -l; /*************** function likelione ***********/ -void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, long *ipmx, double *sw, double *fretone, double (*funcone)(double [])) +void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, long *ipmx, double *sw, double *fretone, double (*func)(double [])) { /* This routine should help understanding what is done with the selection of individuals/waves and @@ -3915,7 +3918,7 @@ void likelione(FILE *ficres,double p[], fprintf(ficresilk," -2*gipw/gsw*weight*ll(total)\n"); } - *fretone=(*funcone)(p); + *fretone=(*func)(p); if(*globpri !=0){ fclose(ficresilk); if (mle ==0) @@ -6009,7 +6012,7 @@ void concatwav(int wav[], int **dh, int /**< Computes the shifted transition matrix \f$ {}{h}_p^{ij}_x\f$ at horizon h. */ hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij,nres); /* Returns p3mat[i][j][h] for h=0 to nhstepm */ - /**< And for each alive state j, sums over i \f$ w^i_x {}{h}_p^{ij}_x\f$, which are the probability + /**< And for each alive state j, sums over i \f$ w^i_x {}{h}_p^{ij}x\f$, which are the probability * at horizon h in state j including mortality. */ for(j=1; j<= nlstate; j++){ @@ -6931,13 +6934,13 @@ divided by h: hPij ",stepm,subdirf2(optionfilefiname,"PE_"),k1,nres,subdirf2(optionfilefiname,"PE_"),k1,nres,subdirf2(optionfilefiname,"PE_"),k1,nres); /* Survival functions (period) in state j */ for(cpt=1; cpt<=nlstate;cpt++){ - fprintf(fichtm,"
\n- Survival functions in state %d. Or probability to survive in state %d being in state (1 to %d) at different ages. %s_%d-%d-%d.svg
\ + fprintf(fichtm,"
\n- Survival functions in state %d. And probability to be observed in state %d being in state (1 to %d) at different ages. %s_%d-%d-%d.svg
\ ", cpt, cpt, nlstate, subdirf2(optionfilefiname,"LIJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJ_"),cpt,k1,nres); } /* State specific survival functions (period) */ for(cpt=1; cpt<=nlstate;cpt++){ - fprintf(fichtm,"
\n- Survival functions from state %d in each live state and total.\ - Or probability to survive in various states (1 to %d) being in state %d at different ages. \ + fprintf(fichtm,"
\n- Survival functions in state %d and in any other live state (total).\ + And probability to be observed in various states (up to %d) being in state %d at different ages. \ %s_%d-%d-%d.svg
", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres); } /* Period (forward stable) prevalence in each health state */ @@ -10199,8 +10202,10 @@ BOOL IsWow64() #endif void syscompilerinfo(int logged) - { - /* #include "syscompilerinfo.h"*/ +{ +#include + + /* #include "syscompilerinfo.h"*/ /* command line Intel compiler 32bit windows, XP compatible:*/ /* /GS /W3 /Gy /Zc:wchar_t /Zi /O2 /Fd"Release\vc120.pdb" /D "WIN32" /D "NDEBUG" /D @@ -10235,6 +10240,8 @@ void syscompilerinfo(int logged) /ManifestFile:"Release\IMaCh.exe.intermediate.manifest" /OPT:ICF /NOLOGO /TLBID:1 */ + + #if defined __INTEL_COMPILER #if defined(__GNUC__) struct utsname sysInfo; /* For Intel on Linux and OS/X */ @@ -10251,8 +10258,6 @@ void syscompilerinfo(int logged) } #endif -#include - printf("Compiled with:");if(logged)fprintf(ficlog,"Compiled with:"); #if defined(__clang__) printf(" Clang/LLVM");if(logged)fprintf(ficlog," Clang/LLVM"); /* Clang/LLVM. ---------------------------------------------- */ @@ -10782,7 +10787,7 @@ int main(int argc, char *argv[]) int *tab; int mobilavproj=0 , prevfcast=0 ; /* moving average of prev, If prevfcast=1 prevalence projection */ - int backcast=0; + /* int backcast=0; */ /* defined as global for mlikeli and mle */ int mobilav=0,popforecast=0; int hstepm=0, nhstepm=0; int agemortsup; @@ -11207,6 +11212,15 @@ int main(int argc, char *argv[]) for(jj=1; jj <=nlstate+ndeath; jj++){ if(jj==i) continue; j++; + while((c=getc(ficpar))=='#' && c!= EOF){ + ungetc(c,ficpar); + fgets(line, MAXLINE, ficpar); + numlinepar++; + fputs(line,stdout); + fputs(line,ficparo); + fputs(line,ficlog); + } + ungetc(c,ficpar); fscanf(ficpar,"%1d%1d",&i1,&j1); if ((i1 != i) || (j1 != jj)){ printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n \ @@ -12821,13 +12835,16 @@ Please run with mle=-1 to get a correct sprintf(plotcmd,"%s %s",pplotcmd, optionfilegnuplot); printf("Starting graphs with: '%s'\n",plotcmd);fflush(stdout); + strcpy(pplotcmd,plotcmd); if((outcmd=system(plotcmd)) != 0){ - printf("gnuplot command might not be in your path: '%s', err=%d\n", plotcmd, outcmd); + printf("Error in gnuplot, command might not be in your path: '%s', err=%d\n", plotcmd, outcmd); printf("\n Trying if gnuplot resides on the same directory that IMaCh\n"); sprintf(plotcmd,"%sgnuplot %s", pathimach, optionfilegnuplot); - if((outcmd=system(plotcmd)) != 0) + if((outcmd=system(plotcmd)) != 0){ printf("\n Still a problem with gnuplot command %s, err=%d\n", plotcmd, outcmd); + strcpy(plotcmd,pplotcmd); + } } printf(" Successful, please wait..."); while (z[0] != 'q') {