#define FILENAMELENGTH 80\r
/*#define DEBUG*/\r
#define windows\r
+#define GLOCK_ERROR_NOPATH -1 /* empty path */\r
+#define GLOCK_ERROR_GETCWD -2 /* cannot get cwd */\r
+\r
+\r
\r
#define MAXPARM 30 /* Maximum number of parameters for the optimization */\r
#define NPARMAX 64 /* (nlstate+ndeath-1)*nlstate*ncovmodel */\r
double ftolhess; /* Tolerance for computing hessian */\r
\r
\r
+static int split( char *path, char *dirc, char *name )\r
+{\r
+ char *s; /* pointer */\r
+ int l1, l2; /* length counters */\r
+\r
+ l1 = strlen( path ); /* length of path */\r
+ if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );\r
+ s = strrchr( path, '\\' ); /* find last / */\r
+ if ( s == NULL ) { /* no directory, so use current */\r
+#if defined(__bsd__) /* get current working directory */\r
+ extern char *getwd( );\r
+\r
+ if ( getwd( dirc ) == NULL ) {\r
+#else\r
+ extern char *getcwd( );\r
+\r
+ if ( getcwd( dirc, FILENAME_MAX ) == NULL ) {\r
+#endif\r
+ return( GLOCK_ERROR_GETCWD );\r
+ }\r
+ strcpy( name, path ); /* we've got it */\r
+ } else { /* strip direcotry from path */\r
+ s++; /* after this, the filename */\r
+ l2 = strlen( s ); /* length of filename */\r
+ if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH );\r
+ strcpy( name, s ); /* save file name */\r
+ strncpy( dirc, path, l1 - l2 ); /* now the directory */\r
+ dirc[l1-l2] = 0; /* add zero */\r
+ }\r
+ l1 = strlen( dirc ); /* length of directory */\r
+ if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; }\r
+ return( 0 ); /* we're done */\r
+}\r
+\r
+\r
/******************************************/\r
\r
void replace(char *s, char*t)\r
int sdeb, sfin; /* Status at beginning and end */\r
int c, h , cpt,l;\r
int ju,jl, mi;\r
- int i1,j1, k1,jk,aa,bb, stepsize;\r
+ int i1,j1, k1,k2,k3,jk,aa,bb, stepsize;\r
int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;\r
\r
int hstepm, nhstepm;\r
double ***eij, ***vareij;\r
double **varpl; /* Variances of prevalence limits by age */\r
double *epj, vepp;\r
- char version[80]="Imach version 0.64, May 2000, INED-EUROREVES ";\r
+ char version[80]="Imach version 62c, May 1999, INED-EUROREVES ";\r
char *alph[]={"a","a","b","c","d","e"}, str[4];\r
+\r
char z[1]="c", occ;\r
#include <sys/time.h>\r
#include <time.h>\r
\r
#ifdef windows\r
scanf("%s",pathtot);\r
- cygwin_split_path(pathtot,path,optionfile);\r
- printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);\r
- chdir(path);\r
- \r
- /*size=30;\r
- getcwd(pathcd, size); \r
- printf("pathcd=%s, path=%s, optionfile=%s\n",pathcd,path,optionfile);\r
- cutv(path,optionfile,pathtot,'\\');\r
+ getcwd(pathcd, size);\r
+ /*cygwin_split_path(pathtot,path,optionfile);\r
+ printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/\r
+ /* cutv(path,optionfile,pathtot,'\\');*/\r
+\r
+split(pathtot, path,optionfile);\r
chdir(path);\r
replace(pathc,path);\r
- printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);\r
- */\r
#endif\r
#ifdef unix\r
scanf("%s",optionfile);\r
} \r
num[i]=atol(stra);\r
\r
- /*printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]), (mint[2][i]), (anint[2][i]), (s[2][i]), (mint[3][i]), (anint[3][i]), (s[3][i]), (mint[4][i]), (anint[4][i]), (s[4][i]), (mint[5][i]), (anint[5][i]), (s[5][i]), (mint[6][i]), (anint[6][i]), (s[6][i]));*/\r
+ /*printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]), (mint[2][i]), (anint[2][i]), (s[2][i]), (mint[3][i]), (anint[3][i]), (s[3][i]), (mint[4][i]), (anint[4][i]), (s[4][i]));*/\r
\r
i=i+1;\r
}\r
and prints on file fileres'p'. */\r
freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax);\r
\r
-\r
- /*scanf("%d ",i);*/\r
-\r
-\r
pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */\r
oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */\r
newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */\r
/*------------ gnuplot -------------*/\r
chdir(pathcd);\r
if((ficgp=fopen("graph.plt","w"))==NULL) {\r
- printf("Problem with file graph.plt");goto end;\r
+ printf("Problem with file graph.gp");goto end;\r
}\r
#ifdef windows\r
fprintf(ficgp,"cd \"%s\" \n",pathc);\r
\r
/*3eme*/\r
\r
- for (k1=1; k1<= m ; k1 ++) { \r
+ for (k1=1; k1<= m ; k1 ++) { \r
for (cpt=1; cpt<= nlstate ; cpt ++) {\r
k=2+nlstate*(cpt-1);\r
fprintf(ficgp,"set ter gif small size 400,300\nplot [%.f:%.f] \"e%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",agemin,fage,fileres,k1-1,k1-1,k,cpt);\r
} \r
fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
}\r
- }\r
+ }\r
\r
/* CV preval stat */\r
- for (k1=1; k1<= m ; k1 ++) { \r
+ for (k1=1; k1<= m ; k1 ++) { \r
for (cpt=1; cpt<nlstate ; cpt ++) {\r
k=3;\r
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",agemin,agemax,fileres,k1,k+cpt+1,k+1);\r
fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
} \r
}\r
- \r
+\r
/* proba elementaires */\r
- for(i=1,jk=1; i <=nlstate; i++){\r
+ for(i=1,jk=1; i <=nlstate; i++){\r
for(k=1; k <=(nlstate+ndeath); k++){\r
if (k != i) {\r
- /* fprintf(ficgp,"%1d%1d ",i,k);*/\r
for(j=1; j <=ncovmodel; j++){\r
- fprintf(ficgp,"%s%1d%1d=%f ",alph[j],i,k,p[jk]);\r
+ /*fprintf(ficgp,"%s%1d%1d=%f ",alph[j],i,k,p[jk]);*/\r
+ /*fprintf(ficgp,"%s",alph[1]);*/\r
+ fprintf(ficgp,"p%d=%f ",jk,p[jk]);\r
jk++; \r
fprintf(ficgp,"\n");\r
}\r
}\r
}\r
- }\r
+ }\r
+\r
for(jk=1; jk <=m; jk++) {\r
fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot [%.f:%.f] ",agemin,agemax);\r
- for(i=1; i <=nlstate; i++) {\r
- for(k=1; k <=(nlstate+ndeath); k++){\r
- if (k != i) {\r
- fprintf(ficgp," exp(a%d%d+b%d%d*x",i,k,i,k);\r
+ i=1;\r
+ for(k2=1; k2<=nlstate; k2++) {\r
+ k3=i;\r
+ for(k=1; k<=(nlstate+ndeath); k++) {\r
+ if (k != k2){\r
+ fprintf(ficgp," exp(p%d+p%d*x",i,i+1);\r
+\r
for(j=3; j <=ncovmodel; j++) \r
- fprintf(ficgp,"+%s%d%d*%d",alph[j],i,k,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
+ fprintf(ficgp,"+p%d*%d",k2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
fprintf(ficgp,")/(1");\r
- for(k1=1; k1 <=(nlstate+ndeath); k1++) \r
- if (k1 != i) {\r
- fprintf(ficgp,"+exp(a%d%d+b%d%d*x",i,k1,i,k1);\r
+\r
+ for(k1=1; k1 <=nlstate+1; k1=k1+2){ \r
+ fprintf(ficgp,"+exp(p%d+p%d*x",k1+k3-1,k1+k3);\r
+\r
for(j=3; j <=ncovmodel; j++)\r
- fprintf(ficgp,"+%s%d%d*%d",alph[j],i,k,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
+ fprintf(ficgp,"+p%d*%d",k2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
fprintf(ficgp,")");\r
- }\r
- fprintf(ficgp,") t \"p%d%d\" ", i,k);\r
- if ((i+k)!= (nlstate*2+ndeath)) fprintf(ficgp,",");\r
- }\r
- }\r
- }\r
-fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk); \r
- }\r
- \r
- fclose(ficgp);\r
-\r
- chdir(path);\r
+ }\r
+ fprintf(ficgp,") t \"p%d%d\" ", k2,k);\r
+ if ((k+k2)!= (nlstate*2+ndeath)) fprintf(ficgp,",");\r
+ i=i+ncovmodel;\r
+ }\r
+ }\r
+ }\r
+ fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk); \r
+ }\r
+ \r
+ fclose(ficgp);\r
+ \r
+chdir(path);\r
free_matrix(agev,1,maxwav,1,imx);\r
free_ivector(wav,1,imx);\r
free_imatrix(dh,1,lastpass-firstpass+1,1,imx);\r
}\r
ungetc(c,ficpar);\r
\r
-\r
fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);\r
printf("agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax, bage, fage);\r
fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);\r
printf("Problem with index.htm \n");goto end;\r
}\r
\r
- fprintf(fichtm,"<body><ul> Imach, Version 0.63<hr> <li>Outputs files<br><br>\n\r
+ fprintf(fichtm,"<body><ul> Imach, Version 0.64a<hr> <li>Outputs files<br><br>\n\r
- Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n\r
- Estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>\r
- Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>\r
}\r
for(cpt=1; cpt<=nlstate;cpt++) {\r
fprintf(fichtm,"\n<br>- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif <br>\r
-<img src=\"ex%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);\r
+<img src=\"exp%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);\r
}\r
fprintf(fichtm,"\n<br>- Total life expectancy by age and\r
health expectancies in states (1) and (2): e%s%d.gif<br>\r
fclose(ficrest);\r
fclose(ficpar);\r
free_vector(epj,1,nlstate+1);\r
- /*scanf("%d ",i); */\r
+ /* scanf("%d ",i); */\r
\r
/*------- Variance limit prevalence------*/ \r
\r