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

/home/pascal/depot/filedata/src/parasolfileformat.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 PARASOLFILEFORMAT_H
00021 #define PARASOLFILEFORMAT_H
00022 
00023 #include <map>
00024 #include "file_tools.h"
00025 #include "tools.h"
00026 #include "file_exceptions.h"
00027 #include "filedataexception.h"
00028 #include "parasolfilerecord.h"
00029 
00030 #include <vector>
00031 
00035 enum PARASOLDataType{
00036     CHAR8,
00037     UCHAR8,
00038     UINT8,
00039     INT8,
00040     INT16,
00041     UINT16,
00042     INT32,
00043     UINT32,
00044     B2, //   2 Bytes bitfield entry
00045     B4, //   4 Bytes bitfield  entry
00046     B8, //   8 Bytes bitfield  entry
00047     B16, // 16 Bytes bitfield  entry
00048     FLOAT12_4, // this type is a string representing a double
00049     EXP12_5, // this type is a string representing a double
00050     FLOAT8_3, // this type is a string representing a double
00051     FLOAT16_7, // this type is a string representing a double
00052 
00053 };
00054 
00059 enum PARASOLProduct{
00060     UNDEFINED=-1,
00061     BASIC_1,
00062     RB_2,
00063     OC_SURF_DIR_2,
00064     OC_SURF_NON_DIR_2,
00065     OC_AEROSOL_2,
00066     LS_SURF_DIR_2,
00067     LS_AEROSOL_2,
00068     RB_3,
00069     OC_MARINE_3,
00070     OC_AEROSOL_3,
00071     LS_DIR_SIGN_3,
00072     LS_ALBEDO_3,
00073     LS_ATMO_3,
00074 };
00075 
00086 class EntryFormat{
00087 public:
00088     string name;
00089     unsigned short pos;
00090     unsigned short len;
00091     PARASOLDataType type;
00092     string desc;
00093 
00094     EntryFormat(const char* name="", unsigned short pos=0,unsigned short len=0,PARASOLDataType type=CHAR8, const char* desc="") : name(name),pos(pos),len(len),type(type),desc(desc){;};
00095     EntryFormat(const EntryFormat& my_entry){
00096         name=my_entry.name;
00097         pos=my_entry.pos;
00098         len=my_entry.len;
00099         type=my_entry.type;
00100         desc=my_entry.desc;
00101     };
00102     EntryFormat &operator=(const EntryFormat &my_entry) {
00103         if (&my_entry == this)
00104             return *this; // protection against self assignation
00105         name=my_entry.name;
00106         pos=my_entry.pos;
00107         len=my_entry.len;
00108         type=my_entry.type;
00109         desc=my_entry.desc;
00110         return *this;
00111     };
00112     ~EntryFormat(){};
00113 } ;
00117 typedef std::vector< EntryFormat > RecordFormat;
00121 class PARASOLFileFormat{
00122     PARASOLProduct product;
00123 public:
00124     PARASOLFileFormat(const PARASOLProduct &product=UNDEFINED) : product(product){};
00125     virtual ~PARASOLFileFormat(){};
00129     static const int full_res_grid_col_max = 6480;
00133     static const int full_res_grid_line_max = 3240;
00139     static const size_t get_size_of(PARASOLDataType code);
00145     static const int get_level(const PARASOLProduct &product);
00150     static const int get_nb_grid_line(const PARASOLProduct &product);
00156     static const int get_grid_factor(const PARASOLProduct &product);
00162     template <typename T>
00163     static const T get_missing_value(const int level) ;
00168     template <typename T>
00169     static const T get_out_of_range_value(const int level) ;
00170 };
00171 
00175 class PARASOLLeaderFormat:public PARASOLFileFormat{
00176     RecordFormat leader_file_descriptor_format;
00177     RecordFormat header_format;
00178     RecordFormat spatio_temporal_characteristics_format;
00179     RecordFormat instrument_setting_parameters_format;
00180     RecordFormat technological_parameters_format;
00181     RecordFormat data_processing_parameters_format;
00182     RecordFormat scaling_factors_format;
00183     RecordFormat annotations_format;
00184 
00188     void build_common_record_format();
00192     void build_level_1_record_format();
00196     void build_level_2_record_format();
00200     void build_level_3_record_format();
00201 
00202 public:
00203 /*************************************
00204 ***  CONSTRUCTORS/DESTRUCTORS  ***
00205 *************************************/
00206 
00207     PARASOLLeaderFormat( const PARASOLProduct product=UNDEFINED);
00208 
00209     ~PARASOLLeaderFormat(){};
00210 
00211     const RecordFormat* get_leader_file_descriptor_format() const {
00212         return &leader_file_descriptor_format;
00213     };
00214     const RecordFormat* get_header_format() const {
00215         return &header_format;
00216     };
00217     const RecordFormat* get_spatio_temporal_characteristics_format() const {
00218         return &spatio_temporal_characteristics_format;
00219     };
00220     const RecordFormat* get_instrument_setting_parameters_format() const {
00221         return &instrument_setting_parameters_format;
00222     };
00223     const RecordFormat* get_technological_parameters_format() const {
00224         return &technological_parameters_format;
00225     };
00226     const RecordFormat* get_data_processing_parameters_format() const {
00227         return &data_processing_parameters_format;
00228     };
00229     const RecordFormat* get_scaling_factors_format() const {
00230         return &scaling_factors_format;
00231     };
00232     const RecordFormat* get_annotations_format() const {
00233         return &annotations_format;
00234     };
00235 };
00240 class PARASOLDataFormat: public PARASOLFileFormat{
00241     RecordFormat data_file_descriptor_format;
00242     RecordFormat data_format;
00243 
00244     void build_data_descriptor_record_format(); // common to all products
00245     void build_data_format(); // should be determined
00246 
00247     // product specific methods
00248     void build_BASIC_1_record_format();
00249     void build_RB_2_record_format();
00250     void build_OC_SURF_DIR_2_record_format();
00251     void build_OC_SURF_NON_DIR_2_record_format();
00252     void build_OC_AEROSOL_2_record_format();
00253     void build_LS_SURF_DIR_2_record_format();
00254     void build_LS_AEROSOL_2_record_format();
00255     void build_RB_3_record_format();
00256     void build_OC_MARINE_3_record_format();
00257     void build_OC_AEROSOL_3_record_format();
00258     void build_LS_DIR_SIGN_3_record_format();
00259     void build_LS_ALBEDO_3_record_format();
00260     void build_LS_ATMO_3_record_format();
00261 
00262 public:
00263 /*************************************
00264 ***  CONSTRUCTORS/DESTRUCTORS  ***
00265 *************************************/
00266 
00267     PARASOLDataFormat( const PARASOLProduct product=UNDEFINED) ;
00268     ~PARASOLDataFormat(){};
00269 
00270     const RecordFormat* get_data_file_descriptor_format() const {
00271         return &data_file_descriptor_format;
00272     };
00273     const RecordFormat* get_data_format() const {
00274         return &data_format;
00275     };
00284     const int get_entry_index(const string& var_name) const;
00285 };
00286 
00287 template <typename T>
00288 const T PARASOLFileFormat::get_missing_value( const int level)
00289 {
00290   if (level<1 || level>3) {
00291     bad_level e(level);
00292     throw e;
00293   }
00294   if (level==1) {
00295     if ( typeid(T)==typeid(unsigned char) ) {
00296       return (T)(255);
00297     } else if ( typeid(T)==typeid(signed char) ) {
00298       return (T)(-127);
00299     } else if ( typeid(T)==typeid(unsigned short) ) {
00300       return (T)(0);
00301     } else if ( typeid(T)==typeid(signed short) ) {
00302       return (T)(-32767);
00303     }
00304   } else if (level==2 || level==3) {
00305     if ( typeid(T)==typeid(unsigned char) ) {
00306       return (T)(255);
00307     } else if ( typeid(T)==typeid(unsigned short) ) {
00308       return (T)(65535);
00309     }
00310   }
00311   return T(1); // no missing value
00312 }
00313 template <typename T>
00314 const T PARASOLFileFormat::get_out_of_range_value( const int level)
00315 {
00316   if (level<1 || level>3) {
00317     bad_level e(level);
00318     throw e;
00319   }
00320   if (level==1) {
00321     if ( typeid(T)==typeid(unsigned char) ) {
00322       return (T)(254);
00323     } else if ( typeid(T)==typeid(signed short) ) {
00324       return (T)(32767);
00325     }
00326   } else if (level==2 || level==3) {
00327     if ( typeid(T)==typeid(unsigned char) ) {
00328       return (T)(254);
00329     } else if ( typeid(T)==typeid(unsigned short) ) {
00330       return (T)(65534);
00331     }
00332   }
00333   return T(1); // no missing value
00334 }
00335 
00336 #endif

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