Salome HOME
For med file version, no more use of static macro but use dynamic lib for users using...
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 10 Nov 2016 15:54:21 +0000 (16:54 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 10 Nov 2016 15:54:21 +0000 (16:54 +0100)
src/MEDLoader/MEDLoader.cxx
src/MEDLoader/Swig/MEDLoaderCommon.i

index c8248fd11036b4737659cb3ebc170c092a1d36ef..61ee8bbc2bdecc8b014297731a3d2129d0c3a91f 100644 (file)
@@ -289,7 +289,21 @@ bool MEDCoupling::HasXDR()
 
 std::string MEDCoupling::MEDFileVersionStr()
 {
-  return std::string(MED_VERSION_STR);
+  const int SZ=20;
+  char buf[SZ];
+  std::fill(buf,buf+SZ,'\0');
+  const char START_EXPECTED[]="MED-";
+  med_err ret(MEDlibraryStrVersion(buf));
+  if(ret!=0)
+    throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
+  std::string zeRet(buf);
+  std::size_t pos(zeRet.find(START_EXPECTED,0));
+  if(pos!=0)
+    {
+      std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
+      throw INTERP_KERNEL::Exception(oss.str());
+    }
+  return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
 }
 
 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
@@ -317,9 +331,13 @@ std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
 
 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
 {
-  major=MED_NUM_MAJEUR;
-  minor=MED_NUM_MINEUR;
-  release=MED_NUM_RELEASE;
+  med_int majj,minn,rell;
+  med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
+  if(ret!=0)
+    throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
+  major=majj;
+  minor=minn;
+  release=rell;
 }
 
 /*!
index 8950a3f784214474b66faf62ec81b73f20599ea7..b5d3561289db76cec6d1263cab263fdfbc42d6a4 100644 (file)
@@ -299,7 +299,7 @@ using namespace MEDCoupling;
 namespace MEDCoupling
 {
   bool HasXDR();
-  std::string MEDFileVersionStr();
+  std::string MEDFileVersionStr() throw(INTERP_KERNEL::Exception);
   std::string MEDFileVersionOfFileStr(const std::string& fileName) throw(INTERP_KERNEL::Exception);
   void SetEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception);
   void SetCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception);
@@ -353,7 +353,7 @@ namespace MEDCoupling
 
 %inline
 {
-  PyObject *MEDFileVersionSwig()
+  PyObject *MEDFileVersionSwig() throw(INTERP_KERNEL::Exception)
   {
     int major,minor,release;
     MEDCoupling::MEDFileVersion(major,minor,release);
@@ -364,7 +364,7 @@ namespace MEDCoupling
     return ret;
   }
 
-  PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
+  PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName) throw(INTERP_KERNEL::Exception)
   {
     std::vector< std::pair<int,int> > res=MEDCoupling::GetFieldIterations(type,fileName,meshName,fieldName);
     PyObject *ret=PyList_New(res.size());