bool 
ChemistryMulti::check (const Scope& scope, const Geometry& geo,
		       const Soil& soil, const SoilWater& soil_water,
		       const SoilHeat& soil_heat, const Chemistry& chemistry,
		       Treelog& msg) const
{ 
  bool ok = true; 
  for (size_t c = 0; c < combine.size (); c++)
    {
      Treelog::Open nest (msg, "Chemistry: '" + combine[c]->objid  + "'");
      if (!combine[c]->check (scope, geo, soil, soil_water, soil_heat,
                              chemistry, msg))
	ok = false;
    }

  // Check for duplicate chemicals.
  std::map<symbol, size_t> found;
  for (size_t i = 0; i < chemicals.size (); i++)
    {
      const symbol type = chemicals[i]->objid;
      std::map<symbol, size_t>::const_iterator f = found.find (type);
      if (f != found.end ())
	{
	  std::ostringstream tmp;
	  tmp << "Chemical '" << type << "' definded in multiple chemistries:";
	  for (size_t j = 0; j < combine.size (); j++)
	    if (combine[j]->know (type))
	      tmp << " '" << combine[j]->objid << "'";
	  msg.error (tmp.str ());
	  ok = false;
	}
      found[type] = i;
    }
  return ok;
}
Exemple #2
0
  bool has_attribute (const symbol name) const
  { 
    bool missing = false;
    for (size_t i = 0; i < layers.size (); i++)
      if (!layers[i]->horizon->has_attribute (name))
	missing = true;
    for (size_t i = 0; i < zones.size (); i++)
      if (!zones[i]->horizon->has_attribute (name))
	missing = true;
    return !missing;
  }
void ErrorEstimatorImpl::output(std::ostream& os) const
{
    os << "[ErrorEstimator] iterations:" << iterationCount_ <<
        " error:" << error_ << endl;
    for (int i=0; i<(int)massSpreads_.size(); i++)
        os << "  " << *massSpreads_[i] << endl;
}
const MassSpread* ErrorEstimatorImpl::massSpread(int index) const
{
    if (index < 0 || index >= (int)massSpreads_.size())
        throw out_of_range("[ErrorEstimatorImpl::massSpread] Index out of range.");

    return massSpreads_[index];
}
void 
ChemistryMulti::tick_top (const Units& units, const Geometry& geo, 
                          const Soil& soil, const SoilWater& soil_water, 
                          const SoilHeat& soil_heat, 
                          const double tillage_age /* [d] */,
                          const Surface& surface,
                          const double snow_leak_rate, // [h^-1]
                          const double canopy_cover, // [],
                          const double canopy_leak_rate, // [h^-1]
                          const double litter_cover, // [],
                          const double litter_leak_rate, // [h^-1]
                          const double surface_runoff_rate /* [h^-1] */,
                          const double surface_water /* [mm] */,
                          const double total_rain /* [mm/h] */,
                          const double direct_rain, // [mm/h]
                          const double canopy_drip /* [mm/h] */, 
                          const double h_veg /* [m] */,
                          Chemistry& chemistry, 
                          const double dt, // [h]
                          Treelog& msg) 
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->tick_top (units, geo, soil, soil_water, soil_heat,
                          tillage_age, surface, 
                          snow_leak_rate, canopy_cover, canopy_leak_rate, 
                          litter_cover, litter_leak_rate,
			  surface_runoff_rate, surface_water,
                          total_rain, direct_rain, canopy_drip, h_veg, 
                          chemistry, dt, msg);
}
    void paintColumns()
	{
	for(size_t i=0;i< columns.size();++i)
	    {

	    }
	}
void 
ChemistryMulti::mass_balance (const Geometry& geo, 
                              const SoilWater& soil_water) const
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->mass_balance (geo, soil_water); 
}
					void clear()
						{
						genes.clear();
						chromStart=-1;
						chromEnd=-1;
						positions.clear();
						sample2positions.clear();
						}
