[Equil] Replace (vcs_)print_stringTrunc with usage of cppformat

This commit is contained in:
Ray Speth 2016-04-06 22:57:04 -04:00
parent ec38f58e73
commit b7f9f230a7
4 changed files with 5 additions and 111 deletions

View file

@ -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.

View file

@ -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<size_t>& orderVectorSpecies,
std::vector<size_t>& 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<int>(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,

View file

@ -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));
}

View file

@ -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;