diff --git a/include/cantera/thermo/FixedChemPotSSTP.h b/include/cantera/thermo/FixedChemPotSSTP.h index 45142e38e..d0eee8a94 100644 --- a/include/cantera/thermo/FixedChemPotSSTP.h +++ b/include/cantera/thermo/FixedChemPotSSTP.h @@ -77,8 +77,7 @@ namespace Cantera * sets the chemical potential to a specific value in J / kmol. * * @code - * sprintf(file_ID,"%s#Li(Fixed)", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", iFile + "#Li(Fixed)", 0); * FixedChemPotSSTP *LiFixed = new FixedChemPotSSTP(*xm); // Set the chemical potential to -2.3E7 J/kmol * LiFixed->setChemicalPotential(-2.3E7.) @@ -87,8 +86,7 @@ namespace Cantera * or by the following call to importPhase(): * * @code - * sprintf(file_ID,"%s#NaCl(S)", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0); * FixedChemPotSSTP solid; * importPhase(*xm, &solid); * @endcode diff --git a/include/cantera/thermo/MetalSHEelectrons.h b/include/cantera/thermo/MetalSHEelectrons.h index 9fe3df2fb..cbe496359 100644 --- a/include/cantera/thermo/MetalSHEelectrons.h +++ b/include/cantera/thermo/MetalSHEelectrons.h @@ -105,8 +105,7 @@ namespace Cantera * or by the following call to importPhase(): * * @code - * sprintf(file_ID,"%s#MetalSHEelectrons", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", iFile + "#MetalSHEelectrons", 0); * MetalSHEelectrons eMetal; * importPhase(*xm, &eMetal); * @endcode diff --git a/include/cantera/thermo/StoichSubstanceSSTP.h b/include/cantera/thermo/StoichSubstanceSSTP.h index a97b1308f..246d899d5 100644 --- a/include/cantera/thermo/StoichSubstanceSSTP.h +++ b/include/cantera/thermo/StoichSubstanceSSTP.h @@ -95,16 +95,14 @@ namespace Cantera * the following code snippets: * * @code - * sprintf(file_ID,"%s#NaCl(S)", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0); * StoichSubstanceSSTP *solid = new StoichSubstanceSSTP(*xm); * @endcode * * or by the following call to importPhase(): * * @code - * sprintf(file_ID,"%s#NaCl(S)", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0); * StoichSubstanceSSTP solid; * importPhase(*xm, &solid); * @endcode diff --git a/src/equil/ChemEquil.cpp b/src/equil/ChemEquil.cpp index 0919f52c8..7e4725791 100644 --- a/src/equil/ChemEquil.cpp +++ b/src/equil/ChemEquil.cpp @@ -553,7 +553,7 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr, bool haveEm = s.getElementPotentials(DATA_PTR(x)); if (haveEm) { if (s.temperature() < 100.) { - printf("we are here %g\n", s.temperature()); + writelog("we are here {:g}\n", s.temperature()); } for (m = 0; m < m_mm; m++) { x[m] *= 1.0 / s.RT(); @@ -696,24 +696,19 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr, for (m = 0; m <= m_mm; m++) { writelog(" [ "); for (size_t n = 0; n <= m_mm; n++) { - writelogf("%10.5g ", jac(m,n)); + writelog("{:10.5g} ", jac(m,n)); } writelog(" ]"); - char xName[32]; if (m < m_mm) { - string nnn = s.elementName(m); - sprintf(xName, "x_%-10s", nnn.c_str()); + writelog("x_{:10s}", s.elementName(m)); + } else if (m_eloc == m) { + writelog("x_ELOC"); + } else if (m == m_skip) { + writelog("x_YY"); } else { - sprintf(xName, "x_XX"); + writelog("x_XX"); } - if (m_eloc == m) { - sprintf(xName, "x_ELOC"); - } - if (m == m_skip) { - sprintf(xName, "x_YY"); - } - writelogf("%-12s", xName); - writelogf(" = - (%10.5g)\n", res_trial[m]); + writelog(" = - ({:10.5g})\n", res_trial[m]); } } diff --git a/src/numerics/RootFind.cpp b/src/numerics/RootFind.cpp index 5d5c7f0d1..33c305381 100644 --- a/src/numerics/RootFind.cpp +++ b/src/numerics/RootFind.cpp @@ -207,9 +207,7 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun callNum++; if (DEBUG_MODE_ENABLED && printLvl >= 3 && writeLogAllowed_) { - char fileName[80]; - sprintf(fileName, "RootFind_%d.log", callNum); - fp = fopen(fileName, "w"); + fp = fopen(fmt::format("RootFind_%d.log", callNum).c_str(), "w"); fprintf(fp, " Iter TP_its xval Func_val | Reasoning\n"); fprintf(fp, "-----------------------------------------------------" "-------------------------------\n"); @@ -382,7 +380,7 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun * a linear approximation from the last two points. */ if (DEBUG_MODE_ENABLED && fabs(x2 - x1) < 1.0E-14) { - printf(" RootFind: we are here x2 = %g x1 = %g\n", x2, x1); + writelogf(" RootFind: we are here x2 = %g x1 = %g\n", x2, x1); } doublereal delXtmp = deltaXControlled(x2, x1); slope = (f2 - f1) / delXtmp; diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index 52855552a..4ec88dff3 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -34,7 +34,6 @@ ReactorNet::~ReactorNet() void ReactorNet::initialize() { size_t n, nv; - char buf[100]; m_nv = 0; debuglog("Initializing reactor network.\n", m_verbose); if (m_reactors.empty()) { @@ -62,12 +61,8 @@ void ReactorNet::initialize() m_start.push_back(m_nv); if (m_verbose) { - sprintf(buf,"Reactor %s: %s variables.\n", - int2str(n).c_str(), int2str(nv).c_str()); - writelog(buf); - sprintf(buf," %s sensitivity params.\n", - int2str(r.nSensParams()).c_str()); - writelog(buf); + writelog("Reactor {:d}: {:d} variables.\n", n, nv); + writelog(" {:d} sensitivity params.\n", r.nSensParams()); } if (r.type() == FlowReactorType && m_reactors.size() > 1) { throw CanteraError("ReactorNet::initialize", @@ -83,10 +78,8 @@ void ReactorNet::initialize() m_integ->setMaxStepSize(m_maxstep); m_integ->setMaxErrTestFails(m_maxErrTestFails); if (m_verbose) { - 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); + writelog("Number of equations: {:d}\n", neq()); + writelog("Maximum time step: {:14.6g}\n", m_maxstep); } m_integ->initialize(m_time, *this); m_integrator_init = true; diff --git a/test_problems/cathermo/HMW_graph_GvI/HMW_graph_GvI.cpp b/test_problems/cathermo/HMW_graph_GvI/HMW_graph_GvI.cpp index cfc2d2020..a7cf23c0b 100644 --- a/test_problems/cathermo/HMW_graph_GvI/HMW_graph_GvI.cpp +++ b/test_problems/cathermo/HMW_graph_GvI/HMW_graph_GvI.cpp @@ -46,13 +46,10 @@ int main(int argc, char** argv) HMW->getMoleFractions(mf); string sName; FILE* ff; - char fname[64]; for (int jTemp = 0; jTemp < 7; jTemp++) { Temp = aTemp[jTemp]; - sprintf(fname, "T%3.0f.csv", Temp); - - ff = fopen(fname, "w"); + ff = fopen(fmt::format("T{:3.0f}.csv", Temp).c_str(), "w"); HMW->setState_TP(Temp, 1.01325E5); printf(" Temperature = %g K\n", Temp); size_t i1 = HMW->speciesIndex("Na+"); diff --git a/test_problems/surfSolverTest/surfaceSolver.cpp b/test_problems/surfSolverTest/surfaceSolver.cpp index 9a2fe09c1..d9a36cc6e 100644 --- a/test_problems/surfSolverTest/surfaceSolver.cpp +++ b/test_problems/surfSolverTest/surfaceSolver.cpp @@ -37,7 +37,6 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do { double x[MSSIZE]; double C[MSSIZE]; - char buf[256]; oooo.precision(3); string gasPhaseName = "gas"; gasTP->getMoleFractions(x); @@ -57,10 +56,8 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do size_t nspGas = gasTP->nSpecies(); for (size_t k = 0; k < nspGas; k++) { kstart = iKin_ptr->kineticsSpeciesIndex(k, 0); - sprintf(buf, "%4d %24s %14.3g %14.3g %14.3e\n", - (int) k, gasTP->speciesName(k).c_str(), - C[k], x[k], src[kstart]); - oooo << buf; + fmt::print(oooo, "{:4d} {:>24s} {:14.3g} {:14.3g} {:14.3e}\n", + k, gasTP->speciesName(k), C[k], x[k], src[kstart]); sum += x[k]; } oooo << "Sum of gas mole fractions= " << sum << endl; @@ -72,7 +69,6 @@ void printBulk(ostream& oooo, { double x[MSSIZE]; double C[MSSIZE]; - char buf[256]; oooo.precision(3); string bulkParticlePhaseName = bulkPhaseTP->id(); bulkPhaseTP->getMoleFractions(x); @@ -95,10 +91,8 @@ void printBulk(ostream& oooo, size_t nspBulk = bulkPhaseTP->nSpecies(); for (size_t k = 0; k < nspBulk; k++) { kstart = iKin_ptr->kineticsSpeciesIndex(k, 1); - sprintf(buf, "%4d %24s %14.3g %14.3g %14.3e\n", - (int) k, bulkPhaseTP->speciesName(k).c_str(), - C[k], x[k], src[kstart]); - oooo << buf; + fmt::print(oooo, "{:4d} {:>24s} {:14.3g} {:14.3g} {:14.3e}\n", + k, bulkPhaseTP->speciesName(k), C[k], x[k], src[kstart]); sum += x[k]; Wsum += src[kstart] * molecW[k]; } @@ -119,7 +113,6 @@ void printSurf(ostream& oooo, ThermoPhase* surfPhaseTP, InterfaceKinetics* iKin_ptr, double* src) { double x[MSSIZE]; - char buf[256]; string surfParticlePhaseName = surfPhaseTP->id(); surfPhaseTP->getMoleFractions(x); size_t kstart = iKin_ptr->kineticsSpeciesIndex(0, 2); @@ -139,10 +132,8 @@ void printSurf(ostream& oooo, if (fabs(srcK) < 1.0E-7) { srcK = 0.0; } - sprintf(buf, "%4d %24s %14.3g %14.3e\n", - (int) k, surfPhaseTP->speciesName(k).c_str(), - x[k], srcK); - oooo << buf; + fmt::print(oooo, "{:4d} {:>24s} {:14.3g} {:14.3e}\n", + k, surfPhaseTP->speciesName(k), x[k], srcK); sum += x[k]; } oooo << "Sum of coverages = " << sum << endl; diff --git a/test_problems/surfSolverTest/surfaceSolver2.cpp b/test_problems/surfSolverTest/surfaceSolver2.cpp index 99c9eab8e..5cce74a54 100644 --- a/test_problems/surfSolverTest/surfaceSolver2.cpp +++ b/test_problems/surfSolverTest/surfaceSolver2.cpp @@ -37,7 +37,6 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do { double x[MSSIZE]; double C[MSSIZE]; - char buf[256]; oooo.precision(3); string gasPhaseName = "gas"; gasTP->getMoleFractions(x); @@ -57,10 +56,8 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do size_t nspGas = gasTP->nSpecies(); for (size_t k = 0; k < nspGas; k++) { kstart = iKin_ptr->kineticsSpeciesIndex(k, 0); - sprintf(buf, "%4d %24s %14g %14g %14e\n", - (int) k, gasTP->speciesName(k).c_str(), - C[k], x[k], src[kstart]); - oooo << buf; + fmt::print(oooo, "{:4d} {:>24s} {:14g} {:14g} {:14e}\n", + k, gasTP->speciesName(k), C[k], x[k], src[kstart]); sum += x[k]; } oooo << "Sum of gas mole fractions= " << sum << endl; @@ -73,7 +70,6 @@ void printBulk(ostream& oooo,ThermoPhase* bulkPhaseTP, InterfaceKinetics* iKin_p { double x[MSSIZE]; double C[MSSIZE]; - char buf[256]; oooo.precision(3); string bulkParticlePhaseName = bulkPhaseTP->id(); bulkPhaseTP->getMoleFractions(x); @@ -96,10 +92,8 @@ void printBulk(ostream& oooo,ThermoPhase* bulkPhaseTP, InterfaceKinetics* iKin_p size_t nspBulk = bulkPhaseTP->nSpecies(); for (size_t k = 0; k < nspBulk; k++) { kstart = iKin_ptr->kineticsSpeciesIndex(k, 1); - sprintf(buf, "%4d %24s %14g %14g %14e\n", - (int) k, bulkPhaseTP->speciesName(k).c_str(), - C[k], x[k], src[kstart]); - oooo << buf; + fmt::print(oooo, "{:4d} {:>24s} {:14g} {:14g} {:14e}\n", + k, bulkPhaseTP->speciesName(k), C[k], x[k], src[kstart]); sum += x[k]; Wsum += src[kstart] * molecW[k]; } @@ -140,10 +134,8 @@ void printSurf(ostream& oooo, ThermoPhase* surfPhaseTP, if (fabs(srcK) < 1.0E-8) { srcK = 0.0; } - sprintf(buf, "%4d %24s %14g %14e\n", - (int) k, surfPhaseTP->speciesName(k).c_str(), - x[k], srcK); - oooo << buf; + fmt::print(oooo, "{:4d} {:>24s} {:14g} {:14e}\n", + k, surfPhaseTP->speciesName(k), x[k], srcK); sum += x[k]; } oooo << "Sum of coverages = " << sum << endl;