Salome HOME
Add to med30 convertor.
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 5 Feb 2021 09:22:15 +0000 (10:22 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 5 Feb 2021 09:22:15 +0000 (10:22 +0100)
src/MEDLoader/Swig/CMakeLists.txt
src/MEDLoader/Swig/ConvertMEDFileTo30.py [new file with mode: 0644]

index 6ab12c817f2f8e2e003443e33dcd180010138319..e94e1415b773f77bd63ab2ad595ddfa77b0f2e34 100644 (file)
@@ -107,7 +107,7 @@ INSTALL(FILES med2sauv PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EX
 INSTALL(FILES sauv2med PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
 INSTALL(FILES case2med PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
 INSTALL(FILES med2case PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
-INSTALL(FILES ConvertMEDFileTo33.py PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
+INSTALL(FILES ConvertMEDFileTo33.py ConvertMEDFileTo30.py PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${MEDCOUPLING_INSTALL_BINS} )
 
 SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 
diff --git a/src/MEDLoader/Swig/ConvertMEDFileTo30.py b/src/MEDLoader/Swig/ConvertMEDFileTo30.py
new file mode 100644 (file)
index 0000000..4a4ef1c
--- /dev/null
@@ -0,0 +1,48 @@
+#! /usr/bin/env python
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2021  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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author : Anthony GEAY (EDF R&D)
+
+import MEDLoader as ml
+import os
+
+def ConvertTo30(nameOfMEDFile):
+    fn,ext=os.path.splitext(nameOfMEDFile)
+    assert(ext in [".med",".rmed"])
+    realFnOut=fn+"_30.med"
+    #
+    initalVersion=ml.MEDFileVersionOfFileStr(nameOfMEDFile)
+    #
+    mfd=ml.MEDFileData(nameOfMEDFile)
+    mfd.write30(realFnOut,2)
+    #
+    finalVersion=ml.MEDFileVersionOfFileStr(realFnOut)
+    #
+    print(("File \"%s\" has been successfully converted to 3.0 ( %s -> %s ) !\nOutput file is here : \"%s\" !"%(fn,initalVersion,finalVersion,realFnOut)))
+    pass
+
+if __name__=="__main__":
+    import argparse
+    parser=argparse.ArgumentParser(description='Convert a MED file into a MED file with 3.3 version (3.3.1)')
+    parser.add_argument('nameOfMEDFile', type=str, nargs=1,help='File name of the MED file to be converted into 3.3.')
+    args=parser.parse_args()
+    nameOfMEDFile=args.nameOfMEDFile[0]
+    ConvertTo30(nameOfMEDFile)
+    pass