/* $Id: cpl_photom-test.c,v 1.17 2008/02/07 10:54:01 llundin Exp $ * * This file is part of the ESO Common Pipeline Library * Copyright (C) 2001-2004 European Southern Observatory * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Author: llundin $ * $Date: 2008/02/07 10:54:01 $ * $Revision: 1.17 $ * $Name: $ */ /*----------------------------------------------------------------------------- Includes -----------------------------------------------------------------------------*/ #include #include "cpl_polynomial.h" #include "cpl_bivector.h" #include "cpl_photom.h" #include "cpl_type.h" #include "cpl_tools.h" #include "cpl_memory.h" /*----------------------------------------------------------------------------- Defines -----------------------------------------------------------------------------*/ #ifndef FUNCTION_SIZE #define FUNCTION_SIZE 1024 #endif /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ int main(void) { cpl_polynomial * poly1 ; cpl_bivector * fun ; cpl_bivector * trans; FILE * ftrans; const double temp = 253; int i; const int half_search = FUNCTION_SIZE/2; cpl_vector * vxc; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Insert tests below */ /* A black-body with T=253K should emit mostly in the range [2;50[ micron */ cpl_test_nonnull( poly1 = cpl_polynomial_new(1) ); i = 0; cpl_polynomial_set_coeff(poly1, &i, 2e-6); i++; cpl_polynomial_set_coeff(poly1, &i, 48e-6/FUNCTION_SIZE); fun = cpl_bivector_new(FUNCTION_SIZE); cpl_test_zero( cpl_vector_fill_polynomial(cpl_bivector_get_x(fun), poly1, 0, 1) ); cpl_test_zero(cpl_photom_fill_blackbody(cpl_bivector_get_y(fun), CPL_UNIT_PHOTONRADIANCE, cpl_bivector_get_x(fun), CPL_UNIT_LENGTH, temp)); cpl_test( ftrans = fopen("planck1.txt", "w") ); cpl_bivector_dump(fun,ftrans); fclose(ftrans); cpl_test_zero(cpl_photom_fill_blackbody(cpl_bivector_get_y(fun), CPL_UNIT_ENERGYRADIANCE, cpl_bivector_get_x(fun), CPL_UNIT_LENGTH, temp)); trans = cpl_bivector_new(FUNCTION_SIZE); cpl_vector_copy(cpl_bivector_get_x(trans),cpl_bivector_get_x(fun)); cpl_test_zero(cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LESS, cpl_bivector_get_x(trans), CPL_UNIT_LENGTH, temp)); cpl_msg_info("", "%g K Black-Body radiation peaks at [m]: %g (%g)", temp, CPL_PHYS_Wien/temp, cpl_vector_get_max(cpl_bivector_get_y(trans))); vxc = cpl_vector_new(2*half_search + 1); cpl_test( cpl_vector_correlate(vxc, cpl_bivector_get_y(trans), cpl_bivector_get_y(fun)) == half_search ); cpl_test( 1 - cpl_vector_get(vxc, half_search) < FUNCTION_SIZE * DBL_EPSILON); cpl_vector_delete(vxc); cpl_test( ftrans = fopen("planck2.txt", "w") ); cpl_bivector_dump(trans,ftrans); fclose(ftrans); cpl_polynomial_delete(poly1); cpl_bivector_delete(fun); cpl_bivector_delete(trans); /* End of tests */ return cpl_test_end(0); }