def __init__(self, model, filename, mode='r', endian = '@', verbose=0): self.model = model # big endian is only for files calculated on Suns or HP # otherwise use '<' FortranBinaryFile.__init__(self, filename, mode, endian, verbose=verbose) # dictionary of model properties, indexed with the # standard variable names of the MARC manual D self.Info = {} self.dataFiles = [self] self.findIncrements() # read title and non incremental data self._readBlock1() self._readBlocks2to13()
def __readRecord(self, type=None): """Read a record from the binary file If the type is non-standard, a special interpretation of the record is invoked """ record = FortranBinaryFile.readRecord(self, type) if record[0] <> None: return record else: # special record types record = record[1] if type == 'c4': lr = len(record)/4 rr = '' for i in range(lr): rr = rr+(struct.unpack(self.endian+'c', record[i*4]))[0] return rr elif type == 'postcode': id = (struct.unpack(self.endian+'i', record[0:4]))[0] record = record[4:] lr = len(record)/4 rr = '' for i in range(lr): rr = rr+(struct.unpack(self.endian+'c', record[i*4]))[0] return id, rr elif type == 'coord': id = (struct.unpack(self.endian+'i', record[0:4]))[0] record = record[4:] rr = self.fromstring(record, 'f') return id, rr