-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbin-format.rb
executable file
·54 lines (45 loc) · 1.26 KB
/
bin-format.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby2.0
load File.dirname(__FILE__) + "/../capture/libs/utils.rb"
require 'optparse'
require 'ostruct'
require 'json'
MIN_UNIX_TIME = -2147483647
MAX_UNIX_TIME = 2147483647
class CustomFormatOptparse
def self.parse(args)
# defaults
options = OpenStruct.new
options.file = "wells.js"
options.keys = ["Date", "Lat", "Lon"]
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: custom-format.rb [options]"
opts.separator ""
opts.separator "Specific options:"
opts.on("-f", "--file FILE", "Begin execution at given time") do |file|
options.file = file
end
end
opt_parser.parse!(args)
options
end
end
def main
options = CustomFormatOptparse.parse(ARGV)
unless File.exists? options.file
puts "Could not find or open #{options.file}"
return
end
unix_times = File.open('wells_unix_times.bin', 'wb')
latlon = File.open('wells_latlon.bin', 'wb')
data = read_json(options.file)
data.each do |d|
if d["Date"].to_i > MIN_UNIX_TIME and d["Date"].to_i < MAX_UNIX_TIME
unix_times.write([d["Date"].to_i].pack("l<"))
latlon.write([d["Lat"].to_f].pack("f"))
latlon.write([d["Lon"].to_f].pack("f"))
end
end
unix_times.close
latlon.close
end
main