/*************************************************************************** * Copyright (C) 2005 by Nicolas PASCAL * * nicolas.pascal@icare.univ-lille1.fr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef METEOFILEDATA_H #define METEOFILEDATA_H #include "filedata.h" /** Generic abstract interface to manage the reading of meteo files @author Nicolas PASCAL */ class MeteoFileData : virtual public FileData { protected: /** * @brief The time resolution */ double delta_time; /** * @brief The average step between two latitudes */ double delta_lat; /** * @brief The average step between two longitudes */ double delta_lon; /** * @brief The number of different heights levels (depend of the meteo file) */ short nb_height_level; /** * @brief the height levels (the Z axis for 3D products) * For 2D products, will always be NULL */ double* height_level; /** * @brief The number of different times levels (depend of the meteo file) */ short nb_time_level; /** * @brief the time stamp of each measure */ double* time_level; /** * @brief check is a the file seems to be a valid meteo data file * The analysis is done with a filename parsing, not with parsing the data inside * @param filename the filename without its path * @return true if the filename seems to be valid, false else or in case of problem (exception...) */ virtual bool check_filename( const std::string& filename ) const = 0; /** * @brief extract some informations using the filename (acquisition start time,etc) * PRECONDITION the file name must be valid. The validity check is done by check_filename * @param filename the filename without its path */ virtual void parse_filename( const std::string& filename ) = 0; protected: /** * @brief check if the height levels have already been set * @warning for 2D products (that aven't got height levels) return true * @return true if the height levels are set */ virtual const bool is_height_level_loaded() const ; /** * @brief if not already set, read the height levels in the file * To implement this interface : the method must : * - set the nb_height_level attribute * - fill the height_level array with the height stamp of each level */ virtual void load_height_level(){}; /** * @brief if loaded, free the height levels * If the product is a 2D one, no height levels are defined. In this case, nothing's done. */ void free_height_level(); /** * @brief check if the time levels have already been set * @return true if the time levels are set */ virtual const bool is_time_level_loaded() const ; /** * @brief if not already set, read the time levels in the file * To implement this interface : the method must : * - set the nb_time_level attribute * - fill the time_level array with the time stamp of each level */ virtual void load_time_level() = 0; /** * @brief if loaded, free the time levels */ void free_time_level(); public: /** * @brief constructor * @param name the filename (with the path) * @param mode opening mode. only "r" at this time */ MeteoFileData(const std::string &name, const std::string &mode="r"); /** * @brief destructor */ virtual ~MeteoFileData(); /** @brief access to the number of height levels @return the number of height levels */ const unsigned short get_nb_height_level(); /** * @brief return the height level values * @return the height values vector */ const double* get_height_level(); /** * @brief access to the number of time levels * load the time level if needed * @return the number of time levels */ const unsigned short get_nb_time_level() ; /** * @brief return the time level values * load the time level if needed * @return the time values vector */ const double* get_time_level(); /** * @brief access to the time of the start of the acquisition * @return the time of the begining of the acquisition (using TAI convention : in sec since the 1993/01/01) */ virtual double get_time_min() const ; /** * @brief access to the time of the end of the acquisition * @return the time of the end of the acquisition (using TAI convention : in sec since the 1993/01/01) */ virtual double get_time_max() const ; /** * @brief return the index of the grid latitude that is the nearest to lat. * @param lat the latitude * @return the index, or -1 if out of range */ virtual const int get_lat_index( const float &lat) const; /** * @brief return the index of the grid longitude that is the nearest to lon. * @param lon the longitude * @return the index, or -1 if out of range */ virtual const int get_lon_index( const float &lon) const; /** * @brief return the index of the grid time that is the nearest to lon. * @param time the time * @return the index, or -1 if out of range */ virtual const int get_time_index(const double &time) const; /** * @brief search the indexes of the data coincident with the point (lat,lon) * If the coincidence can't be found, the output indexes @a index will be set to {-1,-1} * @param lat the latitude * @param lon the longitude * @param index the output indexes as a 2 values array. Mustn't be NULL * @return true if the coincidence has been found */ virtual const bool get_index(const float &lat, const float &lon, int *index) const; /** * @brief search the indexes of the data coincident with the point (lat,lon,time) * If the coincidence can't be found, the output indexes @a index will be set to {-1,-1,-1} * @param lat the latitude * @param lon the longitude * @param time the time (using TAI convention : in sec since the 1993/01/01) * @param index the output indexes as a 3 values array. Mustn't be NULL * @return true if the coincidence has been found */ virtual const bool get_index(const float &lat, const float &lon, const double &time, int *index); /** * @brief get the number of time levels for this type of meteo file * @return the number of time levels */ short get_nb_time_level() const { return nb_time_level; }; /** * @brief accessor to the time step between 2 successive time * @return the minimal time step */ double get_delta_time() const { return delta_time; } /** * @brief accessor to the time step between 2 successive grid latitudes * @return the minimal latitude step */ double get_delta_lat() const { return delta_lat; } /** * @brief accessor to the time step between 2 successive grid longitudes * @return the minimal longitude step */ double get_delta_lon() const { return delta_lon; } }; #endif