dmap/formats/
grid.rs

1//! The [Grid file format](https://radar-software-toolkit-rst.readthedocs.io/en/latest/references/general/grid/).
2
3use crate::record::create_record_type;
4use crate::types::{Fields, Type};
5use lazy_static::lazy_static;
6
7static SCALAR_FIELDS: [(&str, Type); 12] = [
8    ("start.year", Type::Short),
9    ("start.month", Type::Short),
10    ("start.day", Type::Short),
11    ("start.hour", Type::Short),
12    ("start.minute", Type::Short),
13    ("start.second", Type::Double),
14    ("end.year", Type::Short),
15    ("end.month", Type::Short),
16    ("end.day", Type::Short),
17    ("end.hour", Type::Short),
18    ("end.minute", Type::Short),
19    ("end.second", Type::Double),
20];
21
22static SCALAR_FIELDS_OPT: [(&str, Type); 0] = [];
23
24static VECTOR_FIELDS: [(&str, Type); 18] = [
25    ("stid", Type::Short),
26    ("channel", Type::Short),
27    ("nvec", Type::Short),
28    ("freq", Type::Float),
29    ("major.revision", Type::Short),
30    ("minor.revision", Type::Short),
31    ("program.id", Type::Short),
32    ("noise.mean", Type::Float),
33    ("noise.sd", Type::Float),
34    ("gsct", Type::Short),
35    ("v.min", Type::Float),
36    ("v.max", Type::Float),
37    ("p.min", Type::Float),
38    ("p.max", Type::Float),
39    ("w.min", Type::Float),
40    ("w.max", Type::Float),
41    ("ve.min", Type::Float),
42    ("ve.max", Type::Float),
43];
44
45static VECTOR_FIELDS_OPT: [(&str, Type); 13] = [
46    ("vector.mlat", Type::Float),
47    ("vector.mlon", Type::Float),
48    ("vector.kvect", Type::Float),
49    ("vector.stid", Type::Short),
50    ("vector.channel", Type::Short),
51    ("vector.index", Type::Int),
52    ("vector.vel.median", Type::Float),
53    ("vector.vel.sd", Type::Float),
54    ("vector.pwr.median", Type::Float),
55    ("vector.pwr.sd", Type::Float),
56    ("vector.wdt.median", Type::Float),
57    ("vector.wdt.sd", Type::Float),
58    ("vector.srng", Type::Float),
59];
60
61static DATA_FIELDS: [&str; 13] = [
62    "vector.mlat",
63    "vector.mlon",
64    "vector.kvect",
65    "vector.stid",
66    "vector.channel",
67    "vector.index",
68    "vector.vel.median",
69    "vector.vel.sd",
70    "vector.pwr.median",
71    "vector.pwr.sd",
72    "vector.wdt.median",
73    "vector.wdt.sd",
74    "vector.srng",
75];
76
77lazy_static! {
78    static ref MATCHED_VECS: Vec<Vec<&'static str>> = vec![
79        vec![
80            "stid",
81            "channel",
82            "nvec",
83            "freq",
84            "major.revision",
85            "minor.revision",
86            "program.id",
87            "noise.mean",
88            "noise.sd",
89            "gsct",
90            "v.min",
91            "v.max",
92            "p.min",
93            "p.max",
94            "w.min",
95            "w.max",
96            "ve.min",
97            "ve.max",
98        ],
99        vec![
100            "vector.mlat",
101            "vector.mlon",
102            "vector.kvect",
103            "vector.stid",
104            "vector.channel",
105            "vector.index",
106            "vector.vel.median",
107            "vector.vel.sd",
108            "vector.pwr.median",
109            "vector.pwr.sd",
110            "vector.wdt.median",
111            "vector.wdt.sd",
112        ],
113    ];
114    static ref GRID_FIELDS: Fields<'static> = Fields {
115        all_fields: {
116            let mut fields: Vec<&str> = vec![];
117            fields.extend(SCALAR_FIELDS.clone().into_iter().map(|x| x.0));
118            fields.extend(SCALAR_FIELDS_OPT.clone().into_iter().map(|x| x.0));
119            fields.extend(VECTOR_FIELDS.clone().into_iter().map(|x| x.0));
120            fields.extend(VECTOR_FIELDS_OPT.clone().into_iter().map(|x| x.0));
121            fields
122        },
123        scalars_required: SCALAR_FIELDS.to_vec(),
124        scalars_optional: SCALAR_FIELDS_OPT.to_vec(),
125        vectors_required: VECTOR_FIELDS.to_vec(),
126        vectors_optional: VECTOR_FIELDS_OPT.to_vec(),
127        vector_dim_groups: MATCHED_VECS.clone(),
128        data_fields: DATA_FIELDS.to_vec(),
129    };
130}
131
132create_record_type!(grid, GRID_FIELDS);