GribFile

A GribFile functions similarly to a Julia IOStream, except that instead of working as a stream of bytes, GribFile works as a stream of messages. Basic access looks like

GribFile(filename) do f
    # Do things with f
end

Using the do-block construct guarantees that the resources are released after exiting the do-block. The style

f = GribFile(filename)
# Do things with f
destroy(f)

is also valid, but be sure to call destroy when finished with the file.

A GribFile is an iterable, and it defines seek, skip, and seekfirst to aid in navigating the file.

API

GRIB.GribFileMethod
GribFile(filename::AbstractString, mode="rb")

Open a grib file. mode is a mode as described by Base.open.

GRIB.GribFileMethod
GribFile(f::Function, filename::AbstractString, mode="rb")

Open a grib file and automatically close after exucuting f. mode is a mode as described by Base.open.

Example

GribFile(filename) do f
    # do things in read mode
end
Base.readFunction
read(f::GribFile[, nm::Integer])

Read nm messages from f and return as vector. Default is 1.

Base.positionFunction
position(f::GribFile)

Get the current position of the file.

Base.seekFunction
seek(f::GribFile, n::Integer)

Seek the file to the given position n. Throws a DomainError if n is negative.

Base.skipFunction
skip(f::GribFile, offset::Integer)

Seek the file relative to the current position. Throws a DomainError if offset brings the file position to before the start of the file.

GRIB.destroyMethod
destroy(f::GribFile)

Safely close the file.