https://github.com/N-BodyShop/changa
Raw File
Tip revision: 4f6b5374bff392d4c5f597256ccd6276e9293a03 authored by Tim Haines on 23 October 2018, 23:21:25 UTC
Complete overhaul of build system
Tip revision: 4f6b537
readstarlog.py
# Utility to peak at the starlog file.
# The file is written in "network order"
# Based on the size in the header, guesses are made about the number
# of variables in each record, and the first record is printed out
# for confirmation.

import struct
import sys

fmthead = "!i"
fmtevent      = "!qqdddddddddd"
fmteventOLD   = "!IIdddddddddd"
fmteventH2    = "!qqddddddddddd"
fmteventH2OLD = "!IIddddddddddd"

filelog = open(sys.argv[1], mode="rb")
head = filelog.read(4)
size = struct.unpack(fmthead, head)
size = size[0]  # a tuple is returned above

print 'starlog record size is ', size

if size == struct.calcsize(fmteventOLD) :
    print '32 bit iOrders format'
    fmt = fmteventOLD
elif size == struct.calcsize(fmtevent) :
    # test read of first few bytes
    tstbuf = filelog.read(16)
    first = struct.unpack('qq', tstbuf)
    if first[0] < first[1] or first[0] < 0 or first[1] < 0:
        print '32 bit iOrders with H2 or BH'
        fmt = fmteventH2OLD
        filelog.seek(4)
    else :
        print '64 bit iOrders format'
        fmt = fmtevent
elif size == struct.calcsize(fmteventH2) :
    print '64 bit iOrders format with H2 or BH'
    fmt = fmteventH2

rec1 = filelog.read(struct.calcsize(fmt))
print struct.unpack(fmt, rec1)
back to top