--- imach/src/imach.c 2002/02/22 18:08:30 1.23 +++ imach/src/imach.c 2002/03/08 16:17:18 1.30 @@ -1,5 +1,5 @@ -/* $Id: imach.c,v 1.23 2002/02/22 18:08:30 lievre Exp $ - Interpolate Markov Chain +/* $Id: imach.c,v 1.30 2002/03/08 16:17:18 lievre Exp $ + Interpolated Markov Chain Short summary of the programme: @@ -94,8 +94,8 @@ int **dh; /* dh[mi][i] is number of step double jmean; /* Mean space between 2 waves */ double **oldm, **newm, **savm; /* Working pointers to matrices */ double **oldms, **newms, **savms; /* Fixed working pointers to matrices */ -FILE *fic,*ficpar, *ficparo,*ficres, *ficrespl, *ficrespij, *ficrest,*ficresf; -FILE *ficgp, *fichtm,*ficresprob,*ficpop; +FILE *fic,*ficpar, *ficparo,*ficres, *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop; +FILE *ficgp,*ficresprob,*ficpop; FILE *ficreseij; char filerese[FILENAMELENGTH]; FILE *ficresvij; @@ -123,7 +123,7 @@ FILE *ficreseij; static double maxarg1,maxarg2; #define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)>(maxarg2)? (maxarg1):(maxarg2)) #define FMIN(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)<(maxarg2)? (maxarg1):(maxarg2)) - + #define SIGN(a,b) ((b)>0.0 ? fabs(a) : -fabs(a)) #define rint(a) floor(a+0.5) @@ -1176,7 +1176,7 @@ void lubksb(double **a, int n, int *indx } /************ Frequencies ********************/ -void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2) +void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2,double jprev1, double mprev1,double anprev1,double jprev2, double mprev2,double anprev2) { /* Some frequencies */ int i, m, jk, k1,i1, j1, bool, z1,z2,j; @@ -1185,7 +1185,7 @@ void freqsummary(char fileres[], int ag double pos, k2, dateintsum=0,k2cpt=0; FILE *ficresp; char fileresp[FILENAMELENGTH]; - + pp=vector(1,nlstate); probs= ma3x(1,AGESUP,1,NCOVMAX, 1,NCOVMAX); strcpy(fileresp,"p"); @@ -1236,6 +1236,9 @@ void freqsummary(char fileres[], int ag } } } + + fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); + if (cptcovn>0) { fprintf(ficresp, "\n#********** Variable "); for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]); @@ -1304,7 +1307,7 @@ void freqsummary(char fileres[], int ag } /************ Prevalence ********************/ -void prevalence(int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2, double calagedate) +void prevalence(int agemin, float agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2, double calagedate) { /* Some frequencies */ int i, m, jk, k1, i1, j1, bool, z1,z2,j; @@ -1329,14 +1332,14 @@ void prevalence(int agemin, int agemax, for (jk=-1; jk<=nlstate+ndeath; jk++) for(m=agemin; m <= agemax+3; m++) freq[i][jk][m]=0; - + for (i=1; i<=imx; i++) { bool=1; if (cptcovn>0) { for (z1=1; z1<=cptcoveff; z1++) if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) bool=0; - } + } if (bool==1) { for(m=firstpass; m<=lastpass; m++){ k2=anint[m][i]+(mint[m][i]/12.); @@ -1344,12 +1347,11 @@ void prevalence(int agemin, int agemax, if(agev[m][i]==0) agev[m][i]=agemax+1; if(agev[m][i]==1) agev[m][i]=agemax+2; freq[s[m][i]][s[m+1][i]][(int)(agev[m][i]+1-((int)calagedate %12)/12.)] += weight[i]; - freq[s[m][i]][s[m+1][i]][(int)(agemax+3+1)] += weight[i]; + /* freq[s[m][i]][s[m+1][i]][(int)(agemax+3+1)] += weight[i]; */ } } } } - for(i=(int)agemin; i <= (int)agemax+3; i++){ for(jk=1; jk <=nlstate ; jk++){ for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++) @@ -1441,7 +1443,7 @@ void concatwav(int wav[], int **dh, int if (j >= jmax) jmax=j; if (j <= jmin) jmin=j; sum=sum+j; - /* if (j<10) printf("j=%d num=%d ",j,i); */ + /*if (j<0) printf("j=%d num=%d \n",j,i); */ } } else{ @@ -1449,7 +1451,7 @@ void concatwav(int wav[], int **dh, int k=k+1; if (j >= jmax) jmax=j; else if (j <= jmin)jmin=j; - /* if (j<10) printf("j=%d jmin=%d num=%d ",j,jmin,i); */ + /* if (j<10) printf("j=%d jmin=%d num=%d ",j,jmin,i); */ sum=sum+j; } jk= j/stepm; @@ -1544,26 +1546,29 @@ void evsij(char fileres[], double ***eij /* nhstepm age range expressed in number of stepm */ nhstepm=(int) rint((agelim-age)*YEARM/stepm); /* Typically if 20 years = 20*12/6=40 stepm */ - if (stepm >= YEARM) hstepm=1; + /*if (stepm >= YEARM) hstepm=1;*/ +hstepm=1; nhstepm = nhstepm/hstepm;/* Expressed in hstepm, typically 40/4=10 */ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); /* Computed by stepm unit matrices, product of hstepm matrices, stored in an array of nhstepm length: nhstepm=10, hstepm=4, stepm=6 months */ hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm, savm, ij); - - +hf=stepm/YEARM; +/*printf("stepm=%d nhstepm=%d hstepm=%d age=%lf ",stepm, nhstepm, hstepm, age);*/ for(i=1; i<=nlstate;i++) for(j=1; j<=nlstate;j++) - for (h=0, eij[i][j][(int)age]=0; h<=nhstepm; h++){ - eij[i][j][(int)age] +=p3mat[i][j][h]; + for (h=0, eij[i][j][(int)age]=0; h<=nhstepm-1; h++){ + eij[i][j][(int)age] +=hf*(p3mat[i][j][h]+p3mat[i][j][h+1])/2.0; } - hf=1; - if (stepm >= YEARM) hf=stepm/YEARM; - fprintf(ficreseij,"%.0f",age ); + /* hf=1; + if (stepm >= YEARM) hf=stepm/YEARM;*/ +hf=stepm/YEARM; + + fprintf(ficreseij,"%3.0f",age ); for(i=1; i<=nlstate;i++) for(j=1; j<=nlstate;j++){ - fprintf(ficreseij," %.4f", hf*eij[i][j][(int)age]); + fprintf(ficreseij," %9.4f", eij[i][j][(int)age]); } fprintf(ficreseij,"\n"); free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); @@ -1620,7 +1625,7 @@ void varevsij(char fileres[], double *** for(i=1; i<=nlstate;i++) prlim[i][i]=probs[(int)age][i][ij]; } - + for(j=1; j<= nlstate; j++){ for(h=0; h<=nhstepm; h++){ for(i=1, gp[h][j]=0.;i<=nlstate;i++) @@ -1632,7 +1637,7 @@ void varevsij(char fileres[], double *** xp[i] = x[i] - (i==theta ?delti[theta]:0); hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij); prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ij); - + if (popbased==1) { for(i=1; i<=nlstate;i++) prlim[i][i]=probs[(int)age][i][ij]; @@ -1684,7 +1689,7 @@ void varevsij(char fileres[], double *** free_ma3x(trgradg,0,nhstepm,1,nlstate,1,npar); free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); } /* End age */ - + free_vector(xp,1,npar); free_matrix(doldm,1,nlstate,1,npar); free_matrix(dnewm,1,nlstate,1,nlstate); @@ -1876,146 +1881,665 @@ if (i== 4) fprintf(ficresprob,"%.3e %.3e } free_vector(xp,1,npar); fclose(ficresprob); - exit(0); -} - -/***********************************************/ -/**************** Main Program *****************/ -/***********************************************/ - -int main(int argc, char *argv[]) -{ - - int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod; - double agedeb, agefin,hf; - double agemin=1.e20, agemax=-1.e20; - double fret; - double **xi,tmp,delta; - - double dum; /* Dummy variable */ - double ***p3mat; - int *indx; - char line[MAXLINE], linepar[MAXLINE]; - char title[MAXLINE]; - char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH]; - char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH]; - - char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH]; - - char filerest[FILENAMELENGTH]; - char fileregp[FILENAMELENGTH]; - char popfile[FILENAMELENGTH]; - char path[80],pathc[80],pathcd[80],pathtot[80],model[20]; - int firstobs=1, lastobs=10; - int sdeb, sfin; /* Status at beginning and end */ - int c, h , cpt,l; - int ju,jl, mi; - int i1,j1, k1,k2,k3,jk,aa,bb, stepsize, ij; - int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab; - int mobilav=0,popforecast=0; - int hstepm, nhstepm; - int *popage;/*boolprev=0 if date and zero if wave*/ - double jprev1, mprev1,anprev1,jprev2, mprev2,anprev2; +} - double bage, fage, age, agelim, agebase; - double ftolpl=FTOL; - double **prlim; - double *severity; - double ***param; /* Matrix of parameters */ - double *p; - double **matcov; /* Matrix of covariance */ - double ***delti3; /* Scale */ - double *delti; /* Scale */ - double ***eij, ***vareij; - double **varpl; /* Variances of prevalence limits by age */ - double *epj, vepp; - double kk1, kk2; - double *popeffectif,*popcount; - double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,jprojmean,mprojmean,anprojmean, calagedate; - double yp,yp1,yp2; +/******************* Printing html file ***********/ +void printinghtml(char fileres[], char title[], char datafile[], int firstpass, int lastpass, int stepm, int weightopt, char model[],int imx,int jmin, int jmax, double jmeanint,char optionfile[],char optionfilehtm[],char rfileres[] ){ + int jj1, k1, i1, cpt; + FILE *fichtm; + /*char optionfilehtm[FILENAMELENGTH];*/ - char version[80]="Imach version 0.7, February 2002, INED-EUROREVES "; - char *alph[]={"a","a","b","c","d","e"}, str[4]; + strcpy(optionfilehtm,optionfile); + strcat(optionfilehtm,".htm"); + if((fichtm=fopen(optionfilehtm,"w"))==NULL) { + printf("Problem with %s \n",optionfilehtm), exit(0); + } + fprintf(fichtm,"