--- imach/src/imach.c 2003/06/18 12:26:01 1.87
+++ imach/src/imach.c 2003/06/24 12:34:15 1.90
@@ -1,6 +1,19 @@
-/* $Id: imach.c,v 1.87 2003/06/18 12:26:01 brouard Exp $
+/* $Id: imach.c,v 1.90 2003/06/24 12:34:15 brouard Exp $
$State: Exp $
$Log: imach.c,v $
+ Revision 1.90 2003/06/24 12:34:15 brouard
+ (Module): Some bugs corrected for windows. Also, when
+ mle=-1 a template is output in file "or"mypar.txt with the design
+ of the covariance matrix to be input.
+
+ Revision 1.89 2003/06/24 12:30:52 brouard
+ (Module): Some bugs corrected for windows. Also, when
+ mle=-1 a template is output in file "or"mypar.txt with the design
+ of the covariance matrix to be input.
+
+ Revision 1.88 2003/06/23 17:54:56 brouard
+ * imach.c (Repository): Create a sub-directory where all the secondary files are. Only imach, htm, gp and r(imach) are on the main directory. Correct time and other things.
+
Revision 1.87 2003/06/18 12:26:01 brouard
Version 0.96
@@ -161,11 +174,11 @@
#define ODIRSEPARATOR '/'
#endif
-/* $Id: imach.c,v 1.87 2003/06/18 12:26:01 brouard Exp $ */
+/* $Id: imach.c,v 1.90 2003/06/24 12:34:15 brouard Exp $ */
/* $State: Exp $ */
-char version[]="Imach version 0.96, June 2003, INED-EUROREVES ";
-char fullversion[]="$Revision: 1.87 $ $Date: 2003/06/18 12:26:01 $";
+char version[]="Imach version 0.96a, June 2003, INED-EUROREVES ";
+char fullversion[]="$Revision: 1.90 $ $Date: 2003/06/24 12:34:15 $";
int erreur; /* Error number */
int nvar;
int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov;
@@ -208,8 +221,12 @@ char fileresvpl[FILENAMELENGTH];
char title[MAXLINE];
char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH];
char optionfilext[10], optionfilefiname[FILENAMELENGTH], plotcmd[FILENAMELENGTH];
+char tmpout[FILENAMELENGTH];
+char command[FILENAMELENGTH];
+int outcmd=0;
char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH];
+char lfileres[FILENAMELENGTH];
char filelog[FILENAMELENGTH]; /* Log file */
char filerest[FILENAMELENGTH];
char fileregp[FILENAMELENGTH];
@@ -313,10 +330,10 @@ static int split( char *path, char *dirc
/******************************************/
-void replace(char *s, char*t)
+void replace_back_to_slash(char *s, char*t)
{
int i;
- int lg=20;
+ int lg=0;
i=0;
lg=strlen(t);
for(i=0; i<= lg; i++) {
@@ -1357,7 +1374,7 @@ 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,"%ld %6d %1d %1d %1d %1d %3d %10.6f %6.4f\
+ fprintf(ficresilk,"%9d %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]);
@@ -1379,6 +1396,34 @@ double funcone( double *x)
return -l;
}
+char *subdirf(char fileres[])
+{
+
+ strcpy(tmpout,optionfilefiname);
+ strcat(tmpout,"/"); /* Add to the right */
+ strcat(tmpout,fileres);
+ return tmpout;
+}
+
+char *subdirf2(char fileres[], char *preop)
+{
+
+ strcpy(tmpout,optionfilefiname);
+ strcat(tmpout,"/");
+ strcat(tmpout,preop);
+ strcat(tmpout,fileres);
+ return tmpout;
+}
+char *subdirf3(char fileres[], char *preop, char *preop2)
+{
+
+ strcpy(tmpout,optionfilefiname);
+ strcat(tmpout,"/");
+ strcat(tmpout,preop);
+ strcat(tmpout,preop2);
+ strcat(tmpout,fileres);
+ return tmpout;
+}
void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, long *ipmx, double *sw, double *fretone, double (*funcone)(double []))
{
@@ -1389,7 +1434,7 @@ void likelione(FILE *ficres,double p[],
*/
int k;
- if(*globpri !=0){ /* Just counts and sums no printings */
+ if(*globpri !=0){ /* Just counts and sums, no printings */
strcpy(fileresilk,"ilk");
strcat(fileresilk,fileres);
if((ficresilk=fopen(fileresilk,"w"))==NULL) {
@@ -1397,7 +1442,7 @@ void likelione(FILE *ficres,double p[],
fprintf(ficlog,"Problem with resultfile: %s\n", fileresilk);
}
fprintf(ficresilk, "#individual(line's_record) s1 s2 wave# effective_wave# number_of_matrices_product pij weight -2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state(reweighted=-2ll*weightXnumber_of_contribs/sum_of_weights) and_total\n");
- fprintf(ficresilk, "#num_i i s1 s2 mi mw dh likeli weight out sav ");
+ fprintf(ficresilk, "#num_i i s1 s2 mi mw dh likeli weight 2wlli 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," -2*gipw/gsw*weight*ll[%d]++",k);
@@ -1407,12 +1452,13 @@ void likelione(FILE *ficres,double p[],
*fretone=(*funcone)(p);
if(*globpri !=0){
fclose(ficresilk);
- fprintf(fichtm,"\n
File of contributions to the likelihood: %s
\n",fileresilk,fileresilk);
+ fprintf(fichtm,"\n
File of contributions to the likelihood: %s
\n",subdirf(fileresilk),subdirf(fileresilk));
fflush(fichtm);
}
return;
}
+
/*********** Maximum Likelihood Estimation ***************/
void mlikeli(FILE *ficres,double p[], int npar, int ncovmodel, int nlstate, double ftol, double (*func)(double []))
@@ -2368,20 +2414,7 @@ void varevsij(char optionfilefiname[], d
fprintf(ficresprobmorprev," w%1d p%-d%-d",i,i,j);
}
fprintf(ficresprobmorprev,"\n");
- if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) {
- printf("Problem with gnuplot file: %s\n", optionfilegnuplot);
- fprintf(ficlog,"Problem with gnuplot file: %s\n", optionfilegnuplot);
- exit(0);
- }
- else{
- fprintf(ficgp,"\n# Routine varevsij");
- }
-/* 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(ficgp,"\n# Routine varevsij");
fprintf(fichtm,"\n
Computing probabilities of dying over estepm months as a weighted average (i.e global mortality independent of initial healh state)
\n");
fprintf(fichtm,"\n
%s
\n",digitp);
/* } */
@@ -2596,14 +2629,15 @@ void varevsij(char optionfilefiname[], d
/* fprintf(ficgp,"\n plot \"%s\" u 1:($3*%6.3f) not w l 1 ",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 plot \"%s\" u 1:($3) not w l 1 ",fileresprobmorprev);
- fprintf(ficgp,"\n replot \"%s\" u 1:(($3+1.96*$4)) t \"95\%% interval\" w l 2 ",fileresprobmorprev);
- fprintf(ficgp,"\n replot \"%s\" u 1:(($3-1.96*$4)) not w l 2 ",fileresprobmorprev);
- fprintf(fichtm,"\n
File (multiple files are possible if covariates are present): %s\n",fileresprobmorprev,fileresprobmorprev);
- fprintf(fichtm,"\n
Probability is computed over estepm=%d months.
\n", estepm,digitp,optionfilefiname,digit);
+ fprintf(ficgp,"\n plot \"%s\" u 1:($3) not w l 1 ",subdirf(fileresprobmorprev));
+ fprintf(ficgp,"\n replot \"%s\" u 1:(($3+1.96*$4)) t \"95\%% interval\" w l 2 ",subdirf(fileresprobmorprev));
+ fprintf(ficgp,"\n replot \"%s\" u 1:(($3-1.96*$4)) not w l 2 ",subdirf(fileresprobmorprev));
+ fprintf(fichtm,"\n
File (multiple files are possible if covariates are present): %s\n",subdirf(fileresprobmorprev),subdirf(fileresprobmorprev));
+ fprintf(fichtm,"\n
Probability is computed over estepm=%d months.
\n", estepm,subdirf3(optionfilefiname,"varmuptjgr",digitp),digit);
/* fprintf(fichtm,"\n
Probability is computed over estepm=%d months and then divided by estepm and multiplied by %.0f in order to have the probability to die over a year
\n", stepm,YEARM,digitp,digit);
*/
- fprintf(ficgp,"\nset out \"varmuptjgr%s%s%s.png\";replot;",digitp,optionfilefiname,digit);
+/* fprintf(ficgp,"\nset out \"varmuptjgr%s%s%s.png\";replot;",digitp,optionfilefiname,digit); */
+ fprintf(ficgp,"\nset out \"%s%s.png\";replot;\n",subdirf3(optionfilefiname,"varmuptjgr",digitp),digit);
free_vector(xp,1,npar);
free_matrix(doldm,1,nlstate,1,nlstate);
@@ -2613,8 +2647,8 @@ void varevsij(char optionfilefiname[], d
free_matrix(varppt,nlstate+1,nlstate+ndeath,nlstate+1,nlstate+ndeath);
if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
fclose(ficresprobmorprev);
- fclose(ficgp);
-/* fclose(fichtm); */
+ fflush(ficgp);
+ fflush(fichtm);
} /* end varevsij */
/************ Variance of prevlim ******************/
@@ -2771,28 +2805,13 @@ void varprob(char optionfilefiname[], do
mu=matrix(1,(nlstate)*(nlstate+ndeath), (int) bage, (int)fage);
varpij=ma3x(1,nlstate*(nlstate+ndeath),1,nlstate*(nlstate+ndeath),(int) bage, (int) fage);
first=1;
- if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) {
- printf("Problem with gnuplot file: %s\n", optionfilegnuplot);
- fprintf(ficlog,"Problem with gnuplot file: %s\n", optionfilegnuplot);
- exit(0);
- }
- else{
- fprintf(ficgp,"\n# Routine varprob");
- }
-/* 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 Computing and drawing one step probabilities with their confidence intervals
\n");
- fprintf(fichtm,"\n");
-
- fprintf(fichtm,"\n Computing matrix of variance-covariance of step probabilities
\n");
- fprintf(fichtm,"\nWe have drawn ellipsoids of confidence around the pij, pkl to understand the covariance between two incidences. They are expressed in year-1 in order to be less dependent of stepm.
\n");
- fprintf(fichtm,"\n
We have drawn x'cov-1x = 4 where x is the column vector (pij,pkl). It means that if pij and pkl where uncorrelated the (2X2) matrix would have been (1/(var pij), 0 , 0, 1/(var pkl)), and the confidence interval would be 2 standard deviations wide on each axis.
When both incidences are correlated we diagonalised the inverse of the covariance matrix and made the appropriate rotation.
\n");
-
-/* } */
+ fprintf(ficgp,"\n# Routine varprob");
+ fprintf(fichtm,"\n Computing and drawing one step probabilities with their confidence intervals
\n");
+ fprintf(fichtm,"\n");
+
+ fprintf(fichtm,"\n Computing matrix of variance-covariance of step probabilities
\n");
+ fprintf(fichtm,"\nWe have drawn ellipsoids of confidence around the pij, pkl to understand the covariance between two incidences. They are expressed in year-1 in order to be less dependent of stepm.
\n");
+ fprintf(fichtm,"\n
We have drawn x'cov-1x = 4 where x is the column vector (pij,pkl). It means that if pij and pkl where uncorrelated the (2X2) matrix would have been (1/(var pij), 0 , 0, 1/(var pkl)), and the confidence interval would be 2 standard deviations wide on each axis.
When both incidences are correlated we diagonalised the inverse of the covariance matrix and made the appropriate rotation.
\n");
cov[1]=1;
tj=cptcoveff;
@@ -2974,10 +2993,14 @@ void varprob(char optionfilefiname[], do
fprintf(ficgp,"\nset parametric;unset label");
fprintf(ficgp,"\nset log y;set log x; set xlabel \"p%1d%1d (year-1)\";set ylabel \"p%1d%1d (year-1)\"",k1,l1,k2,l2);
fprintf(ficgp,"\nset ter png small\nset size 0.65,0.65");
- fprintf(fichtm,"\n
Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year-1 :varpijgr%s%d%1d%1d-%1d%1d.png, ",k1,l1,k2,l2,optionfilefiname, j1,k1,l1,k2,l2,optionfilefiname, j1,k1,l1,k2,l2);
- fprintf(fichtm,"\n
",optionfilefiname, j1,k1,l1,k2,l2);
+ fprintf(fichtm,"\n
Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year-1\
+ :\
+%s%d%1d%1d-%1d%1d.png, ",k1,l1,k2,l2,\
+ subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2,\
+ subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);
+ fprintf(fichtm,"\n
",subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);
fprintf(fichtm,"\n
Correlation at age %d (%.3f),",(int) age, c12);
- fprintf(ficgp,"\nset out \"varpijgr%s%d%1d%1d-%1d%1d.png\"",optionfilefiname, j1,k1,l1,k2,l2);
+ fprintf(ficgp,"\nset out \"%s%d%1d%1d-%1d%1d.png\"",subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);
fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu1,mu2);
fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k1,l1,k2,l2);
fprintf(ficgp,"\nplot [-pi:pi] %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) not",\
@@ -2994,7 +3017,7 @@ void varprob(char optionfilefiname[], do
}/* if first */
} /* age mod 5 */
} /* end loop age */
- fprintf(ficgp,"\nset out \"varpijgr%s%d%1d%1d-%1d%1d.png\";replot;",optionfilefiname, j1,k1,l1,k2,l2);
+ fprintf(ficgp,"\nset out \"%s%d%1d%1d-%1d%1d.png\";replot;",subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);
first=1;
} /*l12 */
} /* k12 */
@@ -3008,7 +3031,7 @@ void varprob(char optionfilefiname[], do
fclose(ficresprob);
fclose(ficresprobcov);
fclose(ficresprobcor);
- fclose(ficgp);
+ /* fclose(ficgp);*/
}
@@ -3027,12 +3050,15 @@ void printinghtml(char fileres[], char t
/* } */
fprintf(fichtm,"