• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/home/pascal/depot/filedata/src/parasolfiledata.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Nicolas PASCAL   *
00003  *   nicolas.pascal@icare.univ-lille1.fr   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef PARASOLFILEDATA_H
00021 #define PARASOLFILEDATA_H
00022 
00023 #include "filedata.h"
00024 #include "parasolleader.h"
00025 #include "parasoldata.h"
00026 #include "satellitefiledata.h"
00027 
00028 #include <cmath>
00029 #include <cfloat>
00030 #include "hdfi.h"
00031 
00036 class PARASOLFileData : public SatelliteFileData
00037 {
00038 public:
00039     static const int nb_parasol_direction;
00040     // altitude of the satellite in m. It is a virtual mean altitude. The real movement is an ellipse, not a perfect circle
00041     static const double satellite_altitude;
00042     // size in m of a NADIR pixel border (6km)
00043     static const double pix_sz_nadir;
00044     // maximum size in m of an observed pixel border, ie a pixel observed with a zenithal angle of 60 degrees
00045     static const double pix_sz_max;
00046     // maximum angle between viewibng direction and satellite nadir : 60 degrees
00047     static const double max_sat_nadir_angle;
00048     // angle in radians at satellite position on an observed nadir pixel at full resolution (= 1/16 degree earth angle)
00049     static const double pix_obs_nadir_angle;
00050     // maximum number of acquisition sequences
00051     static const int nb_acq_seq_max;
00052     // number of images during an acquisition sequence
00053     static const int nb_acq_img_max;
00054 
00055 protected:
00059     PARASOLLeader* leader;
00063     PARASOLData* data;
00064 private:
00065     template <typename NumType>
00066     static bool greater_comparator (NumType i,NumType j) { return (i > j); };
00070     enum ProcessingLine{
00071         UNDEFINED,
00072         BASIC,
00073         LAND_SURFACE,
00074         OCEAN_COLOR,
00075         RADIATION_BUDGET
00076     };
00077 
00083     static const double lat2time_coef;
00084 
00088     int instrument;
00093     int level;
00097     ProcessingLine processing_line;
00101     char product;
00106     int orbit_cycle_nb;
00111     int orbit_nb;
00115     char reprocessing_nb;
00120     int grid_factor;
00122     int sz_grid [2];
00124     double sz_cell;
00126     string software_version_number;
00130     unsigned short *line_data;
00134     unsigned short *col_data;
00138     float lat_min,lat_max,lon_min,lon_max;
00139     // inner data buffers used to speed up viewing directions computations
00141     short * v_alt_view;
00143     double * v_saa;
00145     double * v_vza;
00147     double * v_raa;
00149     unsigned char * v_ni;
00151     unsigned char * v_sn;
00153     double * v_x_sat;
00154     double * v_y_sat;
00155     double * v_z_sat;
00156 
00160     void init_viewing_direction();
00161 
00162     void init();
00163     void parse_filename(const string& short_filename);
00164     bool check_filename(const string& short_filename) const;
00171     void check_grid_coord (const int irow, const int icol) const;
00177     void set_grid_factor();
00187     bool init_read_data_range(const int entry_idx, int * &start, int * &edges, int &rank);
00199     void* read_count_data(void* data, const int var_idx = -1, int * start = NULL, int * edges = NULL, int rank = -1);
00208     void get_scaling(const int var_idx, double &slope, double &offset, unsigned short& nb_bytes);
00209 
00215     const EntryFormat *get_entry_format(const int &var_idx);
00216 protected:
00222     vector<int> get_data_dimension(const int var_idx);
00223 public:
00230     PARASOLFileData(const string& name, const string& mode="r");
00234     ~PARASOLFileData();
00240     const string get_radix();
00245     const int get_instrument() const {
00246         return instrument;
00247     }
00252     const int get_level() const {
00253         return level;
00254     }
00259     const ProcessingLine get_processing_line() const {
00260         return processing_line;
00261     }
00266     const string get_processing_line_string() const;
00272     const char get_processing_line_char() const;
00277     const char get_product() const {
00278         return product;
00279     }
00284     const int get_orbit_cycle_nb() const {
00285         return orbit_cycle_nb;
00286     }
00291     const int get_orbit_nb() const {
00292         return orbit_nb;
00293     }
00298     const char get_reprocessing_nb() const {
00299         return reprocessing_nb;
00300     }
00306     void geolocation_to_grid(const float * lat_lon, int * grid_idx);
00316     void geolocation_to_grid(const float lat, const float lon, int & irow, int & icol);
00324     void grid_to_geolocation (const int igrid[2], float lat_minmax[2], float lon_minmax[2]);
00330     void grid_to_geolocation (const int igrid[2], float pos[2]);
00337     void grid_to_geolocation (const int igrid[2], float & lat, float & lon);
00346     void grid_to_geolocation (const int irow, const int icol, float & lat, float & lon);
00351     const int get_nrow() const;
00357     const int get_ncol(const int irow = -1) const;
00363     const int get_ncol(const double lat) const;
00370     bool is_earth_grid (const int irow, const int icol) const;
00376     const double get_grid_lat (const int irow) const;
00384     void get_record_coord(const int irec, float &lat, float &lon);
00390     void idata2igrid (const int irec, int igrid[2]);
00396     vector<int> get_data_dimension(const string &var_name);
00436     void* read_count_data(void * data, const char* var_name = "alt", int * start = NULL, int * edges = NULL, int rank = -1);
00480     double* read_scaled_data(double * data, const char * var_name = "alt", int * start = NULL, int * edges = NULL, int rank = -1);
00556     void * read_data(void * data, const char * var_name, int * start = NULL, int * stride = NULL, int * edges = NULL, int rank = -1);
00561     const int get_nb_data();
00565     virtual void load_geolocation_data();
00569     virtual void free_geolocation_data();
00573     void load_v_pixel() ;
00578     virtual const bool is_geolocation_data_loaded() const;
00586     const bool contain_data(const float &lat,const float &lon, const double &time);
00595     const bool contain_data(const float &lat,const float &lon, const double &time, const double &tolerance);
00603     const bool contain_location(const float &lat,const float &lon);
00612     const bool contain_location(const float &lat,const float &lon, const double &tolerance);
00618     const bool contain_pixel(const int* pix_idx);
00626     void get_scaling(const string &var_name, double &slope, double &offset, unsigned short& nb_bytes);
00632     const EntryFormat *get_entry_format(const string &var_name);
00636     void open_data_file(){
00637         assert(data!=NULL);
00638         data->open_file();
00639     };
00640     void close_data_file(){
00641         assert(data!=NULL);
00642         data->close_file();
00643     };
00644     const bool is_data_file_opened(){
00645         return (data!=NULL && data->is_file_loaded());
00646     };
00647     unsigned short* get_line_data() const {
00648         assert(line_data!=NULL); // TODO do load geolocation_data before if NULL
00649         return line_data;
00650     }
00651     unsigned short* get_col_data() const {
00652         assert(col_data!=NULL); // TODO do load geolocation_data before if NULL
00653         return col_data;
00654     }
00663     const bool get_index(const float& lat, const float& lon, int &irec);
00673     const bool get_index(const float &lat, const float& lon, int &irec, const float colocation_tolerance);
00681     const bool get_index(const int ipix[2], int & irec);
00687     const bool get_index(const vector <int> & ipix, int & irec);
00693     void igrid2idata (const int igrid[2], int & irec);
00699     void igrid2idata (const vector<int> & igrid, int & irec);
00708      virtual void get_vindex(vector < vector < int > > &v_index, const float &lat, const float& lon,
00709                                             const float colocation_tolerance) {
00710         UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
00711         throw e;
00712      };
00713 
00714     const float get_nearest_point_distance(const float & lat, const float & lon, const float coloc_tolerance);
00715 
00720     const bool is_file_loaded();
00724     void close_file();
00729     static const int get_max_direction();
00735     void get_pixel(const int &irec, int ipix[2]);
00739     void print_scaling_factors(){
00740         leader->print_scaling_factors();
00741     };
00745     void print_spatio_temp_char(){
00746         leader->print_spatio_temp_char();
00747     };
00751     void print_techno_param(){
00752         leader->print_techno_param();
00753     };
00759     inline const double get_record_time(const int &irec) {
00760       assert(leader->is_record_loaded(SPATIO_TEMPORAL_CHARACTERISTICS));
00761       int pixel[]={-1,-1};
00762       // record to pixel mapping
00763       get_pixel(irec,pixel);
00764       // pixel to geolocation mapping
00765       float latminmax[]={-1.,-1.};
00766       float lonminmax[]={-1.,-1.};
00767       grid_to_geolocation(pixel,latminmax,lonminmax);
00768       float lat=(latminmax[1]-latminmax[0])/2.;
00769       // Ascending node time
00770       string s_asc_node_time(leader->spatio_temp_char->desc_node_date);
00771       s_asc_node_time=s_asc_node_time.substr(0,s_asc_node_time.size()-2);
00772       Date d; d.set_date_str(s_asc_node_time,"%Y%m%d%H%M%S");
00773       return d.get_TAI93_time()+lat*lat2time_coef;
00774     };
00775 
00787     static inline const double get_filter_view_zenith_angle(const double &view_zenith_angle_filter8,
00788                                                              const double &relative_azimuth_angle_filter8,
00789                                                              const double &delta_thetav_cosphi,
00790                                                              const double &delta_thetav_sinphi,
00791                                                              const int    xj) {
00792         double a1=view_zenith_angle_filter8*cos(relative_azimuth_angle_filter8) +
00793                       (double)(xj)*delta_thetav_cosphi;
00794         double a2=view_zenith_angle_filter8*sin(relative_azimuth_angle_filter8) +
00795                       (double)(xj)*delta_thetav_sinphi;
00796         return sqrt(pow (a1,2) + pow(a2,2));
00797     }
00809     static inline const double get_filter_relative_azimuth_angle(const double &view_zenith_angle_filter8,
00810                                                                   const double &relative_azimuth_angle_filter8,
00811                                                                   const double &delta_thetav_cosphi,
00812                                                                   const double &delta_thetav_sinphi,
00813                                                                   const int    xj) {
00814         double a1=view_zenith_angle_filter8*sin(relative_azimuth_angle_filter8) +
00815                       (double)(xj)*delta_thetav_sinphi;
00816         double a2=view_zenith_angle_filter8*cos(relative_azimuth_angle_filter8) +
00817                       (double)(xj)*delta_thetav_cosphi;
00818         double offset=0.;
00819         if (a2<0)
00820             offset+=180.;
00821         return offset + atan (a1/a2) ;
00822     }
00830     virtual void get_pixel_coord (const vector < int > & ipix, float &lat, float &lon, double &time) {
00831         UnimplementedMethod e(__FILE__,__LINE__,__PRETTY_FUNCTION__);
00832         throw e;
00833     };
00838     const string get_software_version_number() const {
00839         return software_version_number;
00840     }
00846 //     virtual void load_viewing_directions ();
00852     virtual void get_viewing_directions (const vector <int> & ipix, vector <Observation> & v_obs);
00856     virtual bool is_viewing_directions_data_loaded();
00860     virtual void load_viewing_directions_data ();
00864     virtual void free_viewing_directions_data ();
00869     virtual void load_pix2data_map ();
00880 //     void get_neighbours_coord (const int irow, const int icol, const int d_irow, const int d_icol, vector<int> & v_irow, vector<int> & v_icol);
00895     void get_neighbours_coord (const int irow, const int icol, int dirow_min, int dirow_max, int dicol_min, int dicol_max, vector<int> & v_irow, vector<int> & v_icol);
00905     void get_v_icol_neighbours (const int irow, const int icol, int dicol_min, int dicol_max, vector <int> & v_icol);
00906 
00911     unsigned char * get_ndir_data() const;
00912 private:
00919     void _get_viewing_directions_l1(const vector< int > & ipix, const int irec, vector< Observation > & v_obs);
00926     void _get_viewing_directions_l2(const vector< int > & ipix, const int irec, vector< Observation > & v_obs);
00927 
00931 //     virtual void _load_viewing_directions_l1 ();
00936 //     virtual void _load_viewing_directions_l2 ();
00937 };
00938 
00939 #endif

Generated on Thu Feb 14 2013 17:59:03 for filedata.kdevelop by  doxygen 1.7.1