diff --git a/src/converters/ck2ct.cpp b/src/converters/ck2ct.cpp index c858cee99..46bf6fd1a 100644 --- a/src/converters/ck2ct.cpp +++ b/src/converters/ck2ct.cpp @@ -236,22 +236,22 @@ static void addFalloff(FILE* f, string type, const vector_fp& params) { if (type == "Troe") { - fprintf(f, (",\n falloff = Troe(A = " - + fp2str(params[0]) + ", T3 = " - + fp2str(params[1]) + ", T1 = " - + fp2str(params[2])).c_str()); + fprintf(f, "%s", (",\n falloff = Troe(A = " + + fp2str(params[0]) + ", T3 = " + + fp2str(params[1]) + ", T1 = " + + fp2str(params[2])).c_str()); if (params.size() >= 4) { - fprintf(f, (", T2 = " + fp2str(params[3])).c_str()); + fprintf(f, "%s", (", T2 = " + fp2str(params[3])).c_str()); } fprintf(f, ")"); } else if (type == "SRI") { - fprintf(f, (",\n falloff = SRI(A = " - + fp2str(params[0]) + ", B = " - + fp2str(params[1]) + ", C = " - + fp2str(params[2])).c_str()); + fprintf(f, "%s", (",\n falloff = SRI(A = " + + fp2str(params[0]) + ", B = " + + fp2str(params[1]) + ", C = " + + fp2str(params[2])).c_str()); if (params.size() >= 5) { - fprintf(f, (", D = " + fp2str(params[3]) - + ", E = " + fp2str(params[4])).c_str()); + fprintf(f, "%s", (", D = " + fp2str(params[3]) + + ", E = " + fp2str(params[4])).c_str()); } fprintf(f, ")"); } @@ -341,7 +341,7 @@ static void addReaction(FILE* f, string idtag, int i, const ckr::ReactionUnits& runits, doublereal version) { - fprintf(f, ("\n# Reaction " + int2str(i+1) + "\n").c_str()); + fprintf(f, "%s", ("\n# Reaction " + int2str(i+1) + "\n").c_str()); int nc = static_cast(rxn.comment.size()); vector options; diff --git a/src/equil/vcs_VolPhase.cpp b/src/equil/vcs_VolPhase.cpp index db3af2bea..0a2316bd9 100644 --- a/src/equil/vcs_VolPhase.cpp +++ b/src/equil/vcs_VolPhase.cpp @@ -16,6 +16,7 @@ #include "cantera/thermo/mix_defs.h" #include +#include #include #include @@ -261,9 +262,9 @@ void vcs_VolPhase::resize(const size_t phaseNum, const size_t nspecies, } else { VP_ID_ = phaseNum; if (!phaseName) { - char itmp[40]; - sprintf(itmp, "Phase_%d", VP_ID_); - PhaseName = itmp; + std::stringstream sstmp; + sstmp << "Phase_" << VP_ID_; + PhaseName = sstmp.str(); } else { PhaseName = phaseName; } @@ -1634,9 +1635,9 @@ size_t vcs_VolPhase::transferElementsFM(const Cantera::ThermoPhase* const tPhase if (cne) { std::string pname = tPhase->id(); if (pname == "") { - char sss[50]; - sprintf(sss, "phase%d", VP_ID_); - pname = sss; + std::stringstream sss; + sss << "phase" << VP_ID_; + pname = sss.str(); } ename = "cn_" + pname; e = ChargeNeutralityElement; diff --git a/src/equil/vcs_solve_TP.cpp b/src/equil/vcs_solve_TP.cpp index aae85cf5e..13d929dbf 100644 --- a/src/equil/vcs_solve_TP.cpp +++ b/src/equil/vcs_solve_TP.cpp @@ -19,6 +19,7 @@ #include "vcs_species_thermo.h" #include "cantera/base/clockWC.h" +#include "cantera/base/stringUtils.h" using namespace std; @@ -4661,7 +4662,7 @@ void VCS_SOLVE::vcs_printSpeciesChemPot(const int stateCalc) const printf(" --- "); } printf("%-24.24s", m_speciesName[kspec].c_str()); - printf(" %-3d", iphase); + printf(" %-3s", Cantera::int2str(iphase).c_str()); printf(" % -12.4e", mfValue); printf(" % -12.4e", m_SSfeSpecies[kspec] * RT); printf(" % -12.4e", log(mfValue) * RT); @@ -5336,7 +5337,7 @@ void VCS_SOLVE::vcs_printDeltaG(const int stateCalc) feFull += log(actCoeff_ptr[kspec]) + log(mfValue); } printf("%-24.24s", m_speciesName[kspec].c_str()); - printf(" %-3d", iphase); + printf(" %-3s", Cantera::int2str(iphase).c_str()); printf(" % -12.4e", molNumSpecies[kspec]); printf(" % -12.4e", mfValue); printf(" % -12.4e", feSpecies[kspec] * RT); diff --git a/src/kinetics/solveSP.cpp b/src/kinetics/solveSP.cpp index 23475875f..d080ab552 100644 --- a/src/kinetics/solveSP.cpp +++ b/src/kinetics/solveSP.cpp @@ -425,7 +425,8 @@ int solveSP::solveSurfProb(int ifunc, doublereal time_scale, doublereal TKelvin, printf("solveSurfProb: init guess, current concentration," "and prod rate:\n"); for (size_t jcol = 0; jcol < m_neq; jcol++) { - printf("\t%d %g %g %g\n", jcol, m_CSolnSPInit[jcol], m_CSolnSP[jcol], + printf("\t%s %g %g %g\n", int2str(jcol).c_str(), + m_CSolnSPInit[jcol], m_CSolnSP[jcol], m_netProductionRatesSave[m_kinSpecIndex[jcol]]); } printf("-----\n"); @@ -1217,7 +1218,7 @@ void solveSP::printIteration(int ioflag, doublereal damp, int label_d, string nm; if (ioflag == 1) { - printf("\t%6d ", iter); + printf("\t%6s ", int2str(iter).c_str()); if (do_time) { printf("%9.4e %9.4e ", t_real, 1.0/inv_t); } else @@ -1314,7 +1315,7 @@ void solveSP::printFinal(int ioflag, doublereal damp, int label_d, int label_t, string nm; if (ioflag == 1) { - printf("\tFIN%3d ", iter); + printf("\tFIN%3s ", int2str(iter).c_str()); if (do_time) { printf("%9.4e %9.4e ", t_real, 1.0/inv_t); } else diff --git a/src/numerics/NonlinearSolver.cpp b/src/numerics/NonlinearSolver.cpp index 7dbcbd55e..331f6336c 100644 --- a/src/numerics/NonlinearSolver.cpp +++ b/src/numerics/NonlinearSolver.cpp @@ -26,6 +26,7 @@ #include "cantera/base/clockWC.h" #include "cantera/base/vec_functions.h" #include "cantera/base/mdp_allo.h" +#include "cantera/base/stringUtils.h" #include #include @@ -549,8 +550,9 @@ doublereal NonlinearSolver::solnErrorNorm(const doublereal* const delta_y, const if (i != npos) { error = delta_y[i] / m_ewt[i]; normContrib = sqrt(error * error); - printf("\t\t %4d %12.4e | %12.4e %12.4e %12.4e %12.4e\n", i, normContrib/sqrt((double)neq_), - delta_y[i], m_y_n_curr[i], m_y_n_curr[i] + dampFactor * delta_y[i], m_ewt[i]); + printf("\t\t %4s %12.4e | %12.4e %12.4e %12.4e %12.4e\n", + int2str(i).c_str(), normContrib/sqrt((double)neq_), delta_y[i], + m_y_n_curr[i], m_y_n_curr[i] + dampFactor * delta_y[i], m_ewt[i]); } } @@ -638,7 +640,8 @@ doublereal NonlinearSolver::residErrorNorm(const doublereal* const resid, const if (i != npos) { error = resid[i] / m_residWts[i]; normContrib = sqrt(error * error); - printf("\t\t %4d %12.4e %12.4e %12.4e | %12.4e\n", i, normContrib, resid[i], m_residWts[i], y[i]); + printf("\t\t %4s %12.4e %12.4e %12.4e | %12.4e\n", + int2str(i).c_str(), normContrib, resid[i], m_residWts[i], y[i]); } } @@ -1329,7 +1332,8 @@ int NonlinearSolver::doAffineNewtonSolve(const doublereal* const y_curr, const printf("\t\t --------------------------------------------------------\n"); for (size_t i =0; i < neq_; i++) { - printf("\t\t %3d %13.5E %13.5E\n", i, delta_y[i], delyNewton[i]); + printf("\t\t %3s %13.5E %13.5E\n", + int2str(i).c_str(), delta_y[i], delyNewton[i]); } printf("\t\t --------------------------------------------------------\n"); } else if (doDogLeg_ && m_print_flag >= 4) { @@ -2113,14 +2117,14 @@ NonlinearSolver::deltaBoundStep(const doublereal* const y_n_curr, const doublere if (m_print_flag >= 3) { if (f_delta_bounds < 1.0) { if (i_fbd) { - printf("\t\tdeltaBoundStep: Increase of Variable %d causing " + printf("\t\tdeltaBoundStep: Increase of Variable %s causing " "delta damping of %g: origVal = %10.3g, undampedNew = %10.3g, dampedNew = %10.3g\n", - i_fbounds, f_delta_bounds, y_n_curr[i_fbounds], y_n_curr[i_fbounds] + step_1[i_fbounds], + int2str(i_fbounds).c_str(), f_delta_bounds, y_n_curr[i_fbounds], y_n_curr[i_fbounds] + step_1[i_fbounds], y_n_curr[i_fbounds] + f_delta_bounds * step_1[i_fbounds]); } else { - printf("\t\tdeltaBoundStep: Decrease of variable %d causing" + printf("\t\tdeltaBoundStep: Decrease of variable %s causing" "delta damping of %g: origVal = %10.3g, undampedNew = %10.3g, dampedNew = %10.3g\n", - i_fbounds, f_delta_bounds, y_n_curr[i_fbounds], y_n_curr[i_fbounds] + step_1[i_fbounds], + int2str(i_fbounds).c_str(), f_delta_bounds, y_n_curr[i_fbounds], y_n_curr[i_fbounds] + step_1[i_fbounds], y_n_curr[i_fbounds] + f_delta_bounds * step_1[i_fbounds]); } } @@ -2410,7 +2414,8 @@ doublereal NonlinearSolver::boundStep(const doublereal* const y, const doublerea */ if (m_print_flag >= 3) { if (f_bounds != 1.0) { - printf("\t\tboundStep: Variable %d causing bounds damping of %g\n", i_lower, f_bounds); + printf("\t\tboundStep: Variable %s causing bounds damping of %g\n", + int2str(i_lower).c_str(), f_bounds); } } @@ -3634,8 +3639,8 @@ print_solnDelta_norm_contrib(const doublereal* const step_1, dmax0 = sqrt(error * error); error = step_2[i] / m_ewt[i]; dmax1 = sqrt(error * error); - printf("\t\t %4d %12.4e %12.4e %12.4e | %12.4e %12.4e %12.4e |%12.4e %12.4e %12.4e\n", - i, y_n_curr[i], step_1[i], y_n_curr[i] + step_1[i], y_n_1[i], + printf("\t\t %4s %12.4e %12.4e %12.4e | %12.4e %12.4e %12.4e |%12.4e %12.4e %12.4e\n", + int2str(i).c_str(), y_n_curr[i], step_1[i], y_n_curr[i] + step_1[i], y_n_1[i], step_2[i], y_n_1[i]+ step_2[i], m_ewt[i], dmax0, dmax1); } } @@ -3747,8 +3752,8 @@ int NonlinearSolver::beuler_jac(GeneralMatrix& J, doublereal* const f, if (neq_ < 20) { printf("\t\tUnk m_ewt y dyVector ResN\n"); for (size_t iii = 0; iii < neq_; iii++) { - printf("\t\t %4d %16.8e %16.8e %16.8e %16.8e \n", - iii, m_ewt[iii], y[iii], dyVector[iii], f[iii]); + printf("\t\t %4s %16.8e %16.8e %16.8e %16.8e \n", + int2str(iii).c_str(), m_ewt[iii], y[iii], dyVector[iii], f[iii]); } } } @@ -3839,8 +3844,8 @@ int NonlinearSolver::beuler_jac(GeneralMatrix& J, doublereal* const f, if (neq_ < 20) { printf("\t\tUnk m_ewt y dyVector ResN\n"); for (size_t iii = 0; iii < neq_; iii++) { - printf("\t\t %4d %16.8e %16.8e %16.8e %16.8e \n", - iii, m_ewt[iii], y[iii], dyVector[iii], f[iii]); + printf("\t\t %4s %16.8e %16.8e %16.8e %16.8e \n", + int2str(iii).c_str(), m_ewt[iii], y[iii], dyVector[iii], f[iii]); } } } @@ -3890,12 +3895,12 @@ int NonlinearSolver::beuler_jac(GeneralMatrix& J, doublereal* const f, double vSmall; size_t ismall = J.checkRows(vSmall); if (vSmall < 1.0E-100) { - printf("WE have a zero row, %d\n", ismall); + printf("WE have a zero row, %s\n", int2str(ismall).c_str()); exit(-1); } ismall = J.checkColumns(vSmall); if (vSmall < 1.0E-100) { - printf("WE have a zero column, %d\n", ismall); + printf("WE have a zero column, %s\n", int2str(ismall).c_str()); exit(-1); } @@ -3908,7 +3913,7 @@ int NonlinearSolver::beuler_jac(GeneralMatrix& J, doublereal* const f, printf("\t\tCurrent Matrix and Residual:\n"); printf("\t\t I,J | "); for (size_t j = 0; j < neq_; j++) { - printf(" %5d ", j); + printf(" %5s ", int2str(j).c_str()); } printf("| Residual \n"); printf("\t\t --"); @@ -3919,7 +3924,7 @@ int NonlinearSolver::beuler_jac(GeneralMatrix& J, doublereal* const f, for (size_t i = 0; i < neq_; i++) { - printf("\t\t %4d |", i); + printf("\t\t %4s |", int2str(i).c_str()); for (size_t j = 0; j < neq_; j++) { printf(" % 11.4E", J(i,j)); } diff --git a/src/numerics/solveProb.cpp b/src/numerics/solveProb.cpp index 8f1850ee3..340a9a327 100644 --- a/src/numerics/solveProb.cpp +++ b/src/numerics/solveProb.cpp @@ -14,6 +14,7 @@ #include "cantera/numerics/solveProb.h" #include "cantera/base/clockWC.h" #include "cantera/numerics/ctlapack.h" +#include "cantera/base/stringUtils.h" /* Standard include files */ @@ -833,7 +834,7 @@ void solveProb::printIteration(int ioflag, doublereal damp, size_t label_d, printf("%9.4e %9.4e", update_norm, resid_norm); if (do_time) { k = label_t; - printf(" %d", k); + printf(" %s", int2str(k).c_str()); } else { for (i = 0; i < 16; i++) { printf(" "); @@ -841,7 +842,7 @@ void solveProb::printIteration(int ioflag, doublereal damp, size_t label_d, } if (label_d >= 0) { k = label_d; - printf(" %d", k); + printf(" %s", int2str(k).c_str()); } printf("\n"); } @@ -923,7 +924,7 @@ void solveProb::printFinal(int ioflag, doublereal damp, size_t label_d, size_t l printf("%9.4e %9.4e", update_norm, resid_norm); if (do_time) { k = label_t; - printf(" %d", k); + printf(" %s", int2str(k).c_str()); } else { for (i = 0; i < 16; i++) { printf(" "); @@ -932,7 +933,7 @@ void solveProb::printFinal(int ioflag, doublereal damp, size_t label_d, size_t l if (label_d >= 0) { k = label_d; - printf(" %d", k); + printf(" %s", int2str(k).c_str()); } printf(" -- success\n"); } diff --git a/src/oneD/MultiNewton.cpp b/src/oneD/MultiNewton.cpp index f58ce5992..419a49970 100644 --- a/src/oneD/MultiNewton.cpp +++ b/src/oneD/MultiNewton.cpp @@ -255,8 +255,8 @@ int MultiNewton::dampStep(const doublereal* x0, const doublereal* step0, // write log information if (loglevel > 0) { doublereal ss = r.ssnorm(x1,step1); - sprintf(m_buf,"\n%d %9.5f %9.5f %9.5f %9.5f %9.5f %4d %d/%d", - m,damp,fbound,log10(ss+SmallNumber), + sprintf(m_buf,"\n%s %9.5f %9.5f %9.5f %9.5f %9.5f %4d %d/%d", + int2str(m).c_str(), damp, fbound, log10(ss+SmallNumber), log10(s0+SmallNumber), log10(s1+SmallNumber), jac.nEvals(), jac.age(), m_maxAge); diff --git a/src/oneD/OneDim.cpp b/src/oneD/OneDim.cpp index 72038c038..b318d3f1b 100644 --- a/src/oneD/OneDim.cpp +++ b/src/oneD/OneDim.cpp @@ -120,12 +120,12 @@ void OneDim::writeStats(int printTime) size_t n = m_gridpts.size(); for (size_t i = 0; i < n; i++) { if (printTime) { - sprintf(buf,"%5i %5i %9.4f %5i %9.4f \n", - m_gridpts[i], m_funcEvals[i], m_funcElapsed[i], + sprintf(buf,"%5s %5i %9.4f %5i %9.4f \n", + int2str(m_gridpts[i]).c_str(), m_funcEvals[i], m_funcElapsed[i], m_jacEvals[i], m_jacElapsed[i]); } else { - sprintf(buf,"%5i %5i NA %5i NA \n", - m_gridpts[i], m_funcEvals[i], m_jacEvals[i]); + sprintf(buf,"%5s %5i NA %5i NA \n", + int2str(m_gridpts[i]).c_str(), m_funcEvals[i], m_jacEvals[i]); } writelog(buf); } diff --git a/src/oneD/newton_utils.cpp b/src/oneD/newton_utils.cpp index 68662cbf4..e065aefb2 100644 --- a/src/oneD/newton_utils.cpp +++ b/src/oneD/newton_utils.cpp @@ -46,8 +46,10 @@ doublereal bound_step(const doublereal* x, const doublereal* step, val = x[index(m,j)]; if (loglevel > 0) { if (val > above + 1.0e-12 || val < below - 1.0e-12) { - sprintf(buf, "domain %d: %20s(%d) = %10.3e (%10.3e, %10.3e)\n", - r.domainIndex(), r.componentName(m).c_str(), j, val, below, above); + sprintf(buf, "domain %s: %20s(%s) = %10.3e (%10.3e, %10.3e)\n", + int2str(r.domainIndex()).c_str(), + r.componentName(m).c_str(), int2str(j).c_str(), + val, below, above); writelog(string("\nERROR: solution out of bounds.\n")+buf); } } @@ -69,9 +71,10 @@ doublereal bound_step(const doublereal* x, const doublereal* step, wroteTitle = true; writelog(buf); } - sprintf(buf, " %4i %12s %4i %10.3e %10.3e %10.3e %10.3e\n", - r.domainIndex(), r.componentName(m).c_str(), j, val, - step[index(m,j)], below, above); + sprintf(buf, " %4s %12s %4s %10.3e %10.3e %10.3e %10.3e\n", + int2str(r.domainIndex()).c_str(), + r.componentName(m).c_str(), int2str(j).c_str(), + val, step[index(m,j)], below, above); writelog(buf); } } diff --git a/src/thermo/HMWSoln.cpp b/src/thermo/HMWSoln.cpp index d5c2d81f6..5b11b86e4 100644 --- a/src/thermo/HMWSoln.cpp +++ b/src/thermo/HMWSoln.cpp @@ -6357,8 +6357,8 @@ void HMWSoln::printCoeffs() const printf("Index Name MoleF MolalityCropped Charge\n"); for (k = 0; k < m_kk; k++) { sni = speciesName(k); - printf("%2d %-16s %14.7le %14.7le %5.1f \n", - k, sni.c_str(), moleF[k], molality[k], charge[k]); + printf("%2s %-16s %14.7le %14.7le %5.1f \n", + int2str(k).c_str(), sni.c_str(), moleF[k], molality[k], charge[k]); } printf("\n Species Species beta0MX " diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index 4260b515f..6d02f58ad 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -68,10 +68,11 @@ void ReactorNet::initialize(doublereal t0) m_nreactors++; if (m_verbose) { - sprintf(buf,"Reactor %d: %d variables.\n",n,nv); + sprintf(buf,"Reactor %s: %s variables.\n", + int2str(n).c_str(), int2str(nv).c_str()); writelog(buf); - sprintf(buf," %d sensitivity params.\n", - r->nSensParams()); + sprintf(buf," %s sensitivity params.\n", + int2str(r->nSensParams()).c_str()); writelog(buf); } if (m_r[n]->type() == FlowReactorType && m_nr > 1) { @@ -124,7 +125,7 @@ void ReactorNet::initialize(doublereal t0) m_integ->setSensitivityTolerances(m_rtolsens, m_atolsens); m_integ->setMaxStepSize(m_maxstep); if (m_verbose) { - sprintf(buf, "Number of equations: %d\n", neq()); + sprintf(buf, "Number of equations: %s\n", int2str(neq()).c_str()); writelog(buf); sprintf(buf, "Maximum time step: %14.6g\n", m_maxstep); writelog(buf);