/* VEquiRect.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 "VEquiRect.h" VEquiRect::VEquiRect(coord_type latitude_orig, coord_type longitude_orig, double resolution /* in km/pixel */, int nrows, int ncols) { PDEBUG; const coord_type MIN_LAT = -90.; const coord_type MAX_LAT = +90.; const coord_type MIN_LON = -180.; const coord_type MAX_LON = +180.; try { lat_ = new coord_type[nrows*ncols]; lon_ = new coord_type[nrows*ncols]; time_ = new time_type[nrows*ncols]; } catch (std::bad_alloc &e) { Debug(std::cerr << APPNAME << ": " << __PRETTY_FUNCTION__ << ": " << e.what() << endl;); destroy(); throw; } catch (...) { std::cerr << APPNAME << ": internal error: unexpected exception" << endl; destroy(); throw; } assert(dimensions_.size() == 0); dimensions_.push_back(nrows); dimensions_.push_back(ncols); const coord_type stride = resolution*DEGREES_PER_KM; // in degrees per pixel const coord_type lat_stride = stride; const coord_type lon_stride = stride; for (int irow = 0 ; irow < nrows ; ++irow) { for (int icol = 0 ; icol < ncols ; ++icol) { const coord_type lat = latitude_orig - irow*lat_stride; const coord_type lon = longitude_orig + icol*lon_stride; const int ipixel = irow*ncols + icol; if ((MIN_LAT <= lat && lat <= MAX_LAT) == false || (MIN_LON <= lon && lon <= MAX_LON) == false) { lat_[ipixel] = g_coord_fill_value; lon_[ipixel] = g_coord_fill_value; continue; } lat_[ipixel] = lat; lon_[ipixel] = lon; time_[ipixel] = INFINITY; } } } void VEquiRect::destroy() { PDEBUG; if (lat_) { delete[] lat_; lat_ = NULL; } if (lon_) { delete[] lon_; lon_ = NULL; } if (time_) { delete[] time_; time_ = NULL; } } VEquiRect::~VEquiRect() { PDEBUG; destroy(); } const double VEquiRect::EARTH_RADIUS_KM = 6370.949; const double VEquiRect::DEGREES_PER_KM = 180./(M_PI*VEquiRect::EARTH_RADIUS_KM);