From 586e60daf0fbd66a89d0269e599a3fdd6d213edf 2014-01-08 15:54:41 From: Daniel Valdez Date: 2014-01-08 15:54:41 Subject: [PATCH] en el metodo readblocks se encuentra un error cuando se intenta hacer el reshape del arreglo junk, este error se produce porque no hay bytes suficientes para un bloque de datos. Para esto se propuso el nuevo metodo waitDataBlock que recalcula el numero de byte necesarios para un bloque y espera un tiempo (sleep) en caso no esten disponibles, se hacen tres intentos, si no se tiene exito el programa retorna 0. --- diff --git a/schainpy/model/jrodataIO.py b/schainpy/model/jrodataIO.py index c9c9595..4430557 100644 --- a/schainpy/model/jrodataIO.py +++ b/schainpy/model/jrodataIO.py @@ -722,6 +722,29 @@ class JRODataReader(JRODataIO, ProcessingUnit): return 0 + def waitDataBlock(self,pointer_location): + + currentPointer = pointer_location + + neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize + + for nTries in range( self.nTries ): + self.fp.close() + self.fp = open( self.filename, 'rb' ) + self.fp.seek( currentPointer ) + + self.fileSize = os.path.getsize( self.filename ) + currentSize = self.fileSize - currentPointer + + if ( currentSize >= neededSize ): + return 1 + + print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) + time.sleep( self.delay ) + + return 0 + + def __jumpToLastBlock(self): if not(self.__isFirstTimeOnline): @@ -1499,14 +1522,18 @@ class VoltageReader(JRODataReader): Exceptions: Si un bloque leido no es un bloque valido """ - + current_pointer_location = self.fp.tell() junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) try: junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) except: - print "The read block (%3d) has not enough data" %self.nReadBlocks - return 0 + #print "The read block (%3d) has not enough data" %self.nReadBlocks + + if self.waitDataBlock(pointer_location=current_pointer_location): + junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) + junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) +# return 0 junk = numpy.transpose(junk, (2,0,1)) self.datablock = junk['real'] + junk['imag']*1j