class geodata: def _writel(self,some_string): # writes to logfile self.log_file.write(str(some_string)+'\n') def _convert_to_hex(self,some_string): # converts string to hex value if len(some_string)==0: return '00' charval = ord(some_string) hexval = hex(charval) hexstrlen = len(hexval) startpos = hexstrlen - 2 if hexval[startpos] == 'x': startpos += 1 hexval = '0'+hexval[startpos] else: hexval = hexval[startpos:hexstrlen] return hexval def _handle_block0000(self): # now less bleh self._writel("block0000") z1_1 = self.conv_file.read(1) z1_2 = self.conv_file.read(1) z2_1 = self.conv_file.read(1) z2_2 = self.conv_file.read(1) z1 = str(self._convert_to_hex(z1_2) + self._convert_to_hex(z1_1)) z2 = str(self._convert_to_hex(z2_2) + self._convert_to_hex(z2_1)) self._writel(z1) self._writel(z2) if z1!=z2: self._writel('Water from floor '+str(int(z1,16))+' to surface '+str(int(z2,16))) return 0 def _handle_block0040(self): # block 4000 handler self._writel("block0040") for item in range(0,64): z1_1 = self.conv_file.read(1) z1_2 = self.conv_file.read(1) self._writel(self._convert_to_hex(z1_1) + self._convert_to_hex(z1_2)) return 0 def _handle_block0041(self): # block 41000 handler self._writel("block0041") for item in range(0,64): layer = 0 layercounter = self.conv_file.read(1) self._writel("layercounter:" + str(int(self._convert_to_hex(layercounter),16))) for item2 in range(0,int(self._convert_to_hex(layercounter),16)): self._writel("layer:" + str(layer)) z1_1 = self.conv_file.read(1) z1_2 = self.conv_file.read(1) self._writel("--" + self._convert_to_hex(z1_1) + self._convert_to_hex(z1_2)) layer+=1 return 0 def __init__(self,filename): # main function self.conv_file = open(filename+'.dat','r') self.filename=filename self.csv_file = open(filename+'.csv','w') self.log_file = open(filename+'.log','w') self.data_all = {} self.conv_file.seek(18) # header dont need that currently for loop1 in range(0,128): self._writel(loop1) for loop2 in range(0,128): self._writel(loop2) block1 = self.conv_file.read(1) block2 = self.conv_file.read(1) block2_hex = self._convert_to_hex(block2) if block2_hex == 'ff': self._writel("error") elif block2_hex == '00': self._handle_block0000() elif block2_hex == '40': self._handle_block0040() else: self._handle_block0041() self.conv_file.close() self.csv_file.close() self.log_file.close() test = geodata('25_19_conv') test2 = geodata('16_22_conv')