+ fd=open(os.path.join(self._dirName,geoFileName),"r+b") ; fd.seek(0,2) ; end=fd.tell() ; fd.seek(0) ; title=fd.read(80)
+ title=title.strip().lower()
+ if "binary" not in title:
+ raise Exception("Error only binary geo files are supported for the moment !")
+ pass
+ zeType=True
+ if "fortran" in title:
+ mcmeshes=self.__convertGeo2MEDFortran(fd,end) ; zeType=False
+ else:
+ mcmeshes=self.__convertGeo2MEDC(fd,end)
+ #
+ ms=MEDFileMeshes()
+ ms.resize(len(mcmeshes))
+ for i,m in enumerate(mcmeshes):
+ mlm=MEDFileUMesh()
+ mlm.setMeshAtLevel(0,m)
+ ms.setMeshAtPos(i,mlm)
+ pass
+ return mcmeshes,ms,zeType
+
+ def __convertGeo2MEDFortran(self,fd,end):
+ mcmeshes=[]
+ fd.read(80) # comment 1
+ fd.read(80) # comment 2
+ fd.read(80) # node id
+ fd.read(80) # element id
+ pos=fd.tell()
+ elt=fd.read(80) ; elt=elt.strip() ; pos=fd.tell()
+ mcmeshes2=[]
+ typ="part"
+ nbOfTurn=0
+ while abs(pos-end)>8 and "part" in typ:
+ if "part" not in elt:
+ raise Exception("Error on reading mesh fortran #1 !")
+ fd.seek(fd.tell()+4)# skip #
+ tmp=fd.read(80) ; meshName=tmp.split("P")[-1]
+ tmp=fd.read(80)
+ if "coordinates" not in tmp:
+ raise Exception("Error on reading mesh fortran #2 !")
+ pos=fd.tell() # 644
+ if nbOfTurn==0:
+ pos+=76 # what else ?
+ else:
+ pos+=40
+ pass
+ nbNodes=np.memmap(fd,dtype='>i4',mode='r',offset=int(pos),shape=(1,)).tolist()[0]
+ pos+=12 # what else ?
+ a=np.memmap(fd,dtype='>f4',mode='r',offset=int(pos),shape=(nbNodes))
+ b=np.memmap(fd,dtype='>f4',mode='r',offset=int(pos+nbNodes*4+2*4),shape=(nbNodes))
+ c=np.memmap(fd,dtype='>f4',mode='r',offset=int(pos+nbNodes*2*4+4*4),shape=(nbNodes))
+ coo=np.zeros(dtype=">f4",shape=(nbNodes*3))
+ coo[:nbNodes]=a ; coo[nbNodes:2*nbNodes]=b ; coo[2*nbNodes:]=c
+ coo=coo.reshape(nbNodes,3)
+ pos+=nbNodes*3*4 ; fd.seek(pos)#np.array(0,dtype='float%i'%(typeOfCoo)).nbytes
+ typ=fd.read(80).strip() ; pos=fd.tell()
+ zeK=""
+ for k in self.dictMCTyp2.keys():
+ if k in typ:
+ zeK=k
+ break
+ pass
+ pass
+ pos+=8*4 # yeh man !
+ nbCellsOfType=np.memmap(fd,dtype='>i4',mode='r',offset=int(pos),shape=(1,)).tolist()[0]
+ pos+=4 # for the number of cells
+ pos+=2*4 # because it's great !
+ nbNodesPerCell=MEDCouplingMesh.GetNumberOfNodesOfGeometricType(self.dictMCTyp2[zeK])
+ nodalConn=np.memmap(fd,dtype='>i4',mode='r',offset=pos,shape=(nbCellsOfType,nbNodesPerCell))
+ meshName=meshName.strip()
+ mcmeshes2.append(self.__traduceMesh(meshName,zeK,coo,nodalConn))
+ pos+=nbNodesPerCell*nbCellsOfType*4
+ if abs(pos-end)>8:
+ fd.seek(pos) ;elt=fd.read(80) ; typ=elt[:] ; pos+=80
+ pass
+ nbOfTurn+=1
+ pass
+ #coo=mcmeshes2[0].getCoords() ; name=mcmeshes2[0].getName()
+ #for itmesh in mcmeshes2: itmesh.setCoords(coo)
+ #m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(mcmeshes2) ; m.setName(name)
+ #mcmeshes.append(m)
+ return mcmeshes2
+
+ def __convertGeo2MEDC(self,fd,end):
+ fd.readline()