iphreeqc/SolutionIsotopeList.cxx
David L Parkhurst 2b76f04a8b Cleaned up header files to remove unnecessary includes of .h files. Moved includes to source code where possible.
Moved some methods for .h to source files to avoid need for includes.

Debug and Release compile. 

Still need to get class version working. 

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3868 1feff8c3-07ed-0310-ac33-dd36852eb9cd
2009-12-07 19:49:38 +00:00

118 lines
2.9 KiB
C++

#include "Utils.h" // define first
#include <cassert> // assert
#include <algorithm> // std::sort
#if !defined(PHREEQC_CLASS)
#define EXTERNAL extern
#include "global.h"
#else
#include "Phreeqc.h"
#endif
#include "SolutionIsotopeList.h"
#include "phqalloc.h"
#include "phrqproto.h"
cxxSolutionIsotopeList::cxxSolutionIsotopeList(void)
//
// default constructor for cxxSolution
//
{
}
cxxSolutionIsotopeList::~cxxSolutionIsotopeList(void)
//
// default destructor for cxxSolution
//
{
}
cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr)
{
int i;
// Isotopes
for (i = 0; i < solution_ptr->count_isotopes; i++)
{
//cxxSolutionIsotope iso(&solution_ptr->isotopes[i]);
(*this).push_back(&solution_ptr->isotopes[i]);
}
}
void
cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive,
double extensive)
{
for (cxxSolutionIsotopeList::const_iterator itold = old.begin();
itold != old.end(); ++itold)
{
//for (std::list <cxxSolutionIsotope>::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) {
bool found = false;
for (cxxSolutionIsotopeList::iterator it = this->begin();
it != this->end(); ++it)
{
//for (std::list <cxxSolutionIsotope>::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) {
if ((it->isotope_number == itold->isotope_number) &&
(it->elt_name == itold->elt_name) &&
(it->isotope_name == itold->isotope_name))
{
it->total += itold->total * extensive;
it->ratio += itold->ratio * intensive;
it->ratio_uncertainty += itold->ratio_uncertainty * intensive;
it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined
|| itold->
ratio_uncertainty_defined);
found = true;
break;
}
}
if (!found)
{
cxxSolutionIsotope iso;
iso.total = itold->total * extensive;
iso.ratio = itold->ratio * intensive;
iso.ratio_uncertainty = itold->ratio_uncertainty * intensive;
iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined;
this->push_back(iso);
}
}
}
void
cxxSolutionIsotopeList::multiply(double extensive)
{
for (cxxSolutionIsotopeList::iterator it = this->begin();
it != this->end(); ++it)
{
it->total *= extensive;
}
}
struct isotope *
cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope()
{
struct isotope *iso;
if (this->size() <= 0)
{
return NULL;
}
else
{
iso =
(struct isotope *)
PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope)));
if (iso == NULL)
malloc_error();
int i = 0;
for (cxxSolutionIsotopeList::iterator it = this->begin();
it != this->end(); ++it)
{
iso[i].isotope_number = it->isotope_number;
iso[i].elt_name = string_hsave(it->elt_name.c_str());
iso[i].total = it->total;
iso[i].ratio = it->ratio;
iso[i].ratio_uncertainty = it->ratio_uncertainty;
iso[i].master = it->master();
iso[i].primary = it->primary();
i++;
}
}
return (iso);
}