# MI - Fimex: include/fimex/Felt_Array.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

# include/fimex/Felt_Array.h

Go to the documentation of this file.

    00001 /*
    00002  * Fimex
    00003  *
    00004  * (C) Copyright 2008, met.no
    00005  *
    00006  * Project Info:  https://wiki.met.no/fimex/start
    00007  *
    00008  * This library is free software; you can redistribute it and/or modify it
    00009  * under the terms of the GNU Lesser General Public License as published by
    00010  * the Free Software Foundation; either version 2.1 of the License, or
    00011  * (at your option) any later version.
    00012  *
    00013  * This library is distributed in the hope that it will be useful, but
    00014  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    00015  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    00016  * License for more details.
    00017  *
    00018  * You should have received a copy of the GNU Lesser General Public
    00019  * License along with this library; if not, write to the Free Software
    00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
    00021  * USA.
    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 <boost/array.hpp>
    00031 #include "fimex/Felt_File_Error.h"
    00032 #include "fimex/Utils.h"
    00033
    00034 namespace MetNoFelt {
    00035 using namespace std;
    00036 using MetNoFimex::epoch_seconds;
    00037
    00042 struct ShortPairLess : public binary_function<const pair<short, short>, const pair<short, short>, bool>
    00043 {
    00044         bool operator()(const pair<short, short>& p1, const pair<short, short>& p2) const {
    00045                 if (p1.first == p2.first) return p1.second < p2.second;
    00046                 return p1.first < p2.first;
    00047         }
    00048 };
    00050 typedef set<pair<short,short>, ShortPairLess > ShortPairSet;
    00052 typedef map<pair<short,short>, short, ShortPairLess > ShortPairMap;
    00053
    00054
    00056
    00060 class Felt_Array
    00061 {
    00062 private:
    00063         typedef map<epoch_seconds, boost::array<short, 4> > TIME_MAP;
    00064         string feltArrayName;
    00065         ShortPairSet levelPairs;
    00066         // the time-array[0,1,2,3] correspond to index-array[2,3,4,9]
    00067         TIME_MAP times;
    00068         map<epoch_seconds, map<short, int> > fieldSizeMap;
    00069         // ident19 stores extra informations which might be time/level dependent
    00070         map<epoch_seconds, ShortPairMap> ident19;
    00071         int nx;
    00072         int ny;
    00073         long scaling_factor;
    00074         int gridType;
    00075         boost::array<short, 16> idx;
    00076         boost::array<short, 20> header;
    00077         boost::array<float, 6> gridParameters;
    00078         string dataType;
    00079         double fillValue;
    00080
    00081 public:
    00083         Felt_Array();
    00090         explicit Felt_Array(const string name, const boost::array<short, 16> idx, const string& dataType = "short");
    00091         virtual ~Felt_Array();
    00096         void addInformationByIndex(const boost::array<short, 16>& idx, int fieldSize) throw(Felt_File_Error);
    00098         const boost::array<short, 16>& getIndexHeader() const {return idx;}
    00099
    00105         void setDataHeader(boost::array<short, 20> header) throw(Felt_File_Error);
    00107         const boost::array<short, 20>& getDataHeader() const {return header;}
    00108
    00110         short getLevelType() const {return idx[10];}
    00112         void setGridType(int gridType) {this->gridType = gridType;}
    00114         int getGridType() const {return gridType;}
    00118         void setGridParameters(boost::array<float, 6> gridParameters) {this->gridParameters = gridParameters;}
    00120         const boost::array<float, 6>& getGridParameters() const {return gridParameters;}
    00121
    00123         const string& getName() const;
    00125         const string& getDatatype() const {return dataType;}
    00127         double getFillValue() const { return fillValue;}
    00129         void setFillValue(double fillValue) {this->fillValue = fillValue;}
    00131         vector<epoch_seconds> getTimes() const;
    00133         vector<short> getLevels() const;
    00137         vector<pair<short, short> > getLevelPairs() const;
    00141         void addIdent19(epoch_seconds time, pair<short, short> levelPair, short value) {ident19[time][levelPair] = value;}
    00146         short getIdent19(epoch_seconds time, pair<short, short> levelPair) const throw(Felt_File_Error);
    00152         short getIdent19(pair<short, short> levelPair) const throw(Felt_File_Error);
    00158         short getIdent19(epoch_seconds time) const throw(Felt_File_Error);
    00164         short getIdent19() const throw(Felt_File_Error);
    00165
    00167         int getX() const {return header[9];}
    00169         int getY() const {return header[10];}
    00171         short getVerticalFeltType() const {return idx[10];}
    00173         double getScalingFactor() const;
    00174
    00176         boost::array<short, 16> const getIndex(epoch_seconds time, short level) throw(Felt_File_Error);
    00177         int getFieldSize(epoch_seconds time, short level) const throw (Felt_File_Error);
    00178
    00179 private:
    00180         void testHeaderElement(short oldVal, short newVal, const std::string& msg) const throw(Felt_File_Error);
    00181 };
    00182
    00186 epoch_seconds index16toTime(const boost::array<short,16>& idx);
    00190 pair<short, short> index16toLevelPair(const boost::array<short, 16>& idx);
    00191
    00192 } // end namespace MetNoFelt
    00193 #endif /*FELT_ARRAY_H_*/