From 6ff27f16bfb1f350e6ef9e8f370a76991fac18b2 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 19 Aug 2003 17:28:21 +0000 Subject: [PATCH] Added some conversion programs. --- tools/src/Makefile.in | 10 ++++- tools/src/ck2cti.cpp | 84 ++++++++++++++++++++++++++++++++++++ tools/src/ck2ctml.cpp | 2 +- tools/src/cti2ctml.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 tools/src/ck2cti.cpp create mode 100644 tools/src/cti2ctml.cpp diff --git a/tools/src/Makefile.in b/tools/src/Makefile.in index 11fe7a9f2..a58fe6bbc 100755 --- a/tools/src/Makefile.in +++ b/tools/src/Makefile.in @@ -20,11 +20,19 @@ CANTERALIB_DEP = @buildlib@/libcantera.a \ .cpp.o: @CXX@ -c $< @DEFS@ $(INCDIR) @CXXFLAGS@ $(CXX_FLAGS) -all: $(BINDIR)/ck2cti +all: $(BINDIR)/ck2ctml $(BINDIR)/cti2ctml $(BINDIR)/ck2cti + +$(BINDIR)/ck2ctml: ck2ctml.o $(CONVLIB_DEP) $(CANTERALIB_DEP) + @CXX@ -o $(BINDIR)/ck2ctml ck2ctml.o $(LCXX_FLAGS) -lconverters $(LOCAL_LIBS) \ + $(LCXX_END_LIBS) $(BINDIR)/ck2cti: ck2cti.o $(CONVLIB_DEP) $(CANTERALIB_DEP) @CXX@ -o $(BINDIR)/ck2cti ck2cti.o $(LCXX_FLAGS) -lconverters $(LOCAL_LIBS) \ $(LCXX_END_LIBS) + +$(BINDIR)/cti2ctml: cti2ctml.o $(CONVLIB_DEP) $(CANTERALIB_DEP) + @CXX@ -o $(BINDIR)/cti2ctml cti2ctml.o $(LCXX_FLAGS) -lconverters $(LOCAL_LIBS) \ + $(LCXX_END_LIBS) clean: $(RM) *.o *.*~ diff --git a/tools/src/ck2cti.cpp b/tools/src/ck2cti.cpp new file mode 100644 index 000000000..099655194 --- /dev/null +++ b/tools/src/ck2cti.cpp @@ -0,0 +1,84 @@ +/** + * @file ck2ctml.cpp + * + * Program to convert CK-format reaction mechanism files to CTML format. + * + */ +#ifdef WIN32 +#pragma warning(disable:4786) +#pragma warning(disable:4503) +#endif + +#include +#include +using namespace std; + +#include "converters/ck2ctml.h" +#include "converters/ck2ct.h" + +using namespace ctml; + +int showHelp() { + cout << "\nck2ckml: convert a CK-format reaction mechanism file to CTML.\n" + << "\n D. G. Goodwin, Caltech \n" + << " Version 1.0, August 2002.\n\n" + << endl; + cout << "options:" << endl; + cout << " -i \n" + << " -o \n" + << " -t \n" + << " -tr \n" + << " -id \n"; + return 0; +} + +int main(int argc, char** argv) { + string infile="chem.inp", dbfile="", trfile="", logfile, outfile=""; + string idtag = "gas"; + // ckr::CKReader r; + //r.validate = true; + int i=1; + if (argc == 1) return showHelp(); + + while (i < argc) { + string arg = string(argv[i]); + if (i < argc-1) { + if (arg == "-i") { + infile = argv[i+1]; + ++i; + } + else if (arg == "-o") { + outfile = argv[i+1]; + ++i; + } + else if (arg == "-t") { + dbfile = argv[i+1]; + ++i; + } + else if (arg == "-tr") { + trfile = argv[i+1]; + ++i; + } + else if (arg == "-id") { + idtag = argv[i+1]; + } + } + else if (arg == "-h" || argc < 3) { + return showHelp(); + } + ++i; + } + +#define MAKE_CT_INPUT +#ifdef MAKE_CT_INPUT + int ierr = pip::convert_ck(infile.c_str(), dbfile.c_str(), trfile.c_str(), + idtag.c_str()); +#else + int ierr = convert_ck(infile.c_str(), dbfile.c_str(), trfile.c_str(), + outfile.c_str(), idtag.c_str()); +#endif + if (ierr < 0) { + showErrors(cerr); + } + return ierr; +} diff --git a/tools/src/ck2ctml.cpp b/tools/src/ck2ctml.cpp index 099655194..e00013deb 100755 --- a/tools/src/ck2ctml.cpp +++ b/tools/src/ck2ctml.cpp @@ -69,7 +69,7 @@ int main(int argc, char** argv) { ++i; } -#define MAKE_CT_INPUT +//#define MAKE_CT_INPUT #ifdef MAKE_CT_INPUT int ierr = pip::convert_ck(infile.c_str(), dbfile.c_str(), trfile.c_str(), idtag.c_str()); diff --git a/tools/src/cti2ctml.cpp b/tools/src/cti2ctml.cpp new file mode 100644 index 000000000..7392d66c1 --- /dev/null +++ b/tools/src/cti2ctml.cpp @@ -0,0 +1,96 @@ +/** + * @file example2.cpp + * + */ + +// Example +// +// Read a mechanism and a thermodynamics file for the +// class IdealSolidSolnPhase in order to test that it's +// working correctly +// + +#include +#include +#include + +#include "ct_defs.h" +#include "xml.h" +#include "ctml.h" + + +using namespace std; + +#ifdef DEBUG_HKM +int iDebug_HKM = 0; +#endif + +/*****************************************************************/ +/*****************************************************************/ +/*****************************************************************/ +static void printUsage() +{ + cout << "ctitoxml [-h] infile.cti" << endl; + cout << " Translates a cti formated file to an xml file" << endl; + cout << " The xml file will be named infile.xml" << endl; +} + + + + + + +int main(int argc, char** argv) { + string infile; + // look for command-line options + if (argc > 1) { + string tok; + for (int j = 1; j < argc; j++) { + tok = string(argv[j]); + if (tok[0] == '-') { + int nopt = tok.size(); + for (int n = 1; n < nopt; n++) { + if (tok[n] == 'h') { + printUsage(); + exit(0); + } else { + printUsage(); + exit(1); + } + } + } else if (infile == "") { + infile = tok; + } + else { + printUsage(); + exit(1); + } + } + } + if (infile == "") { + printUsage(); + exit(1); + } + + try { + XML_Node *xc = new XML_Node(); + string path = findInputFile(infile); + ctml::get_CTML_Tree(xc, path); + XML_Node *xd = new XML_Node(); + xc->copy(xd); + ofstream tout; + tout.open("testdest.xml"); + xc->write(tout); + tout.close(); + tout.open("testdest2.xml"); + xd->write(tout); + tout.close(); + + } + catch (CanteraError) { + showErrors(cout); + } + + return 0; +} +/***********************************************************/