Skip to content

Instantly share code, notes, and snippets.

@tylr
Created July 16, 2014 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylr/a5ae2c90de0958991bd1 to your computer and use it in GitHub Desktop.
Save tylr/a5ae2c90de0958991bd1 to your computer and use it in GitHub Desktop.
Parse Raw Voyager 1 and 2 Pulse Wave Spectrum Analyzer DAT files
require 'pry'
require 'pry-byebug'
require 'date'
require 'json'
def raw_samples
format = 's7c2s16'
samples = []
open('./sample2.dat', 'rb') do |file|
while record = file.read(48)
samples << record.unpack(format)
end
end
samples
end
def formatted_samples
raw_samples.map do |raw_sample|
year = raw_sample.shift # years from 1900 eg 114 == 2014
hour = raw_sample.shift # hour of year, ordinal time
sec = raw_sample.shift # second of hour
msec = raw_sample.shift # millisecond of second
dtime = DateTime.strptime("#{year+1900}-#{hour/24}T#{hour%24}:#{sec/60}:#{sec%60}:#{msec}Z", '%Y-%jT%T:%LZ')
{
time: dtime.to_time,
mod16: raw_sample.shift,
mod60: raw_sample.shift,
fdsl: raw_sample.shift,
tele: raw_sample.shift,
craft: raw_sample.shift,
samples: raw_sample
}
end
end
# samples_to_objects.each{|s| p s[:samples] }
puts formatted_samples.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment