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 #define TRUE 1
00207 #define FALSE 0
00208
00209 #define EPR_PRODUCT_ID_STRLEN 48
00210
00211
00212
00213
00214
00215
00223 struct EPR_ProductId
00224 {
00229 EPR_Magic magic;
00230
00234 char* file_path;
00235
00240 FILE* istream;
00241
00245 uint tot_size;
00246
00250 uint scene_width;
00251
00255 uint scene_height;
00256
00265 char id_string[EPR_PRODUCT_ID_STRLEN + 1];
00266
00270 EPR_SRecord* mph_record;
00271
00275 EPR_SRecord* sph_record;
00276
00281 EPR_SPtrArray* dsd_array;
00282
00292 EPR_SPtrArray* record_info_cache;
00293
00300 EPR_SPtrArray* param_table;
00301
00305 EPR_SPtrArray* dataset_ids;
00306
00310 EPR_SPtrArray* band_ids;
00311
00315 int meris_iodd_version;
00316 };
00317
00318
00319
00320
00333 struct EPR_DatasetId
00334 {
00339 EPR_Magic magic;
00340
00344 EPR_SProductId* product_id;
00345
00349 char* dsd_name;
00350
00354 const EPR_SDSD* dsd;
00355
00359 char* dataset_name;
00360
00364 const struct RecordDescriptor* record_descriptor;
00365
00369 EPR_SRecordInfo* record_info;
00370
00371
00375 char* description;
00376 };
00377
00378
00386 struct EPR_DSD
00387 {
00392 EPR_Magic magic;
00393
00397 int index;
00398
00402 char* ds_name;
00403
00407 char* ds_type;
00408
00412 char* filename;
00413
00417 uint ds_offset;
00418
00422 uint ds_size;
00423
00427 uint num_dsr;
00428
00432 uint dsr_size;
00433 };
00434
00435
00443 struct EPR_Record
00444 {
00449 EPR_Magic magic;
00450
00454 EPR_SRecordInfo* info;
00455
00461 uint num_fields;
00462
00467 EPR_SField** fields;
00468 };
00469
00477 struct EPR_Field
00478 {
00483 EPR_Magic magic;
00484
00489 EPR_SFieldInfo* info;
00490
00511 void* elems;
00512 };
00513
00519 struct EPR_Raster
00520 {
00525 EPR_Magic magic;
00526
00531 EPR_EDataTypeId data_type;
00532
00536 ulong elem_size;
00537
00541 ulong source_width;
00542
00546 ulong source_height;
00547
00551 ulong source_step_x;
00552
00556 ulong source_step_y;
00557
00562 ulong raster_width;
00563
00568 ulong raster_height;
00569
00574 void* buffer;
00575 };
00576
00577
00592 struct EPR_DatasetRef
00593 {
00594 EPR_SDatasetId* dataset_id;
00595 int field_index;
00596 int elem_index;
00597 };
00598
00603 struct EPR_FlagDef
00604 {
00609 EPR_Magic magic;
00610
00614 char* name;
00615
00619 uint bit_mask;
00620
00624 char* description;
00625 };
00626
00627
00639 struct EPR_BandId
00640 {
00645 EPR_Magic magic;
00646
00650 EPR_SProductId* product_id;
00651
00656 char* band_name;
00657
00661 int spectr_band_index;
00662
00669 EPR_SDatasetRef dataset_ref;
00670
00679 EPR_ESampleModel sample_model;
00680
00690 EPR_EDataTypeId data_type;
00691
00699 EPR_EScalingMethod scaling_method;
00700
00710 float scaling_offset;
00711
00721 float scaling_factor;
00722
00726 char* bm_expr;
00727
00733 EPR_SPtrArray* flag_coding;
00734
00738 char* unit;
00739
00743 char* description;
00744
00750 boolean lines_mirrored;
00751 };
00752
00759 struct EPR_Time
00760 {
00761 long days;
00762 ulong seconds;
00763 ulong microseconds;
00764 };
00765
00766
00767
00768
00769
00770
00790 int epr_init_api(EPR_ELogLevel log_level,
00791 EPR_FLogHandler log_handler,
00792 EPR_FErrHandler err_handler);
00793
00794
00801 void epr_close_api();
00802
00803
00804
00805
00806
00807
00808
00819 int epr_set_log_level(EPR_ELogLevel log_level);
00820
00830 void epr_set_log_handler(EPR_FLogHandler log_handler);
00831
00840 void epr_log_message(EPR_ELogLevel log_level, const char* log_message);
00841
00842
00843
00844
00845
00852 void epr_set_err_handler(EPR_FErrHandler err_handler);
00853
00860 EPR_EErrCode epr_get_last_err_code();
00861
00868 const char* epr_get_last_err_message();
00869
00875 void epr_clear_err();
00876
00877
00878
00879
00880
00881
00882
00896 EPR_SProductId* epr_open_product(const char* product_file_path);
00897
00905 int epr_close_product(EPR_SProductId* product_id);
00906
00914 ulong epr_get_scene_width(const EPR_SProductId* product_id);
00915
00923 ulong epr_get_scene_height(const EPR_SProductId* product_id);
00924
00925
00926
00927
00928
00951 void epr_print_record(const EPR_SRecord* record, FILE* ostream);
00952 void epr_print_field(const EPR_SField* field, FILE* ostream);
00953 void epr_print_element(const EPR_SRecord* record, uint field_index, uint element_index, FILE* ostream);
00954 void epr_dump_record(const EPR_SRecord* record);
00955 void epr_dump_field(const EPR_SField* field);
00956 void epr_dump_element(const EPR_SRecord* record, uint field_index, uint element_index);
00959
00960
00961
00962
00963
00964
00965
00972 uint epr_get_num_datasets(EPR_SProductId* product_id);
00973
00982 EPR_SDatasetId* epr_get_dataset_id_at(EPR_SProductId* product_id, uint index);
00983
00991 EPR_SDatasetId* epr_get_dataset_id(EPR_SProductId* product_id, const char* dataset_name);
00992
00999 const char* epr_get_dataset_name(EPR_SDatasetId* dataset_id);
01000
01007 const char* epr_get_dsd_name(const EPR_SDatasetId* dataset_id);
01008
01015 EPR_SRecord* epr_get_mph(const EPR_SProductId* product_id);
01016
01023 EPR_SRecord* epr_get_sph(const EPR_SProductId* product_id);
01024
01031 const EPR_SDSD* epr_get_dsd(const EPR_SDatasetId* dataset_id);
01032
01039 uint epr_get_num_records(const EPR_SDatasetId* dataset_id);
01040
01041
01042 uint epr_get_num_dsds(const EPR_SProductId* product_id);
01043 EPR_SDSD* epr_get_dsd_at(const EPR_SProductId* product_id, uint dsd_index);
01044
01045
01046
01047
01048
01057 EPR_SRecord* epr_create_record(EPR_SDatasetId* dataset_id);
01058
01077 EPR_SRecord* epr_read_record(EPR_SDatasetId* dataset_id,
01078 uint record_index,
01079 EPR_SRecord* record);
01080
01088 void epr_free_record(EPR_SRecord* record);
01089
01090
01091
01092
01103 const EPR_SField* epr_get_field(const EPR_SRecord* record, const char* field_name);
01104
01111 uint epr_get_num_fields(const EPR_SRecord* record);
01112
01121 const EPR_SField* epr_get_field_at(const EPR_SRecord* record, uint field_index);
01122
01129 const char* epr_get_field_unit(const EPR_SField* field);
01130
01138 const char* epr_get_field_description(const EPR_SField* field);
01139
01147 uint epr_get_field_num_elems(const EPR_SField* field);
01148
01156 const char* epr_get_field_name(const EPR_SField* field);
01157
01165 EPR_EDataTypeId epr_get_field_type(const EPR_SField* field);
01166
01167
01168
01169
01183 char epr_get_field_elem_as_char(const EPR_SField* field, uint elem_index);
01184 uchar epr_get_field_elem_as_uchar(const EPR_SField* field, uint elem_index);
01185 short epr_get_field_elem_as_short(const EPR_SField* field, uint elem_index);
01186 ushort epr_get_field_elem_as_ushort(const EPR_SField* field, uint elem_index);
01187 long epr_get_field_elem_as_long(const EPR_SField* field, uint elem_index);
01188 ulong epr_get_field_elem_as_ulong(const EPR_SField* field, uint elem_index);
01189 float epr_get_field_elem_as_float(const EPR_SField* field, uint elem_index);
01190 double epr_get_field_elem_as_double(const EPR_SField* field, uint elem_index);
01191 const EPR_STime* epr_get_field_elem_as_mjd(const EPR_SField* field);
01192 const char* epr_get_field_elem_as_str(const EPR_SField* field);
01195
01196
01197
01209 const char* epr_get_field_elems_char(const EPR_SField* field);
01210 const uchar* epr_get_field_elems_uchar(const EPR_SField* field);
01211 const short* epr_get_field_elems_short(const EPR_SField* field);
01212 const ushort* epr_get_field_elems_ushort(const EPR_SField* field);
01213 const long* epr_get_field_elems_long(const EPR_SField* field);
01214 const ulong* epr_get_field_elems_ulong(const EPR_SField* field);
01215 const float* epr_get_field_elems_float(const EPR_SField* field);
01216 const double* epr_get_field_elems_double(const EPR_SField* field);
01234 uint epr_copy_field_elems_as_doubles(const EPR_SField* field, double* buffer, uint num_elems);
01235 uint epr_copy_field_elems_as_floats(const EPR_SField* field, float* buffer, uint num_elems);
01236 uint epr_copy_field_elems_as_longs(const EPR_SField* field, long* buffer, uint num_elems);
01237 uint epr_copy_field_elems_as_ulongs(const EPR_SField* field, ulong* buffer, uint num_elems);
01240
01241
01242
01243
01244
01245
01280 EPR_SRaster* epr_create_compatible_raster(EPR_SBandId* band_id,
01281 uint source_width,
01282 uint source_height,
01283 uint source_step_x,
01284 uint source_step_y);
01285
01298 EPR_SRaster* epr_create_raster(EPR_EDataTypeId data_type,
01299 uint source_width,
01300 uint source_height,
01301 uint source_step_x,
01302 uint source_step_y);
01303
01304
01315 EPR_SRaster* epr_create_bitmask_raster(uint source_width,
01316 uint source_height,
01317 uint source_step_x,
01318 uint source_step_y);
01319
01337 int epr_read_band_raster(EPR_SBandId* band_id,
01338 int offset_x,
01339 int offset_y,
01340 EPR_SRaster* raster);
01341
01342
01346 ulong epr_get_raster_elem_size(const EPR_SRaster* raster);
01347
01351 void* epr_get_raster_elem_addr(const EPR_SRaster* raster, ulong offset);
01352
01356 void* epr_get_raster_pixel_addr(const EPR_SRaster* raster, ulong x, ulong y);
01357
01361 void* epr_get_raster_line_addr(const EPR_SRaster* raster, ulong y);
01362
01363
01371 ulong epr_get_raster_width(EPR_SRaster* raster);
01372
01380 ulong epr_get_raster_height(EPR_SRaster* raster);
01381
01382
01383
01390 uint epr_get_num_bands(EPR_SProductId* product_id);
01391
01400 EPR_SBandId* epr_get_band_id_at(EPR_SProductId* product_id, uint index);
01401
01409 EPR_SBandId* epr_get_band_id(EPR_SProductId* product_id, const char* band_name);
01410
01417 const char* epr_get_band_name(EPR_SBandId* band_id);
01418
01424 void epr_free_raster(EPR_SRaster* raster);
01425
01426
01427
01428
01440 ulong epr_get_pixel_as_ulong(const EPR_SRaster* raster, int x, int y);
01441 long epr_get_pixel_as_long(const EPR_SRaster* raster, int x, int y);
01442 float epr_get_pixel_as_float(const EPR_SRaster* raster, int x, int y);
01443 double epr_get_pixel_as_double(const EPR_SRaster* raster, int x, int y);
01446
01447
01448
01470 int epr_read_bitmask_raster(EPR_SProductId* product_id,
01471 const char* bm_expr,
01472 int offset_x,
01473 int offset_y,
01474 EPR_SRaster* raster);
01475
01476
01477
01478
01479
01483 uint epr_get_data_type_size(EPR_EDataTypeId data_type_id);
01484
01488 const char* epr_data_type_id_to_str(EPR_EDataTypeId data_type_id);
01489
01490 #ifdef __cplusplus
01491 }
01492 #endif
01493 #endif
01494