NOAA-MDL / grib2io

Python interface to the NCEP G2C Library for reading and writing GRIB2 messages.
https://noaa-mdl.github.io/grib2io
MIT License
30 stars 11 forks source link

Allow for a 0th GRIB2 message #51

Closed EricEngle-NOAA closed 1 year ago

EricEngle-NOAA commented 1 year ago

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
EricEngle-NOAA commented 1 year ago

This is done and working as expected.