# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013 CEA/DEN, EDF R&D
+# Copyright (C) 2007-2016 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
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Author Anthony GEAY (CEA/DEN/DM2S/STMF)
+# Author : Anthony GEAY (CEA/DEN/DM2S/STMF)
from MEDLoader import *
self._tmp=3
return
if name=="PDataArray":
- if self._tmp in self._data_array.keys():
+ if self._tmp in self._data_array:
self._data_array[self._tmp](attrs)
pass
return
VTKTypes_2_MC=[-1,0,-1,1,33,3,-1,5,-1,4,14,-1,NORM_HEXA8,16,15,-1,22,-1,-1,-1,-1,2,6,8,20,30,25,23,9,27,-1,-1,-1,-1,7,-1,-1,-1,-1,-1,-1,-1,31]
class NormalException(Exception):
+ def __init__(self,lineNb):
+ Exception.__init__(self)
+ self._line_nb=lineNb
+ def getLineNb(self):
+ return self._line_nb
pass
class NotRawVTUException(Exception):
offsets=np.memmap(fd,dtype=rd._type_off,mode='r',offset=ref+rd._off_off,shape=(rd._nb_cells,))
offsets=self.__swapIfNecessary(rd._bo,offsets) ; connLgth=offsets[-1] ; offsets2=DataArrayInt(rd._nb_cells+1) ; offsets2.setIJ(0,0,0)
offsets2[1:]=DataArrayInt(offsets)
- offsets3=offsets2.deltaShiftIndex() ; offsets2=offsets3.deepCpy() ; offsets3+=1 ; offsets3.computeOffsets2()
+ offsets3=offsets2.deltaShiftIndex() ; offsets2=offsets3.deepCopy() ; offsets3+=1 ; offsets3.computeOffsetsFull()
offsets=offsets3
- tmp1=DataArrayInt(len(offsets2),2) ; tmp1[:,0]=1 ; tmp1[:,1]=offsets2 ; tmp1.rearrange(1) ; tmp1.computeOffsets2()
+ tmp1=DataArrayInt(len(offsets2),2) ; tmp1[:,0]=1 ; tmp1[:,1]=offsets2 ; tmp1.rearrange(1) ; tmp1.computeOffsetsFull()
tmp1=DataArrayInt.Range(1,2*len(offsets2),2).buildExplicitArrByRanges(tmp1)
conn=np.memmap(fd,dtype=rd._type_conn,mode='r',offset=ref+rd._off_conn,shape=(connLgth,))
conn=self.__swapIfNecessary(rd._bo,conn)
conn2[offsets[0:-1]]=types
conn2[tmp1]=DataArrayInt(conn)
m.setConnectivity(conn2,offsets,True)
- m.checkCoherency() ; mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; ms.pushMesh(mm)
+ m.checkConsistencyLight() ; mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; ms.pushMesh(mm)
# Fields on nodes and on cells
for spatialDisc,nbEnt,fields in [(ON_NODES,rd._nb_nodes,rd._node_fields),(ON_CELLS,rd._nb_cells,rd._cell_fields)]:
for name,typ,nbCompo,off in fields:
vals=np.memmap(fd,dtype=typ,mode='r',offset=ref+off,shape=(nbEnt*nbCompo))
vals=self.__swapIfNecessary(rd._bo,vals)
arr=DataArrayDouble(np.array(vals,dtype='float64')) ; arr.rearrange(nbCompo)
- f.setArray(arr) ; f.checkCoherency()
+ f.setArray(arr) ; f.checkConsistencyLight()
f.setTime(self._time[0],self._time[1],0)
ff.appendFieldNoProfileSBT(f)
fs.pushField(ff)
import xml.sax
class VTU_SAX_Reader(xml.sax.ContentHandler):
def __init__(self):
+ self._loc=None
self._data_array={0:self.DAPoints,1:self.DACells,2:self.DAPointData,3:self.DACellData}
self._node_fields=[]
self._cell_fields=[]
pass
+ def setLocator(self,loc):
+ self._loc=loc
def DAPoints(self,attrs):
self._space_dim=int(attrs["NumberOfComponents"])
self._type_coords=str(attrs["type"]).lower()
return
if name=="AppendedData":
if str(attrs["encoding"])=="raw":
- raise VTURawReader.NormalException("")
+ raise VTURawReader.NormalException(self._loc.getLineNumber())
else:
raise VTURawReader.NotRawVTUException("The file is not a raw VTU ! Change reader !")
pass
rd=VTU_SAX_Reader()
parser=xml.sax.make_parser()
parser.setContentHandler(rd)
+ locator=xml.sax.expatreader.ExpatLocator(parser)
+ rd.setLocator(locator)
isOK=False
try:
parser.parse(fd)
except self.NormalException as e:
isOK=True
fd.seek(0)
- for i in xrange(31): fd.readline()
+ for i in range(e.getLineNb()): fd.readline()
ref=fd.tell()+5
pass
if not isOK:
def __init__(self,fileName,tim=(0.,0)):
msg="The time specified in constructor as 2nd arg should be a tuple containing 2 values 1 float and 1 int !"
- if type(tim)!=tuple:
+ if not isinstance(tim, tuple):
raise Exception(msg)
if len(tim)!=2:
raise Exception(msg)
- if type(tim[0])!=float or type(tim[1])!=int:
+ if not isinstance(tim[0], float) or not isinstance(tim[1], int):
raise Exception(msg)
self._fileName=fileName
self._time=tim