gistools/readers/grib2/sections/_3/
mod.rs

1mod tables;
2mod templates;
3
4pub use tables::*;
5pub use templates::*;
6
7use crate::parsers::Reader;
8
9// import { getGrib2Template3 } from './templates.js';
10// import { grib2LookupTable31 } from './tables.js';
11
12/// # SECTION 3 - GRID DEFINITION SECTION
13///
14/// ## Links
15/// - [Docs](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml)
16#[derive(Debug, Clone, PartialEq)]
17pub struct GridDefinitionSection {
18    /// Number of GRIB section
19    pub section_number: u8,
20    /// Length of GRIB section
21    pub length: u32,
22    /// Source of grid definition
23    pub definition_source: u8,
24    /// Number of data points
25    pub number_of_points: u32,
26    /// Number of octets for optional list of numbers defining number of points
27    pub number_of_octets: u8,
28    /// Interpetation of list of numbers defining number of points [Table 3.11](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-11.shtml)
29    pub interpretation: u8,
30    /// Grid definition template number [Table 3.1](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-1.shtml)
31    pub grid_definition_template: Grib2Table3_1,
32    /// Grid definition values
33    pub values: Grib2Template3,
34}
35impl GridDefinitionSection {
36    /// Create a new instance of GridDefinitionSection
37    ///
38    /// ## Parameters
39    /// - `section`: byte block for section 3
40    ///
41    /// ## Returns
42    /// Parsed grid definition
43    pub fn new<T: Reader>(section: &T) -> Self {
44        let grid_definition_template: Grib2Table3_1 = section.uint16_be(Some(12)).into();
45        Self {
46            section_number: section.uint8(Some(4)),
47            length: section.uint32_be(Some(0)),
48            definition_source: section.uint8(Some(5)),
49            number_of_points: section.uint32_be(Some(6)),
50            number_of_octets: section.uint8(Some(10)),
51            interpretation: section.uint8(Some(11)),
52            grid_definition_template,
53            values: Grib2Template3::new(grid_definition_template, section),
54        }
55    }
56}