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.GribFile
— MethodGribFile(filename::AbstractString, mode="rb")
Open a grib file. mode
is a mode as described by Base.open
.
GRIB.GribFile
— MethodGribFile(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.read
— Functionread(f::GribFile[, nm::Integer])
Read nm
messages from f
and return as vector. Default is 1.
Base.position
— Functionposition(f::GribFile)
Get the current position of the file.
Base.seek
— Functionseek(f::GribFile, n::Integer)
Seek the file to the given position n
. Throws a DomainError
if n
is negative.
Base.skip
— Functionskip(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.destroy
— Methoddestroy(f::GribFile)
Safely close the file.