Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: MSG Native Reader 4 : * Purpose: Base class for reading in the headers of MSG native images 5 : * Author: Frans van den Bergh, fvdbergh@csir.co.za 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2005, Frans van den Bergh <fvdbergh@csir.co.za> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef MSG_READER_CORE_H 14 : #define MSG_READER_CORE_H 15 : 16 : #include "msg_basic_types.h" 17 : #include <stdio.h> 18 : #include "cpl_vsi.h" 19 : 20 : namespace msg_native_format 21 : { 22 : 23 : const unsigned int MSG_NUM_CHANNELS = 12; 24 : 25 : typedef struct 26 : { 27 : double vc; 28 : double A; 29 : double B; 30 : } Blackbody_lut_type; 31 : 32 : typedef enum 33 : { 34 : VIS0_6 = 2, 35 : VIS0_8 = 4, 36 : NIR1_6 = 8, 37 : IR3_9 = 16, 38 : IR6_2 = 32, 39 : IR7_3 = 64, 40 : IR8_7 = 128, 41 : IR9_7 = 256, 42 : IR10_8 = 512, 43 : IR12_0 = 1024, 44 : IR13_4 = 2048, 45 : HRV = 4096 46 : } Msg_channel_names; 47 : 48 0 : class Msg_reader_core final 49 : { 50 : public: 51 : explicit Msg_reader_core(const char *fname); 52 : explicit Msg_reader_core(VSILFILE *fp); 53 : 54 : ~Msg_reader_core(); 55 : 56 0 : bool get_open_success() const 57 : { 58 0 : return _open_success; 59 : } 60 : 61 0 : unsigned int get_lines() const 62 : { 63 0 : return _lines; 64 : } 65 : 66 0 : unsigned int get_columns() const 67 : { 68 0 : return _columns; 69 : } 70 : 71 : void get_pixel_geo_coordinates(unsigned int line, unsigned int column, 72 : double &longitude, double &latitude) 73 : const; // x and y relative to this image, not full disc image 74 : void get_pixel_geo_coordinates( 75 : double line, double column, double &longitude, 76 : double 77 : &latitude); // x and y relative to this image, not full disc image 78 : double compute_pixel_area_sqkm(double line, double column); 79 : 80 : static const Blackbody_lut_type Blackbody_LUT[MSG_NUM_CHANNELS + 1]; 81 : 82 0 : unsigned int get_year() const 83 : { 84 0 : return _year; 85 : } 86 : 87 0 : unsigned int get_month() const 88 : { 89 0 : return _month; 90 : } 91 : 92 0 : unsigned int get_day() const 93 : { 94 0 : return _day; 95 : } 96 : 97 0 : unsigned int get_hour() const 98 : { 99 0 : return _hour; 100 : } 101 : 102 0 : unsigned int get_minute() const 103 : { 104 0 : return _minute; 105 : } 106 : 107 0 : unsigned int get_line_start() const 108 : { 109 0 : return _line_start; 110 : } 111 : 112 0 : unsigned int get_col_start() const 113 : { 114 0 : return _col_start; 115 : } 116 : 117 0 : float get_col_dir_step() const 118 : { 119 0 : return _col_dir_step; 120 : } 121 : 122 0 : float get_line_dir_step() const 123 : { 124 0 : return _line_dir_step; 125 : } 126 : 127 0 : float get_hrv_col_dir_step() const 128 : { 129 0 : return _hrv_col_dir_step; 130 : } 131 : 132 0 : float get_hrv_line_dir_step() const 133 : { 134 0 : return _hrv_line_dir_step; 135 : } 136 : 137 0 : unsigned int get_f_data_offset() const 138 : { 139 0 : return _f_data_offset; 140 : } 141 : 142 0 : unsigned int get_visir_bytes_per_line() const 143 : { 144 0 : return _visir_bytes_per_line; 145 : } 146 : 147 0 : unsigned int get_visir_packet_size() const 148 : { 149 0 : return _visir_packet_size; 150 : } 151 : 152 0 : unsigned int get_hrv_bytes_per_line() const 153 : { 154 0 : return _hrv_bytes_per_line; 155 : } 156 : 157 0 : unsigned int get_hrv_packet_size() const 158 : { 159 0 : return _hrv_packet_size; 160 : } 161 : 162 0 : unsigned int get_interline_spacing() const 163 : { 164 0 : return _interline_spacing; 165 : } 166 : 167 0 : const unsigned char *get_band_map() const 168 : { 169 0 : return _bands; 170 : } 171 : 172 0 : const CALIBRATION *get_calibration_parameters() const 173 : { 174 0 : return _calibration; 175 : } 176 : 177 0 : const IMAGE_DESCRIPTION_RECORD &get_image_description_record() const 178 : { 179 0 : return _img_desc_record; 180 : } 181 : 182 : private: 183 : void read_metadata_block(VSILFILE *fp); 184 : 185 : protected: 186 : static int _chan_to_idx(Msg_channel_names channel); 187 : 188 : unsigned int _lines; 189 : unsigned int _columns; 190 : 191 : unsigned int _line_start; 192 : unsigned int _col_start; 193 : 194 : float _col_dir_step; 195 : float _line_dir_step; 196 : float _hrv_col_dir_step; 197 : float _hrv_line_dir_step; 198 : 199 : MAIN_PROD_HEADER _main_header; 200 : SECONDARY_PROD_HEADER _sec_header; 201 : CALIBRATION _calibration[MSG_NUM_CHANNELS]; 202 : IMAGE_DESCRIPTION_RECORD _img_desc_record; 203 : 204 : unsigned int _f_data_offset; 205 : unsigned int _f_data_size; 206 : unsigned int _f_header_offset; 207 : unsigned int _f_header_size; 208 : unsigned int _f_trailer_offset; 209 : unsigned int _f_trailer_size; 210 : 211 : unsigned int _visir_bytes_per_line; // packed length of a VISIR line, 212 : // without headers 213 : unsigned int _visir_packet_size; // effectively, the spacing between lines 214 : // of consecutive bands in bytes 215 : unsigned int _hrv_bytes_per_line; 216 : unsigned int _hrv_packet_size; 217 : unsigned int _interline_spacing; 218 : 219 : unsigned char _bands[MSG_NUM_CHANNELS]; 220 : 221 : unsigned int _year; 222 : unsigned int _month; 223 : unsigned int _day; 224 : unsigned int _hour; 225 : unsigned int _minute; 226 : 227 : bool _open_success; 228 : }; 229 : 230 : } // namespace msg_native_format 231 : 232 : #endif