Commit df3c84abc373385b7d77c653f2c656f220a6c6b2

Authored by knodlseder
1 parent 818cd3af

add GResponse unit test skeleton

include/GFits.hpp
... ... @@ -41,9 +41,9 @@ public:
41 41 void save(void);
42 42 void saveto(const std::string filename, int clobber);
43 43 void close(void);
44   - GFitsHDU* hdu(std::string extname);
  44 + GFitsHDU* hdu(const std::string extname);
45 45 GFitsHDU* hdu(int extno);
46   -
  46 +
47 47 private:
48 48 // Private methods
49 49 void init_members(void);
... ...
include/GFitsHDU.hpp
... ... @@ -48,7 +48,7 @@ public:
48 48 GFitsHeader* header(void) const;
49 49 GFitsData* data(void) const;
50 50 GFitsTableCol* column(const std::string colname) const;
51   -
  51 +
52 52 private:
53 53 // Private methods
54 54 void init_members(void);
... ...
src/fits/GFits.cpp
... ... @@ -15,6 +15,7 @@
15 15 /* __ Includes ___________________________________________________________ */
16 16 #include "GException.hpp"
17 17 #include "GFits.hpp"
  18 +#include "GTools.hpp"
18 19 #include <iostream> // cout, cerr
19 20  
20 21 /* __ Namespaces _________________________________________________________ */
... ... @@ -233,7 +234,7 @@ void GFits::close(void)
233 234 * Get pointer to HDU *
234 235 * ----------------------------------------------------------------------- *
235 236 ***************************************************************************/
236   -GFitsHDU* GFits::hdu(std::string extname)
  237 +GFitsHDU* GFits::hdu(const std::string extname)
