Added some conversion programs.

This commit is contained in:
Harry Moffat 2003-08-19 17:28:21 +00:00
parent ea0d34ff28
commit 6ff27f16bf
4 changed files with 190 additions and 2 deletions

View file

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

84
tools/src/ck2cti.cpp Normal file
View file

@ -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 <iostream>
#include <string>
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 <input file> \n"
<< " -o <output file> \n"
<< " -t <thermo database> \n"
<< " -tr <transport database> \n"
<< " -id <identifier> \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;
}

View file

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

96
tools/src/cti2ctml.cpp Normal file
View file

@ -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 <iostream>
#include <string>
#include <vector>
#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;
}
/***********************************************************/