gistools/readers/grib2/sections/_7/
tables.rs

1#![cfg_attr(feature = "nightly", coverage(off))]
2
3/// # Table 7.0 - DATA TEMPLATE DEFINITIONS USED IN SECTION 7
4///
5/// **Details**:
6/// - **Section**: 3
7/// - **Octet**: 64
8/// - **Applicable Grid Templates**: 1000
9///
10/// **Reserved Ranges**:
11/// - `5-39`: Reserved
12/// - `43-49`: Reserved
13/// - `52`: Reserved
14/// - `54-49151`: Reserved
15/// - `49152-65534`: Reserved for Local Use
16///
17/// **Special Value**:
18/// - `255`: Missing
19///
20/// ## Description
21/// This table defines the data template definitions used in Section 7 of GRIB2 files,
22/// specifying various data representation types and their corresponding templates.
23///
24/// ## Links
25/// - [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table7-0.shtml)
26///
27/// ## Notes
28/// - Created 05/11/2005
29/// - Red text depicts changes made since 05/11/2005.
30#[repr(u16)]
31#[allow(missing_docs)]
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub enum Grib2Table7_0 {
34    GridPointDataSimplePacking = 0,
35    MatrixValueAtGridPointSimplePacking = 1,
36    GridPointDataComplexPacking = 2,
37    GridPointDataComplexPackingAndSpatialDifferencing = 3,
38    GridPointDataIeeeFloatingPointData = 4,
39    GridPointDataJpeg2000Compression = 40,
40    GridPointDataPortableNetworkGraphicsPngFormat = 41,
41    GridPointAndSpectralDataCcsdsRecommendedLosslessCompression = 42,
42    SpectralDataSimplePacking = 50,
43    SpectralDataComplexPacking = 51,
44    SpectralDataForLimitedAreaModelsComplexPacking = 53,
45    Missing = 255, /* Note: The original JS has 255 as Missing, but the reserved range goes higher. */
46    Unknown(u16),
47}
48
49impl From<u16> for Grib2Table7_0 {
50    fn from(val: u16) -> Self {
51        match val {
52            0 => Self::GridPointDataSimplePacking,
53            1 => Self::MatrixValueAtGridPointSimplePacking,
54            2 => Self::GridPointDataComplexPacking,
55            3 => Self::GridPointDataComplexPackingAndSpatialDifferencing,
56            4 => Self::GridPointDataIeeeFloatingPointData,
57            40 => Self::GridPointDataJpeg2000Compression,
58            41 => Self::GridPointDataPortableNetworkGraphicsPngFormat,
59            42 => Self::GridPointAndSpectralDataCcsdsRecommendedLosslessCompression,
60            50 => Self::SpectralDataSimplePacking,
61            51 => Self::SpectralDataComplexPacking,
62            53 => Self::SpectralDataForLimitedAreaModelsComplexPacking,
63            255 => Self::Missing,
64            other => Self::Unknown(other),
65        }
66    }
67}
68impl core::fmt::Display for Grib2Table7_0 {
69    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
70        let desc = match self {
71            Self::GridPointDataSimplePacking => {
72                "Grid Point Data - Simple Packing (see Template 7.0)"
73            }
74            Self::MatrixValueAtGridPointSimplePacking => {
75                "Matrix Value at Grid Point - Simple Packing (see Template 7.1)"
76            }
77            Self::GridPointDataComplexPacking => {
78                "Grid Point Data - Complex Packing (see Template 7.2)"
79            }
80            Self::GridPointDataComplexPackingAndSpatialDifferencing => {
81                "Grid Point Data - Complex Packing and Spatial Differencing (see Template 7.3)"
82            }
83            Self::GridPointDataIeeeFloatingPointData => {
84                "Grid Point Data - IEEE Floating Point Data (see Template 7.4)"
85            }
86            Self::GridPointDataJpeg2000Compression => {
87                "Grid Point Data - JPEG2000 Compression (see Template 7.40)"
88            }
89            Self::GridPointDataPortableNetworkGraphicsPngFormat => {
90                "Grid Point Data - Portable Network Graphics (PNG) format (see Template 7.41)"
91            }
92            Self::GridPointAndSpectralDataCcsdsRecommendedLosslessCompression => {
93                "Grid Point and Spectral data - CCSDS recommended lossless compression (see \
94                 Template 7.42)"
95            }
96            Self::SpectralDataSimplePacking => "Spectral Data - Simple Packing (see Template 7.50)",
97            Self::SpectralDataComplexPacking => {
98                "Spectral Data - Complex Packing (see Template 7.51)"
99            }
100            Self::SpectralDataForLimitedAreaModelsComplexPacking => {
101                "Spectral Data for limited area models - Complex Packing (see Template 7.53)"
102            }
103            Self::Missing => "Missing",
104            Self::Unknown(v) => return write!(f, "Unknown Data Template Definition ({v})"),
105        };
106        f.write_str(desc)
107    }
108}