From 9fa2a93bdfc7ec92bba69f12573451f1a09ad94a Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 16 Jul 2012 06:47:16 +0000 Subject: [PATCH] Bug correction in MEDPartitionner. --- src/MEDLoader/MEDLoaderBase.cxx | 32 +++++++++++++++++++ src/MEDLoader/MEDLoaderBase.hxx | 3 ++ .../MEDPARTITIONER_MeshCollection.cxx | 9 ++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/MEDLoader/MEDLoaderBase.cxx b/src/MEDLoader/MEDLoaderBase.cxx index 129c027b8..dd69727da 100644 --- a/src/MEDLoader/MEDLoaderBase.cxx +++ b/src/MEDLoader/MEDLoaderBase.cxx @@ -52,6 +52,38 @@ char *MEDLoaderBase::buildEmptyString(int lgth) return ret; } +void MEDLoaderBase::getDirAndBaseName(const std::string& fullName, std::string& dirName, std::string& baseName) throw(INTERP_KERNEL::Exception) +{ + std::size_t pos=fullName.find_last_of(getPathSep()); + if(pos!=std::string::npos) + { + dirName=fullName.substr(0,pos); + baseName=fullName.substr(pos+1); + } + else + { + dirName.clear(); + baseName=fullName; + } +} + +std::string MEDLoaderBase::joinPath(const std::string& dirName, const std::string& baseName) throw(INTERP_KERNEL::Exception) +{ + if(!dirName.empty()) + return dirName+getPathSep()+baseName; + else + return baseName; +} + +std::string MEDLoaderBase::getPathSep() throw(INTERP_KERNEL::Exception) +{ +#ifndef WIN32 + return std::string("/"); +#else + return std::string("\\"); +#endif +} + std::string MEDLoaderBase::buildUnionUnit(const char *name, int nameLgth, const char *unit, int unitLgth) { std::string ret(buildStringFromFortran(name,nameLgth)); diff --git a/src/MEDLoader/MEDLoaderBase.hxx b/src/MEDLoader/MEDLoaderBase.hxx index d23a9b537..b31b8c6ad 100644 --- a/src/MEDLoader/MEDLoaderBase.hxx +++ b/src/MEDLoader/MEDLoaderBase.hxx @@ -30,6 +30,9 @@ class MEDLOADER_EXPORT MEDLoaderBase public: static int getStatusOfFile(const char *fileName); static char *buildEmptyString(int lgth); + static void getDirAndBaseName(const std::string& fullName, std::string& dirName, std::string& baseName) throw(INTERP_KERNEL::Exception); + static std::string getPathSep() throw(INTERP_KERNEL::Exception); + static std::string joinPath(const std::string& dirName, const std::string& baseName) throw(INTERP_KERNEL::Exception); static std::string buildUnionUnit(const char *name, int nameLgth, const char *unit, int unitLgth); static void splitIntoNameAndUnit(const std::string& s, std::string& name, std::string& unit); static void strip(std::string& s); diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx index 2368d0cd8..5a25b6cdb 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx @@ -33,6 +33,7 @@ #include "MEDPARTITIONER_UserGraph.hxx" #include "MEDPARTITIONER_Utils.hxx" +#include "MEDLoaderBase.hxx" #include "MEDLoader.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingUMesh.hxx" @@ -1005,9 +1006,11 @@ MEDPARTITIONER::MeshCollection::MeshCollection(const std::string& filename, Para xml.replace(xml.find("$meshName"),9,meshNames[0]); xml.replace(xml.find("$meshName"),9,meshNames[0]); xml.replace(xml.find("$meshName"),9,meshNames[0]); - std::string nameFileXml=myfile; + std::string nameFileXml(myfile); nameFileXml.replace(nameFileXml.find(".med"),4,".xml"); - nameFileXml="medpartitioner_"+nameFileXml; + std::string nameFileXmlDN,nameFileXmlBN; + MEDLoaderBase::getDirAndBaseName(nameFileXml,nameFileXmlDN,nameFileXmlBN); + nameFileXml=MEDLoaderBase::joinPath(nameFileXmlDN,"medpartitioner_"+nameFileXmlBN); if (_domain_selector->rank()==0) //only on to write it { std::ofstream f(nameFileXml.c_str()); @@ -1026,7 +1029,7 @@ MEDPARTITIONER::MeshCollection::MeshCollection(const std::string& filename, Para } catch(...) { // Handle all exceptions - if ( _driver ) delete _driver; _driver=0; + delete _driver; _driver=0; throw INTERP_KERNEL::Exception("file medpartitioner_xxx.xml does not comply with any recognized format"); } } -- 2.39.2