NOAA-MDL / grib2io

Python interface to the NCEP G2C Library for reading and writing GRIB2 messages.

Home Page:https://noaa-mdl.github.io/grib2io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow for a 0th GRIB2 message

EricEngle-NOAA opened this issue · comments

grib2io is the successor to ncepgrib2 which was developed alongside pygrib and therefore takes on the pygrib convention that there is no 0th GRIB2 message. As we refactor grib2io for v2.0, we should allow a 0th GRIB2 message.

Python (and C) indexing begins at 0, so when reading a file we read in units of bytes, starting at 0. In grib2io, we will use that same idea for reading from files in units of GRIB2 messages.

GOAL:

g = grib2io.open(<file>)
g.seek(0) # Puts the file pointer at the beginning of the file
g.read(1) # Reads the first message (i.e. the 0th message)
g.tell() # Should return 1
msg = g[0] # msg is the first message on the file

This is done and working as expected.