TECA
teca_array_attributes.h
1 #ifndef teca_array_attributes_h
2 #define teca_array_attributes_h
3 
4 #include "teca_metadata.h"
5 
6 #include <ostream>
7 #include <variant>
8 
9 // a convenience container for conventional array attributes.
10 // the attributes listed here are used for CF I/O.
11 //
12 // type_code - storage type as defined by teca_variant_array::type_code()
13 //
14 // centering - one of: no_centering, point_centering, cell_centering,
15 // edge_centering, or face_centering
16 //
17 // size - number of elements in the array
18 //
19 // units - string describing the uints that the variable is in.
20 //
21 // long name - a more descriptive name
22 //
23 // description - text describing the data
24 //
25 // have_fill_value - set non-zero to indicate that a fill_value
26 // has been provided.
27 //
28 // fill_value - value used to identify missing or invalid data
30 {
31  teca_array_attributes() : type_code(0),
32  centering(0), size(0), units(), long_name(), description(),
33  have_fill_value(0), fill_value(1e20f)
34  {}
35 
36  template <typename fv_t = float>
37  teca_array_attributes(unsigned int tc, unsigned int cen,
38  unsigned long n, const std::string &un, const std::string &ln,
39  const std::string &descr, const int &have_fv=0, const fv_t &fv=fv_t(1e20f)) :
40  type_code(tc), centering(cen), size(n), units(un), long_name(ln),
41  description(descr), have_fill_value(have_fv), fill_value(fv)
42  {}
43 
45  teca_array_attributes &operator=(const teca_array_attributes &) = default;
46 
47  // converts from metadata object.
49  type_code(0), centering(0), size(0), units(), long_name(),
50  description(), have_fill_value(0), fill_value(1.e20f)
51  {
52  from(md);
53  }
54 
55  // convert from metadata object
56  teca_array_attributes &operator=(const teca_metadata &md);
57 
58  // converts to a metadata object
59  operator teca_metadata() const;
60 
61  // adds current values to the metadata object
62  int to(teca_metadata &md) const;
63 
64  // adds current values to the metadata object,
65  // only if they don't exist
66  int merge_to(teca_metadata &md) const;
67 
68  // intializes values from the metadata object
69  int from(const teca_metadata &md);
70 
71  // send to the stream in human readable form
72  void to_stream(std::ostream &os);
73 
74  // possible centrings
75  //
76  // for coordinate system with orthogonal axes x,y,z
77  // relative to cell centering:
78  //
79  // If A is one of x,y or z then A_face_centering data is located on the
80  // low A face i.e. shifted in the -A direction and arrays will be longer
81  // by 1 value in the A direction.
82  //
83  // If A is one of x,y or z then A_edge_centering data is located on the
84  // low side edge parallel to A corrdinate axis. i.e. shifted in the -B
85  // and -C directions and arrays will be longer by 1 value in the B and C
86  // directions.
87  //
88  // point_centering data is located on the low corner. i.e. shifted
89  // in the -A,-B, and -C directions and arrays will be longer
90  // by 1 value in the A, B and C directions.
91  //
92  // arrays that are not associated with geometric locations should
93  // be identified as no_centering.
94  //
95  // the default centering is cell centering.
96  enum
97  {
98  invalid_value = 0,
99  cell_centering = 0x0100,
100  x_face_centering = 0x0201,
101  y_face_centering = 0x0202,
102  z_face_centering = 0x0203,
103  x_edge_centering = 0x0401,
104  y_edge_centering = 0x0402,
105  z_edge_centering = 0x0403,
106  point_centering = 0x0800,
107  no_centering = 0x1000,
108  };
109 
110  using fill_value_t =
111  std::variant<char, unsigned char, short, unsigned short,
112  int, unsigned int, long, unsigned long, long long,
113  unsigned long long, float, double>;
114 
115  unsigned int type_code;
116  unsigned int centering;
117  unsigned long size;
118  std::string units;
119  std::string long_name;
120  std::string description;
121  int have_fill_value;
122  fill_value_t fill_value;
123 };
124 
125 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_array_attributes
Definition: teca_array_attributes.h:30