Salome HOME
Copyright update 2021
[plugins/ghs3dprlplugin.git] / src / tools / facespoints2mesh.py
index c330a96125f4fed755bdb64f31ba722bf7aa2e91..b4550e52e0c82fcd6e73147750c8175ca8594ed6 100755 (executable)
@@ -1,11 +1,11 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #  -*- coding: utf-8 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+# Copyright (C) 2007-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.
+# 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
@@ -18,7 +18,6 @@
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-
 """
 these file is using in GHS3DPRL Plugin
 to convert input files .faces and .points of Tepal V1
@@ -30,38 +29,37 @@ example of use (when Tepal V2):
   mesh2facespoints.py DOMAIN
 """
 
-import os
+import codecs
 import sys
 
-file_fp='GHS3DPRL'
-if len(sys.argv)==2:
-   file_fp=sys.argv[1]
 
-f1=file_fp+'.points'
-f2=file_fp+'.faces'
-f3=file_fp+'.mesh'
+file_fp = 'GHS3DPRL'
+if len(sys.argv) == 2:
+    file_fp = sys.argv[1]
+
+f1 = file_fp + '.points'
+f2 = file_fp + '.faces'
+f3 = file_fp + '.mesh'
 
-fs=open(f1, 'r')
-ft=open(f3, 'w')
-ft.write('MeshVersionFormatted 1\n')
-ft.write('\nDimension\n3\n')
-tmp=fs.readline()
-nb=int(tmp)
-ft.write('\nVertices\n')
-ft.write(tmp)
-for i in xrange(0,nb):
-  lig=fs.readline()
-  ft.write(lig)
-fs.close()
+with codecs.open(f3, 'w') as ft:
+    with codecs.open(f1, 'r') as fs:
+        ft.write('MeshVersionFormatted 1\n')
+        ft.write('\nDimension\n3\n')
+        tmp = fs.readline()
+        nb = int(tmp)
+        ft.write('\nVertices\n')
+        ft.write(tmp)
+        for i in range(nb):
+            lig = fs.readline()
+            ft.write(lig)
+    with codecs.open(f2, 'r') as fs:
+        lig = fs.readline()
+        nb = int(lig.split()[0])
+        ft.write('\nTriangles\n' + lig.split()[0] + '\n')
+        for i in range(nb):
+            lig = fs.readline()
+            lig = lig.split()
+            ft.write(lig[1] + ' ' + lig[2] + ' ' + lig[3] + ' ' + lig[4] + '\n')
+        ft.write('\nEnd\n')
 
-fs=open(f2, 'r')
-lig=fs.readline()
-nb=int(lig.split()[0])
-ft.write('\nTriangles\n'+lig.split()[0]+'\n')
-for i in xrange(0,nb):
-  lig=fs.readline()
-  lig=lig.split()
-  ft.write(lig[1]+' '+lig[2]+' '+lig[3]+' '+lig[4]+'\n')
-ft.write('\nEnd\n')
-ft.close()
-print 'facespoints2mesh creation of file '+f3
+print('facespoints2mesh creation of file ' + f3)