--- imach/src/imach.c 2001/03/13 18:10:26 1.2 +++ imach/src/imach.c 2001/05/02 17:42:45 1.5 @@ -51,6 +51,10 @@ #define FILENAMELENGTH 80 /*#define DEBUG*/ #define windows +#define GLOCK_ERROR_NOPATH -1 /* empty path */ +#define GLOCK_ERROR_GETCWD -2 /* cannot get cwd */ + + #define MAXPARM 30 /* Maximum number of parameters for the optimization */ #define NPARMAX 64 /* (nlstate+ndeath-1)*nlstate*ncovmodel */ @@ -59,7 +63,7 @@ #define NLSTATEMAX 8 /* Maximum number of live states (for func) */ #define NDEATHMAX 8 /* Maximum number of dead states (for func) */ #define NCOVMAX 8 /* Maximum number of covariates */ -#define MAXN 80000 +#define MAXN 20000 #define YEARM 12. /* Number of months per year */ #define AGESUP 130 #define AGEBASE 40 @@ -138,6 +142,41 @@ double ftol=FTOL; /* Tolerance for compu double ftolhess; /* Tolerance for computing hessian */ +static int split( char *path, char *dirc, char *name ) +{ + char *s; /* pointer */ + int l1, l2; /* length counters */ + + l1 = strlen( path ); /* length of path */ + if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH ); + s = strrchr( path, '\\' ); /* find last / */ + if ( s == NULL ) { /* no directory, so use current */ +#if defined(__bsd__) /* get current working directory */ + extern char *getwd( ); + + if ( getwd( dirc ) == NULL ) { +#else + extern char *getcwd( ); + + if ( getcwd( dirc, FILENAME_MAX ) == NULL ) { +#endif + return( GLOCK_ERROR_GETCWD ); + } + strcpy( name, path ); /* we've got it */ + } else { /* strip direcotry from path */ + s++; /* after this, the filename */ + l2 = strlen( s ); /* length of filename */ + if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH ); + strcpy( name, s ); /* save file name */ + strncpy( dirc, path, l1 - l2 ); /* now the directory */ + dirc[l1-l2] = 0; /* add zero */ + } + l1 = strlen( dirc ); /* length of directory */ + if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; } + return( 0 ); /* we're done */ +} + + /******************************************/ void replace(char *s, char*t) @@ -168,9 +207,8 @@ void cutv(char *u,char *v, char*t, char { int i,lg,j,p; i=0; - if (t[0]== occ) p=0; for(j=0; j<=strlen(t)-1; j++) { - if((t[j]!= occ) && (t[j+1]==occ)) p=j+1; + if((t[j]!= occ) && (t[j+1]== occ)) p=j+1; } lg=strlen(t); @@ -184,7 +222,6 @@ void cutv(char *u,char *v, char*t, char } } - /********************** nrerror ********************/ void nrerror(char error_text[]) @@ -805,15 +842,14 @@ printf(" %d\n",s[4][i]); cov[1]=1.; cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM; if (cptcovn>0){ - for (k=1; k<=cptcovn;k++) { - cov[2+k]=covar[Tvar[k]][i]; - /* printf("k=%d cptcovn=%d %lf\n",k,cptcovn,covar[Tvar[k]][i]);*/ - } + for (k=1; k<=cptcovn;k++) cov[2+k]=covar[1+k-1][i]; } out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath, 1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate)); savm=oldm; oldm=newm; + + } /* end mult */ lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]); @@ -827,7 +863,6 @@ printf(" %d\n",s[4][i]); for(k=1,l=0.; k<=nlstate; k++) l += ll[k]; /* printf("l1=%f l2=%f ",ll[1],ll[2]); */ l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */ - return -l; } @@ -983,7 +1018,8 @@ double hessii( double x[], double delta, } } delti[theta]=delts; - return res; + return res; + } double hessij( double x[], double delti[], int thetai,int thetaj) @@ -1252,8 +1288,6 @@ float sum=0.; } else{ j= rint( (agev[mw[mi+1][i]][i]*12 - agev[mw[mi][i]][i]*12)); - /*printf("i=%d agevi+1=%lf agevi=%lf j=%d\n", i,agev[mw[mi+1][i]][i],agev[mw[mi][i]][i],j);*/ - k=k+1; if (j >= jmax) jmax=j; else if (j <= jmin)jmin=j; @@ -1578,7 +1612,7 @@ int main() int sdeb, sfin; /* Status at beginning and end */ int c, h , cpt,l; int ju,jl, mi; - int i1,j1, k1,jk,aa,bb, stepsize; + int i1,j1, k1,k2,k3,jk,aa,bb, stepsize; int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab; int hstepm, nhstepm; @@ -1596,6 +1630,7 @@ int main() double *epj, vepp; char version[80]="Imach version 62c, May 1999, INED-EUROREVES "; char *alph[]={"a","a","b","c","d","e"}, str[4]; + char z[1]="c", occ; #include #include @@ -1606,13 +1641,17 @@ int main() gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */ - printf("\nIMACH, Version 0.63"); + printf("\nIMACH, Version 0.64a"); printf("\nEnter the parameter file name: "); #ifdef windows scanf("%s",pathtot); getcwd(pathcd, size); - cutv(path,optionfile,pathtot,'\\'); + /*cygwin_split_path(pathtot,path,optionfile); + printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/ + /* cutv(path,optionfile,pathtot,'\\');*/ + +split(pathtot, path,optionfile); chdir(path); replace(pathc,path); #endif @@ -1777,7 +1816,7 @@ int main() s=imatrix(1,maxwav+1,1,n); adl=imatrix(1,maxwav+1,1,n); tab=ivector(1,NCOVMAX); - ncodemax=ivector(1,NCOVMAX); + ncodemax=ivector(1,8); i=1; while (fgets(line, MAXLINE, fic) != NULL) { @@ -1802,17 +1841,15 @@ int main() } num[i]=atol(stra); - /* 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]));*/ - - /*printf("%d %.lf %.lf %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]),(covar[3][i]), (covar[4][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]));*/ + /*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]));*/ i=i+1; } } - /*scanf("%d",i);*/ + /*scanf("%d",i);*/ imx=i-1; /* Number of individuals */ - + /* Calculation of the number of parameter from char model*/ Tvar=ivector(1,8); @@ -1820,7 +1857,7 @@ int main() j=0; j=nbocc(model,'+'); cptcovn=j+1; - + strcpy(modelsav,model); if (j==0) { cutv(stra,strb,modelsav,'V'); Tvar[1]=atoi(strb); @@ -1835,18 +1872,17 @@ int main() for (k=1; k<=lastobs;k++) covar[ncov+1][k]=covar[atoi(stre)][k]*covar[atoi(strc)][k]; } - else { - cutv(strd,strc,strb,'V'); - Tvar[i+1]=atoi(strc); + else {cutv(strd,strc,strb,'V'); + Tvar[i+1]=atoi(strc); } - strcpy(modelsav,stra); + strcpy(modelsav,stra); } - /*cutv(strd,strc,stra,'V');*/ + cutv(strd,strc,stra,'V'); Tvar[1]=atoi(strc); } } - /*printf("tvar=%d ",Tvar[1]);*/ - /*scanf("%d ",i);*/ + /*printf("tvar=%d ",Tvar[1]); + scanf("%d ",i);*/ fclose(fic); if (weightopt != 1) { /* Maximisation without weights*/ @@ -1858,7 +1894,6 @@ int main() for (i=1; i<=imx; i++) { agedc[i]=(moisdc[i]/12.+andc[i])-(moisnais[i]/12.+annais[i]); for(m=1; (m<= maxwav); m++){ - if (mint[m][i]==99 || anint[m][i]==9999) s[m][i]=-1; if(s[m][i] >0){ if (s[m][i] == nlstate+1) { if(agedc[i]>0) @@ -1871,10 +1906,8 @@ int main() } else if(s[m][i] !=9){ /* Should no more exist */ agev[m][i]=(mint[m][i]/12.+1./24.+anint[m][i])-(moisnais[i]/12.+1./24.+annais[i]); - if(mint[m][i]==99 || anint[m][i]==9999){ + if(mint[m][i]==99 || anint[m][i]==9999) agev[m][i]=1; - /* printf("i=%d m=%d agev=%lf \n",i,m, agev[m][i]); */ - } else if(agev[m][i]
    Imach, Version 0.63
  • Outputs files

    \n + fprintf(fichtm,"
      Imach, Version 0.64a
    • Outputs files

      \n - Observed prevalence in each state: p%s
      \n - Estimated parameters and the covariance matrix: %s
      - Stationary prevalence in each state: pl%s
      @@ -2518,7 +2559,7 @@ strcpy(fileresvpl,"vpl"); #ifdef windows chdir(pathcd); #endif - system("wgnuplot ../gp37mgw/graph.plt"); + system("wgnuplot graph.plt"); #ifdef windows while (z[0] != 'q') {