From b7f9f230a7a4c59770761bec910bdb82096995d6 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 6 Apr 2016 22:57:04 -0400 Subject: [PATCH] [Equil] Replace (vcs_)print_stringTrunc with usage of cppformat --- include/cantera/equil/vcs_internal.h | 15 ------- src/equil/BasisOptimize.cpp | 63 ++-------------------------- src/equil/vcs_solve_TP.cpp | 7 +--- src/equil/vcs_util.cpp | 31 -------------- 4 files changed, 5 insertions(+), 111 deletions(-) diff --git a/include/cantera/equil/vcs_internal.h b/include/cantera/equil/vcs_internal.h index c7d30be0a..88a42d836 100644 --- a/include/cantera/equil/vcs_internal.h +++ b/include/cantera/equil/vcs_internal.h @@ -123,21 +123,6 @@ size_t vcs_optMax(const double* x, const double* xSize, size_t j, size_t n); */ const char* vcs_speciesType_string(int speciesStatus, int length = 100); -//! Print a string within a given space limit -/*! - * This routine limits the amount of the string that will be printed to a - * maximum of "space" characters. Printing is done to to Cantera's writelog() - * function. - * - * @param str String, which must be null terminated. - * @param space space limit for the printing. - * @param alignment Alignment of string within the space: - * - 0 centered - * - 1 right aligned - * - 2 left aligned - */ -void vcs_print_stringTrunc(const char* str, size_t space, int alignment); - //! Simple routine to check whether two doubles are equal up to roundoff error /*! * Currently it's set to check for 10 digits of relative accuracy. diff --git a/src/equil/BasisOptimize.cpp b/src/equil/BasisOptimize.cpp index fc5286b8c..a91028926 100644 --- a/src/equil/BasisOptimize.cpp +++ b/src/equil/BasisOptimize.cpp @@ -12,18 +12,6 @@ namespace Cantera int BasisOptimize_print_lvl = 0; static const double USEDBEFORE = -1; -//! Print a string within a given space limit. -/*! - * This routine limits the amount of the string that will be printed to a - * maximum of "space" characters. - * @param str String -> must be null terminated. - * @param space space limit for the printing. - * @param alignment 0 centered - * 1 right aligned - * 2 left aligned - */ -static void print_stringTrunc(const char* str, int space, int alignment); - size_t BasisOptimize(int* usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase, std::vector& orderVectorSpecies, std::vector& orderVectorElements, @@ -60,18 +48,13 @@ size_t BasisOptimize(int* usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase, writelog(" --- Species | Order | "); for (size_t j = 0; j < ne; j++) { size_t jj = orderVectorElements[j]; - writelog(" "); - std::string ename = mphase->elementName(jj); - print_stringTrunc(ename.c_str(), 4, 1); - writelogf("(%1d)", j); + writelog(" {:>4.4s}({:1d})", mphase->elementName(jj), j); } writelog("\n"); for (size_t k = 0; k < nspecies; k++) { size_t kk = orderVectorSpecies[k]; - writelog(" --- "); - std::string sname = mphase->speciesName(kk); - print_stringTrunc(sname.c_str(), 11, 1); - writelogf(" | %4d |", k); + writelog(" --- {:>11.11s} | {:4d} |", + mphase->speciesName(kk), k); for (size_t j = 0; j < ne; j++) { size_t jj = orderVectorElements[j]; double num = mphase->nAtoms(kk,jj); @@ -307,46 +290,6 @@ size_t BasisOptimize(int* usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase, return nComponents; } // basopt() -/** - * Print a string within a given space limit. This routine limits the amount of - * the string that will be printed to a maximum of "space" characters. - * - * str = String -> must be null terminated. - * space = space limit for the printing. - * alignment = 0 centered - * 1 right aligned - * 2 left aligned - */ -static void print_stringTrunc(const char* str, int space, int alignment) -{ - int i, ls=0, rs=0; - int len = static_cast(strlen(str)); - if ((len) >= space) { - for (i = 0; i < space; i++) { - writelogf("%c", str[i]); - } - } else { - if (alignment == 1) { - ls = space - len; - } else if (alignment == 2) { - rs = space - len; - } else { - ls = (space - len) / 2; - rs = space - len - ls; - } - if (ls != 0) { - for (i = 0; i < ls; i++) { - writelog(" "); - } - } - writelogf("%s", str); - if (rs != 0) { - for (i = 0; i < rs; i++) { - writelog(" "); - } - } - } -} void ElemRearrange(size_t nComponents, const vector_fp& elementAbundances, MultiPhase* mphase, diff --git a/src/equil/vcs_solve_TP.cpp b/src/equil/vcs_solve_TP.cpp index 59f797d84..478c51658 100644 --- a/src/equil/vcs_solve_TP.cpp +++ b/src/equil/vcs_solve_TP.cpp @@ -2149,14 +2149,11 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[], plogf("\n"); plogf(" --- Species | "); for (size_t j = 0; j < m_numElemConstraints; j++) { - plogf(" "); - vcs_print_stringTrunc(m_elementName[j].c_str(), 8, 1); + writelog(" {:>8.8s}", m_elementName[j]); } plogf("\n"); for (k = 0; k < m_numSpeciesTot; k++) { - plogf(" --- "); - vcs_print_stringTrunc(m_speciesName[k].c_str(), 11, 1); - plogf(" | "); + writelog(" --- {:>11.11s} | ", m_speciesName[k]); for (size_t j = 0; j < m_numElemConstraints; j++) { plogf(" %8.2g", m_formulaMatrix(k,j)); } diff --git a/src/equil/vcs_util.cpp b/src/equil/vcs_util.cpp index 7b555bb6c..dec0db717 100644 --- a/src/equil/vcs_util.cpp +++ b/src/equil/vcs_util.cpp @@ -115,37 +115,6 @@ const char* vcs_speciesType_string(int speciesStatus, int length) } } -void vcs_print_stringTrunc(const char* str, size_t space, int alignment) -{ - size_t ls = 0, rs = 0; - size_t len = strlen(str); - if ((len) >= space) { - for (size_t i = 0; i < space; i++) { - plogf("%c", str[i]); - } - } else { - if (alignment == 1) { - ls = space - len; - } else if (alignment == 2) { - rs = space - len; - } else { - ls = (space - len) / 2; - rs = space - len - ls; - } - if (ls != 0) { - for (size_t i = 0; i < ls; i++) { - plogf(" "); - } - } - plogf("%s", str); - if (rs != 0) { - for (size_t i = 0; i < rs; i++) { - plogf(" "); - } - } - } -} - bool vcs_doubleEqual(double d1, double d2) { double denom = fabs(d1) + fabs(d2) + 1.0;