Merged revision(s) 7863-7986 from phreeqc3/branches/multi_punch:

Branching at 7862 for multiple SELECTED_OUTPUT, USER_PUNCH
........
Have multiple SELECTED_OUTPUT working.

Need to have multiple USER_PUNCH.
........
Think multiple instances of both SELECTED_OUTPUT and USER_PUNCH are working.
........
Fixed up inverse.cpp a bit.
........
Fixed missing -pressure in solution dump_raw and read_raw.
........
Merging revisedfandg back into trunk. Makes Excel spreadsheet for carbon-14 dating.

OK by Niel. Has Revised_Fontes_ and_Garnier_ in_NetpathXL.docx to add for documentation.
........
Added Revised_Fontes_ and_Garnier_ in_NetpathXL.docx to installation
Fixed bug that wouldn't allow uninstall
........
updated ftp targets
........
NetpathXL 1.4
........
checkin from make
........
latest test with change in Pitzer pressure, -pressure in SOLUTION_RAW, runs modify_test, has error
........
bugs linux caught, something different about when to print headings
........
Working on multipunch
........
working on high_precision, using SELECTED_OUTPUT 1
........
dump precision
........
Added basic functions:
EQ_FRAC
KIN_TIME
SPECIES_FORMULA
STR_F
STR_E
Added //{{NEW BASIC HERE}} for updating BASIC routines

........
Making backward compatible.

Copying all but lists.

Revised tidy_punch logic.
........
Still working to make backward compatible.

Think there will be one diff, headings will not be rewritten (ddl_flux).
........
updated dump tests (new -pressure line)
........
multi_punch branch

........
Added a Fortran callback.

Will try to revise so that the same callback works for Fortran and C.
........
Revised name to BasicFortran

Added methods for C call SetBasicCallback.

Need to check C side and documentation.
........


git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7987 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2013-08-28 23:11:07 +00:00
commit adf7d98498
19 changed files with 1945 additions and 406 deletions

View File

@ -472,7 +472,19 @@ numtostr(char * Result, LDBLE n)
/* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */
if (ceil(n) == floor(n))
{
if (PhreeqcPtr->punch.high_precision == FALSE)
//if (PhreeqcPtr->current_selected_output != NULL &&
// !PhreeqcPtr->current_selected_output->Get_high_precision())
//{
// sprintf(l_s, "%12.0f", (double) n);
//}
//else
//{
// sprintf(l_s, "%20.0f", (double) n);
//}
bool temp_high_precision = (PhreeqcPtr->current_selected_output != NULL) ?
PhreeqcPtr->current_selected_output->Get_high_precision() :
PhreeqcPtr->high_precision;
if (!temp_high_precision)
{
sprintf(l_s, "%12.0f", (double) n);
}
@ -483,7 +495,10 @@ numtostr(char * Result, LDBLE n)
}
else
{
if (PhreeqcPtr->punch.high_precision == FALSE)
bool temp_high_precision = (PhreeqcPtr->current_selected_output != NULL) ?
PhreeqcPtr->current_selected_output->Get_high_precision() :
PhreeqcPtr->high_precision;
if (!temp_high_precision)
{
sprintf(l_s, "%12.4e", (double) n);
}
@ -4423,10 +4438,14 @@ cmdpunch(struct LOC_exec *LINK)
continue;
}
n = expr(LINK);
bool temp_high_precision = (PhreeqcPtr->current_selected_output != NULL) ?
PhreeqcPtr->current_selected_output->Get_high_precision() :
PhreeqcPtr->high_precision;
if (n.stringval)
{
/* fputs(n.UU.sval, stdout); */
if (PhreeqcPtr->punch.high_precision == FALSE)
if (!temp_high_precision)
{
if (strlen(n.UU.sval) <= 12)
{
@ -4450,7 +4469,7 @@ cmdpunch(struct LOC_exec *LINK)
}
PhreeqcPtr->PHRQ_free(n.UU.sval);
}
else if (PhreeqcPtr->punch.high_precision == FALSE)
else if (!temp_high_precision)
{
PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val);
}

View File

@ -132,7 +132,7 @@ log_msg(const char * str)
// punch ostream methods
// ---------------------------------------------------------------------- */
bool PHRQ_io::
punch_open(const char *file_name, std::ios_base::openmode mode)
punch_open(const char *file_name, std::ios_base::openmode mode, int n_user)
/* ---------------------------------------------------------------------- */
{
return ofstream_open(&punch_ostream, file_name, mode);

View File

@ -78,7 +78,7 @@ public:
bool Get_log_on(void) {return this->log_on;}
// punch_ostream
virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out, int n_user = 1);
void punch_flush(void);
void punch_close(void);
virtual void punch_msg(const char * str);

View File

