Skip to main content

grib/def/grib2/
template4.rs

1use grib_template_derive::{Dump, TryFromSlice, WriteToBuffer};
2
3/// Product definition template 4.0 - Analysis or forecast at a horizontal level
4/// or in a horizontal layer at a point in time.
5#[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
6pub struct Template4_0 {
7    pub param: param_set::ProductParam,
8    pub generating_process: param_set::GeneratingProcess,
9    #[dump(doc(
10        cutoff_hours = "Hours of observational data cutoff after reference time (see Note 1)",
11        cutoff_minutes = "Minutes of observational data cutoff after reference time",
12    ))]
13    pub forecast_time: param_set::ForecastTime,
14    pub horizontal: param_set::Horizontal,
15}
16
17/// Product definition template 4.1 - Individual ensemble forecast, control and
18/// perturbed, at a horizontal level or in a horizontal layer at a point in
19/// time.
20#[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
21pub struct Template4_1 {
22    pub param: param_set::ProductParam,
23    #[dump(doc(
24        process_id = "Forecast generating process identifier (defined by originating centre).",
25    ))]
26    pub generating_process: param_set::GeneratingProcess,
27    pub forecast_time: param_set::ForecastTime,
28    pub horizontal: param_set::Horizontal,
29    pub emsemble_forecast: param_set::EnsembleForecast,
30}
31
32/// Product definition template 4.2 - Derived forecast based on all ensemble
33/// members at a horizontal level or in a horizontal layer at a point in time.
34#[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
35pub struct Template4_2 {
36    pub param: param_set::ProductParam,
37    #[dump(doc(
38        process_id = "Forecast generating process identifier (defined by originating centre).",
39    ))]
40    pub generating_process: param_set::GeneratingProcess,
41    pub forecast_time: param_set::ForecastTime,
42    pub horizontal: param_set::Horizontal,
43    pub derived_forecast: param_set::DerivedForecast,
44}
45
46/// Product definition template 4.5 - Probability forecasts at a horizontal
47/// level or in a horizontal layer at a point in time.
48#[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
49pub struct Template4_5 {
50    pub param: param_set::ProductParam,
51    #[dump(doc(
52        process_id = "Forecast generating process identifier (defined by originating centre).",
53    ))]
54    pub generating_process: param_set::GeneratingProcess,
55    pub forecast_time: param_set::ForecastTime,
56    pub horizontal: param_set::Horizontal,
57    pub probability_forecasts: param_set::ProbabilityForecasts,
58}
59
60/// Product definition template 4.6 - Percentile forecasts at a horizontal level
61/// or in a horizontal layer at a point in time.
62#[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
63pub struct Template4_6 {
64    pub param: param_set::ProductParam,
65    pub generating_process: param_set::GeneratingProcess,
66    pub forecast_time: param_set::ForecastTime,
67    pub horizontal: param_set::Horizontal,
68    pub percentile_forecasts: param_set::PercentileForecasts,
69}
70
71pub(crate) mod param_set {
72    use grib_template_derive::{Dump, TryFromSlice, WriteToBuffer};
73
74    use super::super::template::param_set::{ScaledValue, TimeRange};
75
76    #[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
77    pub struct ProductParam {
78        /// Parameter category (see Code Table 4.1).
79        pub category: u8,
80        /// Parameter number (see Code Table 4.2).
81        pub num: u8,
82    }
83
84    #[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
85    pub struct GeneratingProcess {
86        /// Type of generating process (see Code Table 4.3).
87        pub process_type: u8,
88        /// Background generating process identifier (defined by originating
89        /// centre).
90        pub background_process: u8,
91        /// Analysis or forecast generating processes identifier (defined by
92        /// originating centre).
93        pub process_id: u8,
94    }
95
96    #[derive(Debug, PartialEq, Clone, TryFromSlice, WriteToBuffer, Dump)]
97    pub struct ForecastTime {
98        /// Hours after reference time of data cutoff (see Note 1).
99        pub cutoff_hours: u16,
100        /// Minutes after reference time of data cutoff.
101        pub cutoff_minutes: u8,
102        /// Forecast time.
103        #[dump(doc(
104            unit = "Indicator of unit of time range (see Code Table 4.4).",
105            len = "Forecast time in units defined by octet 18.",
106        ))]
107        pub time: TimeRange<i32>,
108    }
109
110    #[derive(Debug, PartialEq, Eq, Clone, TryFromSlice, WriteToBuffer, Dump)]
111    pub struct Horizontal {
112        #[dump(doc(
113            surface_type = "Type of first fixed surface (see Code Table 4.5).",
114            value(
115                scale_factor = "Scale factor of first fixed surface.",
116                scaled_value = "Scaled value of first fixed surface.",
117            ),
118        ))]
119        pub first_surface: FixedSurface,
120        #[dump(doc(
121            surface_type = "Type of second fixed surface (see Code Table 4.5).",
122            value(
123                scale_factor = "Scale factor of second fixed surface.",
124                scaled_value = "Scaled value of second fixed surface.",
125            ),
126        ))]
127        pub second_surface: FixedSurface,
128    }
129
130    #[derive(Debug, PartialEq, Eq, Clone, TryFromSlice, WriteToBuffer, Dump)]
131    pub struct FixedSurface {
132        /// Type of fixed surface (see Code Table 4.5).
133        pub surface_type: u8,
134        /// Scaled value of fixed surface.
135        pub value: ScaledValue<i8, i32>,
136    }
137
138    #[derive(Debug, PartialEq, Eq, Clone, TryFromSlice, WriteToBuffer, Dump)]
139    pub struct EnsembleForecast {
140        /// Type of ensemble forecast (see Code Table 4.6).
141        pub ensemble_forecast_type: u8,
142        ///  Perturbation number.
143        pub perturbation_num: u8,
144        /// Number of forecasts in ensemble.
145        pub num_forecasts: u8,
146    }
147
148    #[derive(Debug, PartialEq, Eq, Clone, TryFromSlice, WriteToBuffer, Dump)]
149    pub struct DerivedForecast {
150        /// Derived forecast (see Code Table 4.7).
151        pub derived_forecast_type: u8,
152        /// Number of forecasts in ensemble.
153        pub num_forecasts: u8,
154    }
155
156    #[derive(Debug, PartialEq, Eq, Clone, TryFromSlice, WriteToBuffer, Dump)]
157    pub struct ProbabilityForecasts {
158        /// Forecast probability number.
159        pub forecast_probability_num: u8,
160        /// Total number of forecast probabilities.
161        pub total_num_forecast_probabilities: u8,
162        /// Probability type (see Code Table 4.9).
163        pub probability_type: u8,
164        /// Lower limit.
165        #[dump(doc(
166            scale_factor = "Scale factor of lower limit.",
167            scaled_value = "Scaled value of lower limit.",
168        ))]
169        pub lower_limit: ScaledValue<i8, i32>,
170        /// Upper limit.
171        #[dump(doc(
172            scale_factor = "Scale factor of upper limit.",
173            scaled_value = "Scaled value of upper limit.",
174        ))]
175        pub upper_limit: ScaledValue<i8, i32>,
176    }
177
178    #[derive(Debug, PartialEq, Eq, Clone, TryFromSlice, WriteToBuffer, Dump)]
179    pub struct PercentileForecasts {
180        /// Percentile value (from 100% to 0%).
181        pub percentile_value: u8,
182    }
183}