void 
ChemistryMulti::mix (const Geometry& geo, const Soil& soil, 
                     const SoilWater& soil_water,
                     const double from, const double to, 
                     const double penetration)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->mix (geo, soil, soil_water, from, to, penetration); 
}
void 
ChemistryMulti::swap (const Geometry& geo,
                      const Soil& soil, const SoilWater& soil_water,
                      const double from, const double middle,
                      const double to)
{ 
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->swap (geo, soil, soil_water, from, middle, to); 
}
void 
ChemistryMulti::sorption_table (const Soil& soil, const size_t cell, 
                                const double Theta, const double start,
                                const double factor, const int intervals,
                                Treelog& msg) const
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->sorption_table (soil, cell, Theta, start, factor, intervals,
                                msg); 
}
Exemple #12
0
void 
Movement1D::initialize_derived (const Soil& soil,
                                const Groundwater& groundwater,
                                bool has_macropores, Treelog& msg)
{
  TREELOG_MODEL (msg);

  for (size_t i = 0; i < matrix_water.size (); i++)
    matrix_water[i]->has_macropores (has_macropores);
}
void 
ChemistryMulti::tick_source (const Scope& scope, const Geometry& geo,
                             const Soil& soil, const SoilWater& soil_water, 
                             const SoilHeat& soil_heat, 
                             const OrganicMatter& organic, 
                             const Chemistry& chemistry, Treelog& msg)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->tick_source (scope, geo, soil, soil_water, soil_heat, 
                             organic, chemistry, msg);
}
Exemple #14
0
 bool has_attribute (const symbol name, Treelog& msg) const
 { 
   bool missing = false;
   for (size_t i = 0; i < layers.size (); i++)
     if (!layers[i]->horizon->has_attribute (name))
       {
         msg.error ("Required attribute '" 
                    + name + "' is missing from the soil horizon '"
                    + layers[i]->horizon->objid + "'");
         missing = true;
       }
   for (size_t i = 0; i < zones.size (); i++)
     if (!zones[i]->horizon->has_attribute (name))
       {
         msg.error ("Required attribute '" 
                    + name + "' is missing from the soil zone '"
                    + zones[i]->horizon->objid + "'");
         missing = true;
       }
   return !missing;
 }