@ -67,7 +67,7 @@ get_forward_output_to_log(void)
void Phreeqc::
fpunchf_heading(const char *name)
{
if (pr.punch == TRUE && punch.in == TRUE)
if (pr.punch == TRUE && current_selected_output != NULL)
{
punch_msg(name);
}
@ -113,11 +113,16 @@ void Phreeqc::
fpunchf_user(int user_index, const char *format, double d)
{
const char *name;
if (current_user_punch == NULL)
return;
// check headings
//if (user_index < user_punch_count_headings)
int user_punch_count_headings = (int) current_user_punch->Get_headings().size();
if (user_index < user_punch_count_headings)
{
name = user_punch_headings[user_index];
//name = user_punch_headings[user_index];
name = current_user_punch->Get_headings()[user_index].c_str();
}
else
{
@ -146,11 +151,15 @@ void Phreeqc::
fpunchf_user(int user_index, const char *format, char * d)
{
const char *name;
if (current_user_punch == NULL)
return;
int user_punch_count_headings = (int) current_user_punch->Get_headings().size();
// check headings
if (user_index < user_punch_count_headings)
{
name = user_punch_headings[user_index];
//name = user_punch_headings[user_index];
name = current_user_punch->Get_headings()[user_index].c_str();
}
else
{
@ -976,11 +985,11 @@ output_msg(const char * str)
/* ---------------------------------------------------------------------- */
bool Phreeqc::
punch_open(const char *file_name)
punch_open(const char *file_name, int n_user)
/* ---------------------------------------------------------------------- */
{
if (phrq_io)
return this->phrq_io->punch_open(file_name);
return this->phrq_io->punch_open(file_name, std::ios_base::out, n_user);
return false;
}
/* ---------------------------------------------------------------------- */

View File

@ -223,6 +223,10 @@ void Phreeqc::init(void)
last_model.count_surface_charge = -1;
last_model.surface_charge = NULL;
current_selected_output = NULL;
current_user_punch = NULL;
high_precision = false;
#ifdef SKIP
//struct punch punch;
/*
* Initialize punch
@ -266,7 +270,7 @@ void Phreeqc::init(void)
punch.user_punch = TRUE;
punch.charge_balance = FALSE;
punch.percent_error = FALSE;
#endif
// auto Rxn_temperature_map;
// auto Rxn_pressure_map;
@ -638,9 +642,11 @@ void Phreeqc::init(void)
* USER PRINT COMMANDS
* ---------------------------------------------------------------------- */
user_print = NULL;
#ifdef SKIP
user_punch = NULL;
user_punch_headings = NULL;
user_punch_count_headings = 0;
#endif
n_user_punch_index = 0;
fpunchf_user_s_warning = 0;
fpunchf_user_buffer[0] = 0;
@ -728,7 +734,7 @@ void Phreeqc::init(void)
llnl_count_bdot = 0;
llnl_co2_coefs = 0;
llnl_count_co2_coefs = 0;
selected_output_file_name = NULL;
//selected_output_file_name = NULL;
dump_file_name = NULL;
remove_unstable_phases = FALSE;
// auto screen_string;
@ -770,7 +776,7 @@ void Phreeqc::init(void)
phreeqc_mpi_myself = 0;
first_read_input = TRUE;
user_database = NULL;
have_punch_name = FALSE;
//have_punch_name = FALSE;
print_density = 0;
zeros = NULL;
zeros_max = 1;
@ -1157,6 +1163,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
* Initialize punch
*/
//-- skip punch, accept init
high_precision = pSrc->high_precision;
Rxn_temperature_map = pSrc->Rxn_temperature_map;
Rxn_pressure_map = pSrc->Rxn_pressure_map;
@ -1791,6 +1798,9 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
user_print->varbase = NULL;
user_print->loopbase = NULL;
}
// For now, User Punch is not copied
#ifdef SKIP
/*
user_punch = NULL;
*/
@ -1821,6 +1831,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
user_punch_headings[i] = string_hsave(pSrc->user_punch_headings[i]);
}
}
#endif
n_user_punch_index = pSrc->n_user_punch_index;
fpunchf_user_s_warning = pSrc->fpunchf_user_s_warning;
//fpunchf_user_buffer[0] = 0;
@ -1942,6 +1953,11 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
if (llnl_co2_coefs == NULL) malloc_error();
memcpy(llnl_co2_coefs, pSrc->llnl_co2_coefs, (size_t) llnl_count_co2_coefs * sizeof(LDBLE));
}
// Not implemented for now
//SelectedOutput_map = pSrc->SelectedOutput_map;
SelectedOutput_map.clear();
//selected_output_file_name = NULL;
//dump_file_name = NULL;
//remove_unstable_phases = FALSE;
@ -2051,7 +2067,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
phreeqc_mpi_myself = 0;
first_read_input = TRUE;
user_database = string_duplicate(pSrc->user_database);
have_punch_name = pSrc->have_punch_name;
//have_punch_name = pSrc->have_punch_name;
print_density = pSrc->print_density;
#ifdef SKIP
zeros = NULL;

View File

@ -28,6 +28,8 @@
#include "runner.h"
#include "dumper.h"
#include "PHRQ_io.h"
#include "SelectedOutput.h"
#include "UserPunch.h"
#ifdef MULTICHART
#include "ChartHandler.h"
#endif
@ -233,7 +235,7 @@ public:
void output_msg(const char * str);
// punch_ostream
bool punch_open(const char *file_name);
bool punch_open(const char *file_name, int n_user);
void punch_flush(void);
void punch_close(void);
void punch_msg(const char * str);
@ -1142,7 +1144,8 @@ protected:
* ---------------------------------------------------------------------- */
struct model last_model;
struct punch punch;
//struct punch punch;
bool high_precision;
/* ----------------------------------------------------------------------
* Temperatures
@ -1517,9 +1520,9 @@ protected:
* USER PRINT COMMANDS
* ---------------------------------------------------------------------- */
struct rate *user_print;
struct rate *user_punch;
const char **user_punch_headings;
int user_punch_count_headings;
//struct rate *user_punch;
//const char **user_punch_headings;
//int user_punch_count_headings;
int n_user_punch_index;
int fpunchf_user_s_warning;
@ -1612,7 +1615,13 @@ protected:
int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot,
llnl_count_co2_coefs;
char *selected_output_file_name;
//char *selected_output_file_name;
std::map<int, SelectedOutput> SelectedOutput_map;
SelectedOutput * current_selected_output;
std::map <int, UserPunch> UserPunch_map;
UserPunch * current_user_punch;
char *dump_file_name;
int remove_unstable_phases;
std::string screen_string;
@ -1664,7 +1673,7 @@ protected:
int first_read_input;
char *user_database;
int have_punch_name;
//int have_punch_name;
/* VP: Density Start */
int print_density;
/* VP: Density End */
@ -1746,6 +1755,7 @@ protected:
FILE *netpath_file;
int count_inverse_models, count_pat_solutions;
int min_position[32], max_position[32], now[32];
std::vector <std::string> inverse_heading_names;
/* kinetics.cpp ------------------------------- */
public:

78
SelectedOutput.cpp Normal file
View File

@ -0,0 +1,78 @@
#include "SelectedOutput.h"
SelectedOutput::SelectedOutput(int n, PHRQ_io *io)
: cxxNumKeyword(io)
{
this->Set_file_name(n);
this->punch_ostream = NULL;
this->active = true;
this->new_def = false;
this->user_punch_new_def = false;
//std::map<std::string, void *> totals;
//std::map<std::string, void *> molalities;
//std::map<std::string, void *> activities;
//std::map<std::string, void *> pure_phases;
//std::map<std::string, void *> si;
//std::map<std::string, void *> gases;
//std::map<std::string, void *> s_s;
//std::map<std::string, void *> kinetics;
//std::map<std::string, void *> isotopes;
//std::map<std::string, void *> calculate_values;
//std::map<std::string, void *> kinetics;
//std::map<std::string, void *> kinetics;
this->inverse = true;
this->sim = true;
this->state = true;
this->soln = true;
this->dist = true;
this->time = true;
this->step = true;
this->rxn = false;
this->temp = false;
this->ph = true;
this->pe = true;
this->alk = false;
this->mu = false;
this->water = false;
this->high_precision = false;
this->user_punch = true;
this->charge_balance = false;
this->percent_error = false;
this->have_punch_name = false;
}
SelectedOutput::~SelectedOutput(void)
{
if (this->punch_ostream != NULL)
{
delete this->punch_ostream;
}
this->punch_ostream = NULL;
}
void
SelectedOutput::Reset(bool value)
{
sim = value;
state = value;
soln = value;
dist = value;
time = value;
step = value;
ph = value;
pe = value;
rxn = value;
temp = value;
alk = value;
mu = value;
water = value;
charge_balance = value;
percent_error = value;
}
void
SelectedOutput::Set_file_name(int n)
{
std::ostringstream os;
os << "selected_output_" << n << ".sel";
file_name = os.str();
}

112
SelectedOutput.h Normal file
View File

@ -0,0 +1,112 @@
#if !defined(SELECTEDOUTPUT_H_INCLUDED)
#define SELECTEDOUTPUT_H_INCLUDED
#include <string> // std::string
#include <vector>
#include <map>
#include "NumKeyword.h"
class SelectedOutput:public cxxNumKeyword
{
public:
SelectedOutput(int n=1, PHRQ_io *io=NULL);
~SelectedOutput(void);
void Reset(bool tf);
inline std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;}
inline std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;}
inline std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;}
inline std::vector< std::pair< std::string, void * > > & Get_pure_phases(void) {return this->pure_phases;}
inline std::vector< std::pair< std::string, void * > > & Get_si(void) {return this->si;}
inline std::vector< std::pair< std::string, void * > > & Get_gases(void) {return this->gases;}
inline std::vector< std::pair< std::string, void * > > & Get_s_s(void) {return this->s_s;}
inline std::vector< std::pair< std::string, void * > > & Get_kinetics(void) {return this->kinetics;}
inline std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;}
inline std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;}
inline std::string & Get_file_name(void) {return this->file_name;}
inline bool Get_new_def(void) {return this->new_def;}
inline bool Get_sim(void) {return this->sim;}
inline bool Get_state(void) {return this->state;}
inline bool Get_soln(void) {return this->soln;}
inline bool Get_dist(void) {return this->dist;}
inline bool Get_time(void) {return this->time;}
inline bool Get_step(void) {return this->step;}
inline bool Get_rxn(void) {return this->rxn;}
inline bool Get_temp(void) {return this->temp;}
inline bool Get_ph(void) {return this->ph;}
inline bool Get_pe(void) {return this->pe;}
inline bool Get_alk(void) {return this->alk;}
inline bool Get_mu(void) {return this->mu;}
inline bool Get_water(void) {return this->water;}
inline bool Get_high_precision(void) {return this->high_precision;}
inline bool Get_user_punch(void) {return this->user_punch;}
inline bool Get_charge_balance(void) {return this->charge_balance;}
inline bool Get_percent_error(void) {return this->percent_error;}
inline bool Get_inverse(void) {return this->inverse;}
//inline bool Get_punch(void) {return this->punch;}
inline bool Get_active(void) {return this->active;}
inline bool Get_have_punch_name(void) {return this->have_punch_name;}
inline std::ostream* Get_punch_ostream(void) {return this->punch_ostream;}
void Set_file_name(int i);
inline void Set_file_name(std::string s) {this->file_name = s;}
inline void Set_new_def(bool tf) {this->new_def = tf;}
inline void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;}
inline void Set_sim(bool tf) {this->sim = tf;}
inline void Set_state(bool tf) {this->state = tf;}
inline void Set_soln(bool tf) {this->soln = tf;}
inline void Set_dist(bool tf) {this->dist = tf;}
inline void Set_time(bool tf) {this->time = tf;}
inline void Set_step(bool tf) {this->step = tf;}
inline void Set_rxn(bool tf) {this->rxn = tf;}
inline void Set_temp(bool tf) {this->temp = tf;}
inline void Set_ph(bool tf) {this->ph = tf;}
inline void Set_pe(bool tf) {this->pe = tf;}
inline void Set_alk(bool tf) {this->alk = tf;}
inline void Set_mu(bool tf) {this->mu = tf;}
inline void Set_water(bool tf) {this->water = tf;}
inline void Set_high_precision(bool tf) {this->high_precision = tf;}
inline void Set_user_punch(bool tf) {this->user_punch = tf;}
inline void Set_charge_balance(bool tf) {this->charge_balance = tf;}
inline void Set_percent_error(bool tf) {this->percent_error = tf;}
inline void Set_inverse(bool tf) {this->inverse = tf;}
//inline void Set_punch(bool tf) {this->punch = tf;}
inline void Set_active(bool tf) {this->active = tf;}
inline void Set_have_punch_name(bool tf) {this->have_punch_name = tf;}
protected:
std::string file_name;
std::ostream * punch_ostream;
bool active;
bool new_def;
bool user_punch_new_def;
std::vector< std::pair< std::string, void * > > totals;
std::vector< std::pair< std::string, void * > > molalities;
std::vector< std::pair< std::string, void * > > activities;
std::vector< std::pair< std::string, void * > > pure_phases;
std::vector< std::pair< std::string, void * > > si;
std::vector< std::pair< std::string, void * > > gases;
std::vector< std::pair< std::string, void * > > s_s;
std::vector< std::pair< std::string, void * > > kinetics;
std::vector< std::pair< std::string, void * > > isotopes;
std::vector< std::pair< std::string, void * > > calculate_values;
bool sim;
bool state;
bool soln;
bool dist;
bool time;
bool step;
bool rxn;
bool temp;
bool ph;
bool pe;
bool alk;
bool mu;
bool water;
bool high_precision;
bool user_punch;
bool charge_balance;
bool percent_error;
bool inverse;
bool have_punch_name;
};
#endif // !defined(SELECTEDOUTPUT_H_INCLUDED)

19
UserPunch.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "UserPunch.h"
#include "Phreeqc.h"
UserPunch::UserPunch(int n, PHRQ_io *io)
: cxxNumKeyword(io)
{
this->PhreeqcPtr = NULL;
this->rate = NULL;
}
UserPunch::~UserPunch(void)
{
if (this->rate != NULL)
{
this->PhreeqcPtr->rate_free(this->rate);
}
this->PhreeqcPtr->free_check_null(this->rate);
this->rate = NULL;
}

25
UserPunch.h Normal file
View File

@ -0,0 +1,25 @@
#if !defined(USERPUNCH_H_INCLUDED)
#define USERPUNCH_H_INCLUDED
#include <vector>
#include <string> // std::string
#include "NumKeyword.h"
class Phreeqc;
class UserPunch:public cxxNumKeyword
{
public:
UserPunch(int n=1, PHRQ_io *io=NULL);
~UserPunch(void);
std::vector <std::string> &Get_headings() {return this->headings;}
void Set_headings(std::vector <std::string> & h) {this->headings = h;}
Phreeqc * Get_PhreeqcPtr() {return this->PhreeqcPtr;}
void Set_PhreeqcPtr(Phreeqc * p) {this->PhreeqcPtr = p;}
struct rate * Get_rate() {return this->rate;}
void Set_rate(struct rate * r) {this->rate = r;}
protected:
std::vector <std::string> headings;
struct rate * rate;
Phreeqc * PhreeqcPtr;
};
#endif // !defined(USERPUNCH_H_INCLUDED)

View File

