00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef EPR_API_H_INCL
00019 #define EPR_API_H_INCL
00020
00021
00022 #ifdef __cplusplus
00023 extern "C"
00024 {
00025 #endif
00026
00027
00028 #include <stdio.h>
00029
00030
00031 #include "epr_ptrarray.h"
00032
00033 #define EPR_PRODUCT_API_NAME_STR "ENVISAT Product Reader API"
00034 #define EPR_PRODUCT_API_VERSION_STR "2.0.5"
00035
00036
00041 enum EPR_DataTypeId
00042 {
00044 e_tid_unknown = 0,
00046 e_tid_uchar = 1,
00048 e_tid_char = 2,
00050 e_tid_ushort = 3,
00052 e_tid_short = 4,
00054 e_tid_ulong = 5,
00056 e_tid_long = 6,
00058 e_tid_float = 7,
00060 e_tid_double = 8,
00062 e_tid_string = 11,
00064 e_tid_spare = 13,
00066 e_tid_time = 21
00067 };
00068
00069
00074 enum EPR_ErrCode
00075 {
00076
00077 e_err_none = 0,
00078
00079
00080 e_err_null_pointer = 1,
00081 e_err_illegal_arg = 2,
00082 e_err_illegal_state = 3,
00083 e_err_out_of_memory = 4,
00084 e_err_index_out_of_range = 5,
00085 e_err_illegal_conversion = 6,
00086 e_err_illegal_data_type = 7,
00087
00088
00089 e_err_file_not_found = 101,
00090 e_err_file_access_denied = 102,
00091 e_err_file_read_error = 103,
00092 e_err_file_write_error = 104,
00093 e_err_file_open_failed = 105,
00094 e_err_file_close_failed = 106,
00095
00096
00097 e_err_api_not_initialized = 201,
00098 e_err_invalid_product_id = 203,
00099 e_err_invalid_record = 204,
00100 e_err_invalid_band = 205,
00101 e_err_invalid_raster = 206,
00102 e_err_invalid_dataset_name = 207,
00103 e_err_invalid_field_name = 208,
00104 e_err_invalid_record_name = 209,
00105 e_err_invalid_product_name = 210,
00106 e_err_invalid_band_name = 211,
00107 e_err_invalid_data_format = 212,
00108 e_err_invalid_value = 213,
00109 e_err_invalid_keyword_name = 214,
00110 e_err_unknown_endian_order = 216,
00111
00112
00113 e_err_flag_not_found = 301,
00114
00115
00116
00117 e_err_invalid_ddbb_format = 402
00118 };
00119
00120
00125 enum EPR_LogLevel
00126 {
00127 e_log_debug = -1,
00128 e_log_info = 0,
00129 e_log_warning = 1,
00130 e_log_error = 2
00131 };
00132
00133 enum EPR_SampleModel
00134 {
00135 e_smod_1OF1 = 0,
00136 e_smod_1OF2 = 1,
00137 e_smod_2OF2 = 2,
00138 e_smod_3TOI = 3,
00139 e_smod_2TOF = 4
00140 };
00141
00142 enum EPR_ScalingMethod
00143 {
00144 e_smid_non = 0,
00145 e_smid_lin = 1,
00146 e_smid_log = 2
00147 };
00148
00149 struct EPR_ProductId;
00150 struct EPR_DatasetId;
00151 struct EPR_BandId;
00152 struct EPR_Record;
00153 struct EPR_RecordInfo;
00154 struct EPR_Field;
00155 struct EPR_FieldInfo;
00156 struct EPR_ProductInfo;
00157 struct EPR_DSD;
00158 struct EPR_Raster;
00159 struct EPR_DatasetRef;
00160 struct EPR_Flag;
00161 struct EPR_BandId;
00162 struct EPR_ParamElem;
00163 struct EPR_Time;
00164
00165 typedef enum EPR_DataTypeId EPR_EDataTypeId;
00166 typedef enum EPR_ErrCode EPR_EErrCode;
00167 typedef enum EPR_LogLevel EPR_ELogLevel;
00168 typedef enum EPR_SampleModel EPR_ESampleModel;
00169 typedef enum EPR_ScalingMethod EPR_EScalingMethod;
00170 typedef struct EPR_ProductId EPR_SProductId;
00171 typedef struct EPR_DatasetId EPR_SDatasetId;
00172 typedef struct EPR_BandId EPR_SBandId;
00173 typedef struct EPR_Record EPR_SRecord;
00174 typedef struct EPR_RecordInfo EPR_SRecordInfo;
00175 typedef struct EPR_Field EPR_SField;
00176 typedef struct EPR_FieldInfo EPR_SFieldInfo;
00177 typedef struct EPR_DSD EPR_SDSD;
00178 typedef struct EPR_Raster EPR_SRaster;
00179 typedef struct EPR_FlagDef EPR_SFlagDef;
00180 typedef struct EPR_ParamElem EPR_SParamElem;
00181 typedef struct EPR_Time EPR_STime;
00182 typedef struct EPR_DatasetRef EPR_SDatasetRef;
00183 typedef struct EPR_BitmaskTerm EPR_SBitmaskTerm;
00184 typedef struct EPR_FlagSet EPR_SFlagSet;
00185 typedef void (*EPR_FErrHandler)(EPR_EErrCode err_code, const char* err_message);
00186 typedef void (*EPR_FLogHandler)(EPR_ELogLevel log_level, const char* log_message);
00187
00188
00189 typedef int boolean;
00190 typedef unsigned char uchar;
00191 typedef unsigned short ushort;
00192 typedef unsigned int uint;
00193 typedef unsigned long ulong;
00194
00195
00196 typedef long EPR_Magic;
00197
00198 #define EPR_MAGIC_PRODUCT_ID 0xCAFFEE64
00199 #define EPR_MAGIC_DATASET_ID 0xEFEABDCA
00200 #define EPR_MAGIC_BAND_ID 0xFEC21ABD
00201 #define EPR_MAGIC_RECORD 0x7BABACAE
00202 #define EPR_MAGIC_FIELD 0xBA0BABBA
00203 #define EPR_MAGIC_RASTER 0x0BABA0EB
00204 #define EPR_MAGIC_FLAG_DEF 0xCABA11AD
00205
00206 #ifndef TRUE
00207 #define TRUE 1
00208 #endif
00209
00210 #define FALSE 0
00211
00212 #define EPR_PRODUCT_ID_STRLEN 48
00213
00214
00215
00216
00217
00218
00226 struct EPR_ProductId
00227 {
00232 EPR_Magic magic;
00233
00237 char* file_path;
00238
00243 FILE* istream;
00244
00248 uint tot_size;
00249
00253 uint scene_width;
00254
00258 uint scene_height;
00259
00268 char id_string[EPR_PRODUCT_ID_STRLEN + 1];
00269
00273 EPR_SRecord* mph_record;
00274
00278 EPR_SRecord* sph_record;
00279
00284 EPR_SPtrArray* dsd_array;
00285
00295 EPR_SPtrArray* record_info_cache;
00296
00303 EPR_SPtrArray* param_table;
00304
00308 EPR_SPtrArray* dataset_ids;
00309
00313 EPR_SPtrArray* band_ids;
00314
00318 int meris_iodd_version;
00319 };
00320
00321
00322
00323
00336 struct EPR_DatasetId
00337 {
00342 EPR_Magic magic;
00343
00347 EPR_SProductId* product_id;
00348
00352 char* dsd_name;
00353
00357 const EPR_SDSD* dsd;
00358
00362 char* dataset_name;
00363
00367 const struct RecordDescriptor* record_descriptor;
00368
00372 EPR_SRecordInfo* record_info;
00373
00374
00378 char* description;
00379 };
00380
00381
00389 struct EPR_DSD
00390 {
00395 EPR_Magic magic;
00396
00400 int index;
00401
00405 char* ds_name;
00406
00410 char* ds_type;
00411
00415 char* filename;
00416
00420 uint ds_offset;
00421
00425 uint ds_size;
00426
00430 uint num_dsr;
00431
00435 uint dsr_size;
00436 };
00437
00438
00446 struct EPR_Record
00447 {
00452 EPR_Magic magic;
00453
00457 EPR_SRecordInfo* info;
00458
00464 uint num_fields;
00465
00470 EPR_SField** fields;
00471 };
00472
00480 struct EPR_Field
00481 {
00486 EPR_Magic magic;
00487
00492 EPR_SFieldInfo* info;
00493
00514 void* elems;
00515 };
00516
00522 struct EPR_Raster
00523 {
00528 EPR_Magic magic;
00529
00534 EPR_EDataTypeId data_type;
00535
00539 ulong elem_size;
00540
00544 ulong source_width;
00545
00549 ulong source_height;
00550
00554 ulong source_step_x;
00555
00559 ulong source_step_y;
00560
00565 ulong raster_width;
00566
00571 ulong raster_height;
00572
00577 void* buffer;
00578 };
00579
00580
00595 struct EPR_DatasetRef
00596 {
00597 EPR_SDatasetId* dataset_id;
00598 int field_index;
00599 int elem_index;
00600 };
00601
00606 struct EPR_FlagDef
00607 {
00612 EPR_Magic magic;
00613
00617 char* name;
00618
00622 uint bit_mask;
00623
00627 char* description;
00628 };
00629
00630
00642 struct EPR_BandId
00643 {
00648 EPR_Magic magic;
00649
00653 EPR_SProductId* product_id;
00654
00659 char* band_name;
00660
00664 int spectr_band_index;
00665
00672 EPR_SDatasetRef dataset_ref;
00673
00682 EPR_ESampleModel sample_model;
00683
00693 EPR_EDataTypeId data_type;
00694
00702 EPR_EScalingMethod scaling_method;
00703
00713 float scaling_offset;
00714
00724 float scaling_factor;
00725
00729 char* bm_expr;
00730
00736 EPR_SPtrArray* flag_coding;
00737
00741 char* unit;
00742
00746 char* description;
00747
00753 boolean lines_mirrored;
00754 };
00755
00762 struct EPR_Time
00763 {
00764 long days;
00765 ulong seconds;
00766 ulong microseconds;
00767 };
00768
00769
00770
00771
00772
00773
00793 int epr_init_api(EPR_ELogLevel log_level,
00794 EPR_FLogHandler log_handler,
00795 EPR_FErrHandler err_handler);
00796
00797
00804 void epr_close_api();
00805
00806
00807
00808
00809
00810
00811
00822 int epr_set_log_level(EPR_ELogLevel log_level);
00823
00833 void epr_set_log_handler(EPR_FLogHandler log_handler);
00834
00843 void epr_log_message(EPR_ELogLevel log_level, const char* log_message);
00844
00845
00846
00847
00848
00855 void epr_set_err_handler(EPR_FErrHandler err_handler);
00856
00863 EPR_EErrCode epr_get_last_err_code();
00864
00871 const char* epr_get_last_err_message();
00872
00878 void epr_clear_err();
00879
00880
00881
00882
00883
00884
00885
00899 EPR_SProductId* epr_open_product(const char* product_file_path);
00900
00908 int epr_close_product(EPR_SProductId* product_id);
00909
00917 ulong epr_get_scene_width(const EPR_SProductId* product_id);
00918
00926 ulong epr_get_scene_height(const EPR_SProductId* product_id);
00927
00928
00929
00930
00931
00954 void epr_print_record(const EPR_SRecord* record, FILE* ostream);
00955 void epr_print_field(const EPR_SField* field, FILE* ostream);
00956 void epr_print_element(const EPR_SRecord* record, uint field_index, uint element_index, FILE* ostream);
00957 void epr_dump_record(const EPR_SRecord* record);
00958 void epr_dump_field(const EPR_SField* field);
00959 void epr_dump_element(const EPR_SRecord* record, uint field_index, uint element_index);
00962
00963
00964
00965
00966
00967
00968
00975 uint epr_get_num_datasets(EPR_SProductId* product_id);
00976
00985 EPR_SDatasetId* epr_get_dataset_id_at(EPR_SProductId* product_id, uint index);
00986
00994 EPR_SDatasetId* epr_get_dataset_id(EPR_SProductId* product_id, const char* dataset_name);
00995
01002 const char* epr_get_dataset_name(EPR_SDatasetId* dataset_id);
01003
01010 const char* epr_get_dsd_name(const EPR_SDatasetId* dataset_id);
01011
01018 EPR_SRecord* epr_get_mph(const EPR_SProductId* product_id);
01019
01026 EPR_SRecord* epr_get_sph(const EPR_SProductId* product_id);
01027
01034 const EPR_SDSD* epr_get_dsd(const EPR_SDatasetId* dataset_id);
01035
01042 uint epr_get_num_records(const EPR_SDatasetId* dataset_id);
01043
01044
01045 uint epr_get_num_dsds(const EPR_SProductId* product_id);
01046 EPR_SDSD* epr_get_dsd_at(const EPR_SProductId* product_id, uint dsd_index);
01047
01048
01049
01050
01051
01060 EPR_SRecord* epr_create_record(EPR_SDatasetId* dataset_id);
01061
01080 EPR_SRecord* epr_read_record(EPR_SDatasetId* dataset_id,
01081 uint record_index,
01082 EPR_SRecord* record);
01083
01091 void epr_free_record(EPR_SRecord* record);
01092
01093
01094
01095
01106 const EPR_SField* epr_get_field(const EPR_SRecord* record, const char* field_name);
01107
01114 uint epr_get_num_fields(const EPR_SRecord* record);
01115
01124 const EPR_SField* epr_get_field_at(const EPR_SRecord* record, uint field_index);
01125
01132 const char* epr_get_field_unit(const EPR_SField* field);
01133
01141 const char* epr_get_field_description(const EPR_SField* field);
01142
01150 uint epr_get_field_num_elems(const EPR_SField* field);
01151
01159 const char* epr_get_field_name(const EPR_SField* field);
01160
01168 EPR_EDataTypeId epr_get_field_type(const EPR_SField* field);
01169
01170
01171
01172
01186 char epr_get_field_elem_as_char(const EPR_SField* field, uint elem_index);
01187 uchar epr_get_field_elem_as_uchar(const EPR_SField* field, uint elem_index);
01188 short epr_get_field_elem_as_short(const EPR_SField* field, uint elem_index);
01189 ushort epr_get_field_elem_as_ushort(const EPR_SField* field, uint elem_index);
01190 long epr_get_field_elem_as_long(const EPR_SField* field, uint elem_index);
01191 ulong epr_get_field_elem_as_ulong(const EPR_SField* field, uint elem_index);
01192 float epr_get_field_elem_as_float(const EPR_SField* field, uint elem_index);
01193 double epr_get_field_elem_as_double(const EPR_SField* field, uint elem_index);
01194 const EPR_STime* epr_get_field_elem_as_mjd(const EPR_SField* field);
01195 const char* epr_get_field_elem_as_str(const EPR_SField* field);
01198
01199
01200
01212 const char* epr_get_field_elems_char(const EPR_SField* field);
01213 const uchar* epr_get_field_elems_uchar(const EPR_SField* field);
01214 const short* epr_get_field_elems_short(const EPR_SField* field);
01215 const ushort* epr_get_field_elems_ushort(const EPR_SField* field);
01216 const long* epr_get_field_elems_long(const EPR_SField* field);
01217 const ulong* epr_get_field_elems_ulong(const EPR_SField* field);
01218 const float* epr_get_field_elems_float(const EPR_SField* field);
01219 const double* epr_get_field_elems_double(const EPR_SField* field);
01237 uint epr_copy_field_elems_as_doubles(const EPR_SField* field, double* buffer, uint num_elems);
01238 uint epr_copy_field_elems_as_floats(const EPR_SField* field, float* buffer, uint num_elems);
01239 uint epr_copy_field_elems_as_longs(const EPR_SField* field, long* buffer, uint num_elems);
01240 uint epr_copy_field_elems_as_ulongs(const EPR_SField* field, ulong* buffer, uint num_elems);
01243
01244
01245
01246
01247
01248
01283 EPR_SRaster* epr_create_compatible_raster(EPR_SBandId* band_id,
01284 uint source_width,
01285 uint source_height,
01286 uint source_step_x,
01287 uint source_step_y);
01288
01301 EPR_SRaster* epr_create_raster(EPR_EDataTypeId data_type,
01302 uint source_width,
01303 uint source_height,
01304 uint source_step_x,
01305 uint source_step_y);
01306
01307
01318 EPR_SRaster* epr_create_bitmask_raster(uint source_width,
01319 uint source_height,
01320 uint source_step_x,
01321 uint source_step_y);
01322
01340 int epr_read_band_raster(EPR_SBandId* band_id,
01341 int offset_x,
01342 int offset_y,
01343 EPR_SRaster* raster);
01344
01345
01349 ulong epr_get_raster_elem_size(const EPR_SRaster* raster);
01350
01354 void* epr_get_raster_elem_addr(const EPR_SRaster* raster, ulong offset);
01355
01359 void* epr_get_raster_pixel_addr(const EPR_SRaster* raster, ulong x, ulong y);
01360
01364 void* epr_get_raster_line_addr(const EPR_SRaster* raster, ulong y);
01365
01366
01374 ulong epr_get_raster_width(EPR_SRaster* raster);
01375
01383 ulong epr_get_raster_height(EPR_SRaster* raster);
01384
01385
01386
01393 uint epr_get_num_bands(EPR_SProductId* product_id);
01394
01403 EPR_SBandId* epr_get_band_id_at(EPR_SProductId* product_id, uint index);
01404
01412 EPR_SBandId* epr_get_band_id(EPR_SProductId* product_id, const char* band_name);
01413
01420 const char* epr_get_band_name(EPR_SBandId* band_id);
01421
01427 void epr_free_raster(EPR_SRaster* raster);
01428
01429
01430
01431
01443 ulong epr_get_pixel_as_ulong(const EPR_SRaster* raster, int x, int y);
01444 long epr_get_pixel_as_long(const EPR_SRaster* raster, int x, int y);
01445 float epr_get_pixel_as_float(const EPR_SRaster* raster, int x, int y);
01446 double epr_get_pixel_as_double(const EPR_SRaster* raster, int x, int y);
01449
01450
01451
01473 int epr_read_bitmask_raster(EPR_SProductId* product_id,
01474 const char* bm_expr,
01475 int offset_x,
01476 int offset_y,
01477 EPR_SRaster* raster);
01478
01479
01480
01481
01482
01486 uint epr_get_data_type_size(EPR_EDataTypeId data_type_id);
01487
01491 const char* epr_data_type_id_to_str(EPR_EDataTypeId data_type_id);
01492
01493 #ifdef __cplusplus
01494 }
01495 #endif
01496 #endif
01497