Salome HOME
Copyright update 2022
[tools/medcoupling.git] / src / MEDLoader / Swig / CaseReader.py
index 131d63108378d59449b5817b9209261bd5f83f66..d629818d0f2d81486ebd7ddc13b953f9df5f5385 100644 (file)
@@ -1,5 +1,5 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+# Copyright (C) 2007-2022  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
@@ -21,7 +21,7 @@
 
 # http://www-vis.lbl.gov/NERSC/Software/ensight/doc/OnlineHelp/UM-C11.pdf
 import numpy as np
-from MEDLoader import *
+from medcoupling import *
 from CaseIO import CaseIO
 import sys,re,os
 
@@ -45,21 +45,18 @@ class CaseReader(CaseIO):
 
     def __traduceMesh(self,name,typ,coords,cells):
         """ Convert a CASE mesh into a MEDCouplingUMesh. """
+        name = name.decode("ascii")
         nbCoords=len(coords)
         coo=np.array(coords,dtype="float64") ; coo=coo.reshape(nbCoords,3)
         coo=DataArrayDouble(coo) ; coo=coo.fromNoInterlace()
         ct=self.dictMCTyp2[typ]
-        m=MEDCouplingUMesh(str(name),MEDCouplingUMesh.GetDimensionOfGeometricType(ct))
+        m=MEDCouplingUMesh(name,MEDCouplingUMesh.GetDimensionOfGeometricType(ct))
         m.setCoords(coo)
         nbNodesPerCell=MEDCouplingMesh.GetNumberOfNodesOfGeometricType(ct)
         cI=DataArrayInt(len(cells)+1) ; cI.iota() ; cI*=nbNodesPerCell+1
         #
         cells2=cells.reshape(len(cells),nbNodesPerCell)
-        if cells2.dtype=='int32':
-            c2=DataArrayInt(cells2)
-        else:
-            c2=DataArrayInt(np.array(cells2,dtype="int32"))
-            pass
+        c2=DataArrayInt(np.array(cells2,dtype="int{}".format(MEDCouplingSizeOfIDs())) )
         c=DataArrayInt(len(cells),nbNodesPerCell+1) ; c[:,0]=ct ; c[:,1:]=c2-1 ; c.rearrange(1)
         m.setConnectivity(c,cI,True)
         m.checkConsistency()
@@ -218,7 +215,7 @@ class CaseReader(CaseIO):
             typ=fd.read(80).strip() ; pos=fd.tell()
             mcmeshes2=[]
             while pos!=end and typ!=b"part":
-                if typ[0]=='\0': pos+=1; continue
+                if typ[0]==0: pos+=1; continue
                 mctyp=self.dictMCTyp2[typ]
                 nbCellsOfType=np.memmap(fd,dtype='int32',mode='r',offset=int(pos),shape=(1,)).tolist()[0]
                 pos+=4
@@ -265,7 +262,7 @@ class CaseReader(CaseIO):
         st="%0"+str(len(stars))+"i"
         trueFileName=fileName.replace(stars,st%(it))
         fd=open(os.path.join(self._dirName,trueFileName),"r+b") ; fd.seek(0,2) ; end=fd.tell() ; fd.seek(0)
-        name=fd.read(80).strip().split(b" ")[0]
+        name=fd.read(80).strip().split(b" ")[0].decode("ascii")
         if name!=fieldName:
             raise Exception("ConvertField : mismatch")
         pos=fd.tell()
@@ -372,12 +369,12 @@ class CaseReader(CaseIO):
                 end=lines.index("TIME\n")
                 pass
             for i in range(ind + 1,end):
-                m=re.match("^([\w]+)[\s]+\per[\s]+([\w]+)[\s]*\:[\s]*[0-9]*[\s]*([\w]+)[\s]+([\S]+)$",lines[i])
+                m=re.match("^([\w]+)[\s]+per[\s]+([\w]+)[\s]*\:[\s]*[0-9]*[\s]*([\w]+)[\s]+([\S]+)$",lines[i])
                 if m:
                     if m.groups()[0]=="constant":
                         continue
                     spatialDisc=m.groups()[1] ; fieldName=m.groups()[2] ; nbOfCompo=self.dictCompo2[m.groups()[0]] ; fieldFileName=m.groups()[3]
-                    if fieldFileName.endswith("*"):
+                    if "*" in fieldFileName:
                       fieldsInfo.append((fieldName,spatialDisc,nbOfCompo,fieldFileName))
                     pass
                 pass