@ -284,6 +284,7 @@ struct name_phase
const char *name;
struct phase *phase;
};
#ifdef SKIP
struct punch
{
int in;
@ -327,7 +328,7 @@ struct punch
int charge_balance;
int percent_error;
};
#endif
struct Change_Surf
{
const char *comp_name;

View File

@ -26,11 +26,12 @@ inverse_models(void)
if (count_inverse <= 0) return OK;
// Revert to previous headings after inverse modeling
std::vector<std::string> old_headings;
int i;
for (i = 0; i < user_punch_count_headings; i++)
{
old_headings.push_back(user_punch_headings[i]);
}
//int i;
//for (i = 0; i < user_punch_count_headings; i++)
//{
// old_headings.push_back(user_punch_headings[i]);
//}
array1 = NULL;
inv_zero = NULL;
@ -134,15 +135,15 @@ inverse_models(void)
}
}
user_punch_count_headings = (int) old_headings.size();
user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings,
(size_t) (user_punch_count_headings + 1) * sizeof(char *));
if (user_punch_headings == NULL)
malloc_error();
for (i = 0; i < user_punch_count_headings; i++)
{
user_punch_headings[i] = string_hsave(old_headings[i].c_str());
}
//user_punch_count_headings = (int) old_headings.size();
//user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings,
// (size_t) (user_punch_count_headings + 1) * sizeof(char *));
//if (user_punch_headings == NULL)
// malloc_error();
//for (i = 0; i < user_punch_count_headings; i++)
//{
// user_punch_headings[i] = string_hsave(old_headings[i].c_str());
//}
return (OK);
}
@ -158,7 +159,7 @@ setup_inverse(struct inverse *inv_ptr)
int max;
int count_rows_t;
int column, row;
int temp, temppun;
int temp;
LDBLE isotope_number;
LDBLE f, coef, cb, conc;
char token[MAX_LENGTH];
@ -180,11 +181,12 @@ setup_inverse(struct inverse *inv_ptr)
carbon = 1;
temp = pr.status;
pr.status = FALSE;
temppun = punch.in;
punch.in = FALSE;
// current_selected_output is NULL at this point
carbon_derivs(inv_ptr);
pr.status = temp;
punch.in = temppun;
//current_selected_output->Set_inverse(temp_inv);
state = INVERSE;
/*
* tidy isotopes if necessary
@ -2073,77 +2075,175 @@ print_model(struct inverse *inv_ptr)
int Phreeqc::
punch_model_heading(struct inverse *inv_ptr)
/* ---------------------------------------------------------------------- */
{
/*
* Prints model headings to selected output file
*/
int i;
char token[MAX_LENGTH];
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
// set punch file
current_selected_output = &(so_it->second);
if (pr.punch == FALSE ||
current_selected_output == NULL ||
!current_selected_output->Get_inverse() ||
!current_selected_output->Get_active())
continue;
phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream());
int l = (!current_selected_output->Get_high_precision()) ? 15 : 20;
inverse_heading_names.clear();
/*
* Print sum of residuals and maximum fractional error
*/
inverse_heading_names.push_back(sformatf("%*s\t", l, "Sum_resid"));
inverse_heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U"));
inverse_heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr"));
/*
* Print solution numbers
*/
for (i = 0; i < inv_ptr->count_solns; i++)
{
sprintf(token, "Soln_%d", inv_ptr->solns[i]);
std::string tok1(token);
tok1.append("_min");
std::string tok2(token);
tok2.append("_max");
inverse_heading_names.push_back(sformatf("%*s\t", l, token));
inverse_heading_names.push_back(sformatf("%*s\t", l, tok1.c_str()));
inverse_heading_names.push_back(sformatf("%*s\t", l, tok2.c_str()));
}
/*
* Print phase names
*/
for (i = col_phases; i < col_redox; i++)
{
std::string tok1(col_name[i]);
tok1.append("_min");
std::string tok2(col_name[i]);
tok2.append("_max");
inverse_heading_names.push_back(sformatf("%*s\t", l, col_name[i]));
inverse_heading_names.push_back(sformatf("%*s\t", l, tok1.c_str()));
inverse_heading_names.push_back(sformatf("%*s\t", l, tok2.c_str()));
}
size_t j;
for (j = 0; j < inverse_heading_names.size(); j++)
{
fpunchf_heading(inverse_heading_names[j].c_str());
//user_punch_headings[j] = string_hsave(heading_names[j].c_str());
}
fpunchf_heading("\n");
}
current_selected_output = NULL;
phrq_io->Set_punch_ostream(NULL);
/*
* Flush buffer after each model
*/
punch_flush();
return (OK);
}
#ifdef SKIP
/* ---------------------------------------------------------------------- */
int Phreeqc::
punch_model_heading(struct inverse *inv_ptr)
/* ---------------------------------------------------------------------- */
{
/*
* Prints model headings to selected output file
*/
int i;
char token[MAX_LENGTH];
if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE)
return (OK);
//if (/*punch.in == FALSE ||*/ pr.punch == FALSE || punch.inverse == FALSE)
// return (OK);
std::vector<std::string> heading_names;
int l = (punch.high_precision == FALSE) ? 15 : 20;
/*
* Print sum of residuals and maximum fractional error
*/
heading_names.push_back(sformatf("%*s\t", l, "Sum_resid"));
heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U"));
heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr"));
/*
* Print solution numbers
*/
for (i = 0; i < inv_ptr->count_solns; i++)
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
sprintf(token, "Soln_%d", inv_ptr->solns[i]);
std::string tok1(token);
tok1.append("_min");
std::string tok2(token);
tok2.append("_max");
// set punch file
current_selected_output = &(so_it->second);
if (pr.punch == FALSE ||
current_selected_output == NULL ||
current_selected_output->punch_ostream == NULL ||
!current_selected_output->Get_inverse() ||
!current_selected_output->Get_active())
continue;
phrq_io->Set_punch_ostream(current_selected_output->punch_ostream);
heading_names.push_back(sformatf("%*s\t", l, token));
heading_names.push_back(sformatf("%*s\t", l, tok1.c_str()));
heading_names.push_back(sformatf("%*s\t", l, tok2.c_str()));
int l = (!current_selected_output->Get_high_precision()) ? 15 : 20;
heading_names.clear();
/*
* Print sum of residuals and maximum fractional error
*/
heading_names.push_back(sformatf("%*s\t", l, "Sum_resid"));
heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U"));
heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr"));
/*
* Print solution numbers
*/
for (i = 0; i < inv_ptr->count_solns; i++)
{
sprintf(token, "Soln_%d", inv_ptr->solns[i]);
std::string tok1(token);
tok1.append("_min");
std::string tok2(token);
tok2.append("_max");
heading_names.push_back(sformatf("%*s\t", l, token));
heading_names.push_back(sformatf("%*s\t", l, tok1.c_str()));
heading_names.push_back(sformatf("%*s\t", l, tok2.c_str()));
}
/*
* Print phase names
*/
for (i = col_phases; i < col_redox; i++)
{
std::string tok1(col_name[i]);
tok1.append("_max");
std::string tok2(col_name[i]);
tok2.append("_max");
heading_names.push_back(sformatf("%*s\t", l, col_name[i]));
heading_names.push_back(sformatf("%*s\t", l, tok1.c_str()));
heading_names.push_back(sformatf("%*s\t", l, tok2.c_str()));
}
size_t j;
// punch headings
//user_punch_count_headings = (int) heading_names.size();
//user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings,
// (size_t) (user_punch_count_headings + 1) * sizeof(char *));
//if (user_punch_headings == NULL)
// malloc_error();
for (j = 0; j < heading_names.size(); j++)
{
fpunchf_heading(heading_names[j].c_str());
//user_punch_headings[j] = string_hsave(heading_names[j].c_str());
}
fpunchf_heading("\n");
}
/*
* Print phase names
*/
for (i = col_phases; i < col_redox; i++)
{
std::string tok1(col_name[i]);
tok1.append("_max");
std::string tok2(col_name[i]);
tok2.append("_max");
heading_names.push_back(sformatf("%*s\t", l, col_name[i]));
heading_names.push_back(sformatf("%*s\t", l, tok1.c_str()));
heading_names.push_back(sformatf("%*s\t", l, tok2.c_str()));
}
size_t j;
user_punch_count_headings = (int) heading_names.size();
user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings,
(size_t) (user_punch_count_headings + 1) * sizeof(char *));
if (user_punch_headings == NULL)
malloc_error();
for (j = 0; j < heading_names.size(); j++)
{
fpunchf_heading(heading_names[j].c_str());
user_punch_headings[j] = string_hsave(heading_names[j].c_str());
}
fpunchf_heading("\n");
current_selected_output = NULL;
phrq_io->Set_punch_ostream(NULL);
inverse_heading_names = heading_names;
/*
* Flush buffer after each model
*/
punch_flush();
return (OK);
}
#endif
/* ---------------------------------------------------------------------- */
int Phreeqc::
punch_model(struct inverse *inv_ptr)
@ -2154,84 +2254,103 @@ punch_model(struct inverse *inv_ptr)
*/
int i;
LDBLE d1, d2, d3;
if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE)
return (OK);
n_user_punch_index = 0;
/*
* write residual info
*/
if (punch.high_precision == FALSE)
{
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) (error / SCALE_EPSILON));
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) scaled_error);
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) max_pct);
}
else
{
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) (error / SCALE_EPSILON));
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) scaled_error);
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) max_pct);
}
/*
* write solution fractions
*/
for (i = 0; i < inv_ptr->count_solns; i++)
{
d1 = inv_delta1[i];
d2 = min_delta[i];
d3 = max_delta[i];
if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d1 = 0.0;
if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d2 = 0.0;
if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d3 = 0.0;
if (punch.high_precision == FALSE)
{
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1);
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2);
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3);
}
else
{
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1);
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2);
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3);
}
}
/*
* write phase transfers
*/
for (i = col_phases; i < col_redox; i++)
{
d1 = inv_delta1[i];
d2 = min_delta[i];
d3 = max_delta[i];
if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d1 = 0.0;
if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d2 = 0.0;
if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d3 = 0.0;
if (punch.high_precision == FALSE)
{
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1);
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2);
fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3);
}
else
{
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1);
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2);
fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3);
}
}
punch_msg("\n");
//if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE)
// return (OK);
/*
* Flush buffer after each model
*/
punch_flush();
UserPunch temp_user_punch;
current_user_punch = & temp_user_punch;
temp_user_punch.Set_headings(inverse_heading_names);
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
current_selected_output = &(so_it->second);
if (pr.punch == FALSE ||
current_selected_output == NULL ||
!current_selected_output->Get_inverse() ||
!current_selected_output->Get_active())
continue;
phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream());
n_user_punch_index = 0;
/*
* write residual info
*/
if (!current_selected_output->Get_high_precision())
{
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) (error / SCALE_EPSILON));
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) scaled_error);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) max_pct);
}
else
{
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) (error / SCALE_EPSILON));
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) scaled_error);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) max_pct);
}
/*
* write solution fractions
*/
for (i = 0; i < inv_ptr->count_solns; i++)
{
d1 = inv_delta1[i];
d2 = min_delta[i];
d3 = max_delta[i];
if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d1 = 0.0;
if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d2 = 0.0;
if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d3 = 0.0;
if (!current_selected_output->Get_high_precision())
{
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d1);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d2);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d3);
}
else
{
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d1);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d2);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d3);
}
}
/*
* write phase transfers
*/
for (i = col_phases; i < col_redox; i++)
{
d1 = inv_delta1[i];
d2 = min_delta[i];
d3 = max_delta[i];
if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d1 = 0.0;
if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d2 = 0.0;
if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d3 = 0.0;
if (!current_selected_output->Get_high_precision())
{
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d1);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d2);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d3);
}
else
{
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d1);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d2);
fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d3);
}
}
punch_msg("\n");
/*
* Flush buffer after each model
*/
punch_flush();
}
current_selected_output = NULL;
phrq_io->Set_punch_ostream(NULL);
return (OK);
}

View File

