/* VIIR.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 "debug.h" #include "VIIR.h" #include "hdffiledata.h" const double VIIR::wavelengths[] = { 8.65, 10.6, 12.05 }; VIIR::VIIR(const char *filename, const char *dataset, int ichannel) : VHdf(filename, dataset, ichannel) { PDEBUG; if (strstr(dataset, "_8.65") != NULL) { strcpy(sds_time_, "Image_Time_8.65"); wavelength_ = wavelengths[IIR_CHANNEL_8_65]; } else if (strstr(dataset, "_10.6") != NULL) { strcpy(sds_time_, "Image_Time_10.6"); wavelength_ = wavelengths[IIR_CHANNEL_10_6]; } else if (strstr(dataset, "_12.05") != NULL) { strcpy(sds_time_, "Image_Time_12.05"); wavelength_ = wavelengths[IIR_CHANNEL_12_05]; } else { std::cerr << APPNAME ": " << filename << ": " << dataset << ": not a supported dataset: only datasets for channels 8.65, 10.6 and 12.05 um are supported for the time being" << std::endl; exit (EXIT_FAILURE); // FIXME: should throw an exception } if (strstr(dataset, "Calibrated_Radiances") != NULL) { content_ = GRID_CONTENT_RADIANCES; } else { content_ = GRID_CONTENT_DEFAULT; } read_lat_lon_time(); } void VIIR::get_calibration(double &slope, double &offset) const { PDEBUG; slope = 0.01; offset = 0.; } void VIIR::read_lat_lon_time() { PDEBUG; 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 time_dimensions = f_time.get_sds_dimension(sds_time_); vector latlon_dimensions = f_latlon.get_sds_dimension(sds_lat_); const size_t nrows = latlon_dimensions[0]; const size_t ncols = latlon_dimensions[1]; { /* in IIR files, the dataset 'time' is expected to have * dimensions (nrows, 1) where 'nrows' is the number of rows * in the dataset 'data' */ assert(time_dimensions.size() == 2); assert(time_dimensions[0] == latlon_dimensions[0]); assert(time_dimensions[1] == 1); } float64 *time_buffer = NULL; time_buffer = static_cast(f_time.read_data(time_buffer, sds_time_)); time_ = new time_type[nrows*ncols]; assert(time_); for (size_t irow = 0 ; irow < nrows ; ++irow) { for (size_t icol = 0 ; icol < ncols ; ++icol) { time_[irow * ncols + icol] = time_buffer[irow]; } } 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 (...) { cerr << APPNAME << ": " __FILE__ << ": " << __LINE__ << ": unexpected exception" << endl; throw; } }