237 238 {
238 239 // Initialise result to NULL pointer
239 240 GFitsHDU* ptr = NULL;
... ...
src/fits/GFitsHDU.cpp
... ... @@ -14,6 +14,7 @@
14 14  
15 15 /* __ Includes ___________________________________________________________ */
16 16 #include "GException.hpp"
  17 +#include "GTools.hpp"
17 18 #include "GFitsHDU.hpp"
18 19 #include <iostream> // cout, cerr
19 20  
... ... @@ -162,7 +163,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
162 163 m_data->open(m_fitsfile);
163 164  
164 165 // Get HDU name from header
165   - m_name = m_header->string("EXTNAME");
  166 + m_name = strip_whitespace(m_header->string("EXTNAME"));
166 167 if (m_name.length() == 0) {
167 168 if (hdunum == 1)
168 169 m_name = "Primary";
... ...
test/Makefile.am
... ... @@ -12,13 +12,15 @@ check_PROGRAMS = test_GVector \
12 12 test_GMatrix \
13 13 test_GSymMatrix \
14 14 test_GSparseMatrix \
15   - test_GFits
  15 + test_GFits \
  16 + test_GResponse
16 17  
17 18 TESTS = test_GVector \
18 19 test_GMatrix \
19 20 test_GSymMatrix \
20 21 test_GSparseMatrix \
21   - test_GFits
  22 + test_GFits \
  23 + test_GResponse
22 24  
23 25 test_GVector_SOURCES = test_GVector.cpp
24 26 test_GVector_LDADD = ../src/libgamma.la
... ... @@ -30,3 +32,5 @@ test_GSparseMatrix_SOURCES = test_GSparseMatrix.cpp
30 32 test_GSparseMatrix_LDADD = ../src/libgamma.la
31 33 test_GFits_SOURCES = test_GFits.cpp
32 34 test_GFits_LDADD = ../src/libgamma.la
  35 +test_GResponse_SOURCES = test_GResponse.cpp
  36 +test_GResponse_LDADD = ../src/libgamma.la
... ...
test/Makefile.in
... ... @@ -41,7 +41,7 @@ build_triplet = @build@
41 41 host_triplet = @host@
42 42 check_PROGRAMS = test_GVector$(EXEEXT) test_GMatrix$(EXEEXT) \
43 43 test_GSymMatrix$(EXEEXT) test_GSparseMatrix$(EXEEXT) \
44   - test_GFits$(EXEEXT)
  44 + test_GFits$(EXEEXT) test_GResponse$(EXEEXT)
45 45 subdir = test
46 46 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
47 47 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
... ... @@ -57,6 +57,9 @@ test_GFits_DEPENDENCIES = ../src/libgamma.la
57 57 am_test_GMatrix_OBJECTS = test_GMatrix.$(OBJEXT)
58 58 test_GMatrix_OBJECTS = $(am_test_GMatrix_OBJECTS)
59 59 test_GMatrix_DEPENDENCIES = ../src/libgamma.la
  60 +am_test_GResponse_OBJECTS = test_GResponse.$(OBJEXT)
  61 +test_GResponse_OBJECTS = $(am_test_GResponse_OBJECTS)
  62 +test_GResponse_DEPENDENCIES = ../src/libgamma.la
60 63 am_test_GSparseMatrix_OBJECTS = test_GSparseMatrix.$(OBJEXT)
61 64 test_GSparseMatrix_OBJECTS = $(am_test_GSparseMatrix_OBJECTS)
62 65 test_GSparseMatrix_DEPENDENCIES = ../src/libgamma.la
... ... @@ -78,11 +81,11 @@ CXXLD = $(CXX)
78 81 CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
79 82 $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
80 83 SOURCES = $(test_GFits_SOURCES) $(test_GMatrix_SOURCES) \
81   - $(test_GSparseMatrix_SOURCES) $(test_GSymMatrix_SOURCES) \
82   - $(test_GVector_SOURCES)
  84 + $(test_GResponse_SOURCES) $(test_GSparseMatrix_SOURCES) \
  85 + $(test_GSymMatrix_SOURCES) $(test_GVector_SOURCES)
83 86 DIST_SOURCES = $(test_GFits_SOURCES) $(test_GMatrix_SOURCES) \
84   - $(test_GSparseMatrix_SOURCES) $(test_GSymMatrix_SOURCES) \
85   - $(test_GVector_SOURCES)
  87 + $(test_GResponse_SOURCES) $(test_GSparseMatrix_SOURCES) \
  88 + $(test_GSymMatrix_SOURCES) $(test_GVector_SOURCES)
86 89 ETAGS = etags
87 90 CTAGS = ctags
88 91 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
... ... @@ -207,7 +210,8 @@ TESTS = test_GVector \
207 210 test_GMatrix \
208 211 test_GSymMatrix \
209 212 test_GSparseMatrix \
210   - test_GFits
  213 + test_GFits \
  214 + test_GResponse
211 215  
212 216 test_GVector_SOURCES = test_GVector.cpp
213 217 test_GVector_LDADD = ../src/libgamma.la
... ... @@ -219,6 +223,8 @@ test_GSparseMatrix_SOURCES = test_GSparseMatrix.cpp
219 223 test_GSparseMatrix_LDADD = ../src/libgamma.la
220 224 test_GFits_SOURCES = test_GFits.cpp
221 225 test_GFits_LDADD = ../src/libgamma.la
  226 +test_GResponse_SOURCES = test_GResponse.cpp
  227 +test_GResponse_LDADD = ../src/libgamma.la
222 228 all: all-am
223 229  
224 230 .SUFFIXES:
... ... @@ -265,6 +271,9 @@ test_GFits$(EXEEXT): $(test_GFits_OBJECTS) $(test_GFits_DEPENDENCIES)
265 271 test_GMatrix$(EXEEXT): $(test_GMatrix_OBJECTS) $(test_GMatrix_DEPENDENCIES)
266 272 @rm -f test_GMatrix$(EXEEXT)
267 273 $(CXXLINK) $(test_GMatrix_LDFLAGS) $(test_GMatrix_OBJECTS) $(test_GMatrix_LDADD) $(LIBS)
  274 +test_GResponse$(EXEEXT): $(test_GResponse_OBJECTS) $(test_GResponse_DEPENDENCIES)
  275 + @rm -f test_GResponse$(EXEEXT)
  276 + $(CXXLINK) $(test_GResponse_LDFLAGS) $(test_GResponse_OBJECTS) $(test_GResponse_LDADD) $(LIBS)
268 277 test_GSparseMatrix$(EXEEXT): $(test_GSparseMatrix_OBJECTS) $(test_GSparseMatrix_DEPENDENCIES)
269 278 @rm -f test_GSparseMatrix$(EXEEXT)
270 279 $(CXXLINK) $(test_GSparseMatrix_LDFLAGS) $(test_GSparseMatrix_OBJECTS) $(test_GSparseMatrix_LDADD) $(LIBS)
... ...
test/test_GFits.cpp
... ... @@ -283,7 +283,7 @@ int main(void)
283 283 // Dump header
284 284 std::cout << std::endl;
285 285 std::cout << "***********************" << std::endl;
286   - std::cout << "* GFIts class testing *" << std::endl;
  286 + std::cout << "* GFits class testing *" << std::endl;
287 287 std::cout << "***********************" << std::endl;
288 288  
289 289 // Execute the tests
... ...
test/test_GResponse.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * test_GResponse.cpp - test Response classes *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright : (C) 2008 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +
  14 +/* __ Includes ___________________________________________________________ */
  15 +#include "test_GResponse.hpp"
  16 +
  17 +/* __ Namespaces _________________________________________________________ */
  18 +
  19 +/* __ Globals ____________________________________________________________ */
  20 +
  21 +
  22 +/***************************************************************************
  23 + * Test: Open *
  24 + ***************************************************************************/
  25 +void test_open(void)
  26 +{
  27 + std::cout << "Test GResponse: Open PSF FITS file: ";
  28 + try {
  29 + // Open FITS file
  30 + GFits fits;
  31 + fits.open("irf/lat/aeff_Pass5_v0_front.fits");
  32 +
  33 + // Get pointer towards effective area HDU
  34 + GFitsHDU* aeff = fits.hdu("EFFECTIVE AREA");
  35 + if (aeff == NULL) {
  36 + std::cout << std::endl << "TEST ERROR: Unable to find HDU <EFFECTIVE AREA>." << std::endl;
  37 + throw;
  38 + }
  39 +
  40 + // Get columns
  41 + GFitsTableFltCol energ_lo = *((GFitsTableFltCol*)aeff->column("ENERG_LO"));
  42 + GFitsTableFltCol energ_hi = *((GFitsTableFltCol*)aeff->column("ENERG_HI"));
  43 + GFitsTableFltCol ctheta_lo = *((GFitsTableFltCol*)aeff->column("CTHETA_LO"));
  44 + GFitsTableFltCol ctheta_hi = *((GFitsTableFltCol*)aeff->column("CTHETA_HI"));
  45 + GFitsTableFltCol effarea = *((GFitsTableFltCol*)aeff->column("EFFAREA"));
  46 +
  47 + }
  48 + catch (exception &e) {
  49 + std::cout << std::endl << "TEST ERROR: Unable to open FITS file." << std::endl;
  50 + std::cout << e.what() << std::endl;
  51 + throw;
  52 + }
  53 + std::cout << ". ok." << std::endl;
  54 +}
  55 +
  56 +
  57 +/***************************************************************************
  58 + * Main test function *
  59 + ***************************************************************************/
  60 +int main(void)
  61 +{
  62 + // Dump header
  63 + std::cout << std::endl;
  64 + std::cout << "***************************" << std::endl;
  65 + std::cout << "* GResponse class testing *" << std::endl;
  66 + std::cout << "**************************" << std::endl;
  67 +
  68 + // Execute the tests
  69 + test_open();
  70 +
  71 + // Return
  72 + return 0;
  73 +}
... ...
test/test_GResponse.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * test_GResponse.hpp - test Response classes *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright : (C) 2008 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +
  14 +#ifndef TEST_GRESPONSE_HPP
  15 +#define TEST_GRESPONSE_HPP
  16 +
  17 +/* __ Includes ___________________________________________________________ */
  18 +#include "GammaLib.hpp"
  19 +#include <iostream> // cout, cerr
  20 +#include <stdexcept> // std::exception
  21 +//#include <math.h>
  22 +
  23 +#endif /* TEST_GRESPONSE_HPP */
... ...