Exemplo n.º 1
0
struct color input_ambient(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-ambient")!= 0){
      if(i>=argc-1)
         return create_color(1,1,1);
      i++;
   }
   double x = 1;
   double y = 1;
   double z = 1;
   
   if(i+1<argc && !equalToFlag(argc,in,i+1))
      x = convert_double(in[i+1],1);
    else
         return create_color(x,y,z);

   if(i+2<argc&& !equalToFlag(argc,in,i+2))
      y = convert_double(in[i+2],1);
    else
         return create_color(x,y,z);

   if(i+3<argc&& !equalToFlag(argc,in,i+3))
      z = convert_double(in[i+3],1);
    else
         return create_color(x,y,z);

   return create_color(x,y,z); 
}
Exemplo n.º 2
0
struct point input_eye(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-eye")!= 0){
      if(i>=argc-1)
         return create_point(0,0,-14);
      i++;
   }
   double x = 0;
   double y = 0;
   double z = -14;
 
      if(i+1<argc && !equalToFlag(argc,in,i+1))
         x = convert_double(in[i+1],0);
      else
         return create_point(x,y,z);

      if(i+2<argc && !equalToFlag(argc,in,i+2))
         y = convert_double(in[i+2],0);
      else
         return create_point(x,y,z);

      if(i+3<argc && !equalToFlag(argc,in,i+3))
         z = convert_double(in[i+3],-14);
      else
         return create_point(x,y,z);
   
   

   return create_point(x,y,z);
}
Exemplo n.º 3
0
void test_convert_double()
{
   char s1[]={"3.4\0"};
   double a = convert_double(s1,4.2); 
   checkit_double(a,3.4);  

   char s2[]={"asdfcxzv\0"};
   double b = convert_double(s2,3.2);
   checkit_double(b,3.2);

   char s3[]={"asdfdfs3.4asdfasdf\0"};
   double c = convert_double(s3,32.1);
   checkit_double(c,32.1);

   char s4[]={"-3.2\0"};
   double d = convert_double(s4,4.2);
   checkit_double(d,-3.2);
}
Exemplo n.º 4
0
void RateMeyerHaeseler::readRateFile(char *rate_file) {
	cout << "Reading site-specific rate file " << rate_file << " ..." << endl;
	try {
		ifstream in;
		in.exceptions(ios::failbit | ios::badbit);
		in.open(rate_file);
		char line[256];
		int site, i;
		double rate;
		int nsites = phylo_tree->aln->getNSite();
		resize(phylo_tree->aln->getNPattern(), -1.0);
		int saturated_sites = 0, saturated_ptn = 0;

		in.getline(line, sizeof(line));
		//if (strncmp(line, "Site", 4) != 0) throw "Wrong header line";

		for (i = 0; i < nsites; i++) {
			in.getline(line, sizeof(line));
			stringstream ss(line);
			string tmp;
			ss >> tmp;
			site = convert_int(tmp.c_str());
			if (site <= 0 || site > nsites) throw "Wrong site number (must be between 1 and #sites)";
			site--;
			ss >> tmp;
			rate = convert_double(tmp.c_str());
			if (rate < 0.0) throw "Negative rate not allowed";
			if (rate <= 0.0) rate = MIN_SITE_RATE;
			int ptn = phylo_tree->aln->getPatternID(site);
			if (rate >= MAX_SITE_RATE) {
				rate = MAX_SITE_RATE; 
				saturated_sites += phylo_tree->aln->at(ptn).frequency; 
				saturated_ptn ++;
			}
			at(ptn) = rate;
		}
		in.clear();
		// set the failbit again
		in.exceptions(ios::failbit | ios::badbit);
		in.close();

		for (i = 0; i < size(); i++)
			if (at(i) < 0.0) throw "Some site has no rate information";

		if (saturated_sites) {
			stringstream str;
			str << saturated_sites << " sites (" << saturated_ptn << " patterns) show too high rates (>=" << MAX_SITE_RATE << ")";
			outWarning(str.str());
		}
	} catch (const char *str) {
		outError(str);
	} catch (string str) {
		outError(str);
	} catch(ios::failure) {
		outError(ERR_READ_INPUT);
	}
}
Exemplo n.º 5
0
double htrace_conf_get_double(struct htrace_log *log,
                             const struct htrace_conf *cnf, const char *key)
{
    const char *val;
    double out = 0;

    val = htable_get(cnf->values, key);
    if (val) {
        if (convert_double(log, key, val, &out)) {
            return out;
        }
    }
    val = htable_get(cnf->defaults, key);
    if (val) {
        if (convert_double(log, key, val, &out)) {
            return out;
        }
    }
    return 0;
}
Exemplo n.º 6
0
struct view input_view(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-view")!= 0){
      if(i>=argc-1)
         return create_view(-10,10,-7.5,7.5,1024,768);
      i++;
   }
   double minx = -10;
   double maxx = 10;

   double miny = -7.5;
   double maxy = 7.5;

   int width = 1024;
   int height = 768;

   if(i+1<argc && !equalToFlag(argc,in,i+1))
      minx = convert_double(in[i+1],-10);
   else
         return create_view(minx,maxx,miny,maxy,width,height);

   if(i+2<argc && !equalToFlag(argc,in,i+2))
      maxx = convert_double(in[i+2],10);
   else
         return create_view(minx,maxx,miny,maxy,width,height);

   if(i+3<argc && !equalToFlag(argc,in,i+3))
      miny = convert_double(in[i+3],-7.5);
   else
         return create_view(minx,maxx,miny,maxy,width,height);

   if(i+4<argc && !equalToFlag(argc,in,i+4))
      maxy = convert_double(in[i+4],7.5);
   else
         return create_view(minx,maxx,miny,maxy,width,height);

   if(i+5<argc && !equalToFlag(argc,in,i+5))
      width = convert_double(in[i+5],1024);
   else
         return create_view(minx,maxx,miny,maxy,width,height);

   if(i+6<argc && !equalToFlag(argc,in,i+6))
      height = convert_double(in[i+6],768);
   else
         return create_view(minx,maxx,miny,maxy,width,height);

   return create_view(minx,maxx,miny,maxy,width,height);
}
Exemplo n.º 7
0
struct light input_light(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-light")!= 0){
      if(i>=argc-1)
         return create_light(create_point(-100,100,-100),create_color(1.5,1.5,1.5));
      i++;
   }
   double x = -100;
   double y = 100;
   double z = -100;
   
   double r = 1.5;
   double g = 1.5;
   double b = 1.5;

   if(i+1<argc && !equalToFlag(argc,in,i+1))
      x = convert_double(in[i+1],-100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 
 
   if(i+2<argc && !equalToFlag(argc,in,i+2))
      y = convert_double(in[i+2],100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+3<argc && !equalToFlag(argc,in,i+3))
      z = convert_double(in[i+3],-100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+4<argc && !equalToFlag(argc,in,i+4))
      r = convert_double(in[i+4],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 
   
   if(i+5<argc && !equalToFlag(argc,in,i+5))
      g = convert_double(in[i+5],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+6<argc && !equalToFlag(argc,in,i+6))
      b = convert_double(in[i+6],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   return create_light(create_point(x,y,z),create_color(r,g,b)); 
}
Exemplo n.º 8
0
/* writes data to fcell file for either full or partial rows */
static void put_fp_data(int fd, char *null_buf, const void *rast,
			int row, int n, RASTER_MAP_TYPE data_type)
{
    struct fileinfo *fcb = &R__.fileinfo[fd];
    int compressed = (fcb->open_mode == OPEN_NEW_COMPRESSED);
    XDR *xdrs = &fcb->xdrstream;
    void *work_buf;

    if (row < 0 || row >= fcb->cellhd.rows)
	return;

    if (n <= 0)
	return;

    work_buf = G__alloca(fcb->cellhd.cols * fcb->nbytes + 1);

    if (compressed)
	set_file_pointer(fd, row);

    xdrmem_create(xdrs, work_buf,
		  (unsigned int)fcb->nbytes * fcb->cellhd.cols, XDR_ENCODE);
    xdr_setpos(xdrs, 0);

    if (data_type == FCELL_TYPE)
	convert_float(xdrs, null_buf, rast, row, n);
    else
	convert_double(xdrs, null_buf, rast, row, n);

    xdr_destroy(&fcb->xdrstream);

    if (compressed)
	write_data_compressed(fd, row, work_buf, n);
    else
	write_data(fd, row, work_buf, n);

    G__freea(work_buf);
}
Exemplo n.º 9
0
void NGSAlignment::readFritzFile(const char *filename) {
    cout << "Reading Fritz file " << filename << " ..." << endl;
    try {
        ifstream in;
        in.exceptions(ios::failbit | ios::badbit);
        in.open(filename);
        in.clear();
        int i, total_size;
        string tmp;
        in >> tmp;
        ncategory = convert_int(tmp.c_str());
        if (ncategory < 1) throw "Wrong number of positions";
        in >> tmp;
        num_states = convert_int(tmp.c_str());
        total_size = ncategory*num_states*num_states;
        if (num_states < 1) throw "Wrong number of states";
        pair_freq = new double[total_size];
        for (i=0; i < total_size; i++) {
            in >> tmp;
            double count = convert_double(tmp.c_str());
            if (count < 0) throw "Wrong count";
            pair_freq[i] = count;
        }
        // set the failbit again
        in.exceptions(ios::failbit | ios::badbit);
        in.close();
    } catch (const char *str) {
        outError(str);
    } catch (string str) {
        outError(str);
    } catch (ios::failure) {
        outError(ERR_READ_INPUT);
    }

    cout << ncategory << " matrices of size " << num_states << endl;
}
Exemplo n.º 10
0
//
// ------  amount accessor ---
//
double Money::amount(double new_amount)
{
	double temp = (*this).amount();
	convert_double(new_amount);
	return temp;
}
Exemplo n.º 11
0
Money::Money(double amount)
{

  convert_double(amount);	
}