#include "MEDFileUtilities.hxx"
#include "MEDLoaderBase.hxx"
+#include "MEDLoader.hxx"
#include "InterpKernelAutoPtr.hxx"
void MEDCoupling::MEDFileWritableStandAlone::write30(const std::string& fileName, int mode) const
{
med_access_mode medmod(MEDFileUtilities::TraduceWriteMode(mode));
- throw INTERP_KERNEL::Exception("MEDFileWritableStandAlone::write30 : will be implemented with MEDFile >= 3.2.1 !");
- //MEDFileUtilities::AutoFid fid(MEDfileVersionOpen(fileName.c_str(),medmod,3,0,0));
- //writeLL(fid);
+#if MED_NUM_MAJEUR>=3 && MED_NUM_MINEUR>=2 && MED_NUM_RELEASE>=1
+ MEDFileUtilities::AutoFid fid(MEDfileVersionOpen(fileName.c_str(),medmod,3,0,0));
+ writeLL(fid);
+#else
+ std::ostringstream oss; oss << "MEDFileWritableStandAlone::write30 : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
+ throw INTERP_KERNEL::Exception(oss.str());
+#endif
}
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> MEDCoupling::MEDFileWritableStandAlone::serialize() const
return std::string(MED_VERSION_STR);
}
+std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
+{
+ 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);
+}
+
void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
{
major=MED_NUM_MAJEUR;
MEDLOADER_EXPORT void SetTooLongStrPolicy(int val);
MEDLOADER_EXPORT bool HasXDR();
MEDLOADER_EXPORT std::string MEDFileVersionStr();
+ MEDLOADER_EXPORT std::string MEDFileVersionOfFileStr(const std::string& fileName);
MEDLOADER_EXPORT void MEDFileVersion(int& major, int& minor, int& release);
MEDLOADER_EXPORT void CheckFileForRead(const std::string& fileName);
MEDLOADER_EXPORT std::vector<std::string> GetMeshNames(const std::string& fileName);
{
bool HasXDR();
std::string MEDFileVersionStr();
+ 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);
void SetTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception);
import platform
from math import pi,e,sqrt
from MEDLoaderDataForTest import MEDLoaderDataForTest
+from distutils.version import LooseVersion
class MEDLoaderTest3(unittest.TestCase):
def testMEDMesh1(self):
ex=MEDCouplingMappedExtrudedMesh(mesh3D)
mm=MEDFileUMesh(ex)
mm.write(fname,2)
+ assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==list(MEDFileVersion()[:2])) # checks that MED file version of written mesh is thoose of the current MED file lib
ex2=mm.convertToExtrudedMesh()
mm2=MEDFileMesh.New(fname)
ex3=mm2.convertToExtrudedMesh()
self.assertTrue(ex.isEqual(ex3,1e-12))
pass
+ @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
+ def testWriteInto30(self):
+ fname="Pyfile108.med"
+ m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
+ mm=MEDFileUMesh() ; mm[0]=m
+ mm.setFamilyId("FAMILLE_ZERO",0)
+ #
+ mm.write30(fname,2)
+ assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,0]) # checks that just written MED file has a version == 3.0.x
+ mm2=MEDFileUMesh(fname)
+ self.assertTrue(mm.isEqual(mm2,1e-12))
+ pass
pass
if __name__ == "__main__":