grib/def/
grib2.rs

1//! Definitions of parameters contained in GRIB2 data.
2
3use grib_template_derive::{Dump, TryFromSlice};
4
5#[derive(Debug, PartialEq, TryFromSlice, Dump)]
6pub struct Section<T>
7where
8    T: PartialEq + grib_template_helpers::TryFromSlice + grib_template_helpers::Dump,
9{
10    pub header: SectionHeader,
11    pub payload: T,
12}
13
14#[derive(Debug, PartialEq, TryFromSlice, Dump)]
15pub struct SectionHeader {
16    /// Length of section in octets (nn).
17    pub len: u32,
18    /// Number of section.
19    pub sect_num: u8,
20}
21
22pub type Section1 = Section<Section1Payload>;
23
24#[derive(Debug, PartialEq, TryFromSlice, Dump)]
25pub struct Section1Payload {
26    /// Identification of originating/generating centre (see Common Code table
27    /// C–11).
28    pub centre_id: u16,
29    /// Identification of originating/generating subcentre (allocated by
30    /// originating/generating centre).
31    pub subcentre_id: u16,
32    /// GRIB master table version number (see Common Code table C–0 and Note 1).
33    pub master_table_version: u8,
34    /// Version number of GRIB Local tables used to augment Master tables (see
35    /// Code table 1.1 and Note 2).
36    pub local_table_version: u8,
37    /// Significance of reference time (see Code table 1.2).
38    pub ref_time_significance: u8,
39    /// Reference time of data.
40    pub ref_time: RefTime,
41    /// Production status of processed data in this GRIB message (see Code table
42    /// 1.3).
43    pub prod_status: u8,
44    /// Type of processed data in this GRIB message (see Code table 1.4).
45    pub data_type: u8,
46    pub optional: Option<Section1PayloadOptional>,
47}
48
49#[derive(Debug, PartialEq, TryFromSlice, Dump)]
50pub struct RefTime {
51    /// Year (4 digits).
52    pub year: u16,
53    /// Month.
54    pub month: u8,
55    /// Day.
56    pub day: u8,
57    /// Hour.
58    pub hour: u8,
59    /// Minute.
60    pub minute: u8,
61    /// Second.
62    pub second: u8,
63}
64
65#[derive(Debug, PartialEq, TryFromSlice, Dump)]
66pub struct Section1PayloadOptional {
67    /// Identification template number (optional, see Code table 1.5).
68    pub template_num: u16,
69    /// Identification template (optional, see template 1.X, where X is the
70    /// identification template number given in octets 22–23).
71    #[grib_template(variant = "template_num")]
72    pub template: IdentificationTemplate,
73}
74
75#[derive(Debug, PartialEq, TryFromSlice, Dump)]
76#[repr(u16)]
77pub enum IdentificationTemplate {
78    _1_0(template1::Template1_0) = 0,
79    _1_1(template1::Template1_1) = 1,
80    _1_2(template1::Template1_2) = 2,
81}
82
83pub type Section5 = Section<Section5Payload>;
84
85#[derive(Debug, PartialEq, TryFromSlice, Dump)]
86pub struct Section5Payload {
87    /// Number of data points where one or more values are specified in Section
88    /// 7 when a bit map is present, total number of data points when a bit map
89    /// is absent.
90    pub num_encoded_points: u32,
91    /// Data representation template number (see Code table 5.0).
92    pub template_num: u16,
93    /// Data representation template (see template 5.X, where X is the data
94    /// representation template number given in octets 10–11).
95    #[grib_template(variant = "template_num")]
96    pub template: DataRepresentationTemplate,
97}
98
99#[derive(Debug, PartialEq, TryFromSlice, Dump)]
100#[repr(u16)]
101pub enum DataRepresentationTemplate {
102    _5_0(template5::Template5_0) = 0,
103    _5_1(template5::Template5_1) = 1,
104    _5_2(template5::Template5_2) = 2,
105    _5_3(template5::Template5_3) = 3,
106    _5_4(template5::Template5_4) = 4,
107    _5_40(template5::Template5_40) = 40,
108    _5_41(template5::Template5_41) = 41,
109    _5_42(template5::Template5_42) = 42,
110    _5_50(template5::Template5_50) = 50,
111    _5_51(template5::Template5_51) = 51,
112    _5_53(template5::Template5_53) = 53,
113    _5_61(template5::Template5_61) = 61,
114    _5_200(template5::Template5_200) = 200,
115}
116
117pub mod template {
118    //! GRIB2 template definitions.
119
120    pub use super::{template1::*, template5::*};
121}
122
123mod template1;
124mod template5;