--- imach/src/imach.c 2003/06/25 16:33:55 1.93 +++ imach/src/imach.c 2003/06/27 13:00:02 1.94 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.93 2003/06/25 16:33:55 brouard Exp $ +/* $Id: imach.c,v 1.94 2003/06/27 13:00:02 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.94 2003/06/27 13:00:02 brouard + Just cleaning + Revision 1.93 2003/06/25 16:33:55 brouard (Module): On windows (cygwin) function asctime_r doesn't exist so I changed back to asctime which exists. @@ -190,11 +193,11 @@ #define ODIRSEPARATOR '/' #endif -/* $Id: imach.c,v 1.93 2003/06/25 16:33:55 brouard Exp $ */ +/* $Id: imach.c,v 1.94 2003/06/27 13:00:02 brouard Exp $ */ /* $State: Exp $ */ char version[]="Imach version 0.96b, June 2003, INED-EUROREVES "; -char fullversion[]="$Revision: 1.93 $ $Date: 2003/06/25 16:33:55 $"; +char fullversion[]="$Revision: 1.94 $ $Date: 2003/06/27 13:00:02 $"; int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ int nvar; int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; @@ -242,7 +245,7 @@ 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]; @@ -562,6 +565,41 @@ void free_ma3x(double ***m, long nrl, lo free((FREE_ARG)(m+nrl-NR_END)); } +/*************** function subdirf ***********/ +char *subdirf(char fileres[]) +{ + /* Caution optionfilefiname is hidden */ + strcpy(tmpout,optionfilefiname); + strcat(tmpout,"/"); /* Add to the right */ + strcat(tmpout,fileres); + return tmpout; +} + +/*************** function subdirf2 ***********/ +char *subdirf2(char fileres[], char *preop) +{ + + /* Caution optionfilefiname is hidden */ + strcpy(tmpout,optionfilefiname); + strcat(tmpout,"/"); + strcat(tmpout,preop); + strcat(tmpout,fileres); + return tmpout; +} + +/*************** function subdirf3 ***********/ +char *subdirf3(char fileres[], char *preop, char *preop2) +{ + + /* Caution optionfilefiname is hidden */ + strcpy(tmpout,optionfilefiname); + strcat(tmpout,"/"); + strcat(tmpout,preop); + strcat(tmpout,preop2); + strcat(tmpout,fileres); + return tmpout; +} + /***************** f1dim *************************/ extern int ncom; extern double *pcom,*xicom; @@ -1219,31 +1257,10 @@ double func( double *x) oldm=newm; } /* end mult */ - /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */ - /* But now since version 0.9 we anticipate for bias and large stepm. - * If stepm is larger than one month (smallest stepm) and if the exact delay - * (in months) between two waves is not a multiple of stepm, we rounded to - * the nearest (and in case of equal distance, to the lowest) interval but now - * we keep into memory the bias bh[mi][i] and also the previous matrix product - * (i.e to dh[mi][i]-1) saved in 'savm'. The we inter(extra)polate the - * probability in order to take into account the bias as a fraction of the way - * from savm to out if bh is neagtive or even beyond if bh is positive. bh varies - * -stepm/2 to stepm/2 . - * For stepm=1 the results are the same as for previous versions of Imach. - * For stepm > 1 the results are less biased than in previous versions. - */ s1=s[mw[mi][i]][i]; s2=s[mw[mi+1][i]][i]; bbh=(double)bh[mi][i]/(double)stepm; - /* bias is positive if real duration - * is higher than the multiple of stepm and negative otherwise. - */ lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*(savm[s1][s2])):log((1.+bbh)*out[s1][s2])); /* linear interpolation */ - /* lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2]));*/ - /*lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.-+bh)*out[s1][s2])); */ /* exponential interpolation */ - /*lli=(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]);*/ - /*if(lli ==000.0)*/ - /*printf("bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */ ipmx +=1; sw += weight[i]; ll[s[mw[mi][i]][i]] += 2*weight[i]*lli; @@ -1270,30 +1287,10 @@ double func( double *x) oldm=newm; } /* end mult */ - /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */ - /* But now since version 0.9 we anticipate for bias and large stepm. - * If stepm is larger than one month (smallest stepm) and if the exact delay - * (in months) between two waves is not a multiple of stepm, we rounded to - * the nearest (and in case of equal distance, to the lowest) interval but now - * we keep into memory the bias bh[mi][i] and also the previous matrix product - * (i.e to dh[mi][i]-1) saved in 'savm'. The we inter(extra)polate the - * probability in order to take into account the bias as a fraction of the way - * from savm to out if bh is neagtive or even beyond if bh is positive. bh varies - * -stepm/2 to stepm/2 . - * For stepm=1 the results are the same as for previous versions of Imach. - * For stepm > 1 the results are less biased than in previous versions. - */ s1=s[mw[mi][i]][i]; s2=s[mw[mi+1][i]][i]; bbh=(double)bh[mi][i]/(double)stepm; - /* bias is positive if real duration - * is higher than the multiple of stepm and negative otherwise. - */ - /* lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*(savm[s1][s2])):log((1.+bbh)*out[s1][s2])); */ /* linear interpolation */ lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */ - /*lli=(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]);*/ - /*if(lli ==000.0)*/ - /*printf("bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */ ipmx +=1; sw += weight[i]; ll[s[mw[mi][i]][i]] += 2*weight[i]*lli; @@ -1459,35 +1456,8 @@ double funcone( double *x) return -l; } -char *subdirf(char fileres[]) -{ - /* Caution optionfilefiname is hidden */ - 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; -} +/*************** function likelione ***********/ void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, long *ipmx, double *sw, double *fretone, double (*funcone)(double [])) { /* This routine should help understanding what is done with @@ -3751,9 +3721,14 @@ int fileappend(FILE *fichier, char *opti fflush(fichier); return (1); } + + +/**************** function prwizard **********************/ void prwizard(int ncovmodel, int nlstate, int ndeath, char model[], FILE *ficparo) { + /* Wizard to print covariance matrix template */ + char ca[32], cb[32], cc[32]; int i,j, k, l, li, lj, lk, ll, jj, npar, itimes; int numlinepar; @@ -4009,8 +3984,8 @@ int main(int argc, char *argv[]) optionfilext=%s\n\ optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); - printf("Localtime (at start):%s",strstart); - fprintf(ficlog,"Localtime (at start): %s",strstart); + printf("Local time (at start):%s",strstart); + fprintf(ficlog,"Local time (at start): %s",strstart); fflush(ficlog); /* (void) gettimeofday(&curr_time,&tzp); */ /* printf("Elapsed time %d\n", asc_diff_time(curr_time.tv_sec-start_time.tv_sec,tmpout)); */ @@ -4586,9 +4561,6 @@ Title=%s
Datafile=%s Firstpass=%d La strcpy(pathr,path); strcat(pathr,optionfilefiname); chdir(optionfilefiname); /* Move to directory named optionfile */ - strcpy(lfileres,fileres); - strcat(lfileres,"/"); - strcat(lfileres,optionfilefiname); /* Calculates basic frequencies. Computes observed prevalence at single age and prints on file fileres'p'. */ @@ -5129,8 +5101,8 @@ ageminpar, agemax, s[lastpass][imx], age tm = *localtime(&end_time.tv_sec); tmg = *gmtime(&end_time.tv_sec); strcpy(strtend,asctime(&tm)); - printf("Localtime at start %s\nLocaltime at end %s",strstart, strtend); - fprintf(ficlog,"Localtime at start %s\nLocal time at end %s\n",strstart, strtend); + printf("Local time at start %s\nLocaltime at end %s",strstart, strtend); + fprintf(ficlog,"Local time at start %s\nLocal time at end %s\n",strstart, strtend); printf("Total time used %s\n", asc_diff_time(end_time.tv_sec -start_time.tv_sec,tmpout)); printf("Total time was %d Sec.\n", end_time.tv_sec -start_time.tv_sec);