X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FSwig%2FVTKReader.py;h=b541744599bcf7a7daeeaadb2bbacdbca9ceb75d;hb=0b187729ac99d3e9e9bb9d2be8cb8600a783be6c;hp=8359d26da69b7a0f4d167c14d4838ea8781de56b;hpb=4a1bed15b0163612c89f5642ac9b84d3c5aa3ca7;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/Swig/VTKReader.py b/src/MEDLoader/Swig/VTKReader.py index 8359d26da..b54174459 100644 --- a/src/MEDLoader/Swig/VTKReader.py +++ b/src/MEDLoader/Swig/VTKReader.py @@ -1,10 +1,10 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2013 CEA/DEN, EDF R&D +# Copyright (C) 2007-2015 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 @@ -17,7 +17,7 @@ # # 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 * @@ -124,6 +124,11 @@ class VTURawReader: 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): @@ -171,11 +176,12 @@ class VTURawReader: m.checkCoherency() ; 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 rd._node_fields: + for name,typ,nbCompo,off in fields: ff=MEDFileFieldMultiTS() f=MEDCouplingFieldDouble(spatialDisc,ONE_TIME) f.setName(name) ; f.setMesh(m) 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.setTime(self._time[0],self._time[1],0) @@ -189,10 +195,13 @@ class VTURawReader: 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() @@ -245,7 +254,7 @@ class VTURawReader: 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 @@ -253,13 +262,15 @@ class VTURawReader: 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 xrange(e.getLineNb()): fd.readline() ref=fd.tell()+5 pass if not isOK: