Struct grib::SubMessage
source · pub struct SubMessage<'a, R>(pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub Option<SubMessageSection<'a>>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, _);
Tuple Fields§
§0: SubMessageSection<'a>
§1: SubMessageSection<'a>
§2: Option<SubMessageSection<'a>>
§3: SubMessageSection<'a>
§4: SubMessageSection<'a>
§5: SubMessageSection<'a>
§6: SubMessageSection<'a>
§7: SubMessageSection<'a>
§8: SubMessageSection<'a>
Implementations§
source§impl<R> SubMessage<'_, R>
impl<R> SubMessage<'_, R>
sourcepub fn parameter(&self) -> Option<Parameter>
pub fn parameter(&self) -> Option<Parameter>
Returns the product’s parameter.
In the context of GRIB products, parameters refer to weather elements such as air temperature, air pressure, and humidity, and other physical quantities.
§Examples
use std::{
fs::File,
io::{BufReader, Read},
};
use grib::codetables::NCEP;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut buf = Vec::new();
let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
let f = BufReader::new(f);
let mut f = xz2::bufread::XzDecoder::new(f);
f.read_to_end(&mut buf)?;
let f = std::io::Cursor::new(buf);
let grib2 = grib::from_reader(f)?;
let mut iter = grib2.iter();
let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;
let param = message.parameter();
assert_eq!(
param,
Some(grib::Parameter {
discipline: 0,
centre: 7,
master_ver: 2,
local_ver: 1,
category: 3,
num: 1
})
);
let param = param.unwrap();
assert_eq!(
param.description(),
Some("Pressure reduced to MSL".to_owned())
);
assert!(param.is_identical_to(NCEP::PRMSL));
Ok(())
}
pub fn indicator(&self) -> &Indicator
pub fn grid_def(&self) -> &GridDefinition
pub fn prod_def(&self) -> &ProdDefinition
pub fn repr_def(&self) -> &ReprDefinition
pub fn describe(&self) -> String
sourcepub fn grid_shape(&self) -> Result<(usize, usize), GribError>
pub fn grid_shape(&self) -> Result<(usize, usize), GribError>
Returns the shape of the grid, i.e. a tuple of the number of grids in the i and j directions.
§Examples
use std::{
fs::File,
io::{BufReader, Read},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut buf = Vec::new();
let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
let f = BufReader::new(f);
let mut f = xz2::bufread::XzDecoder::new(f);
f.read_to_end(&mut buf)?;
let f = std::io::Cursor::new(buf);
let grib2 = grib::from_reader(f)?;
let mut iter = grib2.iter();
let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;
let shape = message.grid_shape()?;
assert_eq!(shape, (1440, 721));
Ok(())
}
sourcepub fn ij(&self) -> Result<GridPointIndexIterator, GribError>
pub fn ij(&self) -> Result<GridPointIndexIterator, GribError>
Computes and returns an iterator over (i, j)
of grid points.
The order of items is the same as the order of the grid point values,
defined by the scanning mode (ScanningMode
)
in the data.
This iterator allows users to perform their own coordinate calculations for unsupported grid systems and map the results to grid point values.
§Examples
use std::{
fs::File,
io::{BufReader, Read},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut buf = Vec::new();
let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
let f = BufReader::new(f);
let mut f = xz2::bufread::XzDecoder::new(f);
f.read_to_end(&mut buf)?;
let f = std::io::Cursor::new(buf);
let grib2 = grib::from_reader(f)?;
let mut iter = grib2.iter();
let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;
let mut latlons = message.ij()?;
assert_eq!(latlons.next(), Some((0, 0)));
assert_eq!(latlons.next(), Some((1, 0)));
Ok(())
}
sourcepub fn latlons(&self) -> Result<GridPointIterator, GribError>
pub fn latlons(&self) -> Result<GridPointIterator, GribError>
Computes and returns an iterator over latitudes and longitudes of grid points.
The order of lat/lon data of grid points is the same as the order of the
grid point values, defined by the scanning mode
(ScanningMode
) in the data.
§Examples
use std::{
fs::File,
io::{BufReader, Read},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut buf = Vec::new();
let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
let f = BufReader::new(f);
let mut f = xz2::bufread::XzDecoder::new(f);
f.read_to_end(&mut buf)?;
let f = std::io::Cursor::new(buf);
let grib2 = grib::from_reader(f)?;
let mut iter = grib2.iter();
let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;
let mut latlons = message.latlons()?;
assert_eq!(latlons.next(), Some((90.0, 0.0)));
assert_eq!(latlons.next(), Some((90.0, 0.25000003)));
Ok(())
}