Skip to content

Instantly share code, notes, and snippets.

@ASolchen
Created September 16, 2019 17:14
Show Gist options
  • Save ASolchen/6d94aa358172748a32652020a4ffe6a1 to your computer and use it in GitHub Desktop.
Save ASolchen/6d94aa358172748a32652020a4ffe6a1 to your computer and use it in GitHub Desktop.
import struct
from ctypes import *
import numpy as np
def get_timespan(fn):
with open(fn, "rb") as fp:
fp.seek(1024)
data = True
first = None
last = None
while data:
data = fp.read(16)
if data:
if not first:
first = struct.unpack('dd', data)[0]
last = struct.unpack('dd', data)[0]
#print(first, last)
return (round(first, 2), round(last+0.01, 2))
def make_timestamp_rdd(span, step, outfile):
offset = struct.pack("I", 1024)
padding = struct.pack("I", 0)
samples = struct.pack("Q", 0)
first_val = struct.pack("f", span[0])
last_val = struct.pack("f", span[1])
min_val = struct.pack("f", 0)
max_val = struct.pack("f", 0)
header_data = offset + padding + samples + first_val + last_val + min_val + max_val
with open(outfile, "wb") as fp:
fp.write(header_data)
fp.write('\x00'*(1024-32))
ts = span[0]
samples = 0
while ts <= span[1]:
fp.write(struct.pack('dd', ts,samples))
ts += step
samples += 1
fp.seek(8)
fp.write(struct.pack("Q", samples))
fp.seek(16)
fp.write(struct.pack("f", samples))
fp.seek(24)
fp.write(struct.pack("f", samples))
print('{} samples written to {}'.format(samples, outfile))
return
span = get_timespan("Test_Point_PIDD_Out.rdd")
make_timestamp_rdd(span, 0.01, "timestamp.rdd")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment