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

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

# include/fimex/GribFileIndex.h

Go to the documentation of this file.

    00001 /*
    00002  * Fimex, GribFileIndex.h
    00003  *
    00004  * (C) Copyright 2009, 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  *  Created on: Aug 31, 2009
    00024  *      Author: Heiko Klein
    00025  */
    00026
    00027 #ifndef GRIBFILEINDEX_H_
    00028 #define GRIBFILEINDEX_H_
    00029 #include <boost/date_time/posix_time/posix_time.hpp>
    00030 #include <boost/filesystem/operations.hpp>
    00031 #include <vector>
    00032 #include "fimex/XMLDoc.h"
    00033 #include "fimex/GridDefinition.h"
    00034 #include <boost/date_time/posix_time/posix_time_types.hpp>
    00035
    00036 // forward decl of grib_api
    00037 struct grib_handle;
    00038
    00039 namespace MetNoFimex
    00040 {
    00041 class GribFileMessage
    00042 {
    00043 public:
    00044     GribFileMessage();
    00045     GribFileMessage(boost::shared_ptr<grib_handle> gh, const std::string& fileURL, long filePos, long msgPos);
    00046     GribFileMessage(boost::shared_ptr<XMLDoc>, std::string nsPrefix, xmlNodePtr node);
    00047     ~GribFileMessage();
    00048
    00050     bool isValid() const {return fileURL_ != "";}
    00052     std::string toString() const;
    00054     const long getEdition() const;
    00055     const std::string& getFileURL() const;
    00056     const size_t getFilePosition() const;
    00058     const size_t getMessageNumber() const;
    00059     const std::string& getName() const;
    00060     const std::string& getShortName() const;
    00061     boost::posix_time::ptime getValidTime() const;
    00062     boost::posix_time::ptime getReferenceTime() const;
    00063     long getLevelNumber() const;
    00064     long getLevelType() const;
    00070     const std::vector<long>& getParameterIds() const;
    00071     const std::string& getTypeOfGrid() const;
    00072     const GridDefinition& getGridDefinition() const;
    00080     size_t readData(std::vector<double>& data, double missingValue) const;
    00081 private:
    00082     std::string fileURL_;
    00083     size_t filePos_;
    00084     size_t msgPos_; // for multiMessages: multimessages
    00085     std::string parameterName_;
    00086     std::string shortName_;
    00087     // ed1: indicatorOfParameter, gribTablesVersionNo, identificationOfOriginatingGeneratingCentre;
    00088     // ed2: parameterNumber, paramterCategory, discipline
    00089     std::vector<long> gridParmeterIds_;
    00090     long edition_;
    00091     long dataTime_;
    00092     long dataDate_;
    00093     std::string stepUnits_;
    00094     std::string stepType_;
    00095     long stepStart_;
    00096     long stepEnd_;
    00097     long stepRange_;
    00098     long levelType_;
    00099     long levelNo_;
    00100     std::string typeOfGrid_;
    00101     GridDefinition gridDefinition_;
    00102 };
    00103
    00105 class GribFileMessageEqualTime : public std::unary_function<bool, const GribFileMessage&> {
    00106 public:
    00107     GribFileMessageEqualTime(boost::posix_time::ptime time) : time_(time) {}
    00108     ~GribFileMessageEqualTime() {}
    00109     bool operator()(const GribFileMessage& gfm) { return gfm.getValidTime() == time_; }
    00110 private:
    00111     boost::posix_time::ptime time_;
    00112 };
    00113
    00115 class GribFileMessageEqualLevelTime : public std::unary_function<bool, const GribFileMessage&> {
    00116 public:
    00117     GribFileMessageEqualLevelTime(long edition, long levelType, long levelNo, boost::posix_time::ptime time) : edition_(edition), levelType_(levelType), levelNo_(levelNo), time_(time) {}
    00118     ~GribFileMessageEqualLevelTime() {}
    00119     bool operator()(const GribFileMessage& gfm) { return (gfm.getEdition() == edition_) && (gfm.getLevelType() == levelType_) && (gfm.getLevelNumber() == levelNo_) && (gfm.getValidTime() == time_); }
    00120 private:
    00121     long edition_;
    00122     long levelType_;
    00123     long levelNo_;
    00124     boost::posix_time::ptime time_;
    00125 };
    00126
    00127
    00128 class GribFileIndex
    00129 {
    00130 public:
    00131     GribFileIndex();
    00145     GribFileIndex(boost::filesystem::path gribFilePath, bool ignoreExistingXml = false);
    00146     virtual ~GribFileIndex();
    00147     const std::vector<GribFileMessage>& listMessages() const {return messages_;}
    00148     const std::string& getUrl() const {return url_;}
    00149 private:
    00150     std::string url_;
    00151     std::vector<GribFileMessage> messages_;
    00152     void initByGrib(boost::filesystem::path gribFilePath);
    00153     void initByXML(boost::filesystem::path xmlFilePath);
    00154 };
    00155
    00157 std::ostream& operator<<(std::ostream& os, const GribFileMessage& gfm);
    00159 std::ostream& operator<<(std::ostream& os, const GribFileIndex& gfm);
    00160
    00161
    00162 }
    00163
    00164
    00165 #endif /* GRIBFILEINDEX_H_ */