From a549782c7ff6ef9fc410eb7efffd1ab887dfbf7d Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 17 Aug 2012 16:44:50 +0000 Subject: [PATCH] Eliminated some unnecessary usage of strcpy --- include/cantera/thermo/DebyeHuckel.h | 10 ++-------- include/cantera/thermo/HMWSoln.h | 10 ++-------- include/cantera/thermo/WaterSSTP.h | 10 ++-------- .../cathermo/DH_graph_1/DH_graph_1.cpp | 7 +------ .../cathermo/HMW_dupl_test/HMW_dupl_test.cpp | 7 +------ .../cathermo/HMW_graph_CpvT/HMW_graph_CpvT.cpp | 7 +------ .../cathermo/HMW_graph_GvI/HMW_graph_GvI.cpp | 7 +------ .../cathermo/HMW_graph_GvT/HMW_graph_GvT.cpp | 8 +------- .../cathermo/HMW_graph_HvT/HMW_graph_HvT.cpp | 7 +------ .../cathermo/HMW_graph_VvT/HMW_graph_VvT.cpp | 7 +------ .../cathermo/stoichSubSSTP/stoichSubSSTP.cpp | 10 ++-------- .../cathermo/testWaterTP/testWaterSSTP.cpp | 17 +---------------- 12 files changed, 16 insertions(+), 91 deletions(-) diff --git a/include/cantera/thermo/DebyeHuckel.h b/include/cantera/thermo/DebyeHuckel.h index 04a5c7965..ca747c182 100644 --- a/include/cantera/thermo/DebyeHuckel.h +++ b/include/cantera/thermo/DebyeHuckel.h @@ -533,20 +533,14 @@ class PDSS_Water; * or * * @code - * char iFile[80], file_ID[80]; - * strcpy(iFile, "DH_NaCl.xml"); - * sprintf(file_ID,"%s#NaCl_electrolyte", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", "DH_NaCl.xml#NaCl_electrolyte", 0); * DebyeHuckel *dh = new DebyeHuckel(*xm); * @endcode * * or by the following call to importPhase(): * * @code - * char iFile[80], file_ID[80]; - * strcpy(iFile, "DH_NaCl.xml"); - * sprintf(file_ID,"%s#NaCl_electrolyte", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", "DH_NaCl.xml#NaCl_electrolyte", 0); * DebyeHuckel dhphase; * importPhase(*xm, &dhphase); * @endcode diff --git a/include/cantera/thermo/HMWSoln.h b/include/cantera/thermo/HMWSoln.h index dc6187a79..24e1632a7 100644 --- a/include/cantera/thermo/HMWSoln.h +++ b/include/cantera/thermo/HMWSoln.h @@ -1119,20 +1119,14 @@ class PDSS_Water; * or * * @code - * char iFile[80], file_ID[80]; - * strcpy(iFile, "HMW_NaCl.xml"); - * sprintf(file_ID,"%s#NaCl_electrolyte", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", "HMW_NaCl.xml#NaCl_electrolyte", 0); * HMWSoln *dh = new HMWSoln(*xm); * @endcode * * or by the following call to importPhase(): * * @code - * char iFile[80], file_ID[80]; - * strcpy(iFile, "HMW_NaCl.xml"); - * sprintf(file_ID,"%s#NaCl_electrolyte", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", "HMW_NaCl.xml#NaCl_electrolyte", 0); * HMWSoln dhphase; * importPhase(*xm, &dhphase); * @endcode diff --git a/include/cantera/thermo/WaterSSTP.h b/include/cantera/thermo/WaterSSTP.h index c990d0ec3..13ccd7ab0 100644 --- a/include/cantera/thermo/WaterSSTP.h +++ b/include/cantera/thermo/WaterSSTP.h @@ -85,20 +85,14 @@ class WaterProps; * or * * @code - * char iFile[80], file_ID[80]; - * strcpy(iFile, "waterSSTPphase.xml"); - * sprintf(file_ID,"%s#water", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", "waterSSTPphase.xml#water", 0); * WaterSSTP *w = new WaterSSTP(*xm); * @endcode * * or by the following call to importPhase(): * * @code - * char iFile[80], file_ID[80]; - * strcpy(iFile, "waterSSTPphase.xml"); - * sprintf(file_ID,"%s#water", iFile); - * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); + * XML_Node *xm = get_XML_NameID("phase", "waterSSTPphase.xml#water", 0); * WaterSSTP water; * importPhase(*xm, &water); * @endcode diff --git a/test_problems/cathermo/DH_graph_1/DH_graph_1.cpp b/test_problems/cathermo/DH_graph_1/DH_graph_1.cpp index a6824a3b8..5fbab45ed 100644 --- a/test_problems/cathermo/DH_graph_1/DH_graph_1.cpp +++ b/test_problems/cathermo/DH_graph_1/DH_graph_1.cpp @@ -18,12 +18,7 @@ int main(int argc, char** argv) string fName = "DH_graph_1.log"; fileLog* fl = new fileLog(fName); try { - - char iFile[80]; - strcpy(iFile, "DH_NaCl.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } + std::string iFile = (argc > 1) ? argv[1] : "DH_NaCl.xml"; setLogger(fl); DebyeHuckel* DH = new DebyeHuckel(iFile, "NaCl_electrolyte"); diff --git a/test_problems/cathermo/HMW_dupl_test/HMW_dupl_test.cpp b/test_problems/cathermo/HMW_dupl_test/HMW_dupl_test.cpp index 229e394a9..3d6bceb90 100644 --- a/test_problems/cathermo/HMW_dupl_test/HMW_dupl_test.cpp +++ b/test_problems/cathermo/HMW_dupl_test/HMW_dupl_test.cpp @@ -19,12 +19,7 @@ int main(int argc, char** argv) size_t i; try { - - char iFile[80]; - strcpy(iFile, "HMW_NaCl.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } + std::string iFile = (argc > 1) ? argv[1] : "HMW_NaCl.xml"; double Cp0_R[20], pmCp[20]; HMWSoln* HMW = new HMWSoln(iFile, "NaCl_electrolyte"); diff --git a/test_problems/cathermo/HMW_graph_CpvT/HMW_graph_CpvT.cpp b/test_problems/cathermo/HMW_graph_CpvT/HMW_graph_CpvT.cpp index 963cef56e..f56a2917e 100644 --- a/test_problems/cathermo/HMW_graph_CpvT/HMW_graph_CpvT.cpp +++ b/test_problems/cathermo/HMW_graph_CpvT/HMW_graph_CpvT.cpp @@ -19,12 +19,7 @@ int main(int argc, char** argv) size_t i; try { - - char iFile[80]; - strcpy(iFile, "HMW_NaCl.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } + std::string iFile = (argc > 1) ? argv[1] : "HMW_NaCl.xml"; double Cp0_R[20], pmCp[20]; HMWSoln* HMW = new HMWSoln(iFile, "NaCl_electrolyte"); 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 54cf95937..582ac5113 100644 --- a/test_problems/cathermo/HMW_graph_GvI/HMW_graph_GvI.cpp +++ b/test_problems/cathermo/HMW_graph_GvI/HMW_graph_GvI.cpp @@ -17,12 +17,7 @@ int main(int argc, char** argv) size_t i; string commandFile; try { - - char iFile[80]; - strcpy(iFile, "HMW_NaCl.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } + std::string iFile = (argc > 1) ? argv[1] : "HMW_NaCl.xml"; double Temp = 273.15 + 275.; double aTemp[7]; diff --git a/test_problems/cathermo/HMW_graph_GvT/HMW_graph_GvT.cpp b/test_problems/cathermo/HMW_graph_GvT/HMW_graph_GvT.cpp index 9cc683f9e..58584e479 100644 --- a/test_problems/cathermo/HMW_graph_GvT/HMW_graph_GvT.cpp +++ b/test_problems/cathermo/HMW_graph_GvT/HMW_graph_GvT.cpp @@ -22,13 +22,7 @@ int main(int argc, char** argv) int extraCols = 1; try { - //Cantera::ThermoPhase *tp = 0; - char iFile[80]; - strcpy(iFile, "HMW_NaCl.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } - + std::string iFile = (argc > 1) ? argv[1] : "HMW_NaCl.xml"; HMWSoln* HMW = new HMWSoln(iFile, "NaCl_electrolyte"); diff --git a/test_problems/cathermo/HMW_graph_HvT/HMW_graph_HvT.cpp b/test_problems/cathermo/HMW_graph_HvT/HMW_graph_HvT.cpp index 289a7ca30..18e6977b3 100644 --- a/test_problems/cathermo/HMW_graph_HvT/HMW_graph_HvT.cpp +++ b/test_problems/cathermo/HMW_graph_HvT/HMW_graph_HvT.cpp @@ -19,12 +19,7 @@ int main(int argc, char** argv) size_t i; try { - - char iFile[80]; - strcpy(iFile, "HMW_NaCl.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } + std::string iFile = (argc > 1) ? argv[1] : "HMW_NaCl.xml"; double Enth0_RT[20], pmEnth[20], molarEnth; HMWSoln* HMW = new HMWSoln(iFile, "NaCl_electrolyte"); diff --git a/test_problems/cathermo/HMW_graph_VvT/HMW_graph_VvT.cpp b/test_problems/cathermo/HMW_graph_VvT/HMW_graph_VvT.cpp index a87973c40..bd93bc852 100644 --- a/test_problems/cathermo/HMW_graph_VvT/HMW_graph_VvT.cpp +++ b/test_problems/cathermo/HMW_graph_VvT/HMW_graph_VvT.cpp @@ -18,12 +18,7 @@ int main(int argc, char** argv) size_t i; try { - - char iFile[80]; - strcpy(iFile, "HMW_NaCl.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } + std::string iFile = (argc > 1) ? argv[1] : "HMW_NaCl.xml"; double V0[20], pmV[20]; HMWSoln* HMW = new HMWSoln(iFile, "NaCl_electrolyte"); diff --git a/test_problems/cathermo/stoichSubSSTP/stoichSubSSTP.cpp b/test_problems/cathermo/stoichSubSSTP/stoichSubSSTP.cpp index c3176bfca..28bdf5467 100644 --- a/test_problems/cathermo/stoichSubSSTP/stoichSubSSTP.cpp +++ b/test_problems/cathermo/stoichSubSSTP/stoichSubSSTP.cpp @@ -16,14 +16,8 @@ using namespace Cantera; int main(int argc, char** argv) { try { - //Cantera::ThermoPhase *tp = 0; - char iFile[80], file_ID[80]; - strcpy(iFile, "NaCl_Solid.xml"); - if (argc > 1) { - strcpy(iFile, argv[1]); - } - - sprintf(file_ID,"%s#NaCl(S)", iFile); + std::string iFile = (argc > 1) ? argv[1] : "NaCl_Solid.xml"; + std::string file_ID = iFile + "#NaCl(S)"; XML_Node* xm = get_XML_NameID("phase", file_ID, 0); StoichSubstanceSSTP* solid = new StoichSubstanceSSTP(*xm); diff --git a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp index 352c3121d..002113903 100644 --- a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp +++ b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp @@ -23,22 +23,7 @@ int main() #endif double pres; try { - WaterSSTP* w = new WaterSSTP("waterTPphase.xml",""); - delete w; - - char iFile[80], file_ID[80]; - strcpy(iFile, "waterTPphase.xml"); - sprintf(file_ID,"%s#water", iFile); - XML_Node* xm = get_XML_NameID("phase", file_ID, 0); - w = new WaterSSTP(*xm); - delete w; - - strcpy(iFile, "waterTPphase.xml"); - sprintf(file_ID,"%s#water", iFile); - xm = get_XML_NameID("phase", file_ID, 0); - w = new WaterSSTP(); - importPhase(*xm, w); - + WaterSSTP* w = new WaterSSTP("waterTPphase.xml", "water"); /* * Print out the triple point conditions