Salome HOME
Porting to Python 3
[plugins/ghs3dprlplugin.git] / src / tools / facespoints2mesh.py
index 8eeb7b1b1e4e0dcfc6233782a52cbe7361e107f8..c6ebe6ab27275e1cccb35fe651225f0a29414dd7 100755 (executable)
@@ -18,7 +18,6 @@
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 #
 # 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
 """
 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
 """
 
   mesh2facespoints.py DOMAIN
 """
 
-import os
+import codecs
 import sys
 
 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)