]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Bug correction in MEDPartitionner.
authorageay <ageay>
Mon, 16 Jul 2012 06:47:16 +0000 (06:47 +0000)
committerageay <ageay>
Mon, 16 Jul 2012 06:47:16 +0000 (06:47 +0000)
src/MEDLoader/MEDLoaderBase.cxx
src/MEDLoader/MEDLoaderBase.hxx
src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx

index 129c027b83088d76bd212c2bd60654977d708b73..dd69727dab25b17cc9474bbc304147e68cdbfb28 100644 (file)
@@ -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));
index d23a9b5374f9db9ad54bec5d13d565759e950980..b31b8c6adcd714fc925bb360a6ce95b6c680c977 100644 (file)
@@ -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);
index 2368d0cd8f6d40193bc4674aa64a07dde0bfa156..5a25b6cdb8bfe8bddf8b633e51c0dd894d89ed90 100644 (file)
@@ -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");
             }
         }