/* radiances_to_temperatures.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 "common.h" #include "radiances_to_temperatures.h" void convert_radiances_to_temperatures(grid_type *grid) { PDEBUG; assert(grid); assert(grid->content == GRID_CONTENT_RADIANCES); const double C1 = 1.1910E8; /* C1 == 2.h.c^2, in W/m^2/sr/um^-4 */ const double C2 = 1.438833E4; /* C2 == h.c/k, in um.K */ const int nrows = grid->nrows; const int ncols = grid->ncols; const double slope = grid->slope; const double offset = grid->offset; const double lambda = grid->wavelength; /* in microns */ data_type *data = grid->data; assert(lambda > 0.); for (int irow = 0 ; irow < nrows ; ++irow) { for (int icol = 0 ; icol < ncols ; ++icol) { double temperature; data_type count = data[irow * ncols + icol]; if (count == g_data_fill_value) continue; const double radiance = slope*(count - offset); const double x = C1 / (radiance * pow(lambda, 5)); temperature = lambda * log(1 + x); data[irow * ncols + icol] = static_cast(lround(100 * temperature)); } } grid->slope = 0.01; grid->offset = 0.0; }