/* VHdf_Seviri.cpp */ /* remap Copyright (C) 2006 Fabrice Ducos, fabrice.ducos@icare.univ-lille1.fr This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include "debug.h" #include "common.h" #include "VHdf_Seviri.h" #include "hdffiledata.h" #include "normalize_cal_factors.h" const double VHdf_Seviri::wavelengths[] = { 0.6, 0.8, 1.6, 3.9, 6.2, 7.3, 8.703, 9.7, 10.745, 11.910, 13.4 }; VHdf_Seviri::VHdf_Seviri(const char *filename, const char *dataset) : VHdf(filename, dataset, 0) { PDEBUG; strcpy(sds_time_, "Seviri_Acq_Time"); read_lat_lon_time(); } void VHdf_Seviri::read_lat_lon_time() { assert(sds_time_ && *sds_time_); assert(sds_lat_ && *sds_lat_); assert(sds_lon_ && *sds_lon_); assert(lat_ == NULL); assert(lon_ == NULL); assert(time_ == NULL); try { HDFFileData f_latlon(latlon_filename_, "r"); HDFFileData f_time(time_filename_, "r"); vector latlon_dimensions = f_latlon.get_sds_dimension(sds_lat_); vector time_dimensions = f_time.get_sds_dimension(sds_time_); const size_t nrows = latlon_dimensions[0]; const size_t ncols = latlon_dimensions[1]; { assert(time_dimensions.size() == 2); assert(latlon_dimensions == time_dimensions); } uint32 *time_buffer = NULL; time_buffer = static_cast(f_time.read_data(time_buffer, sds_time_)); time_ = new time_type[nrows*ncols]; assert(time_); // converts from Unix time into TAI93 time Date date; for (size_t irow = 0 ; irow < nrows ; ++irow) { for (size_t icol = 0 ; icol < ncols ; ++icol) { date.set_epoch_time(static_cast(time_buffer[irow*ncols + icol])); time_[irow*ncols + icol] = date.get_TAI93_time(); } } delete[] time_buffer; lat_ = static_cast(f_latlon.read_data(lat_, sds_lat_)); lon_ = static_cast(f_latlon.read_data(lon_, sds_lon_)); } catch (bad_file &e) { Debug(cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); throw; } catch (bad_sds_name &e) { Debug(cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); throw; } catch (sd_get_calibration_error &e) { throw; } catch (...) { cerr << APPNAME << ": " __FILE__ << ": " << __LINE__ << ": unexpected exception" << endl; throw; } } void VHdf_Seviri::get_calibration(double &slope, double &offset) const { PDEBUG; try { float64 slope_; float64 slope_err_; float64 offset_; float64 offset_err_; int32 sds_type; HDFFileData f_data(data_filename_, "r"); f_data.get_hdf_file()->get_calibration(sds_data_, slope_, slope_err_ /* unused */, offset_, offset_err_ /* unused */, sds_type /* unused */); slope = static_cast(slope_); // converts from float64 into double offset = static_cast(offset_); // converts from float64 into double // converts slope and offset in order that calibrated data will be in W/m2/sr/um normalize_seviri_factors(sds_data_, slope, offset); } catch (bad_file &e) { Debug(cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); throw; } catch (bad_sds_name &e) { Debug(cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); throw; } catch (sd_get_calibration_error &e) { throw; } catch (...) { cerr << APPNAME << ": " __FILE__ << ": " << __LINE__ << ": unexpected exception" << endl; throw; } }