all tests passing for one selected_output file;

may still need additional tests for TestIPhreeqc case1 and case2

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7919 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2013-08-12 22:24:18 +00:00
parent 3682cff05b
commit 6eaca680af
10 changed files with 108 additions and 101 deletions

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

@ -985,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

@ -232,7 +232,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);

View File

@ -38,7 +38,7 @@ SelectedOutput::SelectedOutput(int n, PHRQ_io *io)
this->user_punch = true;
this->charge_balance = false;
this->percent_error = false;
this->have_punch_name = false;
}

View File

@ -11,65 +11,69 @@ public:
~SelectedOutput(void);
void Reset(bool tf);
std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;}
std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;}
std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;}
std::vector< std::pair< std::string, void * > > & Get_pure_phases(void) {return this->pure_phases;}
std::vector< std::pair< std::string, void * > > & Get_si(void) {return this->si;}
std::vector< std::pair< std::string, void * > > & Get_gases(void) {return this->gases;}
std::vector< std::pair< std::string, void * > > & Get_s_s(void) {return this->s_s;}
std::vector< std::pair< std::string, void * > > & Get_kinetics(void) {return this->kinetics;}
std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;}
std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;}
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;}
std::string & Get_file_name(void) {return this->file_name;}
bool Get_new_def(void) {return this->new_def;}
bool Get_sim(void) {return this->sim;}
bool Get_state(void) {return this->state;}
bool Get_soln(void) {return this->soln;}
bool Get_dist(void) {return this->dist;}
bool Get_time(void) {return this->time;}
bool Get_step(void) {return this->step;}
bool Get_rxn(void) {return this->rxn;}
bool Get_temp(void) {return this->temp;}
bool Get_ph(void) {return this->ph;}
bool Get_pe(void) {return this->pe;}
bool Get_alk(void) {return this->alk;}
bool Get_mu(void) {return this->mu;}
bool Get_water(void) {return this->water;}
bool Get_high_precision(void) {return this->high_precision;}
bool Get_user_punch(void) {return this->user_punch;}
bool Get_charge_balance(void) {return this->charge_balance;}
bool Get_percent_error(void) {return this->percent_error;}
bool Get_inverse(void) {return this->inverse;}
//bool Get_punch(void) {return this->punch;}
bool Get_active(void) {return this->active;}
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);
void Set_file_name(std::string s) {this->file_name = s;}
void Set_new_def(bool tf) {this->new_def = tf;}
void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;}
void Set_sim(bool tf) {this->sim = tf;}
void Set_state(bool tf) {this->state = tf;}
void Set_soln(bool tf) {this->soln = tf;}
void Set_dist(bool tf) {this->dist = tf;}
void Set_time(bool tf) {this->time = tf;}
void Set_step(bool tf) {this->step = tf;}
void Set_rxn(bool tf) {this->rxn = tf;}
void Set_temp(bool tf) {this->temp = tf;}
void Set_ph(bool tf) {this->ph = tf;}
void Set_pe(bool tf) {this->pe = tf;}
void Set_alk(bool tf) {this->alk = tf;}
void Set_mu(bool tf) {this->mu = tf;}
void Set_water(bool tf) {this->water = tf;}
void Set_high_precision(bool tf) {this->high_precision = tf;}
void Set_user_punch(bool tf) {this->user_punch = tf;}
void Set_charge_balance(bool tf) {this->charge_balance = tf;}
void Set_percent_error(bool tf) {this->percent_error = tf;}
void Set_inverse(bool tf) {this->inverse = tf;}
//void Set_punch(bool tf) {this->punch = tf;}
void Set_active(bool tf) {this->active = tf;}
inline 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;
@ -103,5 +107,6 @@ public:
bool charge_balance;
bool percent_error;
bool inverse;
bool have_punch_name;
};
#endif // !defined(SELECTEDOUTPUT_H_INCLUDED)

View File

