Salome HOME
Serialization of DataArrayByte. Serialization of MEDFileData objects. But still some...
[tools/medcoupling.git] / src / MEDLoader / MEDLoader.cxx
index 50009ad4aebb05e48f06ed85c4e221d4f65561da..c8248fd11036b4737659cb3ebc170c092a1d36ef 100644 (file)
@@ -292,6 +292,29 @@ std::string MEDCoupling::MEDFileVersionStr()
   return std::string(MED_VERSION_STR);
 }
 
+std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
+{
+#if MED_NUM_MAJEUR>=3 && MED_NUM_MINEUR>=2 && MED_NUM_RELEASE>=1
+  MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
+  const int SZ=20;
+  const char START_EXPECTED[]="MED-";
+  char buf[SZ];
+  std::fill(buf,buf+SZ,'\0');
+  MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
+  std::string ret(buf);
+  std::size_t pos(ret.find(START_EXPECTED,0));
+  if(pos!=0)
+    {
+      std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
+      throw INTERP_KERNEL::Exception(oss.str());
+    }
+  return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
+#else
+  std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
+  throw INTERP_KERNEL::Exception(oss.str());
+#endif
+}
+
 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
 {
   major=MED_NUM_MAJEUR;