00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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,
00045 B4,
00046 B8,
00047 B16,
00048 FLOAT12_4,
00049 EXP12_5,
00050 FLOAT8_3,
00051 FLOAT16_7,
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;
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
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();
00245 void build_data_format();
00246
00247
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
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);
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);
00334 }
00335
00336 #endif