I succeed in extracting all of the header information, and then only a portion of the data. The data section is 123,410 doubles, but after retrieving 62 of the numbers, I can not go further, struct.unpack indicates that the string argument is the wrong length. I set up a loop to get the numbers one at a time, and it stops at the same place. The file is not corrupt, and will open in the original software. Does anyone have suggestions for figuring out the problem?
Code:
import struct, string, os
bf = "F:/Junker/TestT/TU_TSA.grd"
wbf = open(bf).read() # "rb")
start, stop = 0, struct.calcsize('<7l8d2l')
#Retrieve the header information
try:
TheadID,TheadSize,HSver,TgridID,TgridSize,nRow,nCol,xLL,yLL,xSize,ySize,zMin,zMax,\
Rotation,BlankVal,TdataID,TdataSize = struct.unpack('<7l8d2l', wbf[start:stop])
except:
print "Problem reading Header"
print "TheadID ", TheadID, "\n ", "TheadSize ",TheadSize,"\n ","HSver ", HSver,"\n ","TheadID ",TgridID,"\n ","TgridSize ",TgridSize,"\n ","nRow ",nRow,"\n ","nCol ",nCol,"\n ","xLL ",xLL,"\n ","yLL ",yLL,"\n ","xSize ",xSize,"\n ","ySize ",ySize,"\n ","zMin ",zMin,"\n ","zMax ",zMax,"\n ","Rotation ",Rotation,"\n ","BlankVal ",BlankVal,"\n ","TdataID ",TdataID,"\n ","TdataSize",TdataSize
#Retrieve the data
try:
x = nCol * nRow
while x:
start, stop = stop, stop + struct.calcsize('<d')
DataBlock = struct.unpack('<d', wbf[start:stop])
print DataBlock, " start ",start, " stop ",stop
except:
print "Failed at: start ",start, " stop ",stop
del TheadID,TheadSize,HSver,TgridID,TgridSize,nRow,nCol,xLL,yLL,xSize,ySize,zMin,zMax,\
Rotation,BlankVal,TdataID,TdataSize,start,stop
Comment