#!/usr/bin/ruby def dumpgrib1 line #puts [line.size, ("\0" + line[0,3]).unpack('N').first] ofs = 4 isec = 1 while ofs < line.size secl = ("\0" + line[ofs,3]).unpack('N').first sec = line[ofs,secl] h = { :p1 => sec[18], :p2 => sec[19], :timerange => sec[20], :parameter => sec[8], :leveltype => sec[9], :level => sec[10,2].unpack('n').first } p h return if isec == 1 ofs += secl isec += 1 end end def dumpgrib line case line[3] when 1 then dumpgrib1(line) #when 2 then dumpgrib2 else raise "unsupported grib edition #{line[3]}" end end def dumpfile fnam File.open(fnam, 'rb') {|fp| fp.binmode fp.each('GRIB') {|line| next unless /7777/ === line dumpgrib line } } end for file in ARGV dumpfile file end