diff --git a/src/phreeqcpp/PBasic.cpp b/src/phreeqcpp/PBasic.cpp index 7fff465d..9357be6e 100644 --- a/src/phreeqcpp/PBasic.cpp +++ b/src/phreeqcpp/PBasic.cpp @@ -2651,10 +2651,16 @@ factor(struct LOC_exec * LINK) case tokadd_heading: require(toklp, LINK); - name = stringfactor(STR1, LINK); + name = strexpr(LINK); require(tokrp, LINK); - PhreeqcPtr->current_user_punch->Get_headings().push_back(name); - n.UU.val = (parse_all) ? 1 : (double)PhreeqcPtr->current_user_punch->Get_headings().size(); + if (PhreeqcPtr->current_user_punch != NULL) + { + PhreeqcPtr->current_user_punch->Get_headings().push_back(name); + n.UU.val = (parse_all) ? 1 : (double)PhreeqcPtr->current_user_punch->Get_headings().size(); + } else { + n.UU.val = 0; + } + break; case toksys: @@ -4131,7 +4137,7 @@ factor(struct LOC_exec * LINK) case tokno_newline_: n.stringval = true; - PhreeqcPtr->current_selected_output->Set_punch_newline(false); + PhreeqcPtr->Set_output_newline(false); this->skip_punch = true; break; @@ -5035,17 +5041,21 @@ cmdprint(struct LOC_exec *LINK) n = expr(LINK); if (n.stringval) { -/* fputs(n.UU.sval, stdout); */ - output_msg(PhreeqcPtr->sformatf("%s ", n.UU.sval)); + if (!skip_punch) { + /* fputs(n.UU.sval, stdout); */ + output_msg(PhreeqcPtr->sformatf("%s ", n.UU.sval)); + } PhreeqcPtr->PHRQ_free(n.UU.sval); } else /* printf("%s ", numtostr(STR1, n.UU.val)); */ output_msg(PhreeqcPtr->sformatf("%s ", numtostr(STR1, n.UU.val))); } - if (!semiflag) + if (!semiflag && PhreeqcPtr->Get_output_newline()) /* putchar('\n');*/ output_msg("\n"); + PhreeqcPtr->Set_output_newline(true); + skip_punch = false; } void PBasic:: diff --git a/src/phreeqcpp/Phreeqc.cpp b/src/phreeqcpp/Phreeqc.cpp index 08c747ce..77a16e0b 100644 --- a/src/phreeqcpp/Phreeqc.cpp +++ b/src/phreeqcpp/Phreeqc.cpp @@ -997,6 +997,7 @@ void Phreeqc::init(void) numerical_deriv = FALSE; count_total_steps = 0; phast = FALSE; + output_newline = true; llnl_temp = 0; llnl_count_temp = 0; llnl_adh = 0; @@ -2304,6 +2305,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) numerical_deriv = pSrc->numerical_deriv; count_total_steps = 0; phast = FALSE; + output_newline = true; /* llnl_temp = 0; llnl_count_temp = 0; diff --git a/src/phreeqcpp/Phreeqc.h b/src/phreeqcpp/Phreeqc.h index b1089dfd..d64a2431 100644 --- a/src/phreeqcpp/Phreeqc.h +++ b/src/phreeqcpp/Phreeqc.h @@ -1697,6 +1697,9 @@ protected: int count_total_steps; int phast; + bool output_newline; + inline void Set_output_newline(bool tf) { this->output_newline = tf;} + inline bool Get_output_newline() { return this->output_newline;} LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs, a_llnl, b_llnl; int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, llnl_count_co2_coefs; diff --git a/src/phreeqcpp/SelectedOutput.cpp b/src/phreeqcpp/SelectedOutput.cpp index 492f4c82..b6941b5a 100644 --- a/src/phreeqcpp/SelectedOutput.cpp +++ b/src/phreeqcpp/SelectedOutput.cpp @@ -39,7 +39,6 @@ SelectedOutput::SelectedOutput(int n, PHRQ_io *io) this->charge_balance = false; this->percent_error = false; this->new_line = true; - this->punch_newline = true; // as-is set flags // diff --git a/src/phreeqcpp/SelectedOutput.h b/src/phreeqcpp/SelectedOutput.h index 1d73278e..bb2cea49 100644 --- a/src/phreeqcpp/SelectedOutput.h +++ b/src/phreeqcpp/SelectedOutput.h @@ -83,7 +83,6 @@ public: inline bool Get_charge_balance(void)const {return this->charge_balance;} inline bool Get_percent_error(void)const {return this->percent_error;} inline bool Get_new_line(void)const {return this->new_line; } - inline bool Get_punch_newline(void)const {return this->punch_newline; } // as-is setters inline void Set_user_punch(bool tf) {this->user_punch = tf; this->set_user_punch = true;} @@ -108,7 +107,6 @@ public: inline void Set_charge_balance(bool tf) {this->charge_balance = tf; this->set_charge_balance = true;} inline void Set_percent_error(bool tf) {this->percent_error = tf; this->set_percent_error = true;} inline void Set_new_line(bool tf) {this->new_line = tf; this->set_new_line = true;} - inline void Set_punch_newline(bool tf) {this->punch_newline = tf; this->set_new_line = true; } // set flag getters inline bool was_set_user_punch()const {return this->set_user_punch;} @@ -183,7 +181,7 @@ protected: bool charge_balance; bool percent_error; bool new_line; - bool punch_newline; + //bool punch_newline; // as-is set flags bool set_user_punch; diff --git a/src/phreeqcpp/print.cpp b/src/phreeqcpp/print.cpp index e47c17a9..ffdb8376 100644 --- a/src/phreeqcpp/print.cpp +++ b/src/phreeqcpp/print.cpp @@ -195,9 +195,9 @@ punch_all(void) /* * new line for punch_file */ - if (current_selected_output->Get_new_line() && current_selected_output->Get_punch_newline()) + if (current_selected_output->Get_new_line() && this->Get_output_newline()) punch_msg("\n"); - current_selected_output->Set_punch_newline(true); + this->Set_output_newline(true); /* * signal end of row @@ -2399,7 +2399,10 @@ print_user_print(void) { error_msg("Fatal Basic error in USER_PRINT.", STOP); } - output_msg(sformatf("\n")); + if (this->output_newline) { + output_msg(sformatf("\n")); + } + this->Set_output_newline(true); if (use.Get_kinetics_in() == TRUE) { use.Set_kinetics_ptr(kinetics_ptr);