]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Help from Eric needed \! agy/MED309
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 20 Aug 2015 16:59:32 +0000 (18:59 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 20 Aug 2015 16:59:32 +0000 (18:59 +0200)
src/MEDLoader/MEDFileUtilities.txx
src/MEDLoader/Swig/MEDLoaderCommon.i
src/MEDLoader/Swig/MEDLoaderTest3.py

index 61323db91dbb1c0f8b6d78fd9c32dcc75c5c80f8..0223a0ffeff60e01eaf0196205b1b28e65fe8d68 100644 (file)
@@ -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<DataArrayByte> ret(DataArrayByte::New());
index 36fdbadb8028095de3889417ddf1a786d112d79b..e1de77b6b5327728e2c4c7037d2e58c19856d121 100644 (file)
@@ -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<char *>(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;
index a508d65c9e581d18865a60b939a347caec4c41e9..d393696210dcb253009f55f157d28ad5ed038b81 100644 (file)
@@ -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