From c00e5fc343774a7a1fe44e8fd69a7458e3eb8fe5 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 6 Aug 2004 20:51:45 +0000 Subject: [PATCH] Added the "sleep" system command buf fix for the cygwin environment. Added debugging printouts for the DEFINE DEBUG_PATH. --- Cantera/src/ct2ctml.cpp | 35 +++++++++++++++++++++++++++++++++++ Cantera/src/misc.cpp | 17 +++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Cantera/src/ct2ctml.cpp b/Cantera/src/ct2ctml.cpp index c4353094a..9aa37136e 100644 --- a/Cantera/src/ct2ctml.cpp +++ b/Cantera/src/ct2ctml.cpp @@ -116,6 +116,9 @@ namespace ctml { string cmd = pypath() + " " + path + "> ct2ctml.log 2>&1"; #else string cmd = pypath() + " " + path + " &> ct2ctml.log"; +#endif +#ifdef DEBUG_PATHS + cout << "ct2ctml: executing the command " << cmd << endl; #endif int ierr = 0; try { @@ -125,6 +128,36 @@ namespace ctml { ierr = -10; } + /* + * HKM -> This next section may seem a bit weird. However, + * it is in response to an issue that arises when + * running cantera with cygwin, using cygwin's + * python intepreter. Basically, the xml file is + * written to the local directory by the last + * system command. Then, the xml file is read + * immediately after by an ifstream() c++ + * command. Unfortunately, it seems that the + * directory info is not being synched fast enough + * so that the ifstream() read fails, even + * though the file is actually there. Putting in a + * sleep system call here fixes this problem. Also, + * having the xml file pre-existing fixes the + * problem as well. There may be more direct ways + * to fix this bug; however, I am not aware of them. + */ +#if defined(CYGWIN) +#ifdef DEBUG_PATHS + cout << "sleeping for 3 secs" << endl; +#endif + cmd = "sleep 3"; + try { + ierr = system(cmd.c_str()); + } + catch (...) { + ierr = -10; + } +#endif + try { char ch=0; string s = ""; @@ -155,6 +188,7 @@ namespace ctml { "could not convert input file to CTML\n " "command line was: " + msg); } +#ifndef DEBUG_PATHS #ifdef WIN32 cmd = "cmd /C rm " + path; #else @@ -163,6 +197,7 @@ namespace ctml { system(cmd.c_str()); } catch (...) { ; } +#endif #endif } diff --git a/Cantera/src/misc.cpp b/Cantera/src/misc.cpp index 53c98eccd..c51b06af2 100755 --- a/Cantera/src/misc.cpp +++ b/Cantera/src/misc.cpp @@ -128,18 +128,29 @@ namespace Cantera { * We will assume that we are trying to open a cti file. * First, determine the name of the xml file, ff, derived from * the cti file. + * In all cases, we will write the xml file to the current + * directory. */ string::size_type islash = path.rfind('/'); if (islash != string::npos) ff = string("./")+path.substr(islash+1,idot-islash - 1) + ".xml"; - else + else { ff = string("./")+path.substr(0,idot) + ".xml"; + } +#ifdef DEBUG_PATHS + cout << "get_XML_File(): Expected location of xml file = " + << ff << endl; +#endif /* * Do a search of the existing XML trees to determine if we have * already processed this file. If we have, return a pointer to * the processed xml tree. */ if (app()->xmlfiles.find(ff) != app()->xmlfiles.end()) { +#ifdef DEBUG_PATHS + cout << "get_XML_File(): File, " << ff << ", was previously read." + << " Retrieving the storred xml tree." << endl; +#endif return __app->xmlfiles[ff]; } /* @@ -164,7 +175,9 @@ namespace Cantera { __app->xmlfiles[ff] = x; } else { - throw CanteraError("get_XML_File","cannot open "+ff+" for reading."); + string estring = "cannot open "+ff+" for reading."; + estring += "Note, this error indicates a possible configuration problem."; + throw CanteraError("get_XML_File", estring); } } /*