Exemplo n.º 1
0
double mrand()
#endif
{
    long lval;
    static Real factor = 1.0 / ((Real) MODULUS);

    if (!started)
        smrand(3127);

    inext = (inext >= 54) ? 0 : inext + 1;
    inextp = (inextp >= 54) ? 0 : inextp + 1;

    lval = mrand_list[inext] - mrand_list[inextp];
    if (lval < 0L)
        lval += MODULUS;
    mrand_list[inext] = lval;

    return (double) lval * factor;
}
Exemplo n.º 2
0
void mrandlist(Real a[], int len)
#endif
{
    int i;
    long lval;
    static Real factor = 1.0 / ((Real) MODULUS);

    if (!started)
        smrand(3127);

    for (i = 0; i < len; i++) {
        inext = (inext >= 54) ? 0 : inext + 1;
        inextp = (inextp >= 54) ? 0 : inextp + 1;

        lval = mrand_list[inext] - mrand_list[inextp];
        if (lval < 0L)
            lval += MODULUS;
        mrand_list[inext] = lval;

        a[i] = (Real) lval * factor;
    }
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
  /* working variables */
  int i,j,mf;
  FILE *fp;
  char *cbuf,**infiles,**outfiles;

  printf("# %s",rcsid);

  /* args */
  for(i=j=1;i<argc;i++) {
    if(argv[i][0] != '-') {
      switch(j) {
      case 1: fname_mt=argv[i]; break;
      case 2: fname_rmt=argv[i]; break;
      default: byebye();
      }
      j++;
    } else if(streq(argv[i],"-s")) {
      if(i+1>=argc ||
	 sscanf(argv[i+1],"%lu",&seed) != 1)
	byebye();
      i+=1;
    } else if(streq(argv[i],"-p")) {
      if(i+1>=argc) byebye();
      fname_pa=argv[i+1];
      i+=1;
    } else if(streq(argv[i],"-b")) {
      if(i+1>=argc ||
	 sscanf(argv[i+1],"%lf",&bbfact) != 1)
	byebye();
      i+=1;
    } else if(streq(argv[i],"-f")) {
      sw_fastrep=1;
    } else if(streq(argv[i],"-g")) {
      sw_multi=1;
    } else if(streq(argv[i],"--molphy")) {
      seqmode=SEQ_MOLPHY;
    } else if(streq(argv[i],"--paml")) {
      seqmode=SEQ_PAML;
    } else if(streq(argv[i],"--paup")) {
      seqmode=SEQ_PAUP;
    } else if(streq(argv[i],"--puzzle")) {
      seqmode=SEQ_PUZZLE;
    } else if(streq(argv[i],"--phyml")) {
      seqmode=SEQ_PHYML;
    } else if(streq(argv[i],"-d")) {
      if(i+1>=argc ||
	 sscanf(argv[i+1],"%d",&debugmode) != 1)
	byebye();
      i+=1;
    } else byebye();
  }

  /* random seed */
  smrand(seed);

  /* reading parameters */
  if(fname_pa!=NULL) {
    fp=openfp(fname_pa,fext_pa,"r",&cbuf);
    printf("\n# reading %s",cbuf);
    kk=0;
    rr=fread_vec(fp,&kk); 
    bb=fread_ivec(fp,&kk); 
    fclose(fp); FREE(cbuf);
  } else {
    if(sw_fastrep) {kk=kk00; rr=rr00; bb=bb00;}
    else {kk=kk0; rr=rr0; bb=bb0;}
  }

  for(i=0;i<kk;i++) bb[i] *= bbfact;
  printf("\n# seed:%lu (MT19937 generator)",seed);
  printf("\n# K:%d",kk);
  printf("\n# R:"); for(i=0;i<kk;i++) printf("%g ",rr[i]);
  printf("\n# B:"); for(i=0;i<kk;i++) printf("%d ",bb[i]);

  if(sw_multi) {
    if(fname_mt) fp=openfp(fname_mt,fext_svt,"r",&cbuf); else fp=STDIN;
    mf=0; infiles=fread_svec(fp,&mf);
    if(fname_mt) {fclose(fp); FREE(cbuf);}
    if(fname_rmt) {
      fp=openfp(fname_rmt,fext_svt,"r",&cbuf);
      outfiles=fread_svec(fp,&mf);
      fclose(fp); FREE(cbuf);
    } else {
      outfiles=NEW_A(mf,char*);
      for(i=0;i<mf;i++) outfiles[i]=rmvaxt(infiles[i]);
    }
    for(i=0;i<mf;i++) {
      printf("\n# %d/%d %s %s",i+1,mf,infiles[i],outfiles[i]);
      genrmt(infiles[i],outfiles[i]);
    }
  } else {
    if(fname_mt && !fname_rmt) fname_rmt=rmvaxt(fname_mt);