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 #include <irplib_test.h> 00029 00030 #include <irplib_hist.h> 00031 00032 #include <math.h> 00033 /*---------------------------------------------------------------------------*/ 00034 /* 00035 * @defgroup irplib_hist_test Testing of the IRPLIB utilities 00036 */ 00037 /*---------------------------------------------------------------------------*/ 00038 00039 00040 /*---------------------------------------------------------------------------- 00041 Defines 00042 ----------------------------------------------------------------------------*/ 00043 00044 #define NBINS 100 00045 00046 /*---------------------------------------------------------------------------- 00047 Private Function prototypes 00048 ----------------------------------------------------------------------------*/ 00049 00050 static void irplib_hist_tests(void); 00051 00052 /*---------------------------------------------------------------------------*/ 00053 /* 00054 * @brief Unit tests of fit module 00055 */ 00056 /*---------------------------------------------------------------------------*/ 00057 00058 int main(void) 00059 { 00060 /* Initialize CPL + IRPLIB */ 00061 IRPLIB_TEST_INIT; 00062 00063 irplib_hist_tests(); 00064 00065 IRPLIB_TEST_END; 00066 } 00067 00068 static void irplib_hist_tests(void) 00069 { 00070 irplib_hist * hist; 00071 cpl_image * image; 00072 cpl_error_code error; 00073 int i, j; 00074 float * data; 00075 00076 unsigned long max, max_where; 00077 00078 /* 1. trial: Create a right histogram */ 00079 hist = irplib_hist_new(); 00080 irplib_test(hist != NULL); 00081 irplib_test(!cpl_error_get_code()); 00082 //Cuando descomento esta linea, sale error, "dereferencing pointer..." 00083 // irplib_test(hist -> bins == NULL); 00084 irplib_hist_delete(hist); 00085 00086 /* 3. trial: Histogram for a uniform image */ 00087 image = cpl_image_new(100, 100, CPL_TYPE_FLOAT); 00088 cpl_image_add_scalar(image, 202); 00089 00090 hist = irplib_hist_new(); 00091 00092 error = irplib_hist_init(hist, NBINS, 0, 500); 00093 irplib_test(!error); 00094 error = irplib_hist_fill(hist, image); 00095 irplib_test(!error); 00096 00097 for(i = 0; i < 40; i++) { 00098 irplib_test(irplib_hist_get_value(hist, i) == 0); 00099 } 00100 00101 /* The following call retrieves the value of the 42-st bin */ 00102 /* When i = 41, 42-th is retrieved. 500 - 0 / 100 = 5; 202/5=40,xx 00103 it should be in the 41-th bin but it is in the next one because 00104 there is one before left empty for possible values out of range 00105 0 (hinit) < 202 (image constant) 00106 */ 00107 00108 // irplib_hist_save(hist, "trial.fits"); 00109 irplib_test(irplib_hist_get_value(hist, 40) == 10000); 00110 for(i = 42; i < NBINS; i++) { 00111 irplib_test(irplib_hist_get_value(hist, i) == 0); 00112 } 00113 00114 irplib_hist_delete(hist); 00115 cpl_image_delete(image); 00116 00117 /* 4. trial: Histogram for a normal image: no checking of the output */ 00118 image = cpl_image_new(100, 100, CPL_TYPE_FLOAT); 00119 cpl_image_fill_noise_uniform(image, 0, 200); 00120 00121 hist = irplib_hist_new(); 00122 error = irplib_hist_fill(hist,image); 00123 irplib_test(!error); 00124 00125 irplib_hist_delete(hist); 00126 cpl_image_delete(image); 00127 00128 /* 5. trial: Histogram */ 00129 image = cpl_image_new(100, 100, CPL_TYPE_FLOAT); 00130 data = cpl_image_get_data_float(image); 00131 for (i = 0; i < 100; i++) { 00132 for (j = 0; j < 100; j++) { 00133 *(data + 100*i + j) = i +j; 00134 } 00135 } 00136 00137 hist = irplib_hist_new(); 00138 error = irplib_hist_fill(hist, image); 00139 00140 // irplib_hist_save(hist, "hist.fits"); 00141 max = irplib_hist_get_max(hist, &max_where); 00142 00143 00144 00145 /* The following call retrieves the value of the 41-st bin */ 00146 /* irplib_test(irplib_hist_get_value(hist, 40) == 10000); 00147 for(i = 42; i < NBINS; i++) { 00148 irplib_test(irplib_hist_get_value(hist, i) == 0); 00149 }*/ 00150 00151 00152 // cpl_image_delete(image); 00153 00154 /* 6. trial: all by default ( we use the same image) */ 00155 00156 00157 // irplib_hist_save(hist, "hist_def.fits"); 00158 irplib_test(max_where == irplib_hist_get_nbins(hist)/2); 00159 00160 irplib_hist_delete(hist); 00161 cpl_image_delete(image); 00162 }
1.5.1