00001 /* * 00002 * This file is part of the ESO IRPLIB package * 00003 * Copyright (C) 2004,2005 European Southern Observatory * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the Free Software * 00017 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA * 00018 * */ 00019 00020 #ifdef HAVE_CONFIG_H 00021 #include <config.h> 00022 #endif 00023 00024 /*---------------------------------------------------------------------------- 00025 Includes 00026 ----------------------------------------------------------------------------*/ 00027 00028 00029 #include <irplib_hist.h> 00030 00031 #include <math.h> 00032 /*---------------------------------------------------------------------------*/ 00033 /* 00034 * @defgroup irplib_hist_test Testing of the IRPLIB utilities 00035 */ 00036 /*---------------------------------------------------------------------------*/ 00037 00038 00039 /*---------------------------------------------------------------------------- 00040 Defines 00041 ----------------------------------------------------------------------------*/ 00042 00043 #define NBINS 100 00044 00045 /*---------------------------------------------------------------------------- 00046 Private Function prototypes 00047 ----------------------------------------------------------------------------*/ 00048 00049 static void irplib_hist_tests(void); 00050 00051 /*---------------------------------------------------------------------------*/ 00052 /* 00053 * @brief Unit tests of fit module 00054 */ 00055 /*---------------------------------------------------------------------------*/ 00056 00057 int main(void) 00058 { 00059 /* Initialize CPL + IRPLIB */ 00060 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); 00061 00062 irplib_hist_tests(); 00063 00064 return cpl_test_end(0); 00065 } 00066 00067 static void irplib_hist_tests(void) 00068 { 00069 irplib_hist * hist; 00070 cpl_image * image; 00071 cpl_error_code error; 00072 int i, j; 00073 float * data; 00074 00075 unsigned long max, max_where; 00076 00077 /* 1. trial: Create a right histogram */ 00078 hist = irplib_hist_new(); 00079 cpl_test_nonnull(hist); 00080 cpl_test_error(CPL_ERROR_NONE); 00081 //Cuando descomento esta linea, sale error, "dereferencing pointer..." 00082 // cpl_test_null(hist -> bins); 00083 irplib_hist_delete(hist); 00084 00085 /* 3. trial: Histogram for a uniform image */ 00086 image = cpl_image_new(100, 100, CPL_TYPE_FLOAT); 00087 cpl_image_add_scalar(image, 202); 00088 00089 hist = irplib_hist_new(); 00090 00091 error = irplib_hist_init(hist, NBINS, 0, 500); 00092 cpl_test_zero(error); 00093 error = irplib_hist_fill(hist, image); 00094 cpl_test_zero(error); 00095 00096 for(i = 0; i < 40; i++) { 00097 cpl_test_zero(irplib_hist_get_value(hist, i)); 00098 } 00099 00100 /* The following call retrieves the value of the 42-st bin */ 00101 /* When i = 41, 42-th is retrieved. 500 - 0 / 100 = 5; 202/5=40,xx 00102 it should be in the 41-th bin but it is in the next one because 00103 there is one before left empty for possible values out of range 00104 0 (hinit) < 202 (image constant) 00105 */ 00106 00107 // irplib_hist_save(hist, "trial.fits"); 00108 cpl_test_eq(irplib_hist_get_value(hist, 40), 10000); 00109 for(i = 42; i < NBINS; i++) { 00110 cpl_test_zero(irplib_hist_get_value(hist, i)); 00111 } 00112 00113 irplib_hist_delete(hist); 00114 cpl_image_delete(image); 00115 00116 /* 4. trial: Histogram for a normal image: no checking of the output */ 00117 image = cpl_image_new(100, 100, CPL_TYPE_FLOAT); 00118 cpl_image_fill_noise_uniform(image, 0, 200); 00119 00120 hist = irplib_hist_new(); 00121 error = irplib_hist_fill(hist,image); 00122 cpl_test_zero(error); 00123 00124 irplib_hist_delete(hist); 00125 cpl_image_delete(image); 00126 00127 /* 5. trial: Histogram */ 00128 image = cpl_image_new(100, 100, CPL_TYPE_FLOAT); 00129 data = cpl_image_get_data_float(image); 00130 for (i = 0; i < 100; i++) { 00131 for (j = 0; j < 100; j++) { 00132 *(data + 100*i + j) = i +j; 00133 } 00134 } 00135 00136 hist = irplib_hist_new(); 00137 error = irplib_hist_fill(hist, image); 00138 00139 // irplib_hist_save(hist, "hist.fits"); 00140 max = irplib_hist_get_max(hist, &max_where); 00141 00142 00143 00144 /* The following call retrieves the value of the 41-st bin */ 00145 /* cpl_test_eq(irplib_hist_get_value(hist, 40), 10000); 00146 for(i = 42; i < NBINS; i++) { 00147 cpl_test_zero(irplib_hist_get_value(hist, i)); 00148 }*/ 00149 00150 00151 // cpl_image_delete(image); 00152 00153 /* 6. trial: all by default ( we use the same image) */ 00154 00155 00156 // irplib_hist_save(hist, "hist_def.fits"); 00157 cpl_test_eq(max_where, irplib_hist_get_nbins(hist)/2); 00158 00159 irplib_hist_delete(hist); 00160 cpl_image_delete(image); 00161 }
1.5.1