gistools/readers/grib2/sections/_1/mod.rs
1mod tables;
2
3use crate::{
4 parsers::Reader,
5 readers::{_0::Grib2Table0, other::Grib2TableC},
6 util::Date,
7};
8pub use tables::*;
9use tables::{
10 Grib2Table1_0 as MasterTablesVersion, Grib2Table1_1 as LocalTablesVersion,
11 Grib2Table1_2 as SignificanceOfRT, Grib2Table1_3 as ProductionStatus,
12 Grib2Table1_4 as TypeOfProcessedData,
13};
14
15/// # Identification Section
16///
17/// ## Notes
18/// - 1. Local tables define those parts of the master table which are reserved for local use except for the case described below. In any case, the use of local tables in the messages are intended for non-local or international exchange is strongly discouraged.
19/// - 2. If octet 10 is set to 255 then only local tables are in use. In this case, the local table version number (octet 11) must not be zero nor missing. Local tables may include entries from the entire range of the tables.
20/// - 3. If octet 11 is zero, octet 10 must contain a valid master table version number and only those parts of the tables not reserved for local use may be used.
21/// - 4. If octets 8-9 is zero, Not a sub-center, the originating/generating center is the center defined by octets 6-7.
22///
23/// ## Links
24/// - [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect1.shtml)
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct Grib2IdentificationSection {
27 /// Number of GRIB section
28 pub section_number: u8,
29 /// Length of GRIB section
30 pub length: u32,
31 /// Identification of originating/generating center [Table 0](https://www.nco.ncep.noaa.gov/pmb/docs/on388/table0.html)
32 pub center: Grib2Table0,
33 /// Identification of originating/generating subcenter [Table C](https://www.nco.ncep.noaa.gov/pmb/docs/on388/tablec.html)
34 pub subcenter: Grib2TableC,
35 /// GRIB master tables version number [Table 1.0](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-0.shtml)
36 pub grib_master_tables_version: MasterTablesVersion,
37 /// Version number of GRIB local tables used to augment Master Tables [Table 1.1](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-1.shtml)
38 pub grib_local_tables_version: LocalTablesVersion,
39 /// Significance of reference time [Table 1.2](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-2.shtml)
40 pub significance_of_rt: SignificanceOfRT,
41 /// Reference Time
42 pub ref_time: Date,
43 /// Production Status of Processed data in the GRIB message [Table 1.3](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-3.shtml)
44 pub production_status: ProductionStatus,
45 /// Type of processed data in this GRIB message [Table 1.4](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-4.shtml)
46 pub type_of_processed_data: TypeOfProcessedData,
47}
48impl Grib2IdentificationSection {
49 /// Create a new Grib2IdentificationSection
50 ///
51 /// ## Parameters
52 /// - `section`: The byte block to pull ideintification information
53 ///
54 /// ## Returns
55 /// The parsed identification section
56 pub fn new<T: Reader>(section: &T) -> Grib2IdentificationSection {
57 let center = section.uint16_be(Some(5)) as u8;
58 let subcenter = section.uint16_be(Some(7)) as u8;
59 let grib_master_tables_version = section.uint8(Some(9)); // should be 2
60 let grib_local_tables_version = section.uint8(Some(10));
61 let significance_of_rt = section.uint8(Some(11));
62 let year = section.uint16_be(Some(12));
63 let month = section.uint8(Some(14));
64 let day = section.uint8(Some(15));
65 let hours = section.uint8(Some(16));
66 let minutes = section.uint8(Some(17));
67 let seconds = section.uint8(Some(18));
68 let production_status = section.uint8(Some(19));
69 let type_of_processed_data = section.uint8(Some(20));
70
71 let ref_time = Date::new_full(year, month, day, hours, minutes, seconds);
72
73 if grib_master_tables_version != 2 {
74 panic!("Invalid grib_master_tables_version: {}", grib_master_tables_version);
75 }
76
77 Grib2IdentificationSection {
78 section_number: section.uint8(Some(4)),
79 length: section.uint32_be(Some(0)),
80 center: center.into(),
81 subcenter: subcenter.into(),
82 grib_master_tables_version: grib_master_tables_version.into(),
83 grib_local_tables_version: grib_local_tables_version.into(),
84 significance_of_rt: significance_of_rt.into(),
85 ref_time,
86 production_status: production_status.into(),
87 type_of_processed_data: type_of_processed_data.into(),
88 }
89 }
90}