/* VMOD03.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 "debug.h" #include "common.h" #include "hdffiledata.h" #include "VMOD03.h" VMOD03::VMOD03(const char *filename, const char *dataset, int ichannel) : VHdf(filename, dataset, ichannel) { strcpy(sds_time_, "EV start time"); read_lat_lon_time(); } void VMOD03::get_calibration(double &slope, double &offset) const { slope = 0.01; offset = 0.; } void VMOD03::read_lat_lon_time() { assert(sds_lat_ && *sds_lat_); assert(sds_lon_ && *sds_lon_); assert(sds_time_ && *sds_time_); assert(lat_ == NULL); assert(lon_ == NULL); assert(time_ == NULL); try { HDFFileData f_data(data_filename_, "r"); vector sample_dimensions = f_data.get_sds_dimension(sds_lat_); vector data_dimensions = f_data.get_sds_dimension(sds_data_); vector time_dimensions = f_data.get_sds_dimension(sds_time_); assert(time_dimensions.size() == 1); int data_nrows; int data_ncols; if (data_dimensions.size() == 2) { data_nrows = data_dimensions[0]; data_ncols = data_dimensions[1]; } else if (data_dimensions.size() == 3) { data_nrows = data_dimensions[1]; data_ncols = data_dimensions[2]; } else { std::cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": unexpected value for data_dimensions.size(): " << data_dimensions.size() << std::endl; exit (EXIT_FAILURE); } int nscan = time_dimensions[0]; int nrows_per_scan = data_nrows/nscan; if (nrows_per_scan != 10) { std::cerr << APPNAME << ": " << data_filename_ << ": inconsistency between number of rows in data (" << data_nrows << ") and number of scans (" << nscan << ")" << std::endl; exit (EXIT_FAILURE); } float64 *time_buffer = NULL; time_buffer = f_data.read_data(time_buffer, sds_time_); time_ = new time_type[data_nrows*data_ncols]; for (int irow = 0 ; irow < data_nrows ; ++irow) { const int iscan = irow/nrows_per_scan; for (int icol = 0 ; icol < data_ncols ; ++icol) { time_[irow*data_ncols + icol] = time_buffer[iscan]; } } delete[] time_buffer; time_buffer = NULL; lat_ = f_data.read_data(lat_, "Latitude"); lon_ = f_data.read_data(lon_, "Longitude"); assert(lat_); assert(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; } }