version 1.169, 2014/12/22 23:08:31
|
version 1.182, 2015/02/12 08:19:57
|
Line 1
|
Line 1
|
/* $Id$ |
/* $Id$ |
$State$ |
$State$ |
$Log$ |
$Log$ |
|
Revision 1.182 2015/02/12 08:19:57 brouard |
|
Summary: Trying to keep directest which seems simpler and more general |
|
Author: Nicolas Brouard |
|
|
|
Revision 1.181 2015/02/11 23:22:24 brouard |
|
Summary: Comments on Powell added |
|
|
|
Author: |
|
|
|
Revision 1.180 2015/02/11 17:33:45 brouard |
|
Summary: Finishing move from main to function (hpijx and prevalence_limit) |
|
|
|
Revision 1.179 2015/01/04 09:57:06 brouard |
|
Summary: back to OS/X |
|
|
|
Revision 1.178 2015/01/04 09:35:48 brouard |
|
*** empty log message *** |
|
|
|
Revision 1.177 2015/01/03 18:40:56 brouard |
|
Summary: Still testing ilc32 on OSX |
|
|
|
Revision 1.176 2015/01/03 16:45:04 brouard |
|
*** empty log message *** |
|
|
|
Revision 1.175 2015/01/03 16:33:42 brouard |
|
*** empty log message *** |
|
|
|
Revision 1.174 2015/01/03 16:15:49 brouard |
|
Summary: Still in cross-compilation |
|
|
|
Revision 1.173 2015/01/03 12:06:26 brouard |
|
Summary: trying to detect cross-compilation |
|
|
|
Revision 1.172 2014/12/27 12:07:47 brouard |
|
Summary: Back from Visual Studio and Intel, options for compiling for Windows XP |
|
|
|
Revision 1.171 2014/12/23 13:26:59 brouard |
|
Summary: Back from Visual C |
|
|
|
Still problem with utsname.h on Windows |
|
|
|
Revision 1.170 2014/12/23 11:17:12 brouard |
|
Summary: Cleaning some \%% back to %% |
|
|
|
The escape was mandatory for a specific compiler (which one?), but too many warnings. |
|
|
Revision 1.169 2014/12/22 23:08:31 brouard |
Revision 1.169 2014/12/22 23:08:31 brouard |
Summary: 0.98p |
Summary: 0.98p |
|
|
Outputs some informations on compiler used, OS etc. Testing on different platforms. |
Outputs some informations on compiler used, OS etc. Testing on different platforms. |
|
|
Revision 1.168 2014/12/22 15:17:42 brouard |
Revision 1.168 2014/12/22 15:17:42 brouard |
Summary: udate |
Summary: update |
|
|
Revision 1.167 2014/12/22 13:50:56 brouard |
Revision 1.167 2014/12/22 13:50:56 brouard |
Summary: Testing uname and compiler version and if compiled 32 or 64 |
Summary: Testing uname and compiler version and if compiled 32 or 64 |
Line 519
|
Line 565
|
*/ |
*/ |
|
|
#define POWELL /* Instead of NLOPT */ |
#define POWELL /* Instead of NLOPT */ |
|
#define POWELLDIRECT /* Directest to decide new direction instead of Powell test */ |
|
|
#include <math.h> |
#include <math.h> |
#include <stdio.h> |
#include <stdio.h> |
Line 527
|
Line 574
|
|
|
#ifdef _WIN32 |
#ifdef _WIN32 |
#include <io.h> |
#include <io.h> |
|
#include <windows.h> |
|
#include <tchar.h> |
#else |
#else |
#include <unistd.h> |
#include <unistd.h> |
#endif |
#endif |
|
|
#include <limits.h> |
#include <limits.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/utsname.h> |
|
|
#if defined(__GNUC__) |
|
#include <sys/utsname.h> /* Doesn't work on Windows */ |
|
#endif |
|
|
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <errno.h> |
#include <errno.h> |
/* extern int errno; */ |
/* extern int errno; */ |
Line 598 typedef struct {
|
Line 651 typedef struct {
|
/* $Id$ */ |
/* $Id$ */ |
/* $State$ */ |
/* $State$ */ |
|
|
char version[]="Imach version 0.98p, December 2014,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.98p, FĂ©vrier 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 fullversion[]="$Revision$ $Date$"; |
char strstart[80]; |
char strstart[80]; |
char optionfilext[10], optionfilefiname[FILENAMELENGTH]; |
char optionfilext[10], optionfilefiname[FILENAMELENGTH]; |
Line 1361 void powell(double p[], double **xi, int
|
Line 1414 void powell(double p[], double **xi, int
|
double (*func)(double [])); |
double (*func)(double [])); |
int i,ibig,j; |
int i,ibig,j; |
double del,t,*pt,*ptt,*xit; |
double del,t,*pt,*ptt,*xit; |
|
double directest; |
double fp,fptt; |
double fp,fptt; |
double *xits; |
double *xits; |
int niterf, itmp; |
int niterf, itmp; |
Line 1421 void powell(double p[], double **xi, int
|
Line 1475 void powell(double p[], double **xi, int
|
printf("%d",i);fflush(stdout); |
printf("%d",i);fflush(stdout); |
fprintf(ficlog,"%d",i);fflush(ficlog); |
fprintf(ficlog,"%d",i);fflush(ficlog); |
linmin(p,xit,n,fret,func); |
linmin(p,xit,n,fret,func); |
if (fabs(fptt-(*fret)) > del) { |
if (fabs(fptt-(*fret)) > del) { /* We are keeping the max gain on each of the n directions |
|
because that direction will be replaced unless the gain del is small |
|
in comparison with the 'probable' gain, mu^2, with the last average direction. |
|
Unless the n directions are conjugate some gain in the determinant may be obtained |
|
with the new direction. |
|
*/ |
del=fabs(fptt-(*fret)); |
del=fabs(fptt-(*fret)); |
ibig=i; |
ibig=i; |
} |
} |
Line 1441 void powell(double p[], double **xi, int
|
Line 1500 void powell(double p[], double **xi, int
|
fprintf(ficlog,"\n"); |
fprintf(ficlog,"\n"); |
#endif |
#endif |
} /* end i */ |
} /* end i */ |
if (2.0*fabs(fp-(*fret)) <= ftol*(fabs(fp)+fabs(*fret))) { |
if (2.0*fabs(fp-(*fret)) <= ftol*(fabs(fp)+fabs(*fret))) { /* Did we reach enough precision? */ |
#ifdef DEBUG |
#ifdef DEBUG |
int k[2],l; |
int k[2],l; |
k[0]=1; |
k[0]=1; |
Line 1473 void powell(double p[], double **xi, int
|
Line 1532 void powell(double p[], double **xi, int
|
return; |
return; |
} |
} |
if (*iter == ITMAX) nrerror("powell exceeding maximum iterations."); |
if (*iter == ITMAX) nrerror("powell exceeding maximum iterations."); |
for (j=1;j<=n;j++) { /* Computes an extrapolated point */ |
for (j=1;j<=n;j++) { /* Computes the extrapolated point P_0 + 2 (P_n-P_0) */ |
ptt[j]=2.0*p[j]-pt[j]; |
ptt[j]=2.0*p[j]-pt[j]; |
xit[j]=p[j]-pt[j]; |
xit[j]=p[j]-pt[j]; |
pt[j]=p[j]; |
pt[j]=p[j]; |
} |
} |
fptt=(*func)(ptt); |
fptt=(*func)(ptt); /* f_3 */ |
if (fptt < fp) { /* If extrapolated point is better, decide if we keep that new direction or not */ |
if (fptt < fp) { /* If extrapolated point is better, decide if we keep that new direction or not */ |
/* (x1 f1=fp), (x2 f2=*fret), (x3 f3=fptt), (xm fm) */ |
/* (x1 f1=fp), (x2 f2=*fret), (x3 f3=fptt), (xm fm) */ |
/* From x1 (P0) distance of x2 is at h and x3 is 2h */ |
/* From x1 (P0) distance of x2 is at h and x3 is 2h */ |
/* Let f"(x2) be the 2nd derivative equal everywhere. */ |
/* Let f"(x2) be the 2nd derivative equal everywhere. */ |
/* Then the parabolic through (x1,f1), (x2,f2) and (x3,f3) */ |
/* Then the parabolic through (x1,f1), (x2,f2) and (x3,f3) */ |
/* will reach at f3 = fm + h^2/2 f"m ; f" = (f1 -2f2 +f3 ) / h**2 */ |
/* will reach at f3 = fm + h^2/2 f"m ; f" = (f1 -2f2 +f3 ) / h**2 */ |
/* f1-f3 = delta(2h) = 2 h**2 f'' = 2(f1- 2f2 +f3) */ |
/* Conditional for using this new direction is that mu^2 = (f1-2f2+f3)^2 /2 < del */ |
/* Thus we compare delta(2h) with observed f1-f3 */ |
|
/* or best gain on one ancient line 'del' with total */ |
|
/* gain f1-f2 = f1 - f2 - 'del' with del */ |
|
/* t=2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del)-del*SQR(fp-fptt); */ |
/* t=2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del)-del*SQR(fp-fptt); */ |
|
|
t=2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del); |
t=2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del); /* Intel compiler doesn't work on one line */ |
t= t- del*SQR(fp-fptt); |
t= t- del*SQR(fp-fptt); |
printf("t1= %.12lf, t2= %.12lf, t=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t); |
directest = fp-2.0*(*fret)+fptt - 2.0 * del; /* If del was big enough we change it for a new direction */ |
fprintf(ficlog,"t1= %.12lf, t2= %.12lf, t=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t); |
|
#ifdef DEBUG |
#ifdef DEBUG |
|
printf("t1= %.12lf, t2= %.12lf, t=%.12lf directest=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t,directest); |
|
fprintf(ficlog,"t1= %.12lf, t2= %.12lf, t=%.12lf directest=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t,directest); |
printf("t3= %.12lf, t4= %.12lf, t3*= %.12lf, t4*= %.12lf\n",SQR(fp-(*fret)-del),SQR(fp-fptt), |
printf("t3= %.12lf, t4= %.12lf, t3*= %.12lf, t4*= %.12lf\n",SQR(fp-(*fret)-del),SQR(fp-fptt), |
(fp-(*fret)-del)*(fp-(*fret)-del),(fp-fptt)*(fp-fptt)); |
(fp-(*fret)-del)*(fp-(*fret)-del),(fp-fptt)*(fp-fptt)); |
fprintf(ficlog,"t3= %.12lf, t4= %.12lf, t3*= %.12lf, t4*= %.12lf\n",SQR(fp-(*fret)-del),SQR(fp-fptt), |
fprintf(ficlog,"t3= %.12lf, t4= %.12lf, t3*= %.12lf, t4*= %.12lf\n",SQR(fp-(*fret)-del),SQR(fp-fptt), |
Line 1503 void powell(double p[], double **xi, int
|
Line 1560 void powell(double p[], double **xi, int
|
printf("tt= %.12lf, t=%.12lf\n",2.0*(fp-2.0*(*fret)+fptt)*(fp-(*fret)-del)*(fp-(*fret)-del)-del*(fp-fptt)*(fp-fptt),t); |
printf("tt= %.12lf, t=%.12lf\n",2.0*(fp-2.0*(*fret)+fptt)*(fp-(*fret)-del)*(fp-(*fret)-del)-del*(fp-fptt)*(fp-fptt),t); |
fprintf(ficlog, "tt= %.12lf, t=%.12lf\n",2.0*(fp-2.0*(*fret)+fptt)*(fp-(*fret)-del)*(fp-(*fret)-del)-del*(fp-fptt)*(fp-fptt),t); |
fprintf(ficlog, "tt= %.12lf, t=%.12lf\n",2.0*(fp-2.0*(*fret)+fptt)*(fp-(*fret)-del)*(fp-(*fret)-del)-del*(fp-fptt)*(fp-fptt),t); |
#endif |
#endif |
if (t < 0.0) { /* Then we use it for last direction */ |
#ifdef POWELLDIRECT |
linmin(p,xit,n,fret,func); /* computes mean on the extrapolated direction.*/ |
if (directest*t < 0.0) { /* Contradiction between both tests */ |
|
printf("directest= %.12lf, t= %.12lf, f1= %.12lf,f2= %.12lf,f3= %.12lf, del= %.12lf\n",directest, t, fp,(*fret),fptt); |
|
printf("f1-2f2+f3= %.12lf, f1-f2-del= %.12lf, f1-f3= %.12lf\n",fp-2.0*(*fret)+fptt, fp -(*fret) -del, fp-fptt); |
|
fprintf(ficlog,"directest= %.12lf, t= %.12lf, f1= %.12lf,f2= %.12lf,f3= %.12lf, del= %.12lf\n",directest, t, fp,(*fret),fptt); |
|
fprintf(ficlog,"f1-2f2+f3= %.12lf, f1-f2-del= %.12lf, f1-f3= %.12lf\n",fp-2.0*(*fret)+fptt, fp -(*fret) -del, fp-fptt); |
|
} |
|
if (directest < 0.0) { /* Then we use it for new direction */ |
|
#else |
|
if (t < 0.0) { /* Then we use it for new direction */ |
|
#endif |
|
linmin(p,xit,n,fret,func); /* computes minimum on the extrapolated direction.*/ |
for (j=1;j<=n;j++) { |
for (j=1;j<=n;j++) { |
xi[j][ibig]=xi[j][n]; /* Replace the direction with biggest decrease by n */ |
xi[j][ibig]=xi[j][n]; /* Replace direction with biggest decrease by last direction n */ |
xi[j][n]=xit[j]; /* and nth direction by the extrapolated */ |
xi[j][n]=xit[j]; /* and this nth direction by the by the average p_0 p_n */ |
} |
} |
printf("Gaining to use average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig); |
printf("Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig); |
fprintf(ficlog,"Gaining to use average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig); |
fprintf(ficlog,"Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig); |
|
|
#ifdef DEBUG |
#ifdef DEBUG |
printf("Direction changed last moved %d in place of ibig=%d, new last is the average:\n",n,ibig); |
printf("Direction changed last moved %d in place of ibig=%d, new last is the average:\n",n,ibig); |
Line 2240 void mlikeli(FILE *ficres,double p[], in
|
Line 2307 void mlikeli(FILE *ficres,double p[], in
|
#endif |
#endif |
free_matrix(xi,1,npar,1,npar); |
free_matrix(xi,1,npar,1,npar); |
fclose(ficrespow); |
fclose(ficrespow); |
printf("\n#Number of iterations & function calls = %d & %d, -2 Log likelihood = %.12f\n",iter, countcallfunc,func(p)); |
printf("#Number of iterations & function calls = %d & %d, -2 Log likelihood = %.12f\n",iter, countcallfunc,func(p)); |
fprintf(ficlog,"\n#Number of iterations & function calls = %d & %d, -2 Log likelihood = %.12f\n",iter, countcallfunc,func(p)); |
fprintf(ficlog,"#Number of iterations & function calls = %d & %d, -2 Log likelihood = %.12f\n",iter, countcallfunc,func(p)); |
fprintf(ficres,"\n#Number of iterations & function calls = %d & %d, -2 Log likelihood = %.12f\n",iter, countcallfunc,func(p)); |
fprintf(ficres,"#Number of iterations & function calls = %d & %d, -2 Log likelihood = %.12f\n",iter, countcallfunc,func(p)); |
|
|
} |
} |
|
|
Line 3628 void varevsij(char optionfilefiname[], d
|
Line 3695 void varevsij(char optionfilefiname[], d
|
/* fprintf(ficgp,"\n replot \"%s\" u 1:(($3+1.96*$4)*%6.3f) t \"95\%% interval\" w l 2 ",fileresprobmorprev,YEARM/estepm); */ |
/* fprintf(ficgp,"\n replot \"%s\" u 1:(($3+1.96*$4)*%6.3f) t \"95\%% interval\" w l 2 ",fileresprobmorprev,YEARM/estepm); */ |
/* fprintf(ficgp,"\n replot \"%s\" u 1:(($3-1.96*$4)*%6.3f) not w l 2 ",fileresprobmorprev,YEARM/estepm); */ |
/* fprintf(ficgp,"\n replot \"%s\" u 1:(($3-1.96*$4)*%6.3f) not w l 2 ",fileresprobmorprev,YEARM/estepm); */ |
fprintf(ficgp,"\n plot \"%s\" u 1:($3) not w l lt 1 ",subdirf(fileresprobmorprev)); |
fprintf(ficgp,"\n plot \"%s\" u 1:($3) not w l lt 1 ",subdirf(fileresprobmorprev)); |
fprintf(ficgp,"\n replot \"%s\" u 1:(($3+1.96*$4)) t \"95\%% interval\" w l lt 2 ",subdirf(fileresprobmorprev)); |
fprintf(ficgp,"\n replot \"%s\" u 1:(($3+1.96*$4)) t \"95%% interval\" w l lt 2 ",subdirf(fileresprobmorprev)); |
fprintf(ficgp,"\n replot \"%s\" u 1:(($3-1.96*$4)) not w l lt 2 ",subdirf(fileresprobmorprev)); |
fprintf(ficgp,"\n replot \"%s\" u 1:(($3-1.96*$4)) not w l lt 2 ",subdirf(fileresprobmorprev)); |
fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",subdirf(fileresprobmorprev),subdirf(fileresprobmorprev)); |
fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",subdirf(fileresprobmorprev),subdirf(fileresprobmorprev)); |
fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"%s%s.png\"> <br>\n", estepm,subdirf3(optionfilefiname,"varmuptjgr",digitp),digit); |
fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"%s%s.png\"> <br>\n", estepm,subdirf3(optionfilefiname,"varmuptjgr",digitp),digit); |
Line 4226 void printinggnuplot(char fileres[], cha
|
Line 4293 void printinggnuplot(char fileres[], cha
|
fprintf(ficgp,"set xlabel \"Age\" \n\ |
fprintf(ficgp,"set xlabel \"Age\" \n\ |
set ylabel \"Probability\" \n\ |
set ylabel \"Probability\" \n\ |
set ter png small size 320, 240\n\ |
set ter png small size 320, 240\n\ |
plot [%.f:%.f] \"%s\" every :::%d::%d u 1:2 \"\%%lf",ageminpar,fage,subdirf2(fileres,"vpl"),k1-1,k1-1); |
plot [%.f:%.f] \"%s\" every :::%d::%d u 1:2 \"%%lf",ageminpar,fage,subdirf2(fileres,"vpl"),k1-1,k1-1); |
|
|
for (i=1; i<= nlstate ; i ++) { |
for (i=1; i<= nlstate ; i ++) { |
if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)"); |
if (i==cpt) fprintf(ficgp," %%lf (%%lf)"); |
else fprintf(ficgp," \%%*lf (\%%*lf)"); |
else fprintf(ficgp," %%*lf (%%*lf)"); |
} |
} |
fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2+1.96*$3) \"\%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1); |
fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2+1.96*$3) \"%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1); |
for (i=1; i<= nlstate ; i ++) { |
for (i=1; i<= nlstate ; i ++) { |
if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)"); |
if (i==cpt) fprintf(ficgp," %%lf (%%lf)"); |
else fprintf(ficgp," \%%*lf (\%%*lf)"); |
else fprintf(ficgp," %%*lf (%%*lf)"); |
} |
} |
fprintf(ficgp,"\" t\"95\%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"\%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1); |
fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1); |
for (i=1; i<= nlstate ; i ++) { |
for (i=1; i<= nlstate ; i ++) { |
if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)"); |
if (i==cpt) fprintf(ficgp," %%lf (%%lf)"); |
else fprintf(ficgp," \%%*lf (\%%*lf)"); |
else fprintf(ficgp," %%*lf (%%*lf)"); |
} |
} |
fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l lt 2",subdirf2(fileres,"p"),k1-1,k1-1,2+4*(cpt-1)); |
fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l lt 2",subdirf2(fileres,"p"),k1-1,k1-1,2+4*(cpt-1)); |
} |
} |
Line 4253 plot [%.f:%.f] \"%s\" every :::%d::%d u
|
Line 4320 plot [%.f:%.f] \"%s\" every :::%d::%d u
|
|
|
for (i=1; i<= nlstate+1 ; i ++) { |
for (i=1; i<= nlstate+1 ; i ++) { |
k=2*i; |
k=2*i; |
fprintf(ficgp,"\"%s\" every :::%d::%d u 1:2 \"\%%lf",subdirf2(fileres,"t"),k1-1,k1-1); |
fprintf(ficgp,"\"%s\" every :::%d::%d u 1:2 \"%%lf",subdirf2(fileres,"t"),k1-1,k1-1); |
for (j=1; j<= nlstate+1 ; j ++) { |
for (j=1; j<= nlstate+1 ; j ++) { |
if (j==i) fprintf(ficgp," \%%lf (\%%lf)"); |
if (j==i) fprintf(ficgp," %%lf (%%lf)"); |
else fprintf(ficgp," \%%*lf (\%%*lf)"); |
else fprintf(ficgp," %%*lf (%%*lf)"); |
} |
} |
if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l ,"); |
if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l ,"); |
else fprintf(ficgp,"\" t\"LE in state (%d)\" w l ,",i-1); |
else fprintf(ficgp,"\" t\"LE in state (%d)\" w l ,",i-1); |
fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2-$3*2) \"\%%lf",subdirf2(fileres,"t"),k1-1,k1-1); |
fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2-$3*2) \"%%lf",subdirf2(fileres,"t"),k1-1,k1-1); |
for (j=1; j<= nlstate+1 ; j ++) { |
for (j=1; j<= nlstate+1 ; j ++) { |
if (j==i) fprintf(ficgp," \%%lf (\%%lf)"); |
if (j==i) fprintf(ficgp," %%lf (%%lf)"); |
else fprintf(ficgp," \%%*lf (\%%*lf)"); |
else fprintf(ficgp," %%*lf (%%*lf)"); |
} |
} |
fprintf(ficgp,"\" t\"\" w l lt 0,"); |
fprintf(ficgp,"\" t\"\" w l lt 0,"); |
fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2+$3*2) \"\%%lf",subdirf2(fileres,"t"),k1-1,k1-1); |
fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2+$3*2) \"%%lf",subdirf2(fileres,"t"),k1-1,k1-1); |
for (j=1; j<= nlstate+1 ; j ++) { |
for (j=1; j<= nlstate+1 ; j ++) { |
if (j==i) fprintf(ficgp," \%%lf (\%%lf)"); |
if (j==i) fprintf(ficgp," %%lf (%%lf)"); |
else fprintf(ficgp," \%%*lf (\%%*lf)"); |
else fprintf(ficgp," %%*lf (%%*lf)"); |
} |
} |
if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l lt 0"); |
if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l lt 0"); |
else fprintf(ficgp,"\" t\"\" w l lt 0,"); |
else fprintf(ficgp,"\" t\"\" w l lt 0,"); |
Line 5437 int calandcheckages(int imx, int maxwav,
|
Line 5504 int calandcheckages(int imx, int maxwav,
|
return (1); |
return (1); |
} |
} |
|
|
|
#if defined(_MSC_VER) |
|
/*printf("Visual C++ compiler: %s \n;", _MSC_FULL_VER);*/ |
|
/*fprintf(ficlog, "Visual C++ compiler: %s \n;", _MSC_FULL_VER);*/ |
|
//#include "stdafx.h" |
|
//#include <stdio.h> |
|
//#include <tchar.h> |
|
//#include <windows.h> |
|
//#include <iostream> |
|
typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); |
|
|
|
LPFN_ISWOW64PROCESS fnIsWow64Process; |
|
|
|
BOOL IsWow64() |
|
{ |
|
BOOL bIsWow64 = FALSE; |
|
|
|
//typedef BOOL (APIENTRY *LPFN_ISWOW64PROCESS) |
|
// (HANDLE, PBOOL); |
|
|
|
//LPFN_ISWOW64PROCESS fnIsWow64Process; |
|
|
|
HMODULE module = GetModuleHandle(_T("kernel32")); |
|
const char funcName[] = "IsWow64Process"; |
|
fnIsWow64Process = (LPFN_ISWOW64PROCESS) |
|
GetProcAddress(module, funcName); |
|
|
|
if (NULL != fnIsWow64Process) |
|
{ |
|
if (!fnIsWow64Process(GetCurrentProcess(), |
|
&bIsWow64)) |
|
//throw std::exception("Unknown error"); |
|
printf("Unknown error\n"); |
|
} |
|
return bIsWow64 != FALSE; |
|
} |
|
#endif |
|
|
void syscompilerinfo() |
void syscompilerinfo() |
{ |
{ |
/* #include "syscompilerinfo.h"*/ |
/* #include "syscompilerinfo.h"*/ |
/* #include <gnu/libc-version.h> */ /* Only on gnu */ |
|
|
#if defined __INTEL_COMPILER |
|
#if defined(__GNUC__) |
|
struct utsname sysInfo; /* For Intel on Linux and OS/X */ |
|
#endif |
|
#elif defined(__GNUC__) |
|
#ifndef __APPLE__ |
|
#include <gnu/libc-version.h> /* Only on gnu */ |
|
#endif |
|
struct utsname sysInfo; |
|
int cross = CROSS; |
|
if (cross){ |
|
printf("Cross-"); |
|
fprintf(ficlog, "Cross-"); |
|
} |
|
#endif |
|
|
|
#include <stdint.h> |
|
|
printf("Compiled with:");fprintf(ficlog,"Compiled with:"); |
printf("Compiled with:");fprintf(ficlog,"Compiled with:"); |
#if defined(__clang__) |
#if defined(__clang__) |
Line 5467 void syscompilerinfo()
|
Line 5588 void syscompilerinfo()
|
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) |
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) |
printf(" Oracle Solaris Studio");fprintf(ficlog," Oracle Solaris Studio\n");/* Oracle Solaris Studio. ----------------------------------- */ |
printf(" Oracle Solaris Studio");fprintf(ficlog," Oracle Solaris Studio\n");/* Oracle Solaris Studio. ----------------------------------- */ |
#endif |
#endif |
printf(". ");fprintf(ficlog,". "); |
printf(" for ");fprintf(ficlog," for "); |
|
|
// http://stackoverflow.com/questions/4605842/how-to-identify-platform-compiler-from-preprocessor-macros |
// http://stackoverflow.com/questions/4605842/how-to-identify-platform-compiler-from-preprocessor-macros |
#ifdef _WIN32 // note the underscore: without it, it's not msdn official! |
#ifdef _WIN32 // note the underscore: without it, it's not msdn official! |
// Windows (x64 and x86) |
// Windows (x64 and x86) |
|
printf("Windows (x64 and x86) ");fprintf(ficlog,"Windows (x64 and x86) "); |
#elif __unix__ // all unices, not all compilers |
#elif __unix__ // all unices, not all compilers |
// Unix |
// Unix |
|
printf("Unix ");fprintf(ficlog,"Unix "); |
#elif __linux__ |
#elif __linux__ |
// linux |
// linux |
|
printf("linux ");fprintf(ficlog,"linux "); |
#elif __APPLE__ |
#elif __APPLE__ |
// Mac OS, not sure if this is covered by __posix__ and/or __unix__ though... |
// Mac OS, not sure if this is covered by __posix__ and/or __unix__ though.. |
|
printf("Mac OS ");fprintf(ficlog,"Mac OS "); |
#endif |
#endif |
|
|
/* __MINGW32__ */ |
/* __MINGW32__ */ |
Line 5489 void syscompilerinfo()
|
Line 5614 void syscompilerinfo()
|
/* _WIN64 // Defined for applications for Win64. */ |
/* _WIN64 // Defined for applications for Win64. */ |
/* _M_X64 // Defined for compilations that target x64 processors. */ |
/* _M_X64 // Defined for compilations that target x64 processors. */ |
/* _DEBUG // Defined when you compile with /LDd, /MDd, and /MTd. */ |
/* _DEBUG // Defined when you compile with /LDd, /MDd, and /MTd. */ |
#include <stdint.h> |
|
#if UINTPTR_MAX == 0xffffffff |
#if UINTPTR_MAX == 0xffffffff |
printf(" 32-bit."); /* 32-bit */ |
printf(" 32-bit"); fprintf(ficlog," 32-bit");/* 32-bit */ |
#elif UINTPTR_MAX == 0xffffffffffffffff |
#elif UINTPTR_MAX == 0xffffffffffffffff |
printf(" 64-bit.");/* 64-bit */ |
printf(" 64-bit"); fprintf(ficlog," 64-bit");/* 64-bit */ |
#else |
#else |
printf(" wtf-bit."); /* wtf */ |
printf(" wtf-bit"); fprintf(ficlog," wtf-bit");/* wtf */ |
#endif |
#endif |
|
|
struct utsname sysInfo; |
|
|
|
if (uname(&sysInfo) != -1) { |
|
printf(" %s %s %s %s %s\n",sysInfo.sysname, sysInfo.nodename, sysInfo.release, sysInfo.version, sysInfo.machine); |
|
fprintf(ficlog," %s %s %s %s %s\n ",sysInfo.sysname, sysInfo.nodename, sysInfo.release, sysInfo.version, sysInfo.machine); |
|
} |
|
else |
|
perror("uname() error"); |
|
#if defined(__GNUC__) |
#if defined(__GNUC__) |
# if defined(__GNUC_PATCHLEVEL__) |
# if defined(__GNUC_PATCHLEVEL__) |
# define __GNUC_VERSION__ (__GNUC__ * 10000 \ |
# define __GNUC_VERSION__ (__GNUC__ * 10000 \ |
Line 5515 struct utsname sysInfo;
|
Line 5632 struct utsname sysInfo;
|
# define __GNUC_VERSION__ (__GNUC__ * 10000 \ |
# define __GNUC_VERSION__ (__GNUC__ * 10000 \ |
+ __GNUC_MINOR__ * 100) |
+ __GNUC_MINOR__ * 100) |
# endif |
# endif |
printf("GNU C version %d.\n", __GNUC_VERSION__); |
printf(" using GNU C version %d.\n", __GNUC_VERSION__); |
fprintf(ficlog, "GNU C version %d.\n", __GNUC_VERSION__); |
fprintf(ficlog, " using GNU C version %d.\n", __GNUC_VERSION__); |
|
|
|
if (uname(&sysInfo) != -1) { |
|
printf("Running on: %s %s %s %s %s\n",sysInfo.sysname, sysInfo.nodename, sysInfo.release, sysInfo.version, sysInfo.machine); |
|
fprintf(ficlog,"Running on: %s %s %s %s %s\n ",sysInfo.sysname, sysInfo.nodename, sysInfo.release, sysInfo.version, sysInfo.machine); |
|
} |
|
else |
|
perror("uname() error"); |
|
//#ifndef __INTEL_COMPILER |
|
#if !defined (__INTEL_COMPILER) && !defined(__APPLE__) |
|
printf("GNU libc version: %s\n", gnu_get_libc_version()); |
|
fprintf(ficlog,"GNU libc version: %s\n", gnu_get_libc_version()); |
|
#endif |
#endif |
#endif |
|
|
|
// void main() |
|
// { |
#if defined(_MSC_VER) |
#if defined(_MSC_VER) |
printf("Visual C++ compiler: %s \n;", _MSC_FULL_VER); |
if (IsWow64()){ |
fprintf(ficlog, "Visual C++ compiler: %s \n;", _MSC_FULL_VER); |
printf("The program (probably compiled for 32bit) is running under WOW64 (64bit) emulation.\n"); |
|
fprintf(ficlog, "The program (probably compiled for 32bit) is running under WOW64 (64bit) emulation.\n"); |
|
} |
|
else{ |
|
printf("The process is not running under WOW64 (i.e probably on a 64bit Windows).\n"); |
|
fprintf(ficlog,"The programm is not running under WOW64 (i.e probably on a 64bit Windows).\n"); |
|
} |
|
// printf("\nPress Enter to continue..."); |
|
// getchar(); |
|
// } |
|
|
#endif |
#endif |
|
|
/* printf("GNU libc version: %s\n", gnu_get_libc_version()); */ |
|
|
|
} |
} |
|
|
|
int prevalence_limit(double *p, double **prlim, double ageminpar, double agemaxpar){ |
|
/*--------------- Prevalence limit (period or stable prevalence) --------------*/ |
|
int i, j, k, i1 ; |
|
double ftolpl = 1.e-10; |
|
double age, agebase, agelim; |
|
|
|
strcpy(filerespl,"pl"); |
|
strcat(filerespl,fileres); |
|
if((ficrespl=fopen(filerespl,"w"))==NULL) { |
|
printf("Problem with period (stable) prevalence resultfile: %s\n", filerespl);return 1; |
|
fprintf(ficlog,"Problem with period (stable) prevalence resultfile: %s\n", filerespl);return 1; |
|
} |
|
printf("Computing period (stable) prevalence: result on file '%s' \n", filerespl); |
|
fprintf(ficlog,"Computing period (stable) prevalence: result on file '%s' \n", filerespl); |
|
pstamp(ficrespl); |
|
fprintf(ficrespl,"# Period (stable) prevalence \n"); |
|
fprintf(ficrespl,"#Age "); |
|
for(i=1; i<=nlstate;i++) fprintf(ficrespl,"%d-%d ",i,i); |
|
fprintf(ficrespl,"\n"); |
|
|
|
/* prlim=matrix(1,nlstate,1,nlstate);*/ /* back in main */ |
|
|
|
agebase=ageminpar; |
|
agelim=agemaxpar; |
|
|
|
i1=pow(2,cptcoveff); |
|
if (cptcovn < 1){i1=1;} |
|
|
|
for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
|
/* for(cptcov=1,k=0;cptcov<=1;cptcov++){ */ |
|
//for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){ |
|
k=k+1; |
|
/* to clean */ |
|
//printf("cptcov=%d cptcod=%d codtab=%d\n",cptcov, cptcod,codtab[cptcod][cptcov]); |
|
fprintf(ficrespl,"\n#******"); |
|
printf("\n#******"); |
|
fprintf(ficlog,"\n#******"); |
|
for(j=1;j<=cptcoveff;j++) { |
|
fprintf(ficrespl," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
printf(" V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
fprintf(ficlog," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
} |
|
fprintf(ficrespl,"******\n"); |
|
printf("******\n"); |
|
fprintf(ficlog,"******\n"); |
|
|
|
fprintf(ficrespl,"#Age "); |
|
for(j=1;j<=cptcoveff;j++) { |
|
fprintf(ficrespl,"V%d %d",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
} |
|
for(i=1; i<=nlstate;i++) fprintf(ficrespl,"%d-%d ",i,i); |
|
fprintf(ficrespl,"\n"); |
|
|
|
for (age=agebase; age<=agelim; age++){ |
|
/* for (age=agebase; age<=agebase; age++){ */ |
|
prevalim(prlim, nlstate, p, age, oldm, savm,ftolpl,k); |
|
fprintf(ficrespl,"%.0f ",age ); |
|
for(j=1;j<=cptcoveff;j++) |
|
fprintf(ficrespl,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
for(i=1; i<=nlstate;i++) |
|
fprintf(ficrespl," %.5f", prlim[i][i]); |
|
fprintf(ficrespl,"\n"); |
|
} /* Age */ |
|
/* was end of cptcod */ |
|
} /* cptcov */ |
|
} |
|
|
|
int hPijx(double *p, int bage, int fage){ |
|
/*------------- h Pij x at various ages ------------*/ |
|
|
|
int stepsize; |
|
int agelim; |
|
int hstepm; |
|
int nhstepm; |
|
int h, i, i1, j, k; |
|
|
|
double agedeb; |
|
double ***p3mat; |
|
|
|
strcpy(filerespij,"pij"); strcat(filerespij,fileres); |
|
if((ficrespij=fopen(filerespij,"w"))==NULL) { |
|
printf("Problem with Pij resultfile: %s\n", filerespij); return 1; |
|
fprintf(ficlog,"Problem with Pij resultfile: %s\n", filerespij); return 1; |
|
} |
|
printf("Computing pij: result on file '%s' \n", filerespij); |
|
fprintf(ficlog,"Computing pij: result on file '%s' \n", filerespij); |
|
|
|
stepsize=(int) (stepm+YEARM-1)/YEARM; |
|
/*if (stepm<=24) stepsize=2;*/ |
|
|
|
agelim=AGESUP; |
|
hstepm=stepsize*YEARM; /* Every year of age */ |
|
hstepm=hstepm/stepm; /* Typically 2 years, = 2/6 months = 4 */ |
|
|
|
/* hstepm=1; aff par mois*/ |
|
pstamp(ficrespij); |
|
fprintf(ficrespij,"#****** h Pij x Probability to be in state j at age x+h being in i at x "); |
|
i1= pow(2,cptcoveff); |
|
for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
|
/*for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ |
|
k=k+1; |
|
/* for (k=1; k <= (int) pow(2,cptcoveff); k++){*/ |
|
fprintf(ficrespij,"\n#****** "); |
|
for(j=1;j<=cptcoveff;j++) |
|
fprintf(ficrespij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
fprintf(ficrespij,"******\n"); |
|
|
|
for (agedeb=fage; agedeb>=bage; agedeb--){ /* If stepm=6 months */ |
|
nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */ |
|
nhstepm = nhstepm/hstepm; /* Typically 40/4=10 */ |
|
|
|
/* nhstepm=nhstepm*YEARM; aff par mois*/ |
|
|
|
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
|
oldm=oldms;savm=savms; |
|
hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); |
|
fprintf(ficrespij,"# Cov Agex agex+h hpijx with i,j="); |
|
for(i=1; i<=nlstate;i++) |
|
for(j=1; j<=nlstate+ndeath;j++) |
|
fprintf(ficrespij," %1d-%1d",i,j); |
|
fprintf(ficrespij,"\n"); |
|
for (h=0; h<=nhstepm; h++){ |
|
/*agedebphstep = agedeb + h*hstepm/YEARM*stepm;*/ |
|
fprintf(ficrespij,"%d %3.f %3.f",k, agedeb, agedeb + h*hstepm/YEARM*stepm ); |
|
for(i=1; i<=nlstate;i++) |
|
for(j=1; j<=nlstate+ndeath;j++) |
|
fprintf(ficrespij," %.5f", p3mat[i][j][h]); |
|
fprintf(ficrespij,"\n"); |
|
} |
|
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
|
fprintf(ficrespij,"\n"); |
|
} |
|
/*}*/ |
|
} |
|
} |
|
|
|
|
/***********************************************/ |
/***********************************************/ |
/**************** Main Program *****************/ |
/**************** Main Program *****************/ |
/***********************************************/ |
/***********************************************/ |
Line 6656 Interval (in months) between two waves:
|
Line 6934 Interval (in months) between two waves:
|
|
|
|
|
/*--------------- Prevalence limit (period or stable prevalence) --------------*/ |
/*--------------- Prevalence limit (period or stable prevalence) --------------*/ |
#include "prevlim.h" /* Use ficrespl, ficlog */ |
/*#include "prevlim.h"*/ /* Use ficrespl, ficlog */ |
|
prlim=matrix(1,nlstate,1,nlstate); |
|
prevalence_limit(p, prlim, ageminpar, agemaxpar); |
fclose(ficrespl); |
fclose(ficrespl); |
|
|
#ifdef FREEEXIT2 |
#ifdef FREEEXIT2 |
Line 6664 Interval (in months) between two waves:
|
Line 6944 Interval (in months) between two waves:
|
#endif |
#endif |
|
|
/*------------- h Pij x at various ages ------------*/ |
/*------------- h Pij x at various ages ------------*/ |
#include "hpijx.h" |
/*#include "hpijx.h"*/ |
|
hPijx(p, bage, fage); |
fclose(ficrespij); |
fclose(ficrespij); |
|
|
/*-------------- Variance of one-step probabilities---*/ |
/*-------------- Variance of one-step probabilities---*/ |