/*************************************************************************** * 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 CERESFILEDATA_H #define CERESFILEDATA_H #include "hdffiledata.h" #include "satellitefiledata.h" /** class managing the reading of the CERES file data. CERES products managed : CRS ; SSF ; @author nicolas PASCAL */ class CERESFileData : public SatelliteFileData, public HDFFileData { protected: string product; string platform; string instrument; string version; // // // // float *lat_data; /** the latitudes */ // // // // float *lon_data; /** the longitudes */ // // // // double *time_data; /** the times */ static const string latitude_sds_name; static const string longitude_sds_name; static const float colocation_tolerance; int lat_lon_index_max[1]; /** the data size */ void init(); void parse_filename(const string & short_filename); bool check_filename(const string & short_filename) const; const string get_time_sds_name(const string product="") const{ return "Time of observation"; }; /** * @brief load the list data pixels */ virtual void load_v_pixel() { UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__); throw e; }; public: /************************************* *** CONSTRUCTORS/DESTRUCTORS *** *************************************/ /** Constructor @param name the name (path+filename) of the file to be opened @param mode the opening mode. LIMITATION : only "r" mode treated at this time */ CERESFileData(const string& name, const string& mode="r"); /** Destructor */ ~CERESFileData(); /** * @brief convert a usual longitude in degrees (-180->180) to a longitude in CERES convention (0->360 where the 0 is the greenwich mereidian) * @param lon a usual longitude * @return the longitude used in CERES */ static const float get_ceres_lon(const float & lon); /** * @brief convert a usual latitude in degrees (-90->90) to a colatitude, the convention used in CERES files (colat=90-lat) * @param lat a latitude * @return the colatitude corresponding to @a lat */ static const float get_ceres_lat(const float & lat); /** Set the latitude and longitude indexes extrema */ void set_lat_lon_index_max(); /************************************* *** GETTERS/SETTERS *** *************************************/ /** read the product name (CRS,...) @return the product name */ const string get_product() const { return product; } /** read the platform used in this product @return the platform */ const string get_platform() const { return platform; } /** read the instrument in use in this product @return the instrument */ const string get_instrument() const { return instrument; } /** * access the version of the CERES file * @return the version */ const string get_version() const { return version; } /** return the radix of the file, actually the file name without the date and the dot. Ex : the radix of the file "CER_CRS_Terra-FM2-MODIS_Sample_000000.2001010101" is "CER_CRS_Terra-FM2-MODIS_Sample_000000" @return the radix */ const string get_radix() const; /** * @brief search the index of the nearest point in the data to (@a lat , @a lon ) * It uses a brute force search on the whole data. For better performances, override this method, and use more specifics way like sort the pixels by increasing (lat,lon) then dichotomic search on it... * Only the points that have a distance to ( @a lat, @a lon ) inferior to @a coloc_tolerance will be considered * @param lat the latitude * @param lon the longitude * @param time the time of the observation. If -1., skipped * @param index the index of the eventual coincidence (or -1) * @param coloc_tolerance the frame in which 2 points are considered as colocated * @return true if coincidence found */ virtual const bool get_index(const float &lat, const float& lon, const double time, int &index, const float coloc_tolerance=CERESFileData::colocation_tolerance); /** * @brief compute the distance to (lat,lon) of the nearest point in the data * Only the points that have a distance to ( @a lat, @a lon ) inferior to @a coloc_tolerance will be considered * In the method, calls the get_index method * @param lat the latitude * @param lon the longitude * @param coloc_tolerance the frame in which 2 points are considered as colocated * @param coincidence_idx the index of the eventual coincidence * @return the distance to the nearest point, or -1 if no point in the colocalisation frame has been found. */ virtual const float get_nearest_point_distance(const float &lat,const float &lon, int &coincidence_idx ,float coloc_tolerance=CERESFileData::colocation_tolerance); /** * @brief check if this file has data coincident with ( @a lat , @a lon ) at a distance not bigger than @a tolerance * @param lat the latitude of the event * @param lon the longitude of the event * @return */ virtual const bool contain_location(const float &lat,const float &lon, float tolerance=CERESFileData::colocation_tolerance); /** * @brief read the geolocations data and put it in memory * This method is used to make the search of the indexes of a (lat,lon,time) point faster. */ virtual void load_geolocation_data(); /** * @brief free eventually loaded geolocation data */ virtual void free_geolocation_data(); /** * @brief check if the geolocation data have been already loaded */ virtual const bool is_geolocation_data_loaded() const; /** * @brief access the number of differents geographical points in the file * @return the number of different points */ const int get_nb_geo_points() const; /** * @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 */ const bool get_index(const float &lat, const float& lon, int &nearest_pix_idx, const float colocation_tolerance=CERESFileData::colocation_tolerance); /** * @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 */ virtual void get_vindex(vector < vector < int > > &v_index, const float &lat, const float& lon, const float colocation_tolerance=CERESFileData::colocation_tolerance ) { UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__); throw e; }; /** * @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=CERESFileData::colocation_tolerance); /** * @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=CERESFileData::colocation_tolerance); /** * @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=CERESFileData::colocation_tolerance) ; /** * @brief closes the file. */ virtual void close_data_file() { free_hdf_file(); }; /** * @brief opens the file. */ virtual void open_data_file() { load_hdf_file(); }; /** * @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 */ virtual void get_pixel_coord ( const vector < int > & ipix, float &lat, float &lon, double &time ) { UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__); throw e; }; }; #endif