From: Anthony Geay Date: Thu, 20 Aug 2015 16:59:32 +0000 (+0200) Subject: Help from Eric needed \! X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=944534ccdf6e96acb2ac60fe94e75978c73f0cd2;p=tools%2Fmedcoupling.git Help from Eric needed \! --- diff --git a/src/MEDLoader/MEDFileUtilities.txx b/src/MEDLoader/MEDFileUtilities.txx index 61323db91..0223a0ffe 100644 --- a/src/MEDLoader/MEDFileUtilities.txx +++ b/src/MEDLoader/MEDFileUtilities.txx @@ -36,8 +36,9 @@ namespace ParaMEDMEM { med_memfile memfile; memfile.app_image_ptr=0; + memfile.app_image_size=0; { - MEDFileUtilities::AutoFid fid=MEDmemFileOpen("",&memfile,MED_FALSE,MED_ACC_CREAT); + MEDFileUtilities::AutoFid fid=MEDmemFileOpen("",&memfile,MED_FALSE,MED_ACC_CREAT);//MED_ACC_CREAT item2BSerialized.writeLL(fid); } MEDCouplingAutoRefCountObjectPtr ret(DataArrayByte::New()); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 36fdbadb8..e1de77b6b 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -168,6 +168,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileAnyTypeField1TS::New; %newobject ParaMEDMEM::MEDFileAnyTypeField1TS::shallowCpy; %newobject ParaMEDMEM::MEDFileAnyTypeField1TS::deepCpy; +%newobject ParaMEDMEM::MEDFileAnyTypeField1TS::serialize; %newobject ParaMEDMEM::MEDFileField1TS::New; %newobject ParaMEDMEM::MEDFileField1TS::getFieldAtLevel; %newobject ParaMEDMEM::MEDFileField1TS::getFieldAtTopLevel; @@ -1625,6 +1626,7 @@ namespace ParaMEDMEM static MEDFileAnyTypeField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception); static MEDFileAnyTypeField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception); void write(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception); + DataArrayByte *serialize() const throw(INTERP_KERNEL::Exception); void loadArrays() throw(INTERP_KERNEL::Exception); void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception); void unloadArrays() throw(INTERP_KERNEL::Exception); @@ -1812,6 +1814,22 @@ namespace ParaMEDMEM return MEDFileField1TS::New(); } + static MEDFileField1TS *New(DataArrayByte *dab) throw(INTERP_KERNEL::Exception) + { + if(!dab) + throw INTERP_KERNEL::Exception("MEDFileField1TS::New : null input pointer !"); + dab->checkAllocated(); + if(dab->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDFileField1TS::New : number of components is expected to be 1 !"); + char *ptr=reinterpret_cast(malloc(dab->getNumberOfTuples())); + std::copy(dab->begin(),dab->end(),ptr); + med_memfile memfile; + memfile.app_image_ptr=ptr; + memfile.app_image_size=dab->getNumberOfTuples(); + MEDFileUtilities::AutoFid fid=MEDmemFileOpen("",&memfile,MED_FALSE,MED_ACC_RDWR); + return MEDFileField1TS::New(fid,true); + } + void copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception) { const DataArrayDouble *arr=0; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index a508d65c9..d39369621 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -4552,6 +4552,26 @@ class MEDLoaderTest(unittest.TestCase): os.remove(errfname) # pass +#class MEDLoaderTest(unittest.TestCase): + def tessMEDFileMemSerialization1(self):# second : build a file from scratch + m=MEDCouplingCMesh() + arr=DataArrayDouble(11) ; arr.iota() + m.setCoords(arr,arr) + m.setName("mesh") + mm=MEDFileCMesh() + mm.setMesh(m) + # + f=MEDCouplingFieldDouble(ON_CELLS) + f.setName("field") + f.setMesh(m) + f.setArray(DataArrayDouble(100)) + f.getArray()[:]=100. + f.checkCoherency() + f1ts=MEDFileField1TS() + f1ts.setFieldNoProfileSBT(f) + # + toto=f1ts.serialize() + pass pass