00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef FELT_ARRAY_H_
00025 #define FELT_ARRAY_H_
00026 #include <string>
00027 #include <set>
00028 #include <vector>
00029 #include <map>
00030 #include <ctime>
00031 #include <boost/array.hpp>
00032 #include "fimex/Felt_File_Error.h"
00033
00034 namespace MetNoFelt {
00035 using namespace std;
00036
00041 struct ShortPairLess : public binary_function<const pair<short, short>, const pair<short, short>, bool>
00042 {
00043 bool operator()(const pair<short, short>& p1, const pair<short, short>& p2) const {
00044 if (p1.first == p2.first) return p1.second < p2.second;
00045 return p1.first < p2.first;
00046 }
00047 };
00049 typedef set<pair<short,short>, ShortPairLess > ShortPairSet;
00051 typedef map<pair<short,short>, short, ShortPairLess > ShortPairMap;
00052
00053
00055
00059 class Felt_Array
00060 {
00061 private:
00062 typedef map<time_t, boost::array<short, 4> > TIME_MAP;
00063 string feltArrayName;
00064 ShortPairSet levelPairs;
00065
00066 TIME_MAP times;
00067 map<time_t, map<short, int> > fieldSizeMap;
00068
00069 map<time_t, ShortPairMap> ident19;
00070 int nx;
00071 int ny;
00072 long scaling_factor;
00073 int gridType;
00074 boost::array<short, 16> idx;
00075 boost::array<short, 20> header;
00076 boost::array<float, 6> gridParameters;
00077 string dataType;
00078 double fillValue;
00079
00080 public:
00082 Felt_Array();
00089 explicit Felt_Array(const string name, const boost::array<short, 16> idx, const string& dataType = "short");
00090 virtual ~Felt_Array();
00095 void addInformationByIndex(const boost::array<short, 16>& idx, int fieldSize) throw(Felt_File_Error);
00097 const boost::array<short, 16>& getIndexHeader() const {return idx;}
00098
00104 void setDataHeader(boost::array<short, 20> header) throw(Felt_File_Error);
00106 const boost::array<short, 20>& getDataHeader() const {return header;}
00107
00109 short getLevelType() const {return idx[10];}
00111 void setGridType(int gridType) {this->gridType = gridType;}
00113 int getGridType() const {return gridType;}
00117 void setGridParameters(boost::array<float, 6> gridParameters) {this->gridParameters = gridParameters;}
00119 const boost::array<float, 6>& getGridParameters() const {return gridParameters;}
00120
00122 const string& getName() const;
00124 const string& getDatatype() const {return dataType;}
00126 double getFillValue() const { return fillValue;}
00128 void setFillValue(double fillValue) {this->fillValue = fillValue;}
00130 vector<time_t> getTimes() const;
00132 vector<short> getLevels() const;
00136 vector<pair<short, short> > getLevelPairs() const;
00140 void addIdent19(time_t time, pair<short, short> levelPair, short value) {ident19[time][levelPair] = value;}
00145 short getIdent19(time_t time, pair<short, short> levelPair) const throw(Felt_File_Error);
00151 short getIdent19(pair<short, short> levelPair) const throw(Felt_File_Error);
00157 short getIdent19(time_t time) const throw(Felt_File_Error);
00163 short getIdent19() const throw(Felt_File_Error);
00164
00166 int getX() const {return header[9];}
00168 int getY() const {return header[10];}
00170 short getVerticalFeltType() const {return idx[10];}
00172 double getScalingFactor() const;
00173
00175 boost::array<short, 16> const getIndex(time_t time, short level) throw(Felt_File_Error);
00176 int getFieldSize(time_t time, short level) const throw (Felt_File_Error);
00177
00178 private:
00179 void testHeaderElement(short oldVal, short newVal, const std::string& msg) const throw(Felt_File_Error);
00180 };
00181
00185 time_t index16toTime(const boost::array<short,16>& idx);
00189 pair<short, short> index16toLevelPair(const boost::array<short, 16>& idx);
00190
00191 }
00192 #endif