void 
ChemistryMulti::initialize (const Scope& scope, 
			    const Geometry& geo,
			    const Soil& soil, 
			    const SoilWater& soil_water,
			    const SoilHeat& soil_heat,
			    const Surface& surface, Treelog& msg)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->initialize (scope, geo, soil, soil_water, soil_heat, surface, 
                            msg);
}
Exemple #16
0
void Styler_Syntax::DoStyle(StyleRun& sr, unsigned int offset, const auto_vector<stxmatch>& matches) {
	const unsigned int rstart =  sr.GetRunStart();
	const unsigned int rend = sr.GetRunEnd();
	const unsigned int styleStart = offset < rstart ? rstart - offset : 0;
	const stxmatch m(wxEmptyString, NULL, styleStart, 0, 0, 0, NULL);

	if (matches.empty()) return;

	auto_vector<stxmatch>::const_iterator p = lower_bound(matches.begin(), matches.end(), &m, stxmatch_start_less());
	if (p != matches.begin()) --p;

	for (; p != matches.end(); ++p) {
		const unsigned int mStart = (*p)->start+offset;
		const unsigned int mEnd   = (*p)->end+offset;

		if (mStart > rend) break;

		// Check for overlap
		if (mEnd > rstart && mStart < rend) {
			const unsigned int start = wxMax(rstart, mStart);
			const unsigned int end = wxMin(rend, mEnd);

			const style* st = (*p)->st;
			if (st) {
				if (st->foregroundcolor != wxNullColour) sr.SetForegroundColor(start, end, st->foregroundcolor);
				if (st->backgroundcolor != wxNullColour) {
					sr.SetBackgroundColor(start, end, st->backgroundcolor);
					if (mEnd > rend) sr.SetExtendBgColor(st->backgroundcolor);
				}
				if (st->fontflags != wxFONTFLAG_DEFAULT) sr.SetFontStyle(start, end, st->fontflags);
			}

			// Check if there are submatches
			if ((*p)->subMatch.get()) {
				 DoStyle(sr, (*p)->start+offset, (*p)->subMatch->matches);
			}
		}
	}
}
double 
ChemistryMulti::suggest_dt () const
{
  double dt = 0.0;
  for (size_t c = 0; c < combine.size (); c++)
    {
      const double chem_dt = combine[c]->suggest_dt ();
      if (std::isnormal (chem_dt)
          && (!std::isnormal (dt) || chem_dt < dt))
        dt = chem_dt;
    }
  return dt;
}
void 
ChemistryMulti::tick_soil (const Scope& scope, 
                           const Geometry& geo, const double ponding,
			   const double R_mixing,
			   const Soil& soil, const SoilWater& soil_water,
			   const SoilHeat& soil_heat, Movement& movement,
			   const OrganicMatter& organic_matter,
			   Chemistry& chemistry, 
			   const double dt, Treelog& msg)
{ 
  TREELOG_MODEL (msg);

  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->tick_soil (scope, geo, ponding, R_mixing, 
			   soil, soil_water, soil_heat, movement, 
			   organic_matter, chemistry, dt, msg);
}
void ErrorEstimatorImpl::iterate()
{
    iterationCount_++;

    massSpreads_.clear();

    int measurementCount = int(measurements_.size());

    for (int i=0; i<measurementCount; i++)
        calculateMassSpread(measurements_[i]);

    double errorSum = 0;
    for (int i=0; i<measurementCount; i++)
        errorSum += massSpreads_[i]->error();

    error_ = sqrt(errorSum/measurementCount);

    if (outputFile_)
        output(outputFile_);
}
void 
ChemistryMulti::deposit (const symbol chem, const double flux, Treelog& msg)
{
  bool found = false;

  for (size_t c = 0; c < combine.size (); c++)
    if (combine[c]->know (chem))
      {
	if (found)
	  msg.error ("Duplicate chemical '" + chem + "' detected");

	Chemical& chemical = combine[c]->find (chem);
        chemical.deposit (flux);
	found = true;
      }
  
  if (found)
    return;

  check_ignore (chem, msg);
}
void 
ChemistryMulti::incorporate (const Geometry& geo,
			     const symbol chem, const double amount,
                             const Volume& volume,
			     Treelog& msg)
{
  bool found = false;

  for (size_t c = 0; c < combine.size (); c++)
    if (combine[c]->know (chem))
      {
	if (found)
	  msg.error ("Duplicate chemical '" + chem + "' detected");

	Chemical& chemical = combine[c]->find (chem);
        chemical.incorporate (geo, amount, volume);
	found = true;
      }
  
  if (found)
    return;

  check_ignore (chem, msg);
}
void addBlitterWidgets(auto_vector<BlitterWidget> &blitters, VideoBufferLocker vbl) {
	blitters.push_back(createX11Blitter(vbl).release());
	blitters.push_back(createXvBlitter(vbl).release());
}
void
ChemistryMulti::clear ()
{ 
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->clear (); 
}
void addAudioEngines(auto_vector<AudioEngine> &audioEngines, WId /*winId*/) {
	audioEngines.push_back(new CoreAudioEngine);
//	audioEngines.push_back(createOpenAlEngine().release());
}
void ErrorEstimatorImpl::calculateMassSpread(double measurement)
{
    auto_ptr<const MassSpread> massSpread(MassSpread::create(measurement, error_, &massDatabase_));
    massSpreads_.push_back(massSpread);
}
Exemple #26
0
	int main(int argc,char** argv)
	    {
	    const char* exonFile=0;
	    int optind=1;
	    char* faidxfile=NULL;
	    while(optind < argc)
		{
		if(strcmp(argv[optind],"-h")==0)
		    {
		    this->usage(cerr,argc,argv);
		    return(EXIT_FAILURE);
		    }
		else if(strcmp(argv[optind],"-f")==0 && optind+1< argc)
		    {
		    faidxfile = argv[++optind];
		    }
		else if(strcmp(argv[optind],"-g")==0 && optind+1< argc)
		    {
		    exonFile=argv[++optind];
		    }
		else if(strcmp(argv[optind],"--")==0)
		    {
		    ++optind;
		    break;
		    }
		else if(argv[optind][0]=='-')
		    {
		    cerr << "unknown option '" << argv[optind]<< "'" << endl;
		    this->usage(cerr,argc,argv);
		    return EXIT_FAILURE;
		    }
		else
		    {
		    break;
		    }
		++optind;
		}
	    if(faidxfile==0)
		{
		cerr << "no fasta genome defined." << endl;
		this->usage(cerr,argc,argv);
		return EXIT_FAILURE;
		}
	    this->faidx.reset(new IndexedFasta(faidxfile));





	    if(exonFile==0)
		{
		cerr << "no bed for exons defined." << endl;
		this->usage(cerr,argc,argv);
		return EXIT_FAILURE;
		}



	    if(optind==argc)
		{
		cerr << "BAM files missing"<< endl;
		return EXIT_FAILURE;
		}
	    else
		{
		while(optind< argc)
		    {
		    char* bamfile=argv[optind++];
		    WHERE("Open "<< bamfile);
		    BamFile2* bam=new BamFile2(bamfile);
		    this->bamFiles.push_back(bam);
		    bam->open(true);
		    }
		}

	   //open exon file
	    igzstreambuf buf(exonFile);
	    istream in(&buf);
	    this->readExons(in);
	    buf.close();
	    if(exons.empty())
		{
		cerr << "No exon.\n";
		return EXIT_FAILURE;
		}

	    run();
	    for(size_t i=0;i< bamFiles.size();++i)
		{
		bamFiles[i]->close();
		}
	    return EXIT_SUCCESS;
	    }
void 
ChemistryMulti::update_C (const Soil& soil, const SoilWater& soil_water)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->update_C (soil, soil_water); 
}
void addAudioEngines(auto_vector<AudioEngine> &audioEngines, WId winId) {
	if (WasapiEngine::isUsable())
		audioEngines.push_back(new WasapiEngine);

	audioEngines.push_back(new DirectSoundEngine(winId));
}
void addAudioEngines(auto_vector<AudioEngine> &audioEngines, WId /*winId*/) {
	audioEngines.push_back(new AlsaEngine);
	audioEngines.push_back(new OssEngine);
}
void
ChemistryMulti::harvest (const double removed, const double surface)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->harvest (removed, surface);
}