--- imach/src/imach.c 2002/02/20 17:08:52 1.15 +++ imach/src/imach.c 2002/02/20 17:15:02 1.17 @@ -85,7 +85,7 @@ double jmean; /* Mean space between 2 wa 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; +FILE *ficgp, *fichtm,*ficresprob,*ficpop; FILE *ficreseij; char filerese[FILENAMELENGTH]; FILE *ficresvij; @@ -1150,10 +1150,10 @@ 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, int fprev1,int lprev1) +void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax, int fprev1,int lprev1,double **mint,double **anint) { /* Some frequencies */ - int i, m, jk, k1, i1, j1, bool, z1,z2,j; + int i, m, jk, k1, k2,i1, j1, bool, z1,z2,j; double ***freq; /* Frequencies */ double *pp; double pos; @@ -1161,7 +1161,7 @@ void freqsummary(char fileres[], int ag char fileresp[FILENAMELENGTH]; pp=vector(1,nlstate); - probs= ma3x(1,130 ,1,8, 1,8); + probs= ma3x(1,130 ,1,8, 1,8); strcpy(fileresp,"p"); strcat(fileresp,fileres); if((ficresp=fopen(fileresp,"w"))==NULL) { @@ -1192,13 +1192,16 @@ void freqsummary(char fileres[], int ag bool=0; } if (bool==1) { - for(m=fprev1; m<=lprev1; m++){ + for(m=fprev1; m<=lprev1; m++){ + k2=anint[m][i]+(mint[m][i]/12.); + if ((k2>=1984) && (k2<=1988.5)) { 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]] += weight[i]; freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i]; - } - } + } + } + } } if (cptcovn>0) { fprintf(ficresp, "\n#********** Variable "); @@ -1860,6 +1863,7 @@ int main() 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 */ @@ -1867,8 +1871,9 @@ int main() 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, fprev, lprev ,fprevfore=1, lprevfore=1,nforecast; + int mobilav=0, fprev, lprev ,fprevfore=1, lprevfore=1,nforecast,popforecast=0; int hstepm, nhstepm; + int *popage; double bage, fage, age, agelim, agebase; double ftolpl=FTOL; @@ -1882,7 +1887,8 @@ int main() double ***eij, ***vareij; double **varpl; /* Variances of prevalence limits by age */ double *epj, vepp; - double kk1; + double kk1, kk2; + double *popeffectif,*popcount; char version[80]="Imach version 64b, May 2001, INED-EUROREVES "; char *alph[]={"a","a","b","c","d","e"}, str[4]; @@ -1898,7 +1904,7 @@ int main() gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */ - printf("\nIMACH, Version 0.64b"); + printf("\nIMACH, Version 0.7"); printf("\nEnter the parameter file name: "); #ifdef windows @@ -1955,6 +1961,8 @@ while((c=getc(ficpar))=='#' && c!= EOF){ ungetc(c,ficpar); fscanf(ficpar,"fprevalence=%d lprevalence=%d pop_based=%d\n",&fprev,&lprev,&popbased); + fprintf(ficparo,"fprevalence=%d lprevalence=%d pop_based=%d\n",fprev,lprev,popbased); + while((c=getc(ficpar))=='#' && c!= EOF){ ungetc(c,ficpar); fgets(line, MAXLINE, ficpar); @@ -1964,6 +1972,18 @@ while((c=getc(ficpar))=='#' && c!= EOF){ ungetc(c,ficpar); fscanf(ficpar,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",&fprevfore,&lprevfore,&nforecast,&mobilav); + fprintf(ficparo,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",fprevfore,lprevfore,nforecast,mobilav); + + +while((c=getc(ficpar))=='#' && c!= EOF){ + ungetc(c,ficpar); + fgets(line, MAXLINE, ficpar); + puts(line); + fputs(line,ficparo); + } + ungetc(c,ficpar); + + fscanf(ficpar,"popforecast=%d popfile=%s\n",&popforecast,popfile); covar=matrix(0,NCOVMAX,1,n); cptcovn=0; @@ -2273,8 +2293,8 @@ printf("Total number of individuals= %d, free_imatrix(outcome,1,maxwav+1,1,n); free_vector(moisnais,1,n); free_vector(annais,1,n); - free_matrix(mint,1,maxwav,1,n); - free_matrix(anint,1,maxwav,1,n); + /* free_matrix(mint,1,maxwav,1,n); + free_matrix(anint,1,maxwav,1,n);*/ free_vector(moisdc,1,n); free_vector(andc,1,n); @@ -2306,21 +2326,15 @@ printf("Total number of individuals= %d, } } } - - - /*for(i=1; i <=m ;i++){ - for(k=1; k <=cptcovn; k++){ - printf("i=%d k=%d %d %d",i,k,codtab[i][k], cptcoveff); - } - printf("\n"); - } - scanf("%d",i);*/ /* Calculates basic frequencies. Computes observed prevalence at single age and prints on file fileres'p'. */ - freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprev, lprev); - - pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ + freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprev, lprev,mint,anint); + + free_matrix(mint,1,maxwav,1,n); + free_matrix(anint,1,maxwav,1,n); + + pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ @@ -2335,8 +2349,10 @@ printf("Total number of individuals= %d, } /*--------- results files --------------*/ - fprintf(ficres,"\ntitle=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate, ndeath, maxwav, mle,weightopt,model); - + fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate, ndeath, maxwav, mle,weightopt,model); + fprintf(ficres,"fprevalence=%d lprevalence=%d pop_based=%d\n",fprev,lprev,popbased); + fprintf(ficres,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",fprevfore,lprevfore,nforecast,mobilav); + jk=1; fprintf(ficres,"# Parameters\n"); printf("# Parameters\n"); @@ -2618,7 +2634,7 @@ chdir(path); printf("Problem with %s \n",optionfilehtm);goto end; } - fprintf(fichtm,"