VAPOR3 3.9.4
BOVCollection.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <iostream>
5#include <vapor/MyBase.h>
6#include <vapor/utils.h>
7#include <vapor/DC.h>
8
9namespace VAPoR {
10
12public:
13 enum class parseCodes { PARSE_ERROR = -1, NOT_FOUND = 0, FOUND = 1 };
14
16 int Initialize(const std::vector<std::string> &paths);
17
18 std::vector<std::string> GetDataVariableNames() const;
19 std::string GetTimeDimension() const;
20 std::vector<float> GetUserTimes() const;
21 float GetUserTime(size_t ts) const { return GetUserTimes()[ts]; };
22 std::array<size_t, 3> GetDataSize() const;
23 std::array<std::string, 3> GetSpatialDimensions() const;
25 std::array<double, 3> GetBrickOrigin() const;
26 std::array<double, 3> GetBrickSize() const;
27
28 template<class T> int ReadRegion(std::string varname, size_t ts, const std::vector<size_t> &min, const std::vector<size_t> &max, T region);
29
30private:
31 std::string _currentFilePath;
32
33 float _time;
34 std::vector<float> _times;
35 std::string _dataFile;
36 std::vector<std::string> _dataFiles;
37 std::array<size_t, 3> _gridSize;
38 DC::XType _dataFormat;
39 std::string _variable;
40 std::vector<std::string> _variables;
41 std::array<double, 3> _brickOrigin;
42 std::array<double, 3> _brickSize;
43 size_t _byteOffset;
44
45 // These values are currently parsed and assigned, but are unimplemented (not used)
46 bool _divideBrick;
47 std::string _dataEndian;
48 std::string _centering;
49 int _dataComponents;
50 std::array<size_t, 3> _dataBricklets;
51
52 // Placeholder variables to store values read from BOV descriptor files.
53 // These values must be consistent among BOV files, and are validated before
54 // assigning to "actual" values such as _gridSize, declaired above.
55 DC::XType _tmpDataFormat;
56 std::array<double, 3> _tmpBrickOrigin;
57 std::array<double, 3> _tmpBrickSize;
58 size_t _tmpByteOffset;
59
60 // Note - _tmpGridSize is an array of int type
61 // - _gridSize is of type size_t
62 // The reason for this is when we caluclate data indices like so...
63 //
64 // int xSize = INT_MAX
65 // int ySize = INT_MAX
66 // int zSize = INT_MAX
67 // size_t index = xSize*ySize*zSize;
68 //
69 // ...the rvalue causes integer overflow.
70 //
71 // _tmpGridSize cannot be an array of size_t because users may write
72 // negative values. The parser uses std::stringstream to convert
73 // strings to different datatypes. Unfortunately it does not fail when
74 // converting negative string values such as "-10" to a size_t. Rather,
75 // it converts "-10" to a large positive value".
76 //
77 // Therefore, we read the values in with _tmpGridSize as integers,
78 // and then assign the integers to _gridSize if validation passes.
79 // (Validation in this case: ensure non-negative values, and consistency across files)
80 std::array<int, 3> _tmpGridSize;
81
82 bool _gridSizeAssigned;
83 bool _formatAssigned;
84 bool _brickOriginAssigned;
85 bool _brickSizeAssigned;
86 bool _byteOffsetAssigned;
87
88 // _dataFileMap allows us to access binary data files with a
89 // varname/timestep pair
90 std::map<std::string, std::map<float, std::string>> _dataFileMap;
91
92 std::array<std::string, 3> _spatialDimensions;
93 int _validateParsedValues();
94 std::string _timeDimension;
95
96 int _parseHeader(std::ifstream &header);
97 int _populateDataFileMap();
98
99 template<typename T> int _findToken(const std::string &token, std::string &line, T &value, bool verbose = false);
100 template<typename T> int _findToken(const std::string &token, std::string &line, std::array<T, 3> &value, bool verbose = false);
101
102 void _findTokenValue(std::string &line) const;
103
104 int _sizeOfFormat(DC::XType) const;
105
106 int _invalidVarNameError() const;
107 int _invalidFileSizeError(size_t numElements) const;
108 int _invalidFileError() const;
109 int _invalidDimensionError(const std::string &token) const;
110 int _invalidFormatError(const std::string &token) const;
111 int _failureToReadError(const std::string &token) const;
112 int _inconsistentValueError(const std::string &token) const;
113 int _invalidValueError(const std::string &token) const;
114 int _missingValueError(const std::string &token) const;
115
116 static const std::string TIME_TOKEN;
117 static const std::string DATA_FILE_TOKEN;
118 static const std::string GRID_SIZE_TOKEN;
119 static const std::string FORMAT_TOKEN;
120 static const std::string VARIABLE_TOKEN;
121 static const std::string ORIGIN_TOKEN;
122 static const std::string BRICK_SIZE_TOKEN;
123 static const std::string OFFSET_TOKEN;
124
125 // These tokens are currently parsed but are not used
126 static const std::string ENDIAN_TOKEN;
127 static const std::string CENTERING_TOKEN;
128 static const std::string DIVIDE_BRICK_TOKEN;
129 static const std::string DATA_BRICKLETS_TOKEN;
130 static const std::string DATA_COMPONENTS_TOKEN;
131
132 static const double _defaultTime;
133 static const std::string _defaultFile;
134 static const DC::XType _defaultFormat;
135 static const std::string _defaultVar;
136 static const size_t _defaultByteOffset;
137 static const std::array<double, 3> _defaultOrigin;
138 static const std::array<double, 3> _defaultBrickSize;
139 static const std::array<size_t, 3> _defaultGridSize;
140
141 // These defaults are currently unimplemented in the BOV reader logic
142 static const std::string _defaultEndian;
143 static const std::string _defaultCentering;
144 static const bool _defaultDivBrick;
145 static const std::array<size_t, 3> _defaultBricklets;
146 static const size_t _defaultComponents;
147
148 static const std::string _xDim;
149 static const std::string _yDim;
150 static const std::string _zDim;
151 static const std::string _timeDim;
152
153 static const std::string _byteFormatString;
154 static const std::string _shortFormatString;
155 static const std::string _intFormatString;
156 static const std::string _floatFormatString;
157 static const std::string _doubleFormatString;
158};
159
160// Make gcc happy by moving template specialization outside of the class body
161//
162template<> int BOVCollection::_findToken<DC::XType>(const std::string &token, std::string &line, DC::XType &value, bool verbose);
163} // namespace VAPoR
std::vector< std::string > GetDataVariableNames() const
std::vector< float > GetUserTimes() const
int ReadRegion(std::string varname, size_t ts, const std::vector< size_t > &min, const std::vector< size_t > &max, T region)
std::array< std::string, 3 > GetSpatialDimensions() const
DC::XType GetDataFormat() const
std::array< double, 3 > GetBrickOrigin() const
std::array< double, 3 > GetBrickSize() const
int Initialize(const std::vector< std::string > &paths)
float GetUserTime(size_t ts) const
Definition: BOVCollection.h:21
std::string GetTimeDimension() const
std::array< size_t, 3 > GetDataSize() const
XType
External storage types for primitive data.
Definition: DC.h:154
Wasp base class.
Definition: MyBase.h:67