/***************************************************************************
* 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. *
***************************************************************************/
/***************************************************************************
* History : *
* 25/07/05 : start *
***************************************************************************/
#ifndef FILEDATA_H
#define FILEDATA_H
#include "g_exception.h"
#include "filedataexception.h"
#include "statistic.h"
#include "geometry.h"
#include "observation.h"
/**
Generic class managing the reading. It describes the data generally
@author Nicolas PASCAL
*/
class FileData {
protected:
/**
the name of the file (with its path)
*/
string name;
/**
the opening mode : only "r" supported at this time
*/
string mode;
/**
the date when the data have been acquired
*/
Date *date;
/**
* the duration of the acquisition
*/
double time_coverage;
/**
* set the name of the file
* @param _name the new name
*/
void set_name( const string & name ) { this->name=name; };
/**
* set the acquisition date
* @param _x the new date
*/
void set_date(const Date& d) {
if (&d!=NULL)
*date = d;
};
public:
/**
* @brief Build a generic file reader interface
* @throw bad_file if the name given in parametre doesn't exist or is NULL
* @throw bad_file_opening_mode :
- if the opening mode isn't allowed. At this time, only "r" is allowed.
- if the user isn't authorized to access to this file.
* @param name the name of the file (path included) we want to parse
/ @param mode the file's opening mode for this file. At this time, only "r" is allowed
*/
FileData(const string &name = "",const string &mode = "r");
/**
* @brief Copy constructor
* @param fd the FileData to copy
*/
FileData(const FileData &fd);
/**
* @brief Affectation operator
* @param fd the FileData to copy
* @return this
*/
FileData &operator= (const FileData &fd);
/**
* @brief Destructor
*/
virtual ~FileData();
/**
* @brief file name accessor
* @return the name with its full path
*/
const string get_name() const { return name; };
/**
* @brief alias to get_name method, dfor data2grid/mapsoperator compatibility
* @return
*/
virtual string get_filename(){
return get_name();
};
/**
* @brief return the date of data' acquisition start
* @return the acquisition date
*/
const Date get_date() const { return *date; }
/**
* @brief test if the file contains data that occur at @a time
* If @a time is -1 (deault), always return true
* @param time a measure time using TAI93 convention (number of seconds since 1993/01/01 at 00:00:00)
* @return true if the file has data time stamped with time
*/
const bool contain_time(const double time=-1.) const;
/**
* @brief Read the selected data in the file.
* @warning If you delegate the allocation of the buffer at this method, you need to call delete[] data yourself.
* @param data the buffer to fill with the read values. Can be NULL. In this case, the allocation is done by the method
* @param sds_name the name of the sds (Scientific Data Set) we want to access.
* @param start begining of the selection. If NULL, start at (0,0) if rank is 2 ; (0,0,0) if rank is 3...
* @param stride step between 2 interesting values. If NULL, this step is set to 1 in each dimension (ie all values will be read)
* @param edges number of values to be read in each dimension. if NULL, it will be all data along each dimension.
* @param rank the dimension of start, stride and edges
* @return a pointer to the read data array. It is useful when you let this method manage the allocation to update the allocated pointer to the data. If you've done it yourself or you are using a static buffer, it isn't necessary to catch this return pointer
*/
virtual void* read_data(void* data, const char* sds_name, int * start = NULL, int * stride = NULL, int * edges = NULL, int rank = -1) = 0;
double get_time_coverage() const {
return time_coverage;
};
/**
* @brief closes the file
* @warning here for interface implementation prupose. All subclasses should implement this method
*/
virtual void close_data_file() {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief open the file
* @warning here for interface implementation prupose. All subclasses should implement this method
*/
virtual void open_data_file() {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief check if this file has eventually data coincident with (lat,lon)
* @warning here for interface implementation prupose. All subclasses should implement this method
* @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
*/
virtual const bool contain_location(const float &lat,const float &lon, const double &tolerance) {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief check if the file has possible (lat,lon) coincidence
* @warning it's an EVENTUAL coincidence. That is not a proof !!!
* @warning here for interface implementation prupose. All subclasses should implement this method
* @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
*/
virtual const bool contain_data(const float &lat, const float &lon, const double &time, const double &colocation_tolerance) {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief check the validity of the (lat, lon) coordinates. If @a lat not in [-90, 90] or @a lon not in [-180, 180], raise an exception
* @param lat latitude
* @param lon longitude
*/
static void check_geolocation (const float lat, const float lon);
/**
* @brief read the geolocations data and put it in memory
* @warning here for interface implementation prupose. All subclasses should implement this method
* This method is used to make the search of the indexes of a (lat,lon,time) point faster.
*/
virtual void load_geolocation_data() {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};;
/**
* @brief free eventually loaded geolocation data
* @warning here for interface implementation prupose. All subclasses should implement this method
*/
virtual void free_geolocation_data() {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};;
/**
* @brief check if the geolocation data have been already loaded
* @warning here for interface implementation prupose. All subclasses should implement this method
*/
virtual const bool is_geolocation_data_loaded() const {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief read the given dataset's fill value
* TODO Same method with many names of this method transfered from filedatareader. Need to be reformatted after functionnal tests with Data2Grid/MapsOperator
* @param ds_name [IN] dataset name
* @param fillvalue [OUT] fill value.
*/
virtual void get_dataset_fill_value(const string &ds_name, void * fillvalue) {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief return the given dataset size along each axis
* @param ds_name [IN] dataset name
* @return the axis dimensions in ordering [..., Z, Y, X]
*/
virtual vector get_dataset_dimension(const string &sds_name) {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief read the given dataset's fill value
* @param ds_name [IN] dataset name
* @param fillvalue [OUT] fill value.
*/
template
void get_fillValue(const string & ds_name, X & fillValue) {
get_fillValue(ds_name, (void*)&fillValue);
};
virtual void get_fillValue(const string &ds_name, void *fillValue) {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
template
void get_fill_value(const string & ds_name, X & fillValue) {
get_fill_value(ds_name, (void*)&fillValue);
};
virtual void get_fill_value(const string &ds_name, void * fillValue) {
get_fillValue(ds_name, (void*)&fillValue);
};
/**
* @brief test if the data requested for computing the viewing directions has been loaded
*/
virtual bool is_viewing_directions_data_loaded() {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief load the data requested for computing the viewing directions
*/
virtual void load_viewing_directions_data () {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief free the data requested for computing the viewing directions
*/
virtual void free_viewing_directions_data () {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
/**
* @brief constucts the viewing directions observations for the given pixel
* @param ipix pixel indice(s)
* @param v_obs vector of observation(s) for the given pixel
*/
virtual void get_viewing_directions (const vector & ipix, vector & v_obs) {
UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
throw e;
};
};
#endif