@ -2089,11 +2089,11 @@ punch_model_heading(struct inverse *inv_ptr)
current_selected_output = &(so_it->second);
if (pr.punch == FALSE ||
current_selected_output == NULL ||
current_selected_output->punch_ostream == NULL ||
current_selected_output->Get_punch_ostream() == NULL ||
!current_selected_output->Get_inverse() ||
!current_selected_output->Get_active())
continue;
phrq_io->Set_punch_ostream(current_selected_output->punch_ostream);
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();
@ -2268,11 +2268,11 @@ punch_model(struct inverse *inv_ptr)
current_selected_output = &(so_it->second);
if (pr.punch == FALSE ||
current_selected_output == NULL ||
current_selected_output->punch_ostream == NULL ||
current_selected_output->Get_punch_ostream() == NULL ||
!current_selected_output->Get_inverse() ||
!current_selected_output->Get_active())
continue;
phrq_io->Set_punch_ostream(current_selected_output->punch_ostream);
phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream());
n_user_punch_index = 0;
/*

View File

@ -171,10 +171,10 @@ punch_all(void)
current_selected_output = &(so_it->second);
if (pr.punch == FALSE ||
current_selected_output == NULL ||
!current_selected_output->Get_active() ||
current_selected_output->punch_ostream == NULL)
!current_selected_output->Get_active() /* ||
current_selected_output->Get_punch_ostream() == NULL*/)
continue;
phrq_io->Set_punch_ostream(current_selected_output->punch_ostream);
phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream());
// UserPunch
std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user());

View File

@ -4674,30 +4674,32 @@ read_selected_output(void)
// find if it exists
std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user);
if (so != SelectedOutput_map.end() && n_user == 1)
if (so != SelectedOutput_map.end())
{
SelectedOutput & so_ref = so->second;
temp_selected_output.active = so_ref.active;
temp_selected_output.inverse = so_ref.inverse;
temp_selected_output.sim = so_ref.sim;
temp_selected_output.state = so_ref.state;
temp_selected_output.soln = so_ref.soln;
temp_selected_output.dist = so_ref.dist;
temp_selected_output.time = so_ref.time;
temp_selected_output.step = so_ref.step;
temp_selected_output.rxn = so_ref.rxn;
temp_selected_output.temp = so_ref.temp;
temp_selected_output.ph = so_ref.ph;
temp_selected_output.pe = so_ref.pe;
temp_selected_output.alk = so_ref.alk;
temp_selected_output.mu = so_ref.mu;
temp_selected_output.water = so_ref.water;
temp_selected_output.high_precision = so_ref.high_precision;
temp_selected_output.user_punch = so_ref.user_punch;
temp_selected_output.charge_balance = so_ref.charge_balance;
temp_selected_output.percent_error = so_ref.percent_error;
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
else if(n_user != 1)
{
temp_selected_output.Reset(false);
}
@ -4737,6 +4739,7 @@ read_selected_output(void)
{
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;
@ -5019,7 +5022,7 @@ read_selected_output(void)
break;
}
if (temp_selected_output.Get_new_def())
if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end())
{
// delete if exists
@ -5031,16 +5034,17 @@ read_selected_output(void)
// store new selected output
SelectedOutput_map[n_user] = temp_selected_output;
// open file
std::ofstream *ofs = new std::ofstream(temp_selected_output.Get_file_name().c_str(), std::ios_base::out );
if (ofs && ofs->is_open())
if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user))
{
SelectedOutput_map[n_user].Set_punch_ostream(ofs);
if (this->phrq_io)
{
SelectedOutput_map[n_user].Set_punch_ostream(this->phrq_io->Get_punch_ostream());
this->phrq_io->Set_punch_ostream(NULL);
}
}
else
{
error_string = sformatf( "Can`t open file, %s.", file_name);
error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str());
input_error++;
error_msg(error_string, CONTINUE);
}

View File

@ -1779,8 +1779,7 @@ tidy_punch(void)
for ( ; so_it != SelectedOutput_map.end(); so_it++)
{
current_selected_output = &(so_it->second);
if (current_selected_output == NULL ||
current_selected_output->punch_ostream == NULL)
if (current_selected_output == NULL)
continue;
@ -1846,10 +1845,9 @@ tidy_punch(void)
{
current_selected_output = &(so_it->second);
if (current_selected_output == NULL ||
current_selected_output->punch_ostream == NULL ||
!current_selected_output->Get_new_def())
continue;
phrq_io->Set_punch_ostream(current_selected_output->punch_ostream);
phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream());
int l;