/*************************************************************************** * Copyright (C) 2011 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 DARDARFILEDATA_H #define DARDARFILEDATA_H #include "cloudsatfiledata.h" /** @author Nicolas PASCAL @class DARDARFileData manage the reading of CLOUSAT files */ class DARDARFileData : public SatelliteFileData, public HDFFileData { static const float colocation_tolerance; /***** constants *****/ /** The name of the latitude data field */ string latitude_name; /** The name of the longitude data field */ string longitude_name; /** The name of the time data field */ string time_name; /** * @enum Product_ID defines the different types of DARDAR products */ enum Product_ID { UNDEFINED = 0, DARDAR_CLOUD, DARDAR_MASK, }; /***** Product characteristics *****/ /** the type of DARDAR product */ Product_ID product_id; /** The name of the CLOUDSAT product */ string product; /** The version of the product : concatenation of the reprocessing and the epoch number (format R**_V** where * is a digit number) */ string version; /** The geolocation data array size */ int lat_lon_index_max; /** The number of the orbit */ short orbit_nb; /** * @brief extract sone informations using the filename * @param short_filename the filename without its path */ void parse_filename(const string & short_filename); /** * @brief test if the filename seems to be a valid CLOUDSAT file * @param short_filename the filename without its path */ bool check_filename(const string & short_filename); /** * @brief initialize the attributes during the first read of the file */ void init(); /** * @brief read the geolocation data array size (latitude, and longitude) */ void set_lat_lon_index_max(); /** * @brief compute the time range covered by this file, depending of the product */ void set_time_coverage(); public: /** Number of vertical bins of a DARDAR (MASK+CLOUD) profile (fixed) */ static const int nb_dardar_bin=436; /** altitudes of the bins (m) */ static const int16 dardar_height []; /** * @brief constructor * @param name the filename * @param mode opening mode. only "r" at this time */ DARDARFileData(const string &name, const string &mode="r"); /** * @brief destructor */ ~DARDARFileData(); /** * @brief read the geolocation data (latitude, longitude and time) * This method is used to make the search of the indexes of a (lat,lon,time) point faster. */ void load_geolocation_data(); /** * @brief free eventually loaded geolocation data * If the geolocation data are not loaded, doesn't do anything */ void free_geolocation_data(); /** * @brief load the list data pixels */ void load_v_pixel() ; /** * @brief closes the file. */ void close_data_file() { free_hdf_file(); }; /** * @brief opens the file. */ void open_data_file() { load_hdf_file(); }; /** * @brief retrieve the number of (lat,lon) pixels in the file * @return the number of (lat,lon) pixels */ const int get_nb_geo_points() { return lat_lon_index_max + 1; } /** * @brief access to the product name * @return the product name */ string get_product() const { return product; } /** * @brief access to the version of the product * @return the version of the product */ string get_version() const { return version; } /** * @brief check if this file has eventually data coincident with (lat,lon) * Actually, it only tests if (lat,lon) is contained in the data's bounding rectangle. * @param lat the latitude of the event * @param lon the longitude of the event * @param tolerance acceptable bias between the nearest point in the data and the given (lat,lon) point * @return true if a point in the data has been found in the colocation frame */ const bool contain_location(const float &lat,const float &lon, const double &tolerance=0.01); /** * @brief check if the file has possible (lat,lon) coincidence * @warning it's an EVENTUAL coincidence. That is not a proof !!! * @param lat latitude * @param lon longitude * @param time time * @param colocation_tolerance the acceptable bias (in km or degrees. Supposed to be in, a plane approximation) between [lat,lon] and the nearest data point. * @return true if can eventually contain a coincidence with the point. * @warning at this time always true. I don't have a good way to do it */ const bool contain_data(const float &lat, const float &lon, const double &time, const double &colocation_tolerance=0.01) ; /** * @brief compute the distance to (lat,lon) of the nearest point in the data * If @a coloc_tolerance is given, it will compute only the distance of the points that have a distance to ( @a lat, @a lon ) inferior to @a coloc_tolerance * @param lat the latitude * @param lon the longitude * @param coloc_tolerance the -/+ maximal tolerance for 2 points considered as colocated * @return the distance to the nearest point, or -1 if no point in the colocalisation frame has been found. */ const float get_nearest_point_distance(const float &lat,const float &lon,const float coloc_tolerance=DARDARFileData::colocation_tolerance); /** * @brief find the index of the nearest point to (lat,lon) in the data. * If (lat,lon) is not found or out of the colocalisation_frame, returned indexes are [-1,-1] * @param lat the latitude * @param lon the longitude * @param nearest_pix_idx the index of the nearest measure. -1 if no coincidence found. * @param colocation_tolerance the acceptable bias (in km or degrees. Supposed to be in, a plane approximation) between [lat,lon] and the nearest data point. * @return true if the coincidence has been found */ virtual const bool get_index(const float &lat, const float& lon, int &nearest_pix_idx, const float colocation_tolerance=0.01); /** * @brief build the list of indices of pixels that are in colocation tolerance, sorted by increasing distance to (lat,lon) * If (lat,lon) is not found or out of the colocalisation_frame, returns an empty vector * @param lat the latitude * @param lon the longitude * @param colocation_tolerance the acceptable bias (in km or degrees. Supposed to be in, a plane approximation) between [lat,lon] and the nearest data point. * @return the list of indices of pixels */ void get_vindex(vector < vector < int > > &v_index, const float &lat, const float& lon, const float colocation_tolerance=0.01 ) { UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__); throw e; }; /** * @brief retrieve the coordinates of a pixel using its index * @param ipix [IN] index of the pixel in a unique value vector for interface implementation purpose * @param lat [OUT] latitude of the pixel * @param lon [OUT] longitude of the pixel * @param time [OUT] timestamp of the pixel */ void get_pixel_coord ( const vector < int > & ipix, float &lat, float &lon, double &time ) { get_pixel_coord (ipix[0], lat, lon, time); }; /** * @brief retrieve the coordinates of a pixel using its index * @param ipix [IN] index of the pixel * @param lat [OUT] latitude of the pixel * @param lon [OUT] longitude of the pixel * @param time [OUT] timestamp of the pixel */ void get_pixel_coord ( const int ipix, float &lat, float &lon, double &time ) { if (!is_geolocation_data_loaded()) load_geolocation_data(); lat = lat_data [ ipix ]; lon = lon_data [ ipix ]; time = time_data [ ipix ]; }; /** * @brief accessor to the altitudes of the bins * @return a vector with the bins altitudes in meters */ static const int16* get_dardar_height() { return DARDARFileData::dardar_height; } }; #endif