/* VParasol.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 #include "debug.h" #include "common.h" #include "VParasol.h" #include "hdffiledata.h" VParasol::VParasol(const char *filename, const char *dataset) : VFile(filename, dataset) { PDEBUG; lat_ = NULL; lon_ = NULL; time_ = NULL; data_ = NULL; using namespace std; double slope, offset; unsigned short *rows = NULL; unsigned short *cols = NULL; //unsigned char *counts = NULL; double *scaled_data = NULL; unsigned short nbytes; int ndata; try { PARASOLFileData pfd(data_filename_); ndata = pfd.get_nb_data(); pfd.open_data_file(); pfd.load_geolocation_data(); pfd.close_data_file(); pfd.get_scaling(dataset, slope_, offset_, nbytes); rows = const_cast(pfd.get_line_data()); assert(rows); cols = const_cast(pfd.get_col_data()); assert(cols); const int nrows = 1080; // LEVEL 2 ONLY const int ncols = 2160; // LEVEL 2 ONLY dimensions_.push_back(nrows); dimensions_.push_back(ncols); //counts = static_cast(pfd.read_count_data(counts, dataset)); assert(counts); scaled_data = static_cast(pfd.read_scaled_data(scaled_data, dataset)); assert(scaled_data); for (int idata = 0 ; idata < ndata ; ++idata) { cout << rows[idata] << "\t" << cols[idata] << "\t" << scaled_data[idata] << endl; } } catch (bad_file &e) { Debug(cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); destroy(); throw; } catch (bad_sds_name &e) { Debug(cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); destroy(); throw; } catch (VError &e) { Debug(cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); destroy(); throw; } catch (...) { cerr << APPNAME << ": " __FILE__ << ": " << __LINE__ << ": unexpected exception" << endl; destroy(); throw; } exit (EXIT_FAILURE); } void VParasol::destroy() { PDEBUG; delete[] lat_; lat_ = NULL; delete[] lon_; lon_ = NULL; delete[] time_; time_ = NULL; if (data_) { free(data_); // data_ (allocated with read_data(void *)) is to be free'd with free() and not delete[] data_ = NULL; } } void VParasol::get_calibration(double &slope, double &offset) const { slope = slope_; offset = offset_; PDEBUG; } VParasol::~VParasol() { PDEBUG; destroy(); }