Struct eccodes::codes_handle::KeyedMessage [−][src]
pub struct KeyedMessage { /* fields omitted */ }
Expand description
Structure used to access keys inside the GRIB file message. All data (including data values) contained by the file can only be accessed through the message and keys.
The structure implements Clone
trait which comes with a memory overhead.
You should take care that your system has enough memory before cloning KeyedMessage
.
Keys inside the message can be accessed directly with read_key()
function or using FallibleIterator
.
The function find_nearest()
allows to get the values of four nearest gridpoints
to requested coordinates.
FallibleIterator
parameters can be set with set_iterator_parameters()
to specify the subset of keys to iterate over.
Implementations
Method to get a Key
with provided name from the KeyedMessage
.
This function takes a key name and returns the key value as Key
if requested key exists. Check the Key
documentation for details
of possible key types.
Example
let file_path = Path::new("./data/iceland.grib");
let product_kind = ProductKind::GRIB;
let mut handle = CodesHandle::new_from_file(file_path, product_kind).unwrap();
let message = handle.next().unwrap().unwrap();
let message_short_name = message.read_key("shortName").unwrap();
assert_eq!(message_short_name.value, Str("msl".to_string()));
This function will try to retrieve the key of native string type as string even when the nul byte is not positioned at the end of key value.
If retrieving the key value in native type fails this function will try to read the requested key as bytes.
Errors
Returns CodesInternal::CodesNotFound
wrapped in CodesError::Internal
when a key of given name has not been found in the message.
Returns CodesError::MissingKey
when a given key has a missing type.
Returns CodesError::Internal
when one of internal ecCodes functions to read the key fails.
Returns CodesError::CstrUTF8
and CodesError::NulChar
when the string returned by ecCodes
library cannot be parsed as valid UTF8 Rust string.
Panics
Panics when the size of given key is lower than 1. This indicates corrupted data file, bug in the crate or bug in the ecCodes library. If you encounter this panic please check if your file is correct and report it on Github.
Function that allows to set the flags and namespace for FallibleIterator
.
Must be called before calling the iterator. Changing the parameters
after first call of next()
will have no effect on the iterator.
The flags are set by providing any combination of KeysIteratorFlags
inside a vector. Check the documentation for the details of each flag meaning.
Namespace is set simply as string, eg. "ls"
, "time"
, "parameter"
, "geography"
, "statistics"
.
Invalid namespace will result in empty iterator.
Default parameters are AllKeys
flag and ""
namespace,
which implies iteration over all keys available in the message.
Example
let file_path = Path::new("./data/iceland.grib");
let product_kind = ProductKind::GRIB;
let mut handle = CodesHandle::new_from_file(file_path, product_kind).unwrap();
let mut current_message = handle.next().unwrap().unwrap();
let flags = vec![
KeysIteratorFlags::AllKeys,
KeysIteratorFlags::SkipOptional,
KeysIteratorFlags::SkipReadOnly,
KeysIteratorFlags::SkipDuplicates,
];
let namespace = "geography".to_owned();
current_message.set_iterator_parameters(flags, namespace);
while let Some(key) = current_message.next().unwrap() {
println!("{:?}", key);
}
pub fn find_nearest(
&mut self,
lat: f64,
lon: f64
) -> Result<[NearestGridpoint; 4], CodesError>
pub fn find_nearest(
&mut self,
lat: f64,
lon: f64
) -> Result<[NearestGridpoint; 4], CodesError>
Function to get four NearestGridpoint
s of a point represented by requested coordinates.
The inputs are latitude and longitude of requested point in respectively degrees north and degreed east.
In the output gridpoints, the value field refers to parameter held by the KeyedMessage
for which the function is called in adequate units,
coordinates are in degrees north/east,
and distance field represents the distance between requested point and output point in kilometers.
Example
let file_path = Path::new("./data/iceland.grib");
let product_kind = ProductKind::GRIB;
let mut handle = CodesHandle::new_from_file(file_path, product_kind).unwrap();
let mut msg = handle.next().unwrap().unwrap();
let out = msg.find_nearest(64.13, -21.89).unwrap();
Errors
This function returns CodesInternal
when
one of ecCodes function returns the non-zero code.
Trait Implementations
Custom function to clone the KeyedMessage
. This function comes with memory overhead.
During clone iterator flags and namespace are not copied, and the iterator is reset.
Performs copy-assignment from source
. Read more
Executes the destructor for this type.
This method calls codes_handle_delete()
, codes_keys_iterator_delete()
codes_grib_nearest_delete()
from ecCodes for graceful cleanup.
However in some edge cases ecCodes can return non-zero code.
In such case all pointers and file descriptors are safely deleted.
However memory leaks can still occur.
If any function called in the destructor returns an error warning will appear in log.
If bugs occurs during CodesHandle
drop please enable log output and post issue on Github.
Technical note: delete functions in ecCodes can only fail with CodesInternalError
when other functions corrupt the inner memory of pointer, in that case memory leak is possible.
In case of corrupt pointer segmentation fault will occur.
The pointers are cleared at the end of drop as they ar not not functional despite the result of delete functions.
FallibleIterator
implementation for KeyedMessage to access keyes inside message.
Mainly useful to discover what keys are present inside the message.
This function internally calls read_key()
function
so it is probably more efficient to call that function directly only for keys you
are interested in.
FallibleIterator
is used instead of classic Iterator
because internal ecCodes functions can return internal error in some edge-cases.
The usage of FallibleIterator
is sligthly different than usage of Iterator
,
check its documentation for more details.
Example
let file_path = Path::new("./data/iceland.grib");
let product_kind = ProductKind::GRIB;
let mut handle = CodesHandle::new_from_file(file_path, product_kind).unwrap();
let mut current_message = handle.next().unwrap().unwrap();
while let Some(key) = current_message.next().unwrap() {
println!("{:?}", key);
}
Errors
The next()
method will return CodesInternal
when internal ecCodes function returns non-zero code.
type Error = CodesError
type Error = CodesError
The error type.
Advances the iterator and returns the next value. Read more
Returns bounds on the remaining length of the iterator. Read more
Consumes the iterator, returning the number of remaining items.
Returns the last element of the iterator.
Returns the n
th element of the iterator.
Returns an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
Returns an iterator which yields the elements of this iterator followed by another. Read more
fn zip<I>(
self,
o: I
) -> Zip<Self, <I as IntoFallibleIterator>::IntoFallibleIter> where
I: IntoFallibleIterator<Error = Self::Error>,
fn zip<I>(
self,
o: I
) -> Zip<Self, <I as IntoFallibleIterator>::IntoFallibleIter> where
I: IntoFallibleIterator<Error = Self::Error>,
Returns an iterator that yields pairs of this iterator’s and another iterator’s values. Read more
Returns an iterator which applies a fallible transform to the elements of the underlying iterator. Read more
Calls a fallible closure on each element of an iterator.
Returns an iterator which uses a predicate to determine which values should be yielded. The predicate may fail; such failures are passed to the caller. Read more
Returns an iterator which both filters and maps. The closure may fail; such failures are passed along to the consumer. Read more
Returns an iterator which yields the current iteration count as well as the value. Read more
Returns an iterator that can peek at the next element without consuming it. Read more
Returns an iterator that skips elements based on a predicate.
Returns an iterator that yields elements based on a predicate.
Returns an iterator which skips the first n
values of this iterator.
Returns an iterator that yields only the first n
values of this
iterator. Read more
Returns an iterator which applies a stateful map to values of this iterator. Read more
Returns an iterator which maps this iterator’s elements to iterators, yielding those iterators’ values.
fn flatten(self) -> Flatten<Self> where
Self::Item: IntoFallibleIterator,
<Self::Item as IntoFallibleIterator>::Error == Self::Error,
fn flatten(self) -> Flatten<Self> where
Self::Item: IntoFallibleIterator,
<Self::Item as IntoFallibleIterator>::Error == Self::Error,
Returns an iterator which flattens an iterator of iterators, yielding those iterators’ values.
Returns an iterator which yields this iterator’s elements and ends after
the first Ok(None)
. Read more
Returns an iterator which passes each element to a closure before returning it.
Transforms the iterator into a collection. Read more
Transforms the iterator into two collections, partitioning elements by a closure.
Applies a function over the elements of the iterator, producing a single final value. Read more
Applies a function over the elements of the iterator, producing a single final value. Read more
Determines if all elements of this iterator match a predicate.
Determines if any element of this iterator matches a predicate.
Returns the first element of the iterator that matches a predicate.
Applies a function to the elements of the iterator, returning the first non-None
result.
Returns the position of the first element of this iterator that matches a predicate. The predicate may fail; such failures are returned to the caller. Read more
Returns the maximal element of the iterator.
Returns the element of the iterator which gives the maximum value from the function. Read more
Returns the element that gives the maximum value with respect to the function.
Returns the minimal element of the iterator.
Returns the element of the iterator which gives the minimum value from the function. Read more
Returns the element that gives the minimum value with respect to the function.
Returns an iterator that yields this iterator’s items in the opposite order. Read more
Converts an iterator of pairs into a pair of containers.
Returns an iterator which clones all of its elements.
Returns an iterator which repeas this iterator endlessly.
Lexicographically compares the elements of this iterator to that of another. Read more
fn partial_cmp<I>(self, other: I) -> Result<Option<Ordering>, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn partial_cmp<I>(self, other: I) -> Result<Option<Ordering>, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
Lexicographically compares the elements of this iterator to that of another. Read more
Determines if the elements of this iterator are equal to those of another. Read more
Determines if the elements of this iterator are not equal to those of another. Read more
fn lt<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn lt<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
Determines if the elements of this iterator are lexicographically less than those of another. Read more
fn le<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn le<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
Determines if the elements of this iterator are lexicographically less than or equal to those of another. Read more
fn gt<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn gt<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
Determines if the elements of this iterator are lexicographically greater than those of another. Read more
fn ge<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
fn ge<I>(self, other: I) -> Result<bool, Self::Error> where
I: IntoFallibleIterator<Error = Self::Error>,
Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,
Determines if the elements of this iterator are lexicographically greater than or equal to those of another. Read more
Returns a normal (non-fallible) iterator over Result<Item, Error>
.
Auto Trait Implementations
impl RefUnwindSafe for KeyedMessage
impl !Send for KeyedMessage
impl !Sync for KeyedMessage
impl Unpin for KeyedMessage
impl UnwindSafe for KeyedMessage
Blanket Implementations
Mutably borrows from an owned value. Read more
type Item = <I as FallibleIterator>::Item
type Item = <I as FallibleIterator>::Item
The elements of the iterator.
type Error = <I as FallibleIterator>::Error
type Error = <I as FallibleIterator>::Error
The error value of the iterator.
type IntoFallibleIter = I
type IntoFallibleIter = I
The iterator.
Creates a fallible iterator from a value.