Hello everybody,
I am after a little help using python to read in data from a binary file. This is what i got so far:
import struct
infile = "friday.bin"
FH = open(infile, 'rb')
line = FH.read(32)
data= struct.unpack("<H", line[0:2])
print data
Which produces an output: 38288
I have a data format structure (listed below) and i wanted to know the best way to define this structure and pass it to unpack. The documentation is a little light on this area. I thought it would be a good idea to retrive the year as i know this will be 2008
Thanks for any help or suggestions on how i can acheive this.
toby
The binary data format.
Record-Length = 32 bytes; Data are in little endium (Lower byte = LSB).
-----------------------------------------------------------------------------------
Field Offset Length Description
-----------------------------------------------------------------------------------
Fix 0 1 Unsigned 8 bit data, The fix status; 0,2,3(D) 8 + if DGPS used.
Su 1 1 Unsigned 8 bit data, Satellite No used in fix.
Hdop 2 2 Unsigned 16 bit data, = (HDOP value)*10.
Year 4 2 Unsigned 16 bit data, The year, (2002) for example.
Month 6 1 Unsigned 8 bit data, The month, 1-12.
Day 7 1 Unsigned 8 bit data, The day, 1-31.
Hour 8 1 Unsigned 8 bit data, The hour, 0-23.
Minute 9 1 Unsigned 8 bit data, The minute, 0-59.
Ms 10 2 Unsigned 16 bit data, The millisecond, 0-59999
Lat 12 4 Signed 32 bit data, The latitude, =(DDMM.mmmm)*10000
>0 : North, <0 : South.
Lon 16 4 Signed 32 bit data, The longitude, =(DDDMM.mmmm)*10000
>0 : East, <0 : West.
Signed 32 bit data, The altitude, =(Altitude: meter)*10
Alt 20 4
Vel 24 2 Unsigned 16 bit data, The Velocity, =(VEL:Km/hr)*10
Cog 26 2 Unsigned 16 bit data, The course over ground, =(COG:degree)*10
Type 28 2 Unsigned 16 bit data, Record Type, NOT Used currently.
Rev 30 1 Unsigned 8 bit data, Reserved, NOT Used currently.
Cks 31 1 Unsigned 8 bit data, Internal check, NOT Used by User.