@ -810,21 +810,24 @@ punch_isotopes(void)
/*
* Punch isotope ratios relative to standards
*/
int i;
//int i;
LDBLE iso;
struct isotope_ratio *isotope_ratio_ptr;
struct master_isotope *master_isotope_ptr;
if (punch.in == FALSE || punch.isotopes == FALSE)
return (OK);
if (punch.count_isotopes == 0)
return (OK);
for (i = 0; i < punch.count_isotopes; i++)
//if (punch.in == FALSE || punch.isotopes == FALSE)
// return (OK);
if (current_selected_output->Get_isotopes().size() == 0)
return(OK);
//if (punch.count_isotopes == 0)
// return (OK);
//for (i = 0; i < punch.count_isotopes; i++)
for (size_t i = 0; i < current_selected_output->Get_isotopes().size(); i++)
{
iso = MISSING;
if (state == INITIAL_SOLUTION)
{
isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name);
isotope_ratio_ptr = isotope_ratio_search(current_selected_output->Get_isotopes()[i].first.c_str());
if (isotope_ratio_ptr != NULL)
{
master_isotope_ptr =
@ -838,20 +841,20 @@ punch_isotopes(void)
}
else
{
isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name);
isotope_ratio_ptr = isotope_ratio_search(current_selected_output->Get_isotopes()[i].first.c_str());
if (isotope_ratio_ptr != NULL)
{
iso = isotope_ratio_ptr->converted_ratio;
}
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("I_%s", punch.isotopes[i].name), "%12.4e\t",
fpunchf(sformatf("I_%s", current_selected_output->Get_isotopes()[i].first.c_str()), "%12.4e\t",
(double) iso);
}
else
{
fpunchf(sformatf("I_%s", punch.isotopes[i].name), "%20.12e\t",
fpunchf(sformatf("I_%s", current_selected_output->Get_isotopes()[i].first.c_str()), "%20.12e\t",
(double) iso);
}
@ -867,20 +870,23 @@ punch_calculate_values(void)
/*
* Punch calculate values
*/
int i;
//int i;
LDBLE result;
struct calculate_value *calculate_value_ptr;
char l_command[] = "run";
if (punch.in == FALSE || punch.calculate_values == FALSE)
return (OK);
if (punch.count_calculate_values == 0)
return (OK);
for (i = 0; i < punch.count_calculate_values; i++)
if (current_selected_output->Get_calculate_values().size() == 0)
return OK;
//if (punch.in == FALSE || punch.calculate_values == FALSE)
// return (OK);
//if (punch.count_calculate_values == 0)
// return (OK);
//for (i = 0; i < punch.count_calculate_values; i++)
for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++)
{
result = MISSING;
calculate_value_ptr =
calculate_value_search(punch.calculate_values[i].name);
calculate_value_search(current_selected_output->Get_calculate_values()[i].first.c_str());
if (calculate_value_ptr->calculated == FALSE)
{
rate_moles = NAN;
@ -922,14 +928,14 @@ punch_calculate_values(void)
{
result = calculate_value_ptr->value;
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("V_%s", punch.calculate_values[i].name),
fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first.c_str()),
"%12.4e\t", (double) result);
}
else
{
fpunchf(sformatf("V_%s", punch.calculate_values[i].name),
fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first.c_str()),
"%20.12e\t", (double) result);
}
}

View File

@ -96,6 +96,7 @@ initialize(void)
hcreate_multi((unsigned) max_elements, &elements_hash_table);
hcreate_multi((unsigned) max_s, &species_hash_table);
hcreate_multi((unsigned) max_phases, &phases_hash_table);
#ifdef SKIP_OLD_SELECTED_OUTPUT
/*
* Initialize punch
*/
@ -169,7 +170,7 @@ initialize(void)
(struct name_master *) PHRQ_malloc(sizeof(struct name_master));
if (punch.calculate_values == NULL)
malloc_error();
#endif
// one save_values
save_values =
(struct save_values *) PHRQ_malloc(sizeof(struct save_values));
@ -190,6 +191,7 @@ initialize(void)
user_print->varbase = NULL;
user_print->loopbase = NULL;
#ifdef SKIP
// user_punch
user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate));
if (user_punch == NULL)
@ -202,6 +204,7 @@ initialize(void)
if (user_punch_headings == NULL)
malloc_error();
user_punch_count_headings = 0;
#endif
#if defined PHREEQ98
/*
* user_graph

269
print.cpp
View File

@ -162,31 +162,50 @@ punch_all(void)
chart_handler.Punch_user_graph(this);
}
#endif
if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE))
//if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE))
if (pr.hdf == FALSE && (SelectedOutput_map.size() == 0 || pr.punch == FALSE))
return (OK);
punch_identifiers();
punch_totals();
punch_molalities();
punch_activities();
punch_pp_assemblage();
punch_saturation_indices();
punch_gas_phase();
punch_kinetics();
punch_ss_assemblage();
punch_isotopes();
punch_calculate_values();
punch_user_punch();
/*
* new line for punch_file
*/
punch_msg("\n");
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
current_selected_output = &(so_it->second);
if (pr.punch == FALSE ||
current_selected_output == NULL ||
!current_selected_output->Get_active() /* ||
current_selected_output->Get_punch_ostream() == NULL*/)
continue;
phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream());
/*
* signal end of row
*/
fpunchf_end_row("\n");
punch_flush();
// UserPunch
std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user());
current_user_punch = up_it == UserPunch_map.end() ? NULL : &(up_it->second);
punch_identifiers();
punch_totals();
punch_molalities();
punch_activities();
punch_pp_assemblage();
punch_saturation_indices();
punch_gas_phase();
punch_kinetics();
punch_ss_assemblage();
punch_isotopes();
punch_calculate_values();
punch_user_punch();
/*
* new line for punch_file
*/
punch_msg("\n");
/*
* signal end of row
*/
fpunchf_end_row("\n");
punch_flush();
}
current_selected_output = NULL;
current_user_punch = NULL;
phrq_io->Set_punch_ostream(NULL);
return (OK);
}
/* ---------------------------------------------------------------------- */
@ -2391,12 +2410,13 @@ punch_gas_phase(void)
/*
* Prints selected gas phase data
*/
int i;
//int i;
LDBLE p, total_moles, volume;
LDBLE moles;
bool PR = false;
if (punch.count_gases <= 0)
//if (punch.count_gases <= 0)
if (current_selected_output->Get_gases().size() == 0)
return (OK);
p = 0.0;
total_moles = 0.0;
@ -2435,7 +2455,7 @@ punch_gas_phase(void)
volume = gas_phase_ptr->Get_volume();
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("pressure", "%12.4e\t", (double) p);
fpunchf("total mol", "%12.4e\t", (double) total_moles);
@ -2447,17 +2467,17 @@ punch_gas_phase(void)
fpunchf("total mol", "%20.12e\t", (double) total_moles);
fpunchf("volume", "%20.12e\t", (double) volume);
}
for (i = 0; i < punch.count_gases; i++)
for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++)
{
moles = 0.0;
if (gas_phase_ptr != NULL && punch.gases[i].phase != NULL)
if (gas_phase_ptr != NULL && current_selected_output->Get_gases()[i].second != NULL)
{
for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++)
{
cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[j]);
int k;
struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE);
if (phase_ptr != punch.gases[i].phase)
if (phase_ptr != current_selected_output->Get_gases()[i].second)
continue;
moles = phase_ptr->moles_x;
if (moles <= MIN_TOTAL)
@ -2465,13 +2485,13 @@ punch_gas_phase(void)
break;
}
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("g_%s", punch.gases[i].name), "%12.4e\t", (double) moles);
fpunchf(sformatf("g_%s", current_selected_output->Get_gases()[i].first.c_str()), "%12.4e\t", (double) moles);
}
else
{
fpunchf(sformatf("g_%s", punch.gases[i].name), "%20.12e\t",
fpunchf(sformatf("g_%s", current_selected_output->Get_gases()[i].first.c_str()), "%20.12e\t",
(double) moles);
}
}
@ -2485,27 +2505,27 @@ punch_ss_assemblage(void)
/*
* Prints solid solution composition if present
*/
int j, k;
//int j, k;
int found;
LDBLE moles;
/*
* Print solid solutions
*/
for (k = 0; k < punch.count_s_s; k++)
for (size_t k = 0; k < current_selected_output->Get_s_s().size(); k++)
{
found = FALSE;
if (use.Get_ss_assemblage_ptr() != NULL)
{
std::vector<cxxSS *> ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize();
for (j = 0; j < (int) ss_ptrs.size(); j++)
for (int j = 0; j < (int) ss_ptrs.size(); j++)
{
cxxSS * ss_ptr = ss_ptrs[j];
for (int i = 0; i < (int) ss_ptr->Get_ss_comps().size(); i++)
{
cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]);
if (strcmp_nocase(punch.s_s[k].name, comp_ptr->Get_name().c_str()) == 0)
if (strcmp_nocase(current_selected_output->Get_s_s()[k].first.c_str(), comp_ptr->Get_name().c_str()) == 0)
{
if (ss_ptr->Get_ss_in())
{
@ -2515,14 +2535,14 @@ punch_ss_assemblage(void)
{
moles = 0;
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("s_%s", punch.s_s[k].name),
fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()),
"%12.4e\t", (double) moles);
}
else
{
fpunchf(sformatf("s_%s", punch.s_s[k].name),
fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()),
"%20.12e\t", (double) moles);
}
found = TRUE;
@ -2535,13 +2555,13 @@ punch_ss_assemblage(void)
}
if (found == FALSE)
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("s_%s", punch.s_s[k].name), "%12.4e\t", (double) 0.0);
fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()), "%12.4e\t", (double) 0.0);
}
else
{
fpunchf(sformatf("s_%s", punch.s_s[k].name), "%20.12e\t",
fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()), "%20.12e\t",
(double) 0.0);
}
}
@ -2557,37 +2577,37 @@ punch_totals(void)
/*
* Print total concentrations of elements, molality and moles.
*/
int j;
//int j;
LDBLE molality;
for (j = 0; j < punch.count_totals; j++)
for (size_t j = 0; j < current_selected_output->Get_totals().size(); j++)
{
if (punch.totals[j].master == NULL)
if (current_selected_output->Get_totals()[j].second == NULL)
{
molality = 0.0;
}
else if (punch.totals[j].master->primary == TRUE)
else if (((struct master *) current_selected_output->Get_totals()[j].second)->primary == TRUE)
{
if (strncmp(punch.totals[j].name, "Alkalinity", 20) == 0)
if (strncmp(current_selected_output->Get_totals()[j].first.c_str(), "Alkalinity", 20) == 0)
{
molality = total_alkalinity / mass_water_aq_x;
} else
{
molality = punch.totals[j].master->total_primary / mass_water_aq_x;
molality = ((struct master *) current_selected_output->Get_totals()[j].second)->total_primary / mass_water_aq_x;
}
}
else
{
molality = punch.totals[j].master->total / mass_water_aq_x;
molality = ((struct master *) current_selected_output->Get_totals()[j].second)->total / mass_water_aq_x;
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name),
fpunchf(sformatf("%s(mol/kgw)", current_selected_output->Get_totals()[j].first.c_str()),
"%12.4e\t", (double) molality);
}
else
{
fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name),
fpunchf(sformatf("%s(mol/kgw)", current_selected_output->Get_totals()[j].first.c_str()),
"%20.12e\t", (double) molality);
}
}
@ -2602,25 +2622,25 @@ punch_molalities(void)
/*
* Print concentrations of species (aq, ex, surf)
*/
int j;
//int j;
LDBLE molality;
for (j = 0; j < punch.count_molalities; j++)
for (size_t j = 0; j < current_selected_output->Get_molalities().size(); j++)
{
molality = 0.0;
if (punch.molalities[j].s != NULL
&& punch.molalities[j].s->in == TRUE)
if (current_selected_output->Get_molalities()[j].second != NULL
&& ((struct species *) current_selected_output->Get_molalities()[j].second)->in == TRUE)
{
molality = punch.molalities[j].s->moles / mass_water_aq_x;
molality = ((struct species *) current_selected_output->Get_molalities()[j].second)->moles / mass_water_aq_x;
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name),
fpunchf(sformatf("m_%s(mol/kgw)", current_selected_output->Get_molalities()[j].first.c_str()),
"%12.4e\t", (double) molality);
}
else
{
fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name),
fpunchf(sformatf("m_%s(mol/kgw)", current_selected_output->Get_molalities()[j].first.c_str()),
"%20.12e\t", (double) molality);
}
}
@ -2635,26 +2655,26 @@ punch_activities(void)
/*
* Print concentrations of species (aq, ex, surf)
*/
int j;
//int j;
LDBLE la;
for (j = 0; j < punch.count_activities; j++)
for (size_t j = 0; j < current_selected_output->Get_activities().size(); j++)
{
la = -999.999;
if (punch.activities[j].s != NULL
&& punch.activities[j].s->in == TRUE)
if (current_selected_output->Get_activities()[j].second != NULL
&& ((struct species *) current_selected_output->Get_activities()[j].second)->in == TRUE)
{
/*la = punch.activities[j].s->lm + punch.activities[j].s->lg; */
la = log_activity(punch.activities[j].s->name);
la = log_activity(current_selected_output->Get_activities()[j].first.c_str());
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("la_%s", punch.activities[j].name), "%12.4e\t",
fpunchf(sformatf("la_%s", current_selected_output->Get_activities()[j].first.c_str()), "%12.4e\t",
(double) la);
}
else
{
fpunchf(sformatf("la_%s", punch.activities[j].name),
fpunchf(sformatf("la_%s", current_selected_output->Get_activities()[j].first.c_str()),
"%20.12e\t", (double) la);
}
}
@ -2669,15 +2689,15 @@ punch_pp_assemblage(void)
/*
* Prints masses of selected pure_phases in pp_assemblage
*/
int i, j;
//int i, j;
LDBLE moles, delta_moles;
for (i = 0; i < punch.count_pure_phases; i++)
for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++)
{
delta_moles = 0;
moles = 0.0;
if (punch.pure_phases[i].phase != NULL)
if (current_selected_output->Get_pure_phases()[i].second != NULL)
{
for (j = 0; j < count_unknowns; j++)
for (int j = 0; j < count_unknowns; j++)
{
if (x == NULL || x[j]->type != PP)
continue;
@ -2686,7 +2706,7 @@ punch_pp_assemblage(void)
/*
* Print pure phase assemblage data
*/
if (punch.pure_phases[i].phase != x[j]->phase)
if (current_selected_output->Get_pure_phases()[i].second != x[j]->phase)
continue;
if (state != TRANSPORT && state != PHAST)
{
@ -2704,16 +2724,16 @@ punch_pp_assemblage(void)
break;
}
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(punch.pure_phases[i].name, "%12.4e\t", (double) moles);
fpunchf(sformatf("d_%s", punch.pure_phases[i].name), "%12.4e\t",
fpunchf(current_selected_output->Get_pure_phases()[i].first.c_str(), "%12.4e\t", (double) moles);
fpunchf(sformatf("d_%s", current_selected_output->Get_pure_phases()[i].first.c_str()), "%12.4e\t",
(double) delta_moles);
}
else
{
fpunchf(punch.pure_phases[i].name, "%20.12e\t", (double) moles);
fpunchf(sformatf("d_%s", punch.pure_phases[i].name),
fpunchf(current_selected_output->Get_pure_phases()[i].first.c_str(), "%20.12e\t", (double) moles);
fpunchf(sformatf("d_%s", current_selected_output->Get_pure_phases()[i].first.c_str()),
"%20.12e\t", (double) delta_moles);
}
}
@ -2738,9 +2758,9 @@ punch_identifiers(void)
int i, l;
char token[MAX_LENGTH];
if (punch.in == FALSE)
return (OK);
if (punch.high_precision == FALSE)
//if (punch.in == FALSE)
// return (OK);
if (!current_selected_output->Get_high_precision())
{
l = 12;
sformat = "%12s\t";
@ -2759,7 +2779,7 @@ punch_identifiers(void)
* simulation or simul_tr
*/
if (punch.sim == TRUE)
if (current_selected_output->Get_sim())
{
if (state != TRANSPORT && state != PHAST)
{
@ -2770,7 +2790,7 @@ punch_identifiers(void)
fpunchf(PHAST_NULL("sim"), dformat, simul_tr);
}
}
if (punch.state == TRUE)
if (current_selected_output->Get_state())
{
switch (state)
{
@ -2808,7 +2828,7 @@ punch_identifiers(void)
/*
* solution number or cell number and time
*/
if (punch.soln == TRUE)
if (current_selected_output->Get_soln())
{
if (state == TRANSPORT || state == PHAST)
{
@ -2842,7 +2862,7 @@ punch_identifiers(void)
}
}
}
if (punch.dist == TRUE)
if (current_selected_output->Get_dist())
{
if (state == ADVECTION)
{
@ -2858,7 +2878,7 @@ punch_identifiers(void)
fpunchf(PHAST_NULL("dist_x"), dformat, -99);
}
}
if (punch.time == TRUE)
if (current_selected_output->Get_time())
{
LDBLE reaction_time = kin_time_x;
if (state == REACTION && incremental_reactions == TRUE
@ -2924,7 +2944,7 @@ punch_identifiers(void)
/*
* reaction or transport step
*/
if (punch.step == TRUE)
if (current_selected_output->Get_step())
{
if (state == REACTION)
{
@ -2943,9 +2963,9 @@ punch_identifiers(void)
fpunchf(PHAST_NULL("step"), dformat, -99);
}
}
if (punch.ph == TRUE)
if (current_selected_output->Get_ph())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("pH", "%12g\t", (double) (-s_hplus->la));
}
@ -2954,9 +2974,9 @@ punch_identifiers(void)
fpunchf("pH", "%20.12e\t", (double) (-s_hplus->la));
}
}
if (punch.pe == TRUE)
if (current_selected_output->Get_pe())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("pe", "%12g\t", (double) (-s_eminus->la));
}
@ -2965,11 +2985,11 @@ punch_identifiers(void)
fpunchf("pe", "%20.12e\t", (double) (-s_eminus->la));
}
}
if (punch.rxn == TRUE)
if (current_selected_output->Get_rxn())
{
if (state >= REACTION && use.Get_reaction_in() == TRUE)
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("reaction", "%12.4e\t", (double) step_x);
}
@ -2980,7 +3000,7 @@ punch_identifiers(void)
}
else
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("reaction", "%12d\t", -99);
}
@ -2990,9 +3010,9 @@ punch_identifiers(void)
}
}
}
if (punch.temp == TRUE)
if (current_selected_output->Get_temp())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("temp(C)", "%12.3f\t", (double) tc_x);
}
@ -3001,9 +3021,9 @@ punch_identifiers(void)
fpunchf("temp(C)", "%20.12e\t", (double) tc_x);
}
}
if (punch.alk == TRUE)
if (current_selected_output->Get_alk())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("Alk(eq/kgw)", "%12g\t",
(double) (total_alkalinity / mass_water_aq_x));
@ -3014,9 +3034,9 @@ punch_identifiers(void)
(double) (total_alkalinity / mass_water_aq_x));
}
}
if (punch.mu == TRUE)
if (current_selected_output->Get_mu())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("mu", "%12g\t", (double) mu_x);
}
@ -3025,9 +3045,9 @@ punch_identifiers(void)
fpunchf("mu", "%20.12e\t", (double) mu_x);
}
}
if (punch.water == TRUE)
if (current_selected_output->Get_water())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("mass_H2O", "%12g\t", (double) mass_water_aq_x);
}
@ -3036,9 +3056,9 @@ punch_identifiers(void)
fpunchf("mass_H2O", "%20.12e\t", (double) mass_water_aq_x);
}
}
if (punch.charge_balance == TRUE)
if (current_selected_output->Get_charge_balance())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("charge(eq)", "%12g\t", (double) cb_x);
}
@ -3047,9 +3067,9 @@ punch_identifiers(void)
fpunchf("charge(eq)", "%20.12e\t", (double) cb_x);
}
}
if (punch.percent_error == TRUE)
if (current_selected_output->Get_percent_error())
{
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf("pct_err", "%12g\t",
(double) (100 * cb_x / total_ions_x));
@ -3073,13 +3093,13 @@ punch_saturation_indices(void)
/*
* Prints saturation indices of selected phases
*/
int i;
//int i;
LDBLE si, iap;
struct rxn_token *rxn_ptr;
for (i = 0; i < punch.count_si; i++)
for (size_t i = 0; i < current_selected_output->Get_si().size(); i++)
{
if (punch.si[i].phase == NULL || punch.si[i].phase->in == FALSE)
if (current_selected_output->Get_si()[i].second == NULL || ((struct phase *) current_selected_output->Get_si()[i].second)->in == FALSE)
{
si = -999.999;
}
@ -3089,20 +3109,20 @@ punch_saturation_indices(void)
* Print saturation index
*/
iap = 0.0;
for (rxn_ptr = punch.si[i].phase->rxn_x->token + 1;
for (rxn_ptr = ((struct phase *) current_selected_output->Get_si()[i].second)->rxn_x->token + 1;
rxn_ptr->s != NULL; rxn_ptr++)
{
iap += rxn_ptr->s->la * rxn_ptr->coef;
}
si = -punch.si[i].phase->lk + iap;
si = -((struct phase *) current_selected_output->Get_si()[i].second)->lk + iap;
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("si_%s", punch.si[i].name), "%12.4f\t", (double) si);
fpunchf(sformatf("si_%s", current_selected_output->Get_si()[i].first.c_str()), "%12.4f\t", (double) si);
}
else
{
fpunchf(sformatf("si_%s", punch.si[i].name), "%20.12e\t", (double) si);
fpunchf(sformatf("si_%s", current_selected_output->Get_si()[i].first.c_str()), "%20.12e\t", (double) si);
}
}
return (OK);
@ -3131,7 +3151,7 @@ punch_kinetics(void)
kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2);
}
}
for (int i = 0; i < punch.count_kinetics; i++)
for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++)
{
moles = 0.0;
delta_moles = 0.0;
@ -3141,7 +3161,7 @@ punch_kinetics(void)
{
cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]);
if (strcmp_nocase
(punch.kinetics[i].name,
(current_selected_output->Get_kinetics()[i].first.c_str(),
kinetics_comp_ptr->Get_rate_name().c_str()) == 0)
{
if (state != TRANSPORT && state != PHAST)
@ -3160,18 +3180,18 @@ punch_kinetics(void)
}
}
}
if (punch.high_precision == FALSE)
if (!current_selected_output->Get_high_precision())
{
fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%12.4e\t",
fpunchf(sformatf("k_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%12.4e\t",
(double) moles);
fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%12.4e\t",
fpunchf(sformatf("dk_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%12.4e\t",
(double) delta_moles);
}
else
{
fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%20.12e\t",
fpunchf(sformatf("k_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%20.12e\t",
(double) moles);
fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%20.12e\t",
fpunchf(sformatf("dk_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%20.12e\t",
(double) delta_moles);
}
}
@ -3188,8 +3208,13 @@ punch_user_punch(void)
char l_command[] = "run";
n_user_punch_index = 0;
if (punch.user_punch == FALSE)
return (OK);
//if (punch.user_punch == FALSE)
// return (OK);
if (current_user_punch == NULL || !current_selected_output->Get_user_punch())
return OK;
struct rate * user_punch = current_user_punch->Get_rate();
if (user_punch->commands == NULL)
return (OK);
if (user_punch->new_def == TRUE)

632
read.cpp
View File

@ -16,6 +16,8 @@
#include "SSassemblage.h"
#include "cxxKinetics.h"
#include "Solution.h"
#include "SelectedOutput.h"
#include "UserPunch.h"
/* ---------------------------------------------------------------------- */
int Phreeqc::
@ -4588,7 +4590,486 @@ read_save(void)
/* empty, eof, keyword, print */
return (OK);
}
/* ---------------------------------------------------------------------- */
int Phreeqc::
read_selected_output(void)
/* ---------------------------------------------------------------------- */
{
/*
* Read data for to output to flat file
*/
int value;
int return_value, opt, opt_save;
char *next_char;
const char *opt_list[] = {
"file", /* 0 */
"totals", /* 1 */
"molalities", /* 2 */
"activities", /* 3 */
"pure_phases", /* 4 */
"si", /* 5 */
"saturation_indices", /* 6 */
"gases", /* 7 */
"equilibrium_phases", /* 8 */
"equilibria", /* 9 */
"equilibrium", /* 10 */
"pure", /* 11 */
"inverse", /* 12 */
"kinetic_reactants", /* 13 */
"kinetics", /* 14 */
"solid_solutions", /* 15 */
"inverse_modeling", /* 16 */
"reset", /* 17 */
"simulation", /* 18 */
"sim", /* 19 */
"state", /* 20 */
"solution", /* 21 */
"soln", /* 22 */
"distance", /* 23 */
"dist", /* 24 */
"time", /* 25 */
"step", /* 26 */
"reaction", /* 27 */
"rxn", /* 28 */
"temperature", /* 29 */
"temp", /* 30 */
"ph", /* 31 */
"pe", /* 32 */
"alkalinity", /* 33 */
"alk", /* 34 */
"ionic_strength", /* 35 */
"mu", /* 36 */
"water", /* 37 */
"high_precision", /* 38 */
"user_punch", /* 39 */
"mol", /* 40 */
"kin", /* 41 */
"charge_balance", /* 42 */
"percent_error", /* 43 */
"selected_out", /* 44 */
"selected_output", /* 45 */
"isotopes", /* 46 */
"calculate_values", /* 47 */
"equilibrium_phase", /* 48 */
"active" /* 49 */
};
int count_opt_list = 50;
int i, l;
char file_name[MAX_LENGTH], token[MAX_LENGTH];
char *ptr;
ptr = line;
int n_user, n_user_end;
char *description;
read_number_description(ptr, &n_user, &n_user_end, &description);
SelectedOutput temp_selected_output;
temp_selected_output.Set_new_def(false);
temp_selected_output.Set_file_name(n_user);
temp_selected_output.Set_n_user(n_user);
temp_selected_output.Set_n_user_end(n_user_end);
temp_selected_output.Set_description(description);
free_check_null(description);
// find if it exists
std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user);
if (n_user == 1 && so != SelectedOutput_map.end())
{
// n_user = 1, old definition, keep old definition
SelectedOutput & so_ref = so->second;
temp_selected_output.Set_active ( so_ref.Get_active() );
temp_selected_output.Set_inverse ( so_ref.Get_inverse() );
temp_selected_output.Set_sim ( so_ref.Get_sim() );
temp_selected_output.Set_state ( so_ref.Get_state() );
temp_selected_output.Set_soln ( so_ref.Get_soln() );
temp_selected_output.Set_dist ( so_ref.Get_dist() );
temp_selected_output.Set_time ( so_ref.Get_time() );
temp_selected_output.Set_step ( so_ref.Get_step() );
temp_selected_output.Set_rxn ( so_ref.Get_rxn() );
temp_selected_output.Set_temp ( so_ref.Get_temp() );
temp_selected_output.Set_ph ( so_ref.Get_ph() );
temp_selected_output.Set_pe ( so_ref.Get_pe() );
temp_selected_output.Set_alk ( so_ref.Get_alk() );
temp_selected_output.Set_mu ( so_ref.Get_mu() );
temp_selected_output.Set_water ( so_ref.Get_water() );
temp_selected_output.Set_high_precision ( so_ref.Get_high_precision() );
temp_selected_output.Set_user_punch ( so_ref.Get_user_punch() );
temp_selected_output.Set_charge_balance ( so_ref.Get_charge_balance() );
temp_selected_output.Set_percent_error ( so_ref.Get_percent_error() );
temp_selected_output.Set_have_punch_name ( so_ref.Get_have_punch_name() );
temp_selected_output.Set_file_name ( so_ref.Get_file_name() );
}
else if (n_user == 1 && so == SelectedOutput_map.end())
{
// n_user = 1, new definition, do nothing use; constructor default
}
else
{
// n_user != 1 then reset false
temp_selected_output.Reset(false);
}
CParser parser(this->phrq_io);
/*
* Read eqn from file and call parser
*/
opt_save = OPTION_ERROR;
return_value = UNKNOWN;
for (;;)
{
opt = get_option(opt_list, count_opt_list, &next_char);
if (opt == OPTION_DEFAULT)
{
opt = opt_save;
}
opt_save = opt;
switch (opt)
{
case OPTION_EOF: /* end of file */
return_value = EOF;
break;
case OPTION_KEYWORD: /* keyword */
return_value = KEYWORD;
break;
case OPTION_DEFAULT:
case OPTION_ERROR:
input_error++;
error_msg("Unknown input in SELECTED_OUTPUT keyword.", CONTINUE);
error_msg(line_save, CONTINUE);
break;
case 0: /* file name */
temp_selected_output.Set_new_def(true);
if (string_trim(next_char) != EMPTY)
{
strcpy(file_name, next_char);
temp_selected_output.Set_file_name(file_name);
temp_selected_output.Set_have_punch_name(true);
}
opt_save = OPTION_ERROR;
break;
case 1: /* totals */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
if (i != UPPER && token[0] != '[')
{
error_string = sformatf( "Expected element name to"
" begin with upper case letter.");
warning_msg(error_string);
}
else
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_totals().push_back(t_pair);
}
}
break;
case 2: /* molalities */
case 40: /* mol */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
if (i != UPPER && token[0] != '(' && (token[0] != '['))
{
error_string = sformatf( "Expected species name to"
" begin with upper case letter.");
warning_msg(error_string);
}
else
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_molalities().push_back(t_pair);
}
}
break;
case 3: /* activities */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
if (i != UPPER && token[0] != '(' && (token[0] != '['))
{
error_string = sformatf( "Expected species name to"
" begin with upper case letter.");
warning_msg(error_string);
}
else
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_activities().push_back(t_pair);
}
}
break;
case 4: /* pure_phases */
case 8: /* equilibrium_phases */
case 9: /* equilibria */
case 10: /* equilibrium */
case 11: /* pure */
case 48: /* equilibrium_phase */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_pure_phases().push_back(t_pair);
}
break;
case 5: /* si */
case 6: /* saturation_index */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_si().push_back(t_pair);
}
break;
case 7: /* gases */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_gases().push_back(t_pair);
}
break;
case 12: /* inverse */
case 16: /* inverse_modeling */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_inverse(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 13: /* kinetic_reactants */
case 14: /* kinetics */
case 41: /* kin */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_kinetics().push_back(t_pair);
}
break;
case 15: /* solid_solutions */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_s_s().push_back(t_pair);
}
break;
case 46: /* isotopes */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
if (i != UPPER && token[0] != '[')
{
error_string = sformatf( "Expected element name to"
" begin with upper case letter.");
warning_msg(error_string);
}
else
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_isotopes().push_back(t_pair);
}
}
break;
case 47: /* calculate_values */
temp_selected_output.Set_new_def(true);
while ((i = copy_token(token, &next_char, &l)) != EMPTY)
{
std::pair< std::string, void *> t_pair(token, NULL);
temp_selected_output.Get_calculate_values().push_back(t_pair);
}
break;
case 17: /* reset */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
/* matches print order */
temp_selected_output.Reset(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 18: /* simulation */
case 19: /* sim */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_sim(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 20: /* state */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_state(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 21: /* solution */
case 22: /* soln */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_soln(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 23: /* distance */
case 24: /* dist */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_dist(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 25: /* time */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_time(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 26: /* step */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_step(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 27: /* reaction */
case 28: /* rxn */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_rxn(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 29: /* temperature */
case 30: /* temp */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_temp(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 31: /* ph */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_ph(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 32: /* pe */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_pe(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 33: /* alkalinity */
case 34: /* alk */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_alk(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 35: /* ionic strength */
case 36: /* mu */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_mu(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 37: /* water */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_water(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 38: /* high_precision */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_high_precision(value!=FALSE);
if (n_user == 1)
{
high_precision = (value != FALSE);
}
if (value == TRUE)
{
convergence_tolerance = 1e-12;
}
opt_save = OPTION_ERROR;
break;
case 39: /* user_punch */
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_user_punch(value!=FALSE);
if (so != SelectedOutput_map.end())
{
so->second.Set_user_punch(value!=FALSE);
} opt_save = OPTION_ERROR;
break;
case 42: /* charge_balance */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_charge_balance(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 43: /* percent_error */
temp_selected_output.Set_new_def(true);
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_percent_error(value!=FALSE);
opt_save = OPTION_ERROR;
break;
case 44: /* selected_out */
case 45: /* selected_output */
//warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output");
//value = get_true_false(next_char, TRUE);
//temp_selected_output.Set_active(value!=FALSE);
//opt_save = OPTION_ERROR;
//break;
case 49: /* active */
value = get_true_false(next_char, TRUE);
temp_selected_output.Set_active(value!=FALSE);
if (so != SelectedOutput_map.end())
{
so->second.Set_active(value!=FALSE);
}
opt_save = OPTION_ERROR;
break;
}
if (return_value == EOF || return_value == KEYWORD)
break;
}
if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end())
{
// delete if exists
if (so != SelectedOutput_map.end())
{
SelectedOutput_map.erase(so);
}
// store new selected output
SelectedOutput_map[n_user] = temp_selected_output;
if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user))
{
if (phrq_io)
{
SelectedOutput_map[n_user].Set_punch_ostream(phrq_io->Get_punch_ostream());
phrq_io->Set_punch_ostream(NULL);
}
}
else
{
error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str());
input_error++;
error_msg(error_string, CONTINUE);
}
}
//if (!have_punch_name)
//{
// punch_close();
// if (!punch_open("selected.out"))
// {
// error_string = sformatf( "Can`t open file, %s.", "selected.out");
// input_error++;
// error_msg(error_string, CONTINUE);
// }
//}
return (return_value);
}
#ifdef SKIP
/* ---------------------------------------------------------------------- */
int Phreeqc::
read_selected_output(void)
@ -5046,6 +5527,7 @@ read_selected_output(void)
return (return_value);
}
#endif
/* ---------------------------------------------------------------------- */
int Phreeqc::
read_solution(void)
@ -8772,7 +9254,155 @@ read_user_print(void)
/* output_msg(sformatf( "%s", rates[0].commands));
*/ return (return_value);
}
/* ---------------------------------------------------------------------- */
int Phreeqc::
read_user_punch(void)
/* ---------------------------------------------------------------------- */
{
/*
* Reads basic code with which to calculate rates
*
* Arguments:
* none
*
* Returns:
* KEYWORD if keyword encountered, input_error may be incremented if
* a keyword is encountered in an unexpected position
* EOF if eof encountered while reading mass balance concentrations
* ERROR if error occurred reading data
*
*/
int length, line_length;
int return_value, opt, opt_save;
std::string stdtoken;
char *next_char;
const char *opt_list[] = {
"start", /* 0 */
"end", /* 1 */
"heading", /* 2 */
"headings" /* 3 */
};
int count_opt_list = 4;
opt_save = OPTION_DEFAULT;
/*
* Read lines
*/
int n_user, n_user_end;
char *description;
char *ptr;
ptr = line;
read_number_description(ptr, &n_user, &n_user_end, &description);
UserPunch temp_user_punch;
temp_user_punch.Set_PhreeqcPtr(this);
temp_user_punch.Set_n_user(n_user);
temp_user_punch.Set_n_user_end(n_user_end);
temp_user_punch.Set_description(description);
free_check_null(description);
//std::map < int, UserPunch >::iterator up = UserPunch_map.find(n_user);
//if (up != UserPunch_map.end())
//{
// UserPunch_map.erase(up);
//}
// Malloc rate structure
struct rate *r = (struct rate *) PHRQ_malloc(sizeof(struct rate));
if (r == NULL) malloc_error();
r->new_def = TRUE;
r->linebase = NULL;
r->varbase = NULL;
r->loopbase = NULL;
r->name = string_hsave("user defined Basic punch routine");
return_value = UNKNOWN;
for (;;)
{
opt = get_option(opt_list, count_opt_list, &next_char);
if (opt == OPTION_DEFAULT)
{
opt = opt_save;
}
opt_save = OPTION_DEFAULT;
switch (opt)
{
case OPTION_EOF: /* end of file */
return_value = EOF;
break;
case OPTION_KEYWORD: /* keyword */
return_value = KEYWORD;
break;
case OPTION_ERROR:
input_error++;
error_msg("Unknown input in USER_PUNCH keyword.", CONTINUE);
error_msg(line_save, CONTINUE);
break;
case 0: /* start */
opt_save = OPTION_DEFAULT;
break;
case 1: /* end */
opt_save = OPTION_DEFAULT;
break;
case 2: /* headings */
case 3: /* heading */
while (copy_token(stdtoken, &next_char) != EMPTY)
{
temp_user_punch.Get_headings().push_back(stdtoken);
}
break;
case OPTION_DEFAULT: /* read first command */
{
r->commands = (char *) PHRQ_malloc(sizeof(char));
if (r->commands == NULL) malloc_error();
r->commands[0] = '\0';
}
//rate_free(user_punch);
//user_punch->new_def = TRUE;
//user_punch->commands = (char *) PHRQ_malloc(sizeof(char));
//if (user_punch->commands == NULL)
// malloc_error();
//user_punch->commands[0] = '\0';
//user_punch->linebase = NULL;
//user_punch->varbase = NULL;
//user_punch->loopbase = NULL;
//user_punch->name =
// string_hsave("user defined Basic punch routine");
case OPT_1: /* read command */
length = (int) strlen(r->commands);
line_length = (int) strlen(line);
r->commands = (char *) PHRQ_realloc(r->commands,
(size_t) (length + line_length + 2) * sizeof(char));
if (r->commands == NULL) malloc_error();
r->commands[length] = ';';
r->commands[length + 1] = '\0';
strcat((r->commands), line);
//length = (int) strlen(user_punch->commands);
//line_length = (int) strlen(line);
//user_punch->commands =
// (char *) PHRQ_realloc(user_punch->commands,
// (size_t) (length + line_length +
// 2) * sizeof(char));
//if (user_punch->commands == NULL)
// malloc_error();
//user_punch->commands[length] = ';';
//user_punch->commands[length + 1] = '\0';
//strcat((user_punch->commands), line);
opt_save = OPT_1;
break;
}
if (return_value == EOF || return_value == KEYWORD)
break;
}
UserPunch_map[n_user] = temp_user_punch;
UserPunch_map[n_user].Set_rate(r);
return (return_value);
}
#ifdef SKIP
/* ---------------------------------------------------------------------- */
int Phreeqc::
read_user_punch(void)
@ -8884,7 +9514,7 @@ read_user_punch(void)
}
return (return_value);
}
#endif
#if defined PHREEQ98
/* ---------------------------------------------------------------------- */
int Phreeqc::

View File

@ -960,7 +960,7 @@ dump_cpp(void)
* dumps solution compositions to file
*/
int i, j, l;
int j, l;
if (dump_in == FALSE || pr.dump == FALSE)
return (OK);
@ -1004,106 +1004,113 @@ dump_cpp(void)
sprintf(token, "false\n");
fs << token;
}
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
current_selected_output = &(so_it->second);
sprintf(token, "SELECTED_OUTPUT\n");
fs << token;
sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn");
fs << token;
if (punch.count_totals != 0)
{
sprintf(token, "\t-tot ");
fs << token;
for (i = 0; i < punch.count_totals; i++)
sprintf(token, "SELECTED_OUTPUT %d\n", current_selected_output->Get_n_user());
fs << token ;
//sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn");
//fs << token;
fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n";
//if (punch.count_totals != 0)
if (current_selected_output->Get_totals().size() > 0)
{
sprintf(token, " %s", punch.totals[i].name);
sprintf(token, "\t-tot ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_totals()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
if (punch.count_molalities != 0)
{
sprintf(token, "\t-mol ");
fs << token;
for (i = 0; i < punch.count_molalities; i++)
if (current_selected_output->Get_molalities().size() > 0)
{
sprintf(token, " %s", punch.molalities[i].name);
sprintf(token, "\t-mol ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_molalities()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
if (punch.count_activities != 0)
{
sprintf(token, "\t-act ");
fs << token;
for (i = 0; i < punch.count_activities; i++)
if (current_selected_output->Get_activities().size() > 0)
{
sprintf(token, " %s", punch.activities[i].name);
sprintf(token, "\t-act ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_activities()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
if (punch.count_pure_phases != 0)
{
sprintf(token, "\t-equ ");
fs << token;
for (i = 0; i < punch.count_pure_phases; i++)
if (current_selected_output->Get_pure_phases().size() > 0)
{
sprintf(token, " %s", punch.pure_phases[i].name);
sprintf(token, "\t-equ ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_pure_phases()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
if (punch.count_si != 0)
{
sprintf(token, "\t-si ");
fs << token;
for (i = 0; i < punch.count_si; i++)
if (current_selected_output->Get_si().size() > 0)
{
sprintf(token, " %s", punch.si[i].name);
sprintf(token, "\t-si ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_si().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_si()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
if (punch.count_gases != 0)
{
sprintf(token, "\t-gas ");
fs << token;
for (i = 0; i < punch.count_gases; i++)
if (current_selected_output->Get_gases().size() > 0)
{
sprintf(token, " %s", punch.gases[i].name);
sprintf(token, "\t-gas ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_gases()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
if (punch.count_s_s != 0)
{
sprintf(token, "\t-solid_solutions ");
fs << token;
for (i = 0; i < punch.count_s_s; i++)
if (current_selected_output->Get_s_s().size() > 0)
{
sprintf(token, " %s", punch.s_s[i].name);
sprintf(token, "\t-solid_solutions ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_s_s().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_s_s()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
if (punch.count_kinetics != 0)
{
sprintf(token, "\t-kin ");
fs << token;
for (i = 0; i < punch.count_kinetics; i++)
if (current_selected_output->Get_kinetics().size() > 0)
{
sprintf(token, " %s", punch.kinetics[i].name);
sprintf(token, "\t-kin ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_kinetics()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "\n");
fs << token;
}
sprintf(token, "TRANSPORT\n");
fs << token;
@ -1120,7 +1127,7 @@ dump_cpp(void)
fs << token;
sprintf(token, "\t-timest %13.5e\n", (double) timest);
fs << token;
if (punch.high_precision == FALSE)
if (!high_precision)
{
sprintf(token, "\t-diffc %13.5e\n", (double) diffc);
fs << token;
@ -1144,7 +1151,7 @@ dump_cpp(void)
}
sprintf(token, "\t-length\n");
fs << token;
for (i = 0; i < count_cells; i++)
for (int i = 0; i < count_cells; i++)
{
sprintf(token, "%12.3e", (double) cell_data[i].length);
fs << token;
@ -1158,9 +1165,9 @@ dump_cpp(void)
fs << token;
sprintf(token, "\t-disp\n");
fs << token;
for (i = 0; i < count_cells; i++)
for (int i = 0; i < count_cells; i++)
{
if (punch.high_precision == FALSE)
if (!high_precision)
{
sprintf(token, "%12.3e", (double) cell_data[i].disp);
fs << token;
@ -1185,7 +1192,7 @@ dump_cpp(void)
else
j = count_cells;
l = 0;
for (i = 0; i < j; i++)
for (int i = 0; i < j; i++)
{
if (cell_data[i].punch != TRUE)
continue;
@ -1207,7 +1214,7 @@ dump_cpp(void)
else
j = count_cells;
l = 0;
for (i = 0; i < j; i++)
for (int i = 0; i < j; i++)
{
if (cell_data[i].print != TRUE)
continue;

View File

@ -185,7 +185,7 @@ clean_up(void)
cell_data = (struct cell_data *) free_check_null(cell_data);
/* punch */
#ifdef SKIP
punch.totals = (struct name_master *) free_check_null(punch.totals);
punch.molalities =
(struct name_species *) free_check_null(punch.molalities);
@ -197,19 +197,26 @@ clean_up(void)
punch.gases = (struct name_phase *) free_check_null(punch.gases);
punch.s_s = (struct name_phase *) free_check_null(punch.s_s);
punch.kinetics = (struct name_phase *) free_check_null(punch.kinetics);
#endif
advection_punch = (int *) free_check_null(advection_punch);
advection_print = (int *) free_check_null(advection_print);
#ifdef SKIP
punch.isotopes = (struct name_master *) free_check_null(punch.isotopes);
punch.calculate_values =
(struct name_master *) free_check_null(punch.calculate_values);
#endif
SelectedOutput_map.clear();
UserPunch_map.clear();
/* user_print and user_punch */
rate_free(user_print);
#ifdef SKIP
rate_free(user_punch);
user_print = (struct rate *) free_check_null(user_print);
user_punch = (struct rate *) free_check_null(user_punch);
user_punch_headings = (const char **) free_check_null(user_punch_headings);
#endif
/*
Free llnl aqueous model parameters
@ -344,8 +351,8 @@ clean_up(void)
/* free user database name if defined */
user_database = (char *) free_check_null(user_database);
selected_output_file_name =
(char *) free_check_null(selected_output_file_name);
//selected_output_file_name =
// (char *) free_check_null(selected_output_file_name);
dump_file_name = (char *) free_check_null(dump_file_name);
#ifdef PHREEQCI_GUI
free_spread();

455
tidy.cpp
View File

@ -1929,6 +1929,459 @@ tidy_ss_assemblage(void)
int Phreeqc::
tidy_punch(void)
/* ---------------------------------------------------------------------- */
{
//int i, j, l;
int punch_save;
//char token[MAX_LENGTH];
/*
* tidy punch information
*/
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
current_selected_output = &(so_it->second);
if (current_selected_output == NULL)
continue;
/* totals */
for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++)
{
std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_totals()[i];
pair_ptr.second = master_bsearch(pair_ptr.first.c_str());
}
/* molalities */
for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++)
{
std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_molalities()[i];
pair_ptr.second = s_search(pair_ptr.first.c_str());
}
/* log activities */
//for (i = 0; i < punch.count_activities; i++)
for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++)
{
std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_activities()[i];
pair_ptr.second = s_search(pair_ptr.first.c_str());
}
/* equilibrium phases */
//for (i = 0; i < punch.count_pure_phases; i++)
for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++)
{
int j;
std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_pure_phases()[i];
pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE);
}
/* saturation indices */
//for (i = 0; i < punch.count_si; i++)
for (size_t i = 0; i < current_selected_output->Get_si().size(); i++)
{
int j;
std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_si()[i];
pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE);
}
/* gases */
//for (i = 0; i < punch.count_gases; i++)
for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++)
{
int j;
std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_gases()[i];
pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE);
}
}
/*
* Always write new headings when SELECTED_OUTPUT is read
*/
so_it = SelectedOutput_map.begin();
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
current_selected_output = &(so_it->second);
if (current_selected_output == NULL ||
!current_selected_output->Get_new_def())
continue;
phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream());
int l;
if (current_selected_output->Get_high_precision() == false)
{
l = 12;
}
else
{
l = 20;
}
// UserPunch
std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user());
current_user_punch = up_it == UserPunch_map.end() ? NULL : &(up_it->second);
punch_save = pr.punch;
pr.punch = TRUE;
phrq_io->Set_punch_on(true);
/* constant stuff, sim, pH, etc. */
if (current_selected_output->Get_sim() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "sim"));
}
if (current_selected_output->Get_state() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "state"));
}
if (current_selected_output->Get_soln() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "soln"));
}
if (current_selected_output->Get_dist() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "dist_x"));
}
if (current_selected_output->Get_time() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "time"));
}
if (current_selected_output->Get_step() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "step"));
}
if (current_selected_output->Get_ph() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "pH"));
}
if (current_selected_output->Get_pe() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "pe"));
}
if (current_selected_output->Get_rxn() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "reaction"));
}
if (current_selected_output->Get_temp() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "temp"));
}
if (current_selected_output->Get_alk() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "Alk"));
}
if (current_selected_output->Get_mu() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "mu"));
}
if (current_selected_output->Get_water() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "mass_H2O"));
}
if (current_selected_output->Get_charge_balance() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "charge"));
}
if (current_selected_output->Get_percent_error() == TRUE)
{
fpunchf_heading(sformatf("%*s\t", l, "pct_err"));
}
/* totals */
//for (i = 0; i < punch.count_totals; i++)
for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_totals()[i];
fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str()));
if (pair_ref.second == NULL)
{
error_string = sformatf( "Did not find master species,"
" %s.", pair_ref.first.c_str());
warning_msg(error_string);
}
//fpunchf_heading(sformatf("%*s\t", l, punch.totals[i].name));
//if (punch.totals[i].master == NULL)
//{
// error_string = sformatf( "Did not find master species,"
// " %s.", punch.totals[i].name);
// warning_msg(error_string);
//}
}
/* molalities */
//for (i = 0; i < punch.count_molalities; i++)
for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_molalities()[i];
std::string name = "m_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
if (pair_ref.second == NULL)
{
error_string = sformatf( "Did not find species,"
" %s.", pair_ref.first.c_str());
warning_msg(error_string);
}
//strcpy(token, "m_");
//strcat(token, punch.molalities[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
//if (punch.molalities[i].s == NULL)
//{
// error_string = sformatf( "Did not find species,"
// " %s.", punch.molalities[i].name);
// warning_msg(error_string);
//}
}
/* log activities */
//for (i = 0; i < punch.count_activities; i++)
for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_activities()[i];
std::string name = "la_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
if (pair_ref.second == NULL)
{
error_string = sformatf( "Did not find species,"
" %s.", pair_ref.first.c_str());
warning_msg(error_string);
}
//strcpy(token, "la_");
//strcat(token, punch.activities[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
//if (punch.activities[i].s == NULL)
//{
// error_string = sformatf( "Did not find species, "
// "%s.", punch.activities[i].name);
// warning_msg(error_string);
//}
}
/* equilibrium phases */
//for (i = 0; i < punch.count_pure_phases; i++)
for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_pure_phases()[i];
fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str()));
std::string name = "d_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
if (pair_ref.second == NULL)
{
error_string = sformatf( "Did not find phase,"
" %s.", pair_ref.first.c_str());
warning_msg(error_string);
}
//strcpy(token, "d_");
//strcat(token, punch.pure_phases[i].name);
//fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name));
//fpunchf_heading(sformatf("%*s\t", l, token));
//if (punch.pure_phases[i].phase == NULL)
//{
// error_string = sformatf( "Did not find phase, "
// "%s.", punch.pure_phases[i].name);
// warning_msg(error_string);
//}
}
/* saturation indices */
//for (i = 0; i < punch.count_si; i++)
for (size_t i = 0; i < current_selected_output->Get_si().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_si()[i];
std::string name = "si_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
if (pair_ref.second == NULL)
{
error_string = sformatf( "Did not find phase,"
" %s.", pair_ref.first.c_str());
warning_msg(error_string);
}
//strcpy(token, "si_");
//strcat(token, punch.si[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
//if (punch.si[i].phase == NULL)
//{
// error_string = sformatf( "Did not find phase, "
// "%s.", punch.si[i].name);
// warning_msg(error_string);
//}
}
/* gases */
//if (punch.count_gases > 0)
if (current_selected_output->Get_gases().size() > 0)
{
fpunchf_heading(sformatf("%*s\t", l, "pressure"));
fpunchf_heading(sformatf("%*s\t", l, "total mol"));
fpunchf_heading(sformatf("%*s\t", l, "volume"));
}
//for (i = 0; i < punch.count_gases; i++)
for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_gases()[i];
std::string name = "g_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
if (pair_ref.second == NULL)
{
error_string = sformatf( "Did not find phase,"
" %s.", pair_ref.first.c_str());
warning_msg(error_string);
}
//strcpy(token, "g_");
//strcat(token, punch.gases[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
//if (punch.gases[i].phase == NULL)
//{
// error_string = sformatf( "Did not find phase, "
// "%s.", punch.gases[i].name);
// warning_msg(error_string);
//}
}
/* kinetics */
//for (i = 0; i < punch.count_kinetics; i++)
for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_kinetics()[i];
std::string name = "k_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
name = "dk_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
//strcpy(token, "k_");
//strcat(token, punch.kinetics[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
//strcpy(token, "dk_");
//strcat(token, punch.kinetics[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
}
/* solid solutions */
//for (i = 0; i < punch.count_s_s; i++)
for (size_t i = 0; i < current_selected_output->Get_s_s().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_s_s()[i];
std::string name = "s_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
//strcpy(token, "s_");
//strcat(token, punch.s_s[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
}
/* isotopes */
//for (i = 0; i < punch.count_isotopes; i++)
for (size_t i = 0; i < current_selected_output->Get_isotopes().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_isotopes()[i];
if (isotope_ratio_search(pair_ref.first.c_str()) == NULL)
{
error_string = sformatf(
"Did not find isotope_ratio definition for "
"%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.",
pair_ref.first.c_str(), pair_ref.first.c_str());
warning_msg(error_string);
}
std::string name = "I_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
//if (isotope_ratio_search(punch.isotopes[i].name) == NULL)
//{
// error_string = sformatf(
// "Did not find isotope_ratio definition for "
// "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.",
// punch.isotopes[i].name, punch.isotopes[i].name);
// warning_msg(error_string);
//}
//strcpy(token, "I_");
//strcat(token, punch.isotopes[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
}
/* calculate_values */
//for (i = 0; i < punch.count_calculate_values; i++)
for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++)
{
std::pair< std::string, void *> &pair_ref = current_selected_output->Get_calculate_values()[i];
if (calculate_value_search(pair_ref.first.c_str()) == NULL)
{
error_string = sformatf(
"Did not find calculate_values definition for "
"%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.",
pair_ref.first.c_str(),
pair_ref.first.c_str());
warning_msg(error_string);
}
std::string name = "V_";
name.append(pair_ref.first);
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
//if (calculate_value_search(punch.calculate_values[i].name) == NULL)
//{
// error_string = sformatf(
// "Did not find calculate_values definition for "
// "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.",
// punch.calculate_values[i].name,
// punch.calculate_values[i].name);
// warning_msg(error_string);
//}
//strcpy(token, "V_");
//strcat(token, punch.calculate_values[i].name);
//fpunchf_heading(sformatf("%*s\t", l, token));
}
/* user_punch */
if (current_user_punch != NULL && current_selected_output->Get_user_punch())
{
for (size_t i = 0; i < current_user_punch->Get_headings().size(); i++)
{
fpunchf_heading(sformatf("%*s\t", l, current_user_punch->Get_headings()[i].c_str()));
}
}
fpunchf_heading("\n");
//if (punch.user_punch == TRUE)
//{
// for (i = 0; i < user_punch_count_headings; i++)
// {
// fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i]));
// }
//}
//fpunchf_heading("\n");
current_selected_output->Set_new_def(false);
pr.punch = punch_save;
phrq_io->Set_punch_on(pr.punch == TRUE);
punch_flush();
}
current_selected_output = NULL;
current_user_punch = NULL;
phrq_io->Set_punch_ostream(NULL);
return (OK);
}
#ifdef SKIP
/* ---------------------------------------------------------------------- */
int Phreeqc::
tidy_punch(void)
/* ---------------------------------------------------------------------- */
{
int i, j, l;
int punch_save;
@ -2229,7 +2682,7 @@ tidy_punch(void)
punch_flush();
return (OK);
}
#endif
/* ---------------------------------------------------------------------- */
int Phreeqc::
tidy_species(void)