Salome HOME
Deal with 2D/0D pointlocator into Remapper
[tools/medcoupling.git] / src / PyWrapping / medcoupling_pycode
index 08914fce54218665f7624bdc7284587beb038c4d..05794b32a5a509a8c4a75c969f2bff093ee5b116 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017  CEA/DEN, EDF R&D
+// Copyright (C) 2017-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -58,4 +58,45 @@ def AdvancedExtensionsStr(sz=60):
 def ShowAdvancedExtensions(sz=60):
     print(AdvancedExtensionsStr(sz))
 
+def MEDCouplingWriterHelper(mci,fileName,medFunc):
+    import os
+    fileWithoutExt,ext=os.path.splitext(fileName)
+    if ext in [".med",".rmed",""]:
+        outFileName=fileName
+        if ext=="":
+            outFileName=fileWithoutExt+".med"
+        if HasMEDFileExt():
+            medFunc(outFileName,mci,True)
+            pass
+        else:
+            raise InterpKernelException("Request for writing \"%s\" MED file, but MED file is not activated in your medcoupling !")
+        pass
+    elif ext[:3]==".vt" and len(ext)==4:
+        mci.writeVTK(fileName)
+    else:
+        raise InterpKernelException("The extension \"%s\" of input file \"%s\" is not recognized !"%(ext,fileName))
+    pass
+
+if HasMEDFileExt():
+    def MEDCouplingMesh_write(self,fileName):
+        MEDCouplingWriterHelper(self,fileName,WriteMesh)
+
+    def MEDCouplingField_write(self,fileName):
+        MEDCouplingWriterHelper(self,fileName,WriteField)
+
+    def MEDCouplingFieldT_copyTimeInfoFrom(self,mlf1ts):
+        assert(isinstance(mlf1ts,MEDFileAnyTypeField1TS))
+        a,b,c=mlf1ts.getTime()
+        self.setTime(c,a,b)
+        pass
+
+    MEDCouplingMesh.write=MEDCouplingMesh_write
+    del MEDCouplingMesh_write
+    MEDCouplingField.write=MEDCouplingField_write
+    del MEDCouplingField_write
+    MEDCouplingFieldDouble.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom
+    MEDCouplingFieldInt.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom
+    MEDCouplingFieldFloat.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom
+    del MEDCouplingFieldT_copyTimeInfoFrom
+    pass
 %}