예제 #1
0
파일: utils.cpp 프로젝트: jbloomlab/phydms
double readResult(string result,string rate,string date,int nb_tree){
       FILE *f = fopen(result.c_str(),"rt");
       if (f!=NULL){
          FILE *w = fopen(rate.c_str(),"wt");  
          FILE *wd = fopen(date.c_str(),"wt");
          string s= readWord(f,result);
          while (s.compare("Exit)")!=0) s = readWord(f,result);          
          for (int y=0;y<nb_tree;y++){
              s = readWord(f,result);
              while (s.compare("rate")!=0) s = readWord(f,result);
              double r=readdouble(f,result);
              while (s.compare("tMRCA")!=0) s = readWord(f,result);
              double t=readdouble(f,result);
              fprintf(w,"%f\n",r);
              fprintf(wd,"%f\n",t);
          }
          while (s.compare("time:")!=0) s = readWord(f,result);       
          double time=readdouble(f,result);
          fclose(f);
          fclose(w);
          fclose(wd);
          return time;
       }
       else{
            cout<<"Impossible to open file "<<result<<endl;
            exit (EXIT_FAILURE);
       }
}
예제 #2
0
파일: Estudiant.cpp 프로젝트: Outer2g/PRO2
void Estudiant::llegir_estudiant()
{
  DNI= readint();
  if (DNI<0) throw PRO2Excepcio(ER4);
  double x = readdouble();
  if (x >= 0 and x <= MAX_NOTA)    nota = x;
  else nota=-1;
}
예제 #3
0
void tree2dataS(FILE * tree,int n,int m,int* &P,double* &B,string* &Support,string* &leaves){
      int inode = 0;//number of internal nodes;
      stack<int> pileNode;    
      char c = readBracket(tree,"input tree");
      int a=1;
      int countleaf=n;
      P[0]=-1;
      B[0]=-1;
      do{
             c = readChar(tree,"input tree");
                   if (c==')'){    
                        a--;inode++;
                        int s1=pileNode.top();pileNode.pop();
                        int s2=pileNode.top();pileNode.pop();                   
                        P[s1]=n-inode;
                        P[s2]=n-inode;
                        if (a>0){                      
                           Support[n-inode]=readSupport(tree,"input tree");  
                           B[n-inode]=readdouble(tree,"input tree");                                       
                        }
                        else while (!pileNode.empty()){
                             int s=pileNode.top();pileNode.pop();
                             P[s]=n-inode;                                
                        }  
                        pileNode.push(n-inode);                  
                   }
                   else if (c!='(' && c!=',' && c!=-1 && c!=';' && c!='\n'){
                       string lb=readLabel(c,tree);
                        pileNode.push(countleaf);                        
                        leaves[countleaf]=lb;
                        B[countleaf]=readdouble(tree,"input tree");
                        Support[countleaf]="";
                        countleaf++;
                   }                    
                   else if (c=='(') {a++;}
           }  while (a>0);
}
예제 #4
0
bool			SmallConf::GetDouble(double		*v,
					     SmallConf		*root,
					     SmallConf		*local,
					     SmallConf		*artif,
					     SmallConf		*param) const
{
  if (alias_on)
    return (alias_on->GetDouble(v, root, local, artif, param));

  if (distant_double)
    {
      *v = *distant_double;
      return (true);
    }

  if (expression && (root || local || artif || param))
    {
      if (expr_compute((SmallConf&)*this, NULL, false, root, local, artif, param) == false)
	return (false);
    }
  if (have_value == false)
    {
      if (array.size() == 1)
	{
	  if (array[0]->GetDouble(v, root, local, artif, param) == false)
	    return (false);
	  converted = *v;
	  return (true);
	}
      return (false);
    }
  if (is_converted == false)
    {
      int		tmp;
      ssize_t		i = 0;

      if (readdouble(original_value.c_str(), i, converted) == false)
	{
	  if (readinteger(original_value.c_str(), i, tmp) == false)
	    return (false);
	  converted = tmp;
	}
      is_converted = true;
    }
  *v = converted;
  return (true);
}
예제 #5
0
bool tree2data(FILE * tree,string date,int n,int m,int* &P,double* &B,string* &Support,double* &T,string* &leaves){
      int inode = 0;//number of internal nodes;
      stack<int> pileNode;    
      char c = readBracket(tree,"input tree");
      int a=1;
      int countleaf=n;
      P[0]=-1;
      B[0]=-1;
      bool all=false;
      do{
             c = readChar(tree,"input tree");
                   if (c==')'){    
                        a--;inode++;
                        int s1=pileNode.top();pileNode.pop();
                        int s2=pileNode.top();pileNode.pop();                   
                        P[s1]=n-inode;
                        P[s2]=n-inode;
                        if (a>0){
                           Support[n-inode]=readSupport(tree,"input tree");  
                           B[n-inode]=readdouble(tree,"input tree");
                        }
                        else
                            while (!pileNode.empty()){
                             int s=pileNode.top();pileNode.pop();
                             P[s]=n-inode;                                
                        }  
                        pileNode.push(n-inode);                  
                   }
                   else if (c!='(' && c!=',' && c!=-1 && c!=';' && c!='\n'){
                        string lb=readLabel(c,tree);  
                        pileNode.push(countleaf);                        
                        leaves[countleaf]=lb;
                        B[countleaf]=readdouble(tree,"input tree");
                        Support[countleaf]="";
                        countleaf++;
                   }                    
                   else if (c=='(') {a++;}
           }  while (a>0);
           FILE * dateFile = fopen(date.c_str(),"rt");
           if (dateFile == NULL)  cout << "Can not open the file " <<date<< endl;
           else{
               int ino=readInt(dateFile,"Error in the date file, the file should begin with an integer (the number of dated tips)");
               for (int i=0;i<=m;i++) T[i]=-1;
              int count=0;
              double first=-1;
              for (int i=0;i<ino;i++){
                     string s=readWord(dateFile,date);
                     double lt=readdouble(dateFile,date);                    
                     int k = getPosition(leaves,s,n,m+1);
                     if (k!=-1) {
                         if (count==0) first=lt;
                         else if (lt!=first) all=true;                                
                         T[k]=lt;
                         count++;
                     }
              }       
              if (count<countleaf-n){
                 cout<<"The dates of some taxa are missing. If the input tree contains some outgroups, use option -g to specify the file name of outgroups. "<<endl;
                 exit(EXIT_FAILURE);
              }  
              fclose(dateFile);              
           }
      return all;
}
예제 #6
0
double EMUFILE::readdouble()
{
	double temp;
	readdouble(&temp);
	return temp;
}
예제 #7
0
/* init: initializes global variables. */
void init(char* infilename) { 
  char keyword[101];
  FILE *infile = fopen(infilename, "r");
  int i, j;
	
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  if (rank == 0) {
    assert(infile);
    readint(infile, "nx", &nx);
    readdouble(infile, "k", &k);
    readint(infile, "nsteps", &nsteps);
    readint(infile, "wstep", &wstep);
    printf("Diffusion1d with nx=%d, k=%f, nsteps=%d, wstep=%d nprocs=%d\n",
	   nx, k, nsteps, wstep, nprocs);
  }
  MPI_Bcast(&nx, 1, MPI_INT, 0, MPI_COMM_WORLD);
  MPI_Bcast(&k, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Bcast(&nsteps, 1, MPI_INT, 0, MPI_COMM_WORLD);
  MPI_Bcast(&wstep, 1, MPI_INT, 0, MPI_COMM_WORLD);

  assert(nx>=nprocs); /* is this necessary ? */
  assert(k>0 && k<.5);
  assert(nx>=2);
  assert(nsteps>=1);

  // nxl: number actual points (incl. end-points)
  // nxl+2: size of array (incl. ghost cells)
  first = firstForProc(rank);  
  nxl = countForProc(rank);
  if (first == 0 || nxl == 0) left = MPI_PROC_NULL; else left = OWNER(first-1);
  if (first+nxl >= nx || nxl == 0) right = MPI_PROC_NULL; else right = OWNER(first+nxl);  

  u = (double*)malloc((nxl+2)*sizeof(double));
  assert(u!=NULL);
  u_new = (double*)malloc((nxl+2)*sizeof(double));
  assert(u_new);
  if (rank == 0) {
    buf = (double*)malloc((1+nx/nprocs)*sizeof(double));
    for (i=1; i <= nxl; i++){
      if (fscanf(infile, "%lf", u+i) != 1) quit();
    }
    for (i=1; i < nprocs; i++){
      for (j=0; j<countForProc(i); j++){
        if (fscanf(infile, "%lf", buf+j) != 1) quit();
      }
      MPI_Send(buf, countForProc(i), MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
    }
  }
  else {
    MPI_Recv(u+1, nxl, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  }
  if (rank == OWNER(0)) {
    start = 2;
  }
  else {
    start = 1;
  }
  if (rank == OWNER(nx-1)) {
    stop = nxl - 1;
  }
  else {
    stop = nxl;
  }
  if (rank == 0) {
    buf = (double*)malloc((1+nx/nprocs)*sizeof(double));
    assert(buf);
    file = fopen("./parout/out.gif", "wb");
    assert(file);
    colors = (int*)malloc(MAXCOLORS*sizeof(int));
    assert(colors);
  } else {
    buf = NULL;
  }
}
예제 #8
0
파일: hat-check.c 프로젝트: noahl/sombrero
void
nextnode (void)
{
  FileOffset offset = nextoffset;
  char b;
  int marked, err;
  err = fread(&b,sizeof(char),1,f); nextoffset+=1;
  if (err!=1) return;
  if (rmode || xmode) {
    marked = ismarked(b);
    if (marked) {
      cleartag(&b);
      newtagat(&b, offset);
    }
    if (amode) printf("%s", (marked ? "=> " : "   "));
  }
  {
    int k = lo5(b);
    if ((ExpDoStmt<k && k<AtomVariable) || k>ListCons) {
      fprintf(stderr, "strange tag %d at byte offset 0x%x\n",
                      k, offset);
      exit(1);
    } else if (smode) {
      count[k]++;
      if (rmode && marked) reachcount[k]++;
    }
    switch (k) {
    case ListCons:
	if (gmode) printf("%d [label=\"0x%x ListCons\"]\n", offset, offset);
        if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
	if (amode) printf("elem=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "e");
	if (amode) printf(" tail=");
        dopointer(MAYBEZERO, ListCons, readpointer(), k, offset, "t");
      break;
    case Module:
      if (amode) {
        if (tracedModule(b))
             printf("0x%x:  Module (suspect) \t", offset);
        else printf("0x%x:  Module (trusted) \t", offset);
      }
      { char *s = readstring(); if (amode) printf("%s\t", s); }
      { char *s = readstring(); if (amode) printf("\"%s\"", s); }
      break;
    case SrcPos:
      if (amode) printf("0x%x:  SrcPos\t\t\t", offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      break;
    case AtomVariable:
      if (amode) {
        if (localDef(b))
             printf("0x%x:  AtomVariable (local)\t", offset);
        else printf("0x%x:  AtomVariable (toplevel)\t", offset);
      }
      if (gmode) printf("%d [label=\"0x%x AtomVariable", offset, offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      { char *fp = readfixpri(); if (*fp!='\0' && amode) printf("%s ", fp); }
      { unsigned int a = readarity();
        if (amode || gmode) printf(amode ? " arity=%u," : " %u", a); }
      { char *n = readstring(); if (amode || gmode) printf(" %s", n); }
      if (gmode) printf("\"]\n");
      break;
    case AtomConstructor:
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (gmode) printf("%d [label=\"0x%x AtomConstructor", offset, offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      { char *fp = readfixpri(); if (*fp!='\0' && amode) printf("%s", fp); }
      { unsigned int a = readarity();
        if (amode || gmode) printf(amode ? " arity=%u," : " %u", a);
        { char *n = readstring(); if (amode || gmode) printf(" %s", n); }
        if (gmode) printf("\"]\n");
        if hasFields(b) {
	  int i;
          if (amode) printf(" fields:");
          for (i=1; i<=a; i++) {
            dopointer(NONZERO, AtomVariable, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
          }
        }
      }
      break;
    case AtomAbstract:
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (gmode) printf("%d [label=\"0x%x AtomAbstract ", offset, offset);
      { char *s = readstring(); if (amode || gmode) printf("%s", s); }
      if (gmode) printf("\"]\n");
      break;
    default: {
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (hasSrcPos(b)) {
	  if (amode) printf("use=");
          dopointer(NONZERO, SrcPos, readpointer(), k, offset, "");
	  if (amode) printf(" ");
      }
   // if (amode && (ExpChar <= k) && (k <= ExpConstUse)) {
   //     printf("(");
   //     if (!isEntered(b)) printf("not ");
   //     printf("entered) ");
   // }
      switch (k) {
      case ExpApp:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" fun=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "f");
        if (gmode) printf("%d [label=\"0x%x ExpApp", offset, offset);
        { unsigned int a = readarity();
	  int i;
	  if (amode || gmode)
	    printf(amode ? " arity=%u, args " : " %u\"]\n",a);
	  for (i=1; i<=a; i++)
	    dopointer(NONZERO, ANYEXP, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
	}
	break;
      case ExpValueApp:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" fun=");
        dopointer(NONZERO, ANYATOM, readpointer(), k, offset, "f");
        if (gmode) printf("%d [label=\"0x%x ExpValueApp", offset, offset);
        { unsigned int a = readarity();
	  int i;
	  if (amode || gmode)
	    printf(amode ? " arity=%u, args " : " %u\"]\n",a);
	  for (i=1; i<=a; i++)
	    dopointer(NONZERO, ANYEXP, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
	}
	break;
      case ExpChar:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char c = nextbyte();
	  if (gmode) printf("%d [label=\"ExpChar", offset);
	  if (amode || gmode) printf(" '%c'", c);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpInt:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { int i; i = readfourbytes();
	  if (gmode) printf("%d [label=\"ExpInt", offset);
	  if (amode || gmode) printf(" %d", i);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpInteger:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char* i; i = readinteger();
	  if (gmode) printf("%d [label=\"ExpInteger", offset);
	  if (amode || gmode) printf(" %s", i);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpRat:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { int n,d; n=readfourbytes(); d=readfourbytes();
	  if (gmode) printf("%d [label=\"ExpRat", offset);
          if (amode || gmode) printf(" %d%%%d", n,d);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpRational:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char* r = readrational();
	  if (gmode) printf("%d [label=\"ExpRational", offset);
	  if (amode || gmode) printf(" %s", r);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpFloat:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { float f = readfloat();
	  if (gmode) printf("%d [label=\"ExpFloat", offset);
	  if (amode || gmode) printf(" %f", f);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpDouble:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { double d = readdouble();
	  if (gmode) printf("%d [label=\"ExpDouble", offset);
	  if (amode || gmode) printf(" %f", d);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpValueUse:
	if (gmode) printf("%d [label=\"0x%x ExpValueUse\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" value=");
        dopointer(MAYBELAMBDA, ANYATOM, readpointer(), ExpValueUse, offset,"v");
	break;
      case ExpConstUse:
	if (gmode) printf("%d [label=\"0x%x ExpConstUse\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" const=");
        dopointer(NONZERO, ExpConstDef, readpointer(), k, offset, "c");
	break;
      case ExpConstDef:
	if (gmode) printf("%d [label=\"0x%x ExpConstDef\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" var=");
        dopointer(NONZERO, AtomVariable, readpointer(), k, offset, "v");
	break;
      case ExpGuard:
      case ExpCase:
      case ExpIf:
	if (gmode) printf("%d [label=\"0x%x %s\"]\n", offset, offset,
                  k==ExpGuard ? "ExpGuard" : k==ExpCase ? "ExpCase" : "ExpIf");
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" cond=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "c");
	break;
      case ExpFieldUpdate:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" arg=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "a");
        { unsigned int i, arity = readarity();
	  if (gmode) printf("%d [label=\"0x%x ExpFieldUpdate %u\"]\n", offset, offset, arity);
	  if (amode) printf(" arity=%u, binders ",arity);
          for (i=0; i<arity; i++) {
            dopointer(NONZERO, AtomVariable, readpointer(), k, offset, "");
          }
	  if (amode) printf(", bindees ",arity);
          for (i=0; i<arity; i++) {
            dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "");
          }
        }
	break;
      case ExpProjection:
	if (gmode) printf("%d [label=\"0x%x ExpProjection\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" exp=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "e");
	break;
      case ExpHidden:
	if (gmode) printf("%d [label=\"0x%x ExpHidden\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" children=");
	dopointer(MAYBEZERO, ListCons, readpointer(), k, offset, "c");
	break;
      case ExpForward:
	if (gmode) printf("%d [label=\"0x%x ExpForward\"]\n", offset, offset);
	if (amode) printf("result=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "r");
	break;
      case ExpDoStmt:
	if (gmode) printf("%d [label=\"0x%x ExpDoStmt\"]\n", offset, offset);
	if (amode) printf("stmt=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "s");
	break;
      }
    }}
    if (amode) printf("\n");
    if (smode) space[k] += nextoffset - offset;
  }
}
예제 #9
0
void checkRooted(Pr* opt){
    FILE * tree = fopen(opt->inFile.c_str(),"rt");
    if (tree==NULL){
        cout<<"Error: can not open the input file"<<endl;
        exit(EXIT_FAILURE);
    }
    stack<int> pileNode;
    char c = readBracket(tree,"input tree");
    int a=1;
    int s=0;
    int nbChild=0;
    int n=0;
    int m=0;
    do{
        c = readChar(tree,"input tree");
        if (c==')'){
            a--;
            s=0;
            nbChild=0;
            while (!pileNode.empty() && s!=-1) {
                s=pileNode.top();pileNode.pop();
                if (s!=-1){
                    nbChild++;
                }
            }
            string sp=readSupport(tree,"input tree");
            if (a>0) {
                double d = readdouble(tree,"input tree");
            }
            pileNode.push(1);
            n++;
            m++;
        }
        else if (c!='(' && c!=',' && c!=-1 && c!=';' && c!='\n'){
            string s= readLabel(c,tree,a);
            pileNode.push(1);
            double d =readdouble(tree,"input tree");
            m++;
        }
        else if (c=='(') {a++;pileNode.push(-1);}
        else if (c=='\n') {
            c=readChar(tree,"input tree");
        }
    }  while (a>0);
    fclose(tree);
    m--;
    opt->nbINodes=n;
    opt->nbBranches=m;
    if (m==2*n) {
        opt->rooted=true;
    }
    else if (m==2*n+1 && nbChild==3){
        opt->rooted=false;
    }
    else if (nbChild==2) {
        opt->rooted=true;
    }
    else{
        opt->rooted=false;
    }
}