Commit 926b69e7033e622df1080b14df129d9b166114bf

Authored by Jürgen Knödlseder
1 parent dea67fa5

Refactorise code.

Macros are now used to reduce the code complexity and guarantee uniform testing of all classes. The tests have furthermore been adapted to the new unit test suite.
test/test_GFits.cpp
Changes suppressed. Click to show
... ... @@ -21,16 +21,11 @@
21 21 /**
22 22 * @file test_GFits.cpp
23 23 * @brief Implementation of unit tests for FITS classes
24   - * @author J. Knoedlseder
  24 + * @author Juergen Knoedlseder
25 25 */
26 26  
27 27 /* __ Includes ___________________________________________________________ */
28   -#include <iostream> // std::cout, cerr
29   -#include <stdexcept> // std::exception
30   -#include <stdlib.h>
31   -#include <stdio.h>
32 28 #include <cmath>
33   -#include "GammaLib.hpp"
34 29 #include "GTools.hpp"
35 30 #include "test_GFits.hpp"
36 31  
... ... @@ -38,12 +33,247 @@
38 33  
39 34 /* __ Globals ____________________________________________________________ */
40 35  
  36 +/* __ Test macros ________________________________________________________ */
  37 +#define TEST_1D_ACCESS(NX) \
  38 + for (int ix = 0, i = 0; ix < NX; ++ix, ++i) { \
  39 + test_value(image1(ix), pixels[i], 1e-10, \
  40 + "Test pixel access operator for pixel "+str(i)); \
  41 + test_value(image1.at(ix), pixels[i], 1e-10, \
  42 + "Test at() method for pixel "+str(i)); \
  43 + test_value(image1.pixel(ix), pixels[i], 1e-10, \
  44 + "Test pixel() method for pixel "+str(i)); \
  45 + }
  46 +#define TEST_2D_ACCESS(NX,NY) \
  47 + for (int iy = 0, i = 0; iy < NY; ++iy) { \
  48 + for (int ix = 0; ix < NX; ++ix, ++i) { \
  49 + test_value(image2(ix,iy), pixels[i], 1e-10, \
  50 + "Test pixel access operator for pixel "+str(i)); \
  51 + test_value(image2.at(ix,iy), pixels[i], 1e-10, \
  52 + "Test at() method for pixel "+str(i)); \
  53 + test_value(image2.pixel(ix,iy), pixels[i], 1e-10, \
  54 + "Test pixel() method for pixel "+str(i)); \
  55 + } \
  56 + }
  57 +#define TEST_3D_ACCESS(NX,NY,NZ) \
  58 + for (int iz = 0, i = 0; iz < NZ; ++iz) { \
  59 + for (int iy = 0; iy < NY; ++iy) { \
  60 + for (int ix = 0; ix < NX; ++ix, ++i) { \
  61 + test_value(image3(ix,iy,iz), pixels[i], 1e-10, \
  62 + "Test pixel access operator for pixel "+str(i)); \
  63 + test_value(image3.at(ix,iy,iz), pixels[i], 1e-10, \
  64 + "Test at() method for pixel "+str(i)); \
  65 + test_value(image3.pixel(ix,iy,iz), pixels[i], 1e-10, \
  66 + "Test pixel() method for pixel "+str(i)); \
  67 + } \
  68 + } \
  69 + }
  70 +#define TEST_4D_ACCESS(NX,NY,NZ,NT) \
  71 + for (int it = 0, i = 0; it < NT; ++it) { \
  72 + for (int iz = 0; iz < NZ; ++iz) { \
  73 + for (int iy = 0; iy < NY; ++iy) { \
  74 + for (int ix = 0; ix < NX; ++ix, ++i) { \
  75 + test_value(image4(ix,iy,iz, it), pixels[i], 1e-10, \
  76 + "Test pixel access operator for pixel "+str(i)); \
  77 + test_value(image4.at(ix,iy,iz, it), pixels[i], 1e-10, \
  78 + "Test at() method for pixel "+str(i)); \
  79 + test_value(image4.pixel(ix,iy,iz, it), pixels[i], 1e-10, \
  80 + "Test pixel() method for pixel "+str(i)); \
  81 + } \
  82 + } \
  83 + } \
  84 + }
  85 +#define TEST_4D_ACCESS_IO(NX,NY,NZ,NT) \
  86 + for (int it = 0, i = 0; it < NT; ++it) { \
  87 + for (int iz = 0; iz < NZ; ++iz) { \
  88 + for (int iy = 0; iy < NY; ++iy) { \
  89 + for (int ix = 0; ix < NX; ++ix, ++i) { \
  90 + test_value(ptr->pixel(ix,iy,iz, it), pixels[i], 1e-10, \
  91 + "Test pixel() method for pixel "+str(i)); \
  92 + } \
  93 + } \
  94 + } \
  95 + }
  96 +#define TEST_TABLE1 \
  97 + for (int i = 0; i < nrows; ++i) { \
  98 + col1(i) = (double(i)*3.57+1.29); \
  99 + } \
  100 + for (int i = 0; i < nrows; ++i) { \
  101 + double val = (double(i)*3.57+1.29); \
  102 + test_value(col1(i), val, 1e-6, \
  103 + "Test access operator row "+str(i)); \
  104 + test_value(col1.real(i), val, 1e-6, \
  105 + "Test real() method for row "+str(i)); \
  106 + test_value(col1.integer(i), int(val), 1e-6, \
  107 + "Test integer() method for row "+str(i)); \
  108 + test_assert((col1.string(i) == str(val)), \
  109 + "Test string() method for row "+str(i), \
  110 + col1.string(i)+" is not "+str(val)); \
  111 + }
  112 +#define TEST_TABLE1_INT \
  113 + for (int i = 0; i < nrows; ++i) { \
  114 + col1(i) = i*3+1; \
  115 + } \
  116 + for (int i = 0; i < nrows; ++i) { \
  117 + int val = i*3+1; \
  118 + test_assert((col1(i) == val), \
  119 + "Test access operator row "+str(i), \
  120 + str(col1(i))+" is not "+str(val)); \
  121 + test_assert((col1.real(i) == double(val)), \
  122 + "Test real() method for row "+str(i), \
  123 + str(col1.real(i))+" is not "+str(double(val))); \
  124 + test_assert((col1.integer(i) == val), \
  125 + "Test integer() method for row "+str(i), \
  126 + str(col1.integer(i))+" is not "+str(val)); \
  127 + test_assert((col1.string(i) == str(val)), \
  128 + "Test string() method for row "+str(i), \
  129 + col1.string(i)+" is not "+str(val)); \
  130 + }
  131 +#define TEST_TABLE1_BOOL \
  132 + for (int i = 0; i < nrows; ++i) { \
  133 + col1(i) = (i % 2); \
  134 + } \
  135 + for (int i = 0; i < nrows; ++i) { \
  136 + int ival = (i % 2); \
  137 + std::string sval = (i % 2) ? "T" : "F"; \
  138 + test_assert((col1(i) == ival), \
  139 + "Test access operator row "+str(i), \
  140 + str(col1(i))+" is not "+str(ival)); \
  141 + test_assert((col1.real(i) == double(ival)), \
  142 + "Test real() method for row "+str(i), \
  143 + str(col1.real(i))+" is not "+str(double(ival))); \
  144 + test_assert((col1.integer(i) == int(ival)), \
  145 + "Test integer() method for row "+str(i), \
  146 + str(col1.integer(i))+" is not "+str(int(ival))); \
  147 + test_assert((col1.string(i) == str(ival) || col1.string(i) == sval), \
  148 + "Test string() method for row "+str(i), \
  149 + col1.string(i)+" is not "+str(ival)+" or "+sval); \
  150 + }
  151 +#define TEST_TABLE1_STRING \
  152 + for (int i = 0; i < nrows; ++i) { \
  153 + col1(i) = str(double(i)*3.57+1.29); \
  154 + } \
  155 + for (int i = 0; i < nrows; ++i) { \
  156 + double val = (double(i)*3.57+1.29); \
  157 + test_value(todouble(col1(i)), val, 1e-6, \
  158 + "Test access operator row "+str(i)); \
  159 + test_value(col1.real(i), val, 1e-6, \
  160 + "Test real() method for row "+str(i)); \
  161 + test_value(col1.integer(i), int(val), 1e-6, \
  162 + "Test integer() method for row "+str(i)); \
  163 + test_assert((col1.string(i) == str(val)), \
  164 + "Test string() method for row "+str(i), \
  165 + col1.string(i)+" is not "+str(val)); \
  166 + }
  167 +#define TEST_TABLE2 \
  168 + for (int i = 0; i < nrows; ++i) { \
  169 + for (int j = 0; j < nvec; ++j) { \
  170 + col2(i,j) = double(i)*2.3 + double(j)*11.7 + 0.95; \
  171 + } \
  172 + } \
  173 + for (int i = 0; i < nrows; ++i) { \
  174 + for (int j = 0; j < nvec; ++j) { \
  175 + double val = double(i)*2.3 + double(j)*11.7 + 0.95; \
  176 + test_value(col2(i,j), val, 1e-6, \
  177 + "Test access operator row "+str(i)+" and element "+str(j)); \
  178 + test_value(col2.real(i,j), val, 1e-6, \
  179 + "Test real() method for row "+str(i)+" and element "+str(j)); \
  180 + test_value(col2.integer(i,j), int(val), 1e-6, \
  181 + "Test integer() method for row "+str(i)+" and element "+str(j)); \
  182 + test_assert((col2.string(i,j) == str(val)), \
  183 + "Test string() method for row "+str(i)+" and element "+str(j), \
  184 + col2.string(i,j)+" is not "+str(val)); \
  185 + } \
  186 + }
  187 +#define TEST_TABLE2_INT \
  188 + for (int i = 0; i < nrows; ++i) { \
  189 + for (int j = 0; j < nvec; ++j) { \
  190 + col2(i,j) = i + j*11; \
  191 + } \
  192 + } \
  193 + for (int i = 0; i < nrows; ++i) { \
  194 + for (int j = 0; j < nvec; ++j) { \
  195 + int val = i + j*11; \
  196 + test_assert((col2(i,j) == val), \
  197 + "Test access operator row "+str(i)+" and element "+str(j), \
  198 + str(col2(i,j))+" is not "+str(val)); \
  199 + test_assert((col2.real(i,j) == double(val)), \
  200 + "Test real() method for row "+str(i)+" and element "+str(j), \
  201 + str(col2.real(i,j))+" is not "+str(double(val))); \
  202 + test_assert((col2.integer(i,j) == val), \
  203 + "Test integer() method for row "+str(i)+" and element "+str(j), \
  204 + str(col2.integer(i,j))+" is not "+str(val)); \
  205 + test_assert((col2.string(i,j) == str(val)), \
  206 + "Test string() method for row "+str(i)+" and element "+str(j), \
  207 + col2.string(i,j)+" is not "+str(val)); \
  208 + } \
  209 + }
  210 +#define TEST_TABLE2_BOOL \
  211 + for (int i = 0; i < nrows; ++i) { \
  212 + for (int j = 0; j < nvec; ++j) { \
  213 + col2(i,j) = (i % 2) * (j % 2); \
  214 + } \
  215 + } \
  216 + for (int i = 0; i < nrows; ++i) { \
  217 + for (int j = 0; j < nvec; ++j) { \
  218 + int ival = ((i % 2) * (j % 2)); \
  219 + std::string sval = ((i % 2) * (j % 2)) ? "T" : "F"; \
  220 + test_assert((col2(i,j) == ival), \
  221 + "Test access operator row "+str(i)+" and element "+str(j), \
  222 + str(col2(i,j))+" is not "+str(ival)); \
  223 + test_assert((col2.real(i,j) == double(ival)), \
  224 + "Test real() method for row "+str(i)+" and element "+str(j), \
  225 + str(col2.real(i,j))+" is not "+str(double(ival))); \
  226 + test_assert((col2.integer(i,j) == int(ival)), \
  227 + "Test integer() method for row "+str(i)+" and element "+str(j), \
  228 + str(col2.integer(i,j))+" is not "+str(int(ival))); \
  229 + test_assert((col2.string(i,j) == str(ival) || col2.string(i,j) == sval), \
  230 + "Test string() method for row "+str(i)+" and element "+str(j), \
  231 + col2.string(i,j)+" is not "+str(ival)+" or "+sval); \
  232 + } \
  233 + }
  234 +#define TEST_TABLE2_STRING \
  235 + for (int i = 0; i < nrows; ++i) { \
  236 + for (int j = 0; j < nvec; ++j) { \
  237 + col2(i,j) = str(double(i)*2.3 + double(j)*11.7 + 0.95); \
  238 + } \
  239 + } \
  240 + for (int i = 0; i < nrows; ++i) { \
  241 + for (int j = 0; j < nvec; ++j) { \
  242 + double val = double(i)*2.3 + double(j)*11.7 + 0.95; \
  243 + test_value(todouble(col2(i,j)), val, 1e-6, \
  244 + "Test access operator row "+str(i)+" and element "+str(j)); \
  245 + test_value(col2.real(i,j), val, 1e-6, \
  246 + "Test real() method for row "+str(i)+" and element "+str(j)); \
  247 + test_value(col2.integer(i,j), int(val), 1e-6, \
  248 + "Test integer() method for row "+str(i)+" and element "+str(j)); \
  249 + test_assert((col2.string(i,j) == str(val)), \
  250 + "Test string() method for row "+str(i)+" and element "+str(j), \
  251 + col2.string(i,j)+" is not "+str(val)); \
  252 + } \
  253 + }
  254 +#define TEST_WRITE_TABLES \
  255 + test_try("Write Table"); \
  256 + try { \
  257 + GFits fits; \
  258 + fits.open(filename, true); \
  259 + GFitsBinTable table = GFitsBinTable(nrows); \
  260 + table.append_column(col1); \
  261 + table.insert_column(1, col2); \
  262 + fits.append(table); \
  263 + fits.save(); \
  264 + fits.close(); \
  265 + test_try_success(); \
  266 + } \
  267 + catch(std::exception &e) { \
  268 + test_try_failure(e); \
  269 + }
  270 +
41 271  
42 272 /***********************************************************************//**
43 273 * @brief Set parameters and tests
44 274 **************************************************************************/
45   -void TestGFits::set(void){
46   -
  275 +void TestGFits::set(void)
  276 +{
47 277 // Set test name
48 278 name("GFits");
49 279  
... ... @@ -73,23 +303,6 @@ void TestGFits::set(void){
73 303 }
74 304  
75 305  
76   -/***********************************************************************//**
77   - * @brief Verification routines
78   - **************************************************************************/
79   -int TestGFits::equal(double val, double ref, double eps)
80   -{
81   - return (fabs(val-ref) < eps) ? 1 : 0;
82   -}
83   -int TestGFits::fequal(double val, double ref)
84   -{
85   - return (fabs(val-ref) < 1.0e-5) ? 1 : 0;
86   -}
87   -int TestGFits::dequal(double val, double ref)
88   -{
89   - return (fabs(val-ref) < 1.0e-10) ? 1 : 0;
90   -}
91   -
92   -
93 306 /***************************************************************************
94 307 * @brief Test FITS file creation
95 308 *
... ... @@ -112,7 +325,7 @@ void TestGFits::test_create(void)
112 325 test_try_success();
113 326 }
114 327 catch (std::exception &e) {
115   - test_try_failure();
  328 + test_try_failure(e);
116 329 }
117 330  
118 331 // Create FITS file with empty double precision image
... ... @@ -126,7 +339,7 @@ void TestGFits::test_create(void)
126 339 test_try_success();
127 340 }
128 341 catch (std::exception &e) {
129   - test_try_failure();
  342 + test_try_failure(e);
130 343 }
131 344  
132 345 // Attach double precision image
... ... @@ -156,29 +369,26 @@ void TestGFits::test_create(void)
156 369 }
157 370  
158 371 // Re-open double precision image
  372 + double total = 0.0;
159 373 test_try("Re-open double precision image");
160   - {
161   - double total = 0.0;
162   - try{
163   - GFits fits;
164   - fits.open("test.fits");
165   - GFitsHDU* hdu = fits.hdu(0);
166   - GFitsImageDouble* image = (GFitsImageDouble*)fits.hdu(1);
167   - int nx = image->naxes(0);
168   - int ny = image->naxes(1);
169   -
170   - for (int ix = 0; ix < nx; ++ix) {
171   - for (int iy = 0; iy < ny; ++iy) {
172   - total += (*image)(ix,iy);
173   - }
  374 + try {
  375 + GFits fits;
  376 + fits.open("test.fits");
  377 + GFitsHDU* hdu = fits.hdu(0);
  378 + GFitsImageDouble* image = static_cast<GFitsImageDouble*>(fits.hdu(1));
  379 + int nx = image->naxes(0);
  380 + int ny = image->naxes(1);
  381 + for (int ix = 0; ix < nx; ++ix) {
  382 + for (int iy = 0; iy < ny; ++iy) {
  383 + total += (*image)(ix,iy);
174 384 }
175   - test_try_success();
176   - }
177   - catch (std::exception &e) {
178   - test_try_failure();
179 385 }
180   - test_assert(dequal(total, sum),"Bad values in loaded image.");
  386 + test_try_success();
  387 + }
  388 + catch (std::exception &e) {
  389 + test_try_failure(e);
181 390 }
  391 + test_value(total, sum, 1e-10, "Test loading of double precision image");
182 392  
183 393 // Attach binary table (save variant)
184 394 test_try("Attach binary table (save variant)");
... ... @@ -196,8 +406,6 @@ void TestGFits::test_create(void)
196 406 first(1) = 2.0;
197 407 first(2) = 3.0;
198 408 second(0) = -99.0;
199   - //std::cout << std::endl << first << std::endl;
200   - //std::cout << second << std::endl;
201 409 table.append_column(first);
202 410 table.append_column(second);
203 411  
... ... @@ -210,7 +418,7 @@ void TestGFits::test_create(void)
210 418 test_try_success();
211 419 }
212 420 catch (std::exception &e) {
213   - test_try_failure();
  421 + test_try_failure(e);
214 422 }
215 423  
216 424  
... ... @@ -240,7 +448,7 @@ void TestGFits::test_create(void)
240 448 test_try_success();
241 449 }
242 450 catch (std::exception &e) {
243   - test_try_failure();
  451 + test_try_failure(e);
244 452 }
245 453  
246 454 // Return
... ... @@ -257,143 +465,45 @@ void TestGFits::test_image_byte(void)
257 465 std::string filename = "test_image_byte.fits";
258 466 remove(filename.c_str());
259 467  
  468 + // Set number of pixels
  469 +
260 470 // Create pixel array
261   - unsigned char* pixels = new unsigned char[256];
262   - for (int i = 0; i < 256; ++i)
  471 + unsigned char* pixels = new unsigned char[16];
  472 + for (int i = 0; i < 16; ++i) {
263 473 pixels[i] = (unsigned char)(i);
  474 + }
  475 +
  476 + // Test 1D pixel access
  477 + GFitsImageByte image1(2, pixels);
  478 + TEST_1D_ACCESS(2)
264 479  
265   - // Test pixel access 1D
266   - test_try("Test pixel access 1D");
267   - try {
268   - // Test 1D image
269   - GFitsImageByte image(256, pixels);
270   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
271   -
272   - if(!dequal(image(ix), pixels[i]))
273   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
274   - if(!dequal(image.at(ix), pixels[i]))
275   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
276   - if(!dequal(image.pixel(ix), pixels[i]))
277   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
278   - }
279   -
280   - test_try_success();
281   - }
282   - catch (std::exception &e) {
283   - test_try_failure(e);
284   - }
285   -
286   - // Test pixel access 2D
287   - test_try("Test pixel access 2D");
288   - try {
289   - GFitsImageByte image(16, 16, pixels);
290   - for (int iy = 0, i = 0; iy < 16; ++iy) {
291   - for (int ix = 0; ix < 16; ++ix, ++i) {
292   - if(!dequal(image(ix,iy), pixels[i]))
293   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
294   -
295   - if(!dequal(image.at(ix,iy), pixels[i]))
296   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
297   -
298   - if(!dequal(image.pixel(ix,iy), pixels[i]))
299   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
300   - }
301   - }
302   - test_try_success();
303   - }
304   - catch (std::exception &e) {
305   - test_try_failure(e);
306   - }
307   -
308   - // Test pixel access 3D
309   - test_try("Test pixel access 3D");
310   - try {
311   - GFitsImageByte image(16, 4, 4, pixels);
312   - for (int iz = 0, i = 0; iz < 4; ++iz) {
313   - for (int iy = 0; iy < 4; ++iy) {
314   - for (int ix = 0; ix < 16; ++ix, ++i) {
315   -
316   - if (!dequal(image(ix,iy,iz), pixels[i]))
317   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
318   -
319   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
320   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
321   -
322   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
323   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
324   - }
325   - }
326   - }
327   - }
328   - test_try_success();
329   - }
330   - catch (std::exception &e) {
331   - test_try_failure(e);
332   - }
333   -
334   - // Test 4D image
335   - test_try("Test pixel access 4D");
336   - try {
337   - GFitsImageByte image (4, 4, 4, 4, pixels);
338   - for (int it = 0, i = 0; it < 4; ++it) {
339   - for (int iz = 0; iz < 4; ++iz) {
340   - for (int iy = 0; iy < 4; ++iy) {
341   - for (int ix = 0; ix < 4; ++ix, ++i) {
342   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
343   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
344   - }
345   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
346   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
347   - }
348   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
349   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
350   - }
351   - }
352   - }
353   - }
354   - }
355   - test_try_success();
356   - }
357   - catch (std::exception &e) {
358   - test_try_failure(e);
359   - }
  480 + // Test 2D pixel access
  481 + GFitsImageByte image2(2, 2, pixels);
  482 + TEST_2D_ACCESS(2,2)
360 483  
  484 + // Test 3D pixel access
  485 + GFitsImageByte image3(2, 2, 2, pixels);
  486 + TEST_3D_ACCESS(2,2,2)
361 487  
  488 + // Test 4D pixel access
  489 + GFitsImageByte image4(2, 2, 2, 2, pixels);
  490 + TEST_4D_ACCESS(2,2,2,2)
362 491  
363 492 // Test image I/O with 4D image
364   - test_try("Test image I/O with 4D image");
365   - try{
366   - // Create 4D image
367   - int naxes[] = {4,4,4,4};
368   - GFitsImageByte image(4, naxes, pixels);
369   -
370   - // Save image
371   - GFits fits(filename, true);
372   - fits.append(image);
373   - fits.save();
  493 + int naxes[] = {2,2,2,2};
  494 + GFitsImageByte image(4, naxes, pixels);
374 495  
375   - // Open FITS image
376   - GFits infile(filename);
377   - GFitsImage* ptr = infile.image(0);
378   -
379   - // Test 4D image
380   - for (int it = 0, i = 0; it < 4; ++it) {
381   - for (int iz = 0; iz < 4; ++iz) {
382   - for (int iy = 0; iy < 4; ++iy) {
383   - for (int ix = 0; ix < 4; ++ix, ++i) {
384   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
385   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
386   - }
387   - }
388   - }
389   - }
390   - }
  496 + // Save image
  497 + GFits fits(filename, true);
  498 + fits.append(image);
  499 + fits.save();
391 500  
392   - test_try_success();
393   - }
394   - catch (std::exception &e) {
395   - test_try_failure(e);
396   - }
  501 + // Open FITS image
  502 + GFits infile(filename);
  503 + GFitsImage* ptr = infile.image(0);
  504 +
  505 + // Test 4D pixel access
  506 + TEST_4D_ACCESS_IO(2,2,2,2)
397 507  
398 508 // Return
399 509 return;
... ... @@ -411,138 +521,42 @@ void TestGFits::test_image_ushort(void)
411 521 remove(filename.c_str());
412 522  
413 523 // Create pixel array
414   - unsigned short* pixels = new unsigned short[256];
415   - for (int i = 0; i < 256; ++i)
  524 + unsigned short* pixels = new unsigned short[16];
  525 + for (int i = 0; i < 16; ++i) {
416 526 pixels[i] = (unsigned short)(i);
417   -
418   - // Test pixel access (1D to 4D)
419   - test_try("Test pixel access 1D");
420   - try {
421   -
422   - // Test 1D image
423   - GFitsImageUShort image(256, pixels);
424   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
425   - if(!dequal(image(ix), pixels[i]))
426   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
427   - if(!dequal(image.at(ix), pixels[i]))
428   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
429   - if(!dequal(image.pixel(ix), pixels[i]))
430   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
431   - }
432   -
433   - test_try_success();
434 527 }
435   - catch (std::exception &e) {
436   - test_try_failure(e);
437   - }
438   -
439   - // Test 2D image
440   - test_try("Test pixel access 2D");
441   - try {
442   - GFitsImageUShort image(16, 16, pixels);
443   - for (int iy = 0, i = 0; iy < 16; ++iy) {
444   - for (int ix = 0; ix < 16; ++ix, ++i) {
445   - if(!dequal(image(ix,iy), pixels[i]))
446   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
447 528  
448   - if(!dequal(image.at(ix,iy), pixels[i]))
449   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
  529 + // Test 1D pixel access
  530 + GFitsImageUShort image1(2, pixels);
  531 + TEST_1D_ACCESS(2)
450 532  
451   - if(!dequal(image.pixel(ix,iy), pixels[i]))
452   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
453   - }
454   - }
455   - test_try_success();
456   - }
457   - catch (std::exception &e) {
458   - test_try_failure(e);
459   - }
  533 + // Test 2D pixel access
  534 + GFitsImageUShort image2(2, 2, pixels);
  535 + TEST_2D_ACCESS(2,2)
460 536  
461   - // Test 3D image
462   - test_try("Test pixel access 3D");
463   - try {
464   - GFitsImageUShort image(16, 4, 4, pixels);
465   - for (int iz = 0, i = 0; iz < 4; ++iz) {
466   - for (int iy = 0; iy < 4; ++iy) {
467   - for (int ix = 0; ix < 16; ++ix, ++i) {
468   - if (!dequal(image(ix,iy,iz), pixels[i]))
469   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
470   -
471   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
472   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
473   -
474   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
475   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
476   - }
477   - }
478   - }
479   - }
480   - test_try_success();
481   - }
482   - catch (std::exception &e) {
483   - test_try_failure(e);
484   - }
  537 + // Test 3D pixel access
  538 + GFitsImageUShort image3(2, 2, 2, pixels);
  539 + TEST_3D_ACCESS(2,2,2)
485 540  
486   - // Test 4D image
487   - test_try("Test pixel access 4D");
488   - try {
489   - GFitsImageUShort image(4, 4, 4, 4, pixels);
490   - for (int it = 0, i = 0; it < 4; ++it) {
491   - for (int iz = 0; iz < 4; ++iz) {
492   - for (int iy = 0; iy < 4; ++iy) {
493   - for (int ix = 0; ix < 4; ++ix, ++i) {
494   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
495   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
496   - }
497   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
498   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
499   - }
500   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
501   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
502   - }
503   - }
504   - }
505   - }
506   - }
507   - test_try_success();
508   - }
509   - catch (std::exception &e) {
510   - test_try_failure(e);
511   - }
  541 + // Test 4D pixel access
  542 + GFitsImageUShort image4(2, 2, 2, 2, pixels);
  543 + TEST_4D_ACCESS(2,2,2,2)
512 544  
513 545 // Test image I/O with 4D image
514   - test_try("Test image I/O with 4D image");
515   - try{
516   - // Create 4D image
517   - int naxes[] = {4,4,4,4};
518   - GFitsImageUShort image(4, naxes, pixels);
519   -
520   - // Save image
521   - GFits fits(filename, true);
522   - fits.append(image);
523   - fits.save();
  546 + int naxes[] = {2,2,2,2};
  547 + GFitsImageUShort image(4, naxes, pixels);
524 548  
525   - // Open FITS image
526   - GFits infile(filename);
527   - GFitsImage* ptr = infile.image(0);
528   -
529   - // Test 4D image
530   - for (int it = 0, i = 0; it < 4; ++it) {
531   - for (int iz = 0; iz < 4; ++iz) {
532   - for (int iy = 0; iy < 4; ++iy) {
533   - for (int ix = 0; ix < 4; ++ix, ++i) {
534   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
535   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
536   - }
537   - }
538   - }
539   - }
540   - }
541   - test_try_success();
542   - }
543   - catch (std::exception &e) {
544   - test_try_failure(e);
545   - }
  549 + // Save image
  550 + GFits fits(filename, true);
  551 + fits.append(image);
  552 + fits.save();
  553 +
  554 + // Open FITS image
  555 + GFits infile(filename);
  556 + GFitsImage* ptr = infile.image(0);
  557 +
  558 + // Test 4D pixel access
  559 + TEST_4D_ACCESS_IO(2,2,2,2)
546 560  
547 561 // Return
548 562 return;
... ... @@ -559,137 +573,42 @@ void TestGFits::test_image_short(void)
559 573 remove(filename.c_str());
560 574  
561 575 // Create pixel array
562   - short* pixels = new short[256];
563   - for (int i = 0; i < 256; ++i)
  576 + short* pixels = new short[16];
  577 + for (int i = 0; i < 16; ++i) {
564 578 pixels[i] = (short)(i);
565   -
566   - // Test pixel access 1D
567   - test_try("Test pixel access 1D");
568   - try {
569   -
570   - // Test 1D image
571   - GFitsImageShort image(256, pixels);
572   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
573   - if(!dequal(image(ix), pixels[i]))
574   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
575   - if(!dequal(image.at(ix), pixels[i]))
576   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
577   - if(!dequal(image.pixel(ix), pixels[i]))
578   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
579   - }
580   - test_try_success();
581   - }
582   - catch (std::exception &e) {
583   - test_try_failure(e);
584 579 }
585   -
586   - // Test 2D image
587   - test_try("Test pixel access 2D");
588   - try {
589   - GFitsImageShort image(16, 16, pixels);
590   - for (int iy = 0, i = 0; iy < 16; ++iy) {
591   - for (int ix = 0; ix < 16; ++ix, ++i) {
592   - if(!dequal(image(ix,iy), pixels[i]))
593   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
594 580  
595   - if(!dequal(image.at(ix,iy), pixels[i]))
596   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
  581 + // Test 1D pixel access
  582 + GFitsImageShort image1(2, pixels);
  583 + TEST_1D_ACCESS(2)
597 584  
598   - if(!dequal(image.pixel(ix,iy), pixels[i]))
599   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
600   - }
601   - }
602   - test_try_success();
603   - }
604   - catch (std::exception &e) {
605   - test_try_failure(e);
606   - }
  585 + // Test 2D pixel access
  586 + GFitsImageShort image2(2, 2, pixels);
  587 + TEST_2D_ACCESS(2,2)
607 588  
608   - // Test 3D image
609   - test_try("Test pixel access 3D");
610   - try {
611   - GFitsImageShort image(16, 4, 4, pixels);
612   - for (int iz = 0, i = 0; iz < 4; ++iz) {
613   - for (int iy = 0; iy < 4; ++iy) {
614   - for (int ix = 0; ix < 16; ++ix, ++i) {
615   - if (!dequal(image(ix,iy,iz), pixels[i]))
616   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
617   -
618   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
619   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
620   -
621   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
622   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
623   - }
624   - }
625   - }
626   - }
627   - test_try_success();
628   - }
629   - catch (std::exception &e) {
630   - test_try_failure(e);
631   - }
  589 + // Test 3D pixel access
  590 + GFitsImageShort image3(2, 2, 2, pixels);
  591 + TEST_3D_ACCESS(2,2,2)
632 592  
633   - // Test 4D image
634   - test_try("Test pixel access 4D");
635   - try {
636   - GFitsImageShort image(4, 4, 4, 4, pixels);
637   - for (int it = 0, i = 0; it < 4; ++it) {
638   - for (int iz = 0; iz < 4; ++iz) {
639   - for (int iy = 0; iy < 4; ++iy) {
640   - for (int ix = 0; ix < 4; ++ix, ++i) {
641   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
642   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
643   - }
644   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
645   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
646   - }
647   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
648   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
649   - }
650   - }
651   - }
652   - }
653   - }
654   - test_try_success();
655   - }
656   - catch (std::exception &e) {
657   - test_try_failure(e);
658   - }
  593 + // Test 4D pixel access
  594 + GFitsImageShort image4(2, 2, 2, 2, pixels);
  595 + TEST_4D_ACCESS(2,2,2,2)
659 596  
660 597 // Test image I/O with 4D image
661   - test_try("Test image I/O with 4D image");
662   - try{
663   - // Create 4D image
664   - int naxes[] = {4,4,4,4};
665   - GFitsImageShort image(4, naxes, pixels);
666   -
667   - // Save image
668   - GFits fits(filename, true);
669   - fits.append(image);
670   - fits.save();
  598 + int naxes[] = {2,2,2,2};
  599 + GFitsImageShort image(4, naxes, pixels);
671 600  
672   - // Open FITS image
673   - GFits infile(filename);
674   - GFitsImage* ptr = infile.image(0);
675   -
676   - // Test 4D image
677   - for (int it = 0, i = 0; it < 4; ++it) {
678   - for (int iz = 0; iz < 4; ++iz) {
679   - for (int iy = 0; iy < 4; ++iy) {
680   - for (int ix = 0; ix < 4; ++ix, ++i) {
681   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
682   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
683   - }
684   - }
685   - }
686   - }
687   - }
688   - test_try_success();
689   - }
690   - catch (std::exception &e) {
691   - test_try_failure(e);
692   - }
  601 + // Save image
  602 + GFits fits(filename, true);
  603 + fits.append(image);
  604 + fits.save();
  605 +
  606 + // Open FITS image
  607 + GFits infile(filename);
  608 + GFitsImage* ptr = infile.image(0);
  609 +
  610 + // Test 4D pixel access
  611 + TEST_4D_ACCESS_IO(2,2,2,2)
693 612  
694 613 // Return
695 614 return;
... ... @@ -706,140 +625,42 @@ void TestGFits::test_image_ulong(void)
706 625 remove(filename.c_str());
707 626  
708 627 // Create pixel array
709   - unsigned long* pixels = new unsigned long[256];
710   - for (int i = 0; i < 256; ++i)
  628 + unsigned long* pixels = new unsigned long[16];
  629 + for (int i = 0; i < 16; ++i) {
711 630 pixels[i] = (unsigned long)(i);
712   -
713   - // Test pixel access (1D to 4D)
714   - test_try("Test pixel access 1D");
715   - try {
716   -
717   - // Test 1D image
718   - GFitsImageULong image(256, pixels);
719   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
720   - if(!dequal(image(ix), pixels[i]))
721   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
722   - if(!dequal(image.at(ix), pixels[i]))
723   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
724   - if(!dequal(image.pixel(ix), pixels[i]))
725   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
726   - }
727   -
728   - test_try_success();
729   - }
730   - catch (std::exception &e) {
731   - test_try_failure(e);
732 631 }
733 632  
734   - // Test 2D image
735   - test_try("Test pixel access 2D");
736   - try {
737   - GFitsImageULong image(16, 16, pixels);
738   - for (int iy = 0, i = 0; iy < 16; ++iy) {
739   - for (int ix = 0; ix < 16; ++ix, ++i) {
740   - if(!dequal(image(ix,iy), pixels[i]))
741   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
742   -
743   - if(!dequal(image.at(ix,iy), pixels[i]))
744   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
745   -
746   - if(!dequal(image.pixel(ix,iy), pixels[i]))
747   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
748   - }
749   - }
750   - test_try_success();
751   - }
752   - catch (std::exception &e) {
753   - test_try_failure(e);
754   - }
  633 + // Test 1D pixel access
  634 + GFitsImageULong image1(2, pixels);
  635 + TEST_1D_ACCESS(2)
755 636  
756   - // Test 3D image
757   - test_try("Test pixel access 3D");
758   - try{
759   - GFitsImageULong image(16, 4, 4, pixels);
760   - for (int iz = 0, i = 0; iz < 4; ++iz) {
761   - for (int iy = 0; iy < 4; ++iy) {
762   - for (int ix = 0; ix < 16; ++ix, ++i) {
763   - if (!dequal(image(ix,iy,iz), pixels[i]))
764   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
765   -
766   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
767   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
768   -
769   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
770   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
771   - }
772   - }
773   - }
774   - }
775   - test_try_success();
776   - }
777   - catch (std::exception &e) {
778   - test_try_failure(e);
779   - }
  637 + // Test 2D pixel access
  638 + GFitsImageULong image2(2, 2, pixels);
  639 + TEST_2D_ACCESS(2,2)
780 640  
781   - // Test 4D image
782   - test_try("Test pixel access 4D");
783   - try {
784   - GFitsImageULong image(4, 4, 4, 4, pixels);
785   - for (int it = 0, i = 0; it < 4; ++it) {
786   - for (int iz = 0; iz < 4; ++iz) {
787   - for (int iy = 0; iy < 4; ++iy) {
788   - for (int ix = 0; ix < 4; ++ix, ++i) {
789   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
790   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
791   - }
792   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
793   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
794   - }
795   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
796   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
797   - }
798   - }
799   - }
800   - }
801   - }
802   - test_try_success();
803   - }
804   - catch (std::exception &e) {
805   - test_try_failure(e);
806   - }
  641 + // Test 3D pixel access
  642 + GFitsImageULong image3(2, 2, 2, pixels);
  643 + TEST_3D_ACCESS(2,2,2)
807 644  
  645 + // Test 4D pixel access
  646 + GFitsImageULong image4(2, 2, 2, 2, pixels);
  647 + TEST_4D_ACCESS(2,2,2,2)
808 648  
809 649 // Test image I/O with 4D image
810   - test_try("Test image I/O with 4D image");
811   - try{
812   - // Create 4D image
813   - int naxes[] = {4,4,4,4};
814   - GFitsImageULong image(4, naxes, pixels);
815   -
816   - // Save image
817   - GFits fits(filename, true);
818   - fits.append(image);
819   - fits.save();
  650 + int naxes[] = {2,2,2,2};
  651 + GFitsImageULong image(4, naxes, pixels);
820 652  
821   - // Open FITS image
822   - GFits infile(filename);
823   - GFitsImage* ptr = infile.image(0);
824   - std::cout << ".";
825   -
826   - // Test 4D image
827   - for (int it = 0, i = 0; it < 4; ++it) {
828   - for (int iz = 0; iz < 4; ++iz) {
829   - for (int iy = 0; iy < 4; ++iy) {
830   - for (int ix = 0; ix < 4; ++ix, ++i) {
831   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
832   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
833   - }
834   - }
835   - }
836   - }
837   - }
838   - test_try_success();
839   - }
840   - catch (std::exception &e) {
841   - test_try_failure(e);
842   - }
  653 + // Save image
  654 + GFits fits(filename, true);
  655 + fits.append(image);
  656 + fits.save();
  657 +
  658 + // Open FITS image
  659 + GFits infile(filename);
  660 + GFitsImage* ptr = infile.image(0);
  661 +
  662 + // Test 4D pixel access
  663 + TEST_4D_ACCESS_IO(2,2,2,2)
843 664  
844 665 // Return
845 666 return;
... ... @@ -856,140 +677,42 @@ void TestGFits::test_image_long(void)
856 677 remove(filename.c_str());
857 678  
858 679 // Create pixel array
859   - long* pixels = new long[256];
860   - for (int i = 0; i < 256; ++i)
  680 + long* pixels = new long[16];
  681 + for (int i = 0; i < 16; ++i) {
861 682 pixels[i] = (long)(i);
  683 + }
862 684  
863   - // Test pixel access (1D to 4D)
864   - test_try("Test pixel access 1D");
865   - try {
  685 + // Test 1D pixel access
  686 + GFitsImageLong image1(2, pixels);
  687 + TEST_1D_ACCESS(2)
866 688  
867   - // Test 1D image
868   - GFitsImageLong image(256, pixels);
869   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
870   - if(!dequal(image(ix), pixels[i]))
871   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
872   - if(!dequal(image.at(ix), pixels[i]))
873   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
874   - if(!dequal(image.pixel(ix), pixels[i]))
875   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
876   - }
  689 + // Test 2D pixel access
  690 + GFitsImageLong image2(2, 2, pixels);
  691 + TEST_2D_ACCESS(2,2)
877 692  
878   - test_try_success();
879   - }
880   - catch (std::exception &e) {
881   - test_try_failure(e);
882   - }
  693 + // Test 3D pixel access
  694 + GFitsImageLong image3(2, 2, 2, pixels);
  695 + TEST_3D_ACCESS(2,2,2)
883 696  
884   - // Test 2D image
885   - test_try("Test pixel access 2D");
886   - try {
887   - GFitsImageLong image(16, 16, pixels);
888   - for (int iy = 0, i = 0; iy < 16; ++iy) {
889   - for (int ix = 0; ix < 16; ++ix, ++i) {
890   - if(!dequal(image(ix,iy), pixels[i]))
891   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
  697 + // Test 4D pixel access
  698 + GFitsImageLong image4(2, 2, 2, 2, pixels);
  699 + TEST_4D_ACCESS(2,2,2,2)
892 700  
893   - if(!dequal(image.at(ix,iy), pixels[i]))
894   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
  701 + // Test image I/O with 4D image
  702 + int naxes[] = {2,2,2,2};
  703 + GFitsImageLong image(4, naxes, pixels);
895 704  
896   - if(!dequal(image.pixel(ix,iy), pixels[i]))
897   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
898   - }
899   - }
900   - test_try_success();
901   - }
902   - catch (std::exception &e) {
903   - test_try_failure(e);
904   - }
  705 + // Save image
  706 + GFits fits(filename, true);
  707 + fits.append(image);
  708 + fits.save();
905 709  
906   - // Test 3D image
907   - test_try("Test pixel access 3D");
908   - try{
909   - GFitsImageLong image(16, 4, 4, pixels);
910   - for (int iz = 0, i = 0; iz < 4; ++iz) {
911   - for (int iy = 0; iy < 4; ++iy) {
912   - for (int ix = 0; ix < 16; ++ix, ++i) {
913   - if (!dequal(image(ix,iy,iz), pixels[i]))
914   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
915   -
916   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
917   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
  710 + // Open FITS image
  711 + GFits infile(filename);
  712 + GFitsImage* ptr = infile.image(0);
918 713  
919   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
920   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
921   - }
922   - }
923   - }
924   - }
925   - test_try_success();
926   - }
927   - catch (std::exception &e) {
928   - test_try_failure(e);
929   - }
930   -
931   - // Test 4D image
932   - test_try("Test pixel access 4D");
933   - try {
934   - GFitsImageLong image(4, 4, 4, 4, pixels);
935   - for (int it = 0, i = 0; it < 4; ++it) {
936   - for (int iz = 0; iz < 4; ++iz) {
937   - for (int iy = 0; iy < 4; ++iy) {
938   - for (int ix = 0; ix < 4; ++ix, ++i) {
939   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
940   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
941   - }
942   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
943   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
944   - }
945   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
946   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
947   - }
948   - }
949   - }
950   - }
951   - }
952   - test_try_success();
953   - }
954   - catch (std::exception &e) {
955   - test_try_failure(e);
956   - }
957   -
958   -
959   - // Test image I/O with 4D image
960   - test_try("Test image I/O with 4D image");
961   - try{
962   - // Create 4D image
963   - int naxes[] = {4,4,4,4};
964   - GFitsImageLong image(4, naxes, pixels);
965   -
966   - // Save image
967   - GFits fits(filename, true);
968   - fits.append(image);
969   - fits.save();
970   -
971   - // Open FITS image
972   - GFits infile(filename);
973   - GFitsImage* ptr = infile.image(0);
974   - std::cout << ".";
975   -
976   - // Test 4D image
977   - for (int it = 0, i = 0; it < 4; ++it) {
978   - for (int iz = 0; iz < 4; ++iz) {
979   - for (int iy = 0; iy < 4; ++iy) {
980   - for (int ix = 0; ix < 4; ++ix, ++i) {
981   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
982   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
983   - }
984   - }
985   - }
986   - }
987   - }
988   - test_try_success();
989   - }
990   - catch (std::exception &e) {
991   - test_try_failure(e);
992   - }
  714 + // Test 4D pixel access
  715 + TEST_4D_ACCESS_IO(2,2,2,2)
993 716  
994 717 // Return
995 718 return;
... ... @@ -999,7 +722,6 @@ void TestGFits::test_image_long(void)
999 722 /***************************************************************************
1000 723 * @brief Test GFitsImageLongLong class
1001 724 ***************************************************************************/
1002   -
1003 725 void TestGFits::test_image_longlong(void)
1004 726 {
1005 727 // Set filename
... ... @@ -1007,140 +729,42 @@ void TestGFits::test_image_longlong(void)
1007 729 remove(filename.c_str());
1008 730  
1009 731 // Create pixel array
1010   - long long* pixels = new long long[256];
1011   - for (int i = 0; i < 256; ++i)
  732 + long long* pixels = new long long[16];
  733 + for (int i = 0; i < 16; ++i) {
1012 734 pixels[i] = (long long)(i);
1013   -
1014   - // Test pixel access (1D to 4D)
1015   - test_try("Test pixel access 1D");
1016   - try {
1017   -
1018   - // Test 1D image
1019   - GFitsImageLongLong image(256, pixels);
1020   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
1021   - if(!dequal(image(ix), pixels[i]))
1022   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
1023   - if(!dequal(image.at(ix), pixels[i]))
1024   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
1025   - if(!dequal(image.pixel(ix), pixels[i]))
1026   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
1027   - }
1028   -
1029   - test_try_success();
1030 735 }
1031   - catch (std::exception &e) {
1032   - test_try_failure(e);
1033   - }
1034   -
1035   - // Test 2D image
1036   - test_try("Test pixel access 2D");
1037   - try {
1038   - GFitsImageLongLong image(16, 16, pixels);
1039   - for (int iy = 0, i = 0; iy < 16; ++iy) {
1040   - for (int ix = 0; ix < 16; ++ix, ++i) {
1041   - if(!dequal(image(ix,iy), pixels[i]))
1042   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
1043   -
1044   - if(!dequal(image.at(ix,iy), pixels[i]))
1045   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
1046 736  
1047   - if(!dequal(image.pixel(ix,iy), pixels[i]))
1048   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
1049   - }
1050   - }
1051   - test_try_success();
1052   - }
1053   - catch (std::exception &e) {
1054   - test_try_failure(e);
1055   - }
  737 + // Test 1D pixel access
  738 + GFitsImageLongLong image1(2, pixels);
  739 + TEST_1D_ACCESS(2)
1056 740  
1057   - // Test 3D image
1058   - test_try("Test pixel access 3D");
1059   - try{
1060   - GFitsImageLongLong image(16, 4, 4, pixels);
1061   - for (int iz = 0, i = 0; iz < 4; ++iz) {
1062   - for (int iy = 0; iy < 4; ++iy) {
1063   - for (int ix = 0; ix < 16; ++ix, ++i) {
1064   - if (!dequal(image(ix,iy,iz), pixels[i]))
1065   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
1066   -
1067   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
1068   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
1069   -
1070   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
1071   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
1072   - }
1073   - }
1074   - }
1075   - }
1076   - test_try_success();
1077   - }
1078   - catch (std::exception &e) {
1079   - test_try_failure(e);
1080   - }
  741 + // Test 2D pixel access
  742 + GFitsImageLongLong image2(2, 2, pixels);
  743 + TEST_2D_ACCESS(2,2)
1081 744  
1082   - // Test 4D image
1083   - test_try("Test pixel access 4D");
1084   - try {
1085   - GFitsImageLongLong image(4, 4, 4, 4, pixels);
1086   - for (int it = 0, i = 0; it < 4; ++it) {
1087   - for (int iz = 0; iz < 4; ++iz) {
1088   - for (int iy = 0; iy < 4; ++iy) {
1089   - for (int ix = 0; ix < 4; ++ix, ++i) {
1090   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
1091   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
1092   - }
1093   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
1094   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
1095   - }
1096   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
1097   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
1098   - }
1099   - }
1100   - }
1101   - }
1102   - }
1103   - test_try_success();
1104   - }
1105   - catch (std::exception &e) {
1106   - test_try_failure(e);
1107   - }
  745 + // Test 3D pixel access
  746 + GFitsImageLongLong image3(2, 2, 2, pixels);
  747 + TEST_3D_ACCESS(2,2,2)
1108 748  
  749 + // Test 4D pixel access
  750 + GFitsImageLongLong image4(2, 2, 2, 2, pixels);
  751 + TEST_4D_ACCESS(2,2,2,2)
1109 752  
1110 753 // Test image I/O with 4D image
1111   - test_try("Test image I/O with 4D image");
1112   - try{
1113   - // Create 4D image
1114   - int naxes[] = {4,4,4,4};
1115   - GFitsImageLongLong image(4, naxes, pixels);
1116   -
1117   - // Save image
1118   - GFits fits(filename, true);
1119   - fits.append(image);
1120   - fits.save();
  754 + int naxes[] = {2,2,2,2};
  755 + GFitsImageLongLong image(4, naxes, pixels);
1121 756  
1122   - // Open FITS image
1123   - GFits infile(filename);
1124   - GFitsImage* ptr = infile.image(0);
1125   - std::cout << ".";
1126   -
1127   - // Test 4D image
1128   - for (int it = 0, i = 0; it < 4; ++it) {
1129   - for (int iz = 0; iz < 4; ++iz) {
1130   - for (int iy = 0; iy < 4; ++iy) {
1131   - for (int ix = 0; ix < 4; ++ix, ++i) {
1132   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
1133   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
1134   - }
1135   - }
1136   - }
1137   - }
1138   - }
1139   - test_try_success();
1140   - }
1141   - catch (std::exception &e) {
1142   - test_try_failure(e);
1143   - }
  757 + // Save image
  758 + GFits fits(filename, true);
  759 + fits.append(image);
  760 + fits.save();
  761 +
  762 + // Open FITS image
  763 + GFits infile(filename);
  764 + GFitsImage* ptr = infile.image(0);
  765 +
  766 + // Test 4D pixel access
  767 + TEST_4D_ACCESS_IO(2,2,2,2)
1144 768  
1145 769 // Return
1146 770 return;
... ... @@ -1156,140 +780,42 @@ void TestGFits::test_image_float(void)
1156 780 remove(filename.c_str());
1157 781  
1158 782 // Create pixel array
1159   - float* pixels = new float[256];
1160   - for (int i = 0; i < 256; ++i)
  783 + float* pixels = new float[16];
  784 + for (int i = 0; i < 16; ++i) {
1161 785 pixels[i] = (float)(i);
1162   -
1163   - // Test pixel access (1D to 4D)
1164   - test_try("Test pixel access 1D");
1165   - try {
1166   -
1167   - // Test 1D image
1168   - GFitsImageFloat image(256, pixels);
1169   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
1170   - if(!dequal(image(ix), pixels[i]))
1171   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
1172   - if(!dequal(image.at(ix), pixels[i]))
1173   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
1174   - if(!dequal(image.pixel(ix), pixels[i]))
1175   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
1176   - }
1177   -
1178   - test_try_success();
1179   - }
1180   - catch (std::exception &e) {
1181   - test_try_failure(e);
1182 786 }
1183 787  
1184   - // Test 2D image
1185   - test_try("Test pixel access 2D");
1186   - try {
1187   - GFitsImageFloat image(16, 16, pixels);
1188   - for (int iy = 0, i = 0; iy < 16; ++iy) {
1189   - for (int ix = 0; ix < 16; ++ix, ++i) {
1190   - if(!dequal(image(ix,iy), pixels[i]))
1191   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
1192   -
1193   - if(!dequal(image.at(ix,iy), pixels[i]))
1194   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
1195   -
1196   - if(!dequal(image.pixel(ix,iy), pixels[i]))
1197   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
1198   - }
1199   - }
1200   - test_try_success();
1201   - }
1202   - catch (std::exception &e) {
1203   - test_try_failure(e);
1204   - }
  788 + // Test 1D pixel access
  789 + GFitsImageFloat image1(2, pixels);
  790 + TEST_1D_ACCESS(2)
1205 791  
1206   - // Test 3D image
1207   - test_try("Test pixel access 3D");
1208   - try{
1209   - GFitsImageFloat image(16, 4, 4, pixels);
1210   - for (int iz = 0, i = 0; iz < 4; ++iz) {
1211   - for (int iy = 0; iy < 4; ++iy) {
1212   - for (int ix = 0; ix < 16; ++ix, ++i) {
1213   - if (!dequal(image(ix,iy,iz), pixels[i]))
1214   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
1215   -
1216   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
1217   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
1218   -
1219   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
1220   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
1221   - }
1222   - }
1223   - }
1224   - }
1225   - test_try_success();
1226   - }
1227   - catch (std::exception &e) {
1228   - test_try_failure(e);
1229   - }
  792 + // Test 2D pixel access
  793 + GFitsImageFloat image2(2, 2, pixels);
  794 + TEST_2D_ACCESS(2,2)
1230 795  
1231   - // Test 4D image
1232   - test_try("Test pixel access 4D");
1233   - try {
1234   - GFitsImageFloat image(4, 4, 4, 4, pixels);
1235   - for (int it = 0, i = 0; it < 4; ++it) {
1236   - for (int iz = 0; iz < 4; ++iz) {
1237   - for (int iy = 0; iy < 4; ++iy) {
1238   - for (int ix = 0; ix < 4; ++ix, ++i) {
1239   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
1240   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
1241   - }
1242   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
1243   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
1244   - }
1245   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
1246   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
1247   - }
1248   - }
1249   - }
1250   - }
1251   - }
1252   - test_try_success();
1253   - }
1254   - catch (std::exception &e) {
1255   - test_try_failure(e);
1256   - }
  796 + // Test 3D pixel access
  797 + GFitsImageFloat image3(2, 2, 2, pixels);
  798 + TEST_3D_ACCESS(2,2,2)
1257 799  
  800 + // Test 4D pixel access
  801 + GFitsImageFloat image4(2, 2, 2, 2, pixels);
  802 + TEST_4D_ACCESS(2,2,2,2)
1258 803  
1259 804 // Test image I/O with 4D image
1260   - test_try("Test image I/O with 4D image");
1261   - try{
1262   - // Create 4D image
1263   - int naxes[] = {4,4,4,4};
1264   - GFitsImageFloat image(4, naxes, pixels);
1265   -
1266   - // Save image
1267   - GFits fits(filename, true);
1268   - fits.append(image);
1269   - fits.save();
  805 + int naxes[] = {2,2,2,2};
  806 + GFitsImageFloat image(4, naxes, pixels);
1270 807  
1271   - // Open FITS image
1272   - GFits infile(filename);
1273   - GFitsImage* ptr = infile.image(0);
1274   - std::cout << ".";
1275   -
1276   - // Test 4D image
1277   - for (int it = 0, i = 0; it < 4; ++it) {
1278   - for (int iz = 0; iz < 4; ++iz) {
1279   - for (int iy = 0; iy < 4; ++iy) {
1280   - for (int ix = 0; ix < 4; ++ix, ++i) {
1281   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
1282   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
1283   - }
1284   - }
1285   - }
1286   - }
1287   - }
1288   - test_try_success();
1289   - }
1290   - catch (std::exception &e) {
1291   - test_try_failure(e);
1292   - }
  808 + // Save image
  809 + GFits fits(filename, true);
  810 + fits.append(image);
  811 + fits.save();
  812 +
  813 + // Open FITS image
  814 + GFits infile(filename);
  815 + GFitsImage* ptr = infile.image(0);
  816 +
  817 + // Test 4D pixel access
  818 + TEST_4D_ACCESS_IO(2,2,2,2)
1293 819  
1294 820 // Return
1295 821 return;
... ... @@ -1299,7 +825,6 @@ void TestGFits::test_image_float(void)
1299 825 /***************************************************************************
1300 826 * @brief Test GFitsImageDouble class
1301 827 ***************************************************************************/
1302   -
1303 828 void TestGFits::test_image_double(void)
1304 829 {
1305 830 // Set filename
... ... @@ -1307,3506 +832,410 @@ void TestGFits::test_image_double(void)
1307 832 remove(filename.c_str());
1308 833  
1309 834 // Create pixel array
1310   - double* pixels = new double[256];
1311   - for (int i = 0; i < 256; ++i)
  835 + double* pixels = new double[16];
  836 + for (int i = 0; i < 16; ++i) {
1312 837 pixels[i] = (double)(i);
  838 + }
1313 839  
1314   - // Test pixel access (1D to 4D)
1315   - test_try("Test pixel access 1D");
1316   - try {
  840 + // Test 1D pixel access
  841 + GFitsImageDouble image1(2, pixels);
  842 + TEST_1D_ACCESS(2)
1317 843  
1318   - // Test 1D image
1319   - GFitsImageDouble image(256, pixels);
1320   - for (int ix = 0, i = 0; ix < 256; ++ix, ++i) {
1321   - if(!dequal(image(ix), pixels[i]))
1322   - throw exception_failure("Unexpected pixel content (has "+str(image(ix))+", expected "+str(pixels[i])+" (operator access).");
1323   - if(!dequal(image.at(ix), pixels[i]))
1324   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix))+", expected "+str(pixels[i])+" (at access).");
1325   - if(!dequal(image.pixel(ix), pixels[i]))
1326   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix))+", expected "+str(pixels[i])+" (pixel access).");
1327   - }
  844 + // Test 2D pixel access
  845 + GFitsImageDouble image2(2, 2, pixels);
  846 + TEST_2D_ACCESS(2,2)
1328 847  
1329   - test_try_success();
1330   - }
1331   - catch (std::exception &e) {
1332   - test_try_failure(e);
1333   - }
  848 + // Test 3D pixel access
  849 + GFitsImageDouble image3(2, 2, 2, pixels);
  850 + TEST_3D_ACCESS(2,2,2)
1334 851  
1335   - // Test 2D image
1336   - test_try("Test pixel access 2D");
1337   - try {
1338   - GFitsImageDouble image(16, 16, pixels);
1339   - for (int iy = 0, i = 0; iy < 16; ++iy) {
1340   - for (int ix = 0; ix < 16; ++ix, ++i) {
1341   - if(!dequal(image(ix,iy), pixels[i]))
1342   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy))+", expected "+str(pixels[i])+" (operator access).");
  852 + // Test 4D pixel access
  853 + GFitsImageDouble image4(2, 2, 2, 2, pixels);
  854 + TEST_4D_ACCESS(2,2,2,2)
1343 855  
1344   - if(!dequal(image.at(ix,iy), pixels[i]))
1345   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy))+", expected "+str(pixels[i])+" (at access).");
  856 + // Test image I/O with 4D image
  857 + int naxes[] = {2,2,2,2};
  858 + GFitsImageDouble image(4, naxes, pixels);
1346 859  
1347   - if(!dequal(image.pixel(ix,iy), pixels[i]))
1348   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy))+", expected "+str(pixels[i])+" (pixel access).");
1349   - }
1350   - }
1351   - test_try_success();
1352   - }
1353   - catch (std::exception &e) {
1354   - test_try_failure(e);
1355   - }
  860 + // Save image
  861 + GFits fits(filename, true);
  862 + fits.append(image);
  863 + fits.save();
1356 864  
1357   - // Test 3D image
1358   - test_try("Test pixel access 3D");
1359   - try{
1360   - GFitsImageDouble image(16, 4, 4, pixels);
1361   - for (int iz = 0, i = 0; iz < 4; ++iz) {
1362   - for (int iy = 0; iy < 4; ++iy) {
1363   - for (int ix = 0; ix < 16; ++ix, ++i) {
1364   - if (!dequal(image(ix,iy,iz), pixels[i]))
1365   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz))+", expected "+str(pixels[i])+" (operator access).");
  865 + // Open FITS image
  866 + GFits infile(filename);
  867 + GFitsImage* ptr = infile.image(0);
1366 868  
1367   - if (!dequal(image.at(ix,iy,iz), pixels[i]))
1368   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz))+", expected "+str(pixels[i])+" (at access).");
  869 + // Test 4D pixel access
  870 + TEST_4D_ACCESS_IO(2,2,2,2)
  871 +
  872 + // Return
  873 + return;
  874 +}
  875 +
  876 +
  877 +
  878 +/***************************************************************************
  879 + * @brief Test double precision FITS binary table
  880 + ***************************************************************************/
  881 +void TestGFits::test_bintable_double(void)
  882 +{
  883 + // Set filename
  884 + std::string filename = "test_bintable_double.fits";
  885 +
  886 + // Remove FITS file
  887 + std::string cmd = "rm -rf "+ filename;
  888 + int rc = system(cmd.c_str());
  889 +
  890 + // Set number of rows and vector columns
  891 + int nrows = 3;
  892 + int nvec = 3;
1369 893  
1370   - if (!dequal(image.pixel(ix,iy,iz), pixels[i])) {
1371   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz))+", expected "+str(pixels[i])+" (pixel access).");
1372   - }
1373   - }
1374   - }
1375   - }
  894 + // Test single column table
  895 + GFitsTableDoubleCol col1("DOUBLE", nrows);
  896 + TEST_TABLE1;
  897 +
  898 + // Test multiple column table
  899 + GFitsTableDoubleCol col2("DOUBLE10", nrows, nvec);
  900 + TEST_TABLE2;
  901 +
  902 + // Write tables
  903 + TEST_WRITE_TABLES;
  904 +
  905 + // Read tables back
  906 + test_try("Read Tables");
  907 + try {
  908 + GFits fits(filename);
  909 + col1 = static_cast<GFitsTableDoubleCol&>((*fits.table(1))["DOUBLE"]);
  910 + col2 = static_cast<GFitsTableDoubleCol&>((*fits.table(1))["DOUBLE10"]);
  911 + fits.close();
1376 912 test_try_success();
1377 913 }
1378   - catch (std::exception &e) {
  914 + catch(std::exception &e) {
1379 915 test_try_failure(e);
1380 916 }
  917 +
  918 + // Test single column table
  919 + TEST_TABLE1;
  920 +
  921 + // Test multiple column table
  922 + TEST_TABLE2;
  923 +
  924 + // Return
  925 + return;
  926 +}
  927 +
  928 +/***************************************************************************
  929 + * @brief Test single precision FITS binary table
  930 + ***************************************************************************/
  931 +void TestGFits::test_bintable_float(void)
  932 +{
  933 + // Set filename
  934 + std::string filename = "test_bintable_float.fits";
  935 +
  936 + // Remove FITS file
  937 + std::string cmd = "rm -rf "+ filename;
  938 + int rc = system(cmd.c_str());
  939 +
  940 + // Set number of rows and vector columns
  941 + int nrows = 3;
  942 + int nvec = 3;
  943 +
  944 + // Test single column table
  945 + GFitsTableFloatCol col1("FLOAT", nrows);
  946 + TEST_TABLE1;
1381 947  
1382   - // Test 4D image
1383   - test_try("Test pixel access 4D");
  948 + // Test multiple column table
  949 + GFitsTableFloatCol col2("FLOAT10", nrows, nvec);
  950 + TEST_TABLE2;
  951 +
  952 + // Write tables
  953 + TEST_WRITE_TABLES;
  954 +
  955 + // Read tables back
  956 + test_try("Read Tables");
1384 957 try {
1385   - GFitsImageDouble image(4, 4, 4, 4, pixels);
1386   - for (int it = 0, i = 0; it < 4; ++it) {
1387   - for (int iz = 0; iz < 4; ++iz) {
1388   - for (int iy = 0; iy < 4; ++iy) {
1389   - for (int ix = 0; ix < 4; ++ix, ++i) {
1390   - if (!dequal(image(ix,iy,iz,it), pixels[i])) {
1391   - throw exception_failure("Unexpected pixel content (has "+str(image(ix,iy,iz,it))+", expected "+str(pixels[i])+" (operator access).");
1392   - }
1393   - if (!dequal(image.at(ix,iy,iz,it), pixels[i])) {
1394   - throw exception_failure("Unexpected pixel content (has "+str(image.at(ix,iy,iz,it))+", expected "+str(pixels[i])+" (at access).");
1395   - }
1396   - if (!dequal(image.pixel(ix,iy,iz,it), pixels[i])) {
1397   - throw exception_failure("Unexpected pixel content (has "+str(image.pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
1398   - }
1399   - }
1400   - }
1401   - }
1402   - }
  958 + GFits fits(filename);
  959 + col1 = static_cast<GFitsTableFloatCol&>((*fits.table(1))["FLOAT"]);
  960 + col2 = static_cast<GFitsTableFloatCol&>((*fits.table(1))["FLOAT10"]);
  961 + fits.close();
1403 962 test_try_success();
1404 963 }
1405   - catch (std::exception &e) {
  964 + catch(std::exception &e) {
1406 965 test_try_failure(e);
1407 966 }
  967 +
  968 + // Test single column table
  969 + TEST_TABLE1;
1408 970  
  971 + // Test multiple column table
  972 + TEST_TABLE2;
1409 973  
1410   - // Test image I/O with 4D image
1411   - test_try("Test image I/O with 4D image");
1412   - try{
1413   - // Create 4D image
1414   - int naxes[] = {4,4,4,4};
1415   - GFitsImageDouble image(4, naxes, pixels);
1416   -
1417   - // Save image
1418   - GFits fits(filename, true);
1419   - fits.append(image);
1420   - fits.save();
  974 + // Return
  975 + return;
  976 +}
1421 977  
1422   - // Open FITS image
1423   - GFits infile(filename);
1424   - GFitsImage* ptr = infile.image(0);
1425   - std::cout << ".";
1426   -
1427   - // Test 4D image
1428   - for (int it = 0, i = 0; it < 4; ++it) {
1429   - for (int iz = 0; iz < 4; ++iz) {
1430   - for (int iy = 0; iy < 4; ++iy) {
1431   - for (int ix = 0; ix < 4; ++ix, ++i) {
1432   - if (!dequal(ptr->pixel(ix,iy,iz,it), pixels[i])) {
1433   - throw exception_failure("Unexpected pixel content (has "+str(ptr->pixel(ix,iy,iz,it))+", expected "+str(pixels[i])+" (pixel access).");
1434   - }
1435   - }
1436   - }
1437   - }
1438   - }
  978 +
  979 +/***************************************************************************
  980 + * @brief Test short FITS binary table
  981 + ***************************************************************************/
  982 +void TestGFits::test_bintable_short(void)
  983 +{
  984 + // Set filename
  985 + std::string filename = "test_bintable_short.fits";
  986 +
  987 + // Remove FITS file
  988 + std::string cmd = "rm -rf "+ filename;
  989 + int rc = system(cmd.c_str());
  990 +
  991 + // Set number of rows and vector columns
  992 + int nrows = 3;
  993 + int nvec = 3;
  994 +
  995 + // Test single column table
  996 + GFitsTableShortCol col1("SHORT", nrows);
  997 + TEST_TABLE1_INT;
  998 +
  999 + // Test multiple column table
  1000 + GFitsTableShortCol col2("SHORT10", nrows, nvec);
  1001 + TEST_TABLE2_INT;
  1002 +
  1003 + // Write tables
  1004 + TEST_WRITE_TABLES;
  1005 +
  1006 + // Read tables back
  1007 + test_try("Read Tables");
  1008 + try {
  1009 + GFits fits(filename);
  1010 + col1 = static_cast<GFitsTableShortCol&>((*fits.table(1))["SHORT"]);
  1011 + col2 = static_cast<GFitsTableShortCol&>((*fits.table(1))["SHORT10"]);
  1012 + fits.close();
1439 1013 test_try_success();
1440 1014 }
1441   - catch (std::exception &e) {
  1015 + catch(std::exception &e) {
1442 1016 test_try_failure(e);
1443 1017 }
  1018 +
  1019 + // Test single column table
  1020 + TEST_TABLE1_INT;
  1021 +
  1022 + // Test multiple column table
  1023 + TEST_TABLE2_INT;
1444 1024  
1445 1025 // Return
1446 1026 return;
1447 1027 }
1448 1028  
  1029 +
1449 1030 /***************************************************************************
1450   - * @brief Test double precision FITS binary table
  1031 + * @brief Test unsigned short FITS binary table
1451 1032 ***************************************************************************/
1452   -
1453   -void TestGFits::test_bintable_double(void)
  1033 + void TestGFits::test_bintable_ushort(void)
1454 1034 {
1455   -
1456 1035 // Set filename
1457   - std::string filename = "test_bintable_double.fits";
  1036 + std::string filename = "test_bintable_ushort.fits";
1458 1037  
1459 1038 // Remove FITS file
1460 1039 std::string cmd = "rm -rf "+ filename;
1461 1040 int rc = system(cmd.c_str());
1462 1041  
1463   - // Allocate reference sums
1464   - double sum_dbl = 0.0;
1465   - double sum_dbl10 = 0.0;
1466   - int sum_dbl_int = 0;
1467   - int sum_dbl10_int = 0;
1468   - std::string sum_dbl_str;
1469   - std::string sum_dbl10_str;
1470   -
1471   - // Build tables
1472   - test_try("Build tables");
1473   - try {
1474   - // Create FITS file
1475   - GFits fits;
1476   - fits.open(filename, true);
1477   -
1478   - // Set number of rows
1479   - int nrows = 10;
1480   - int nvec = 10;
  1042 + // Set number of rows and vector columns
  1043 + int nrows = 3;
  1044 + int nvec = 3;
1481 1045  
1482   - // Initial control sums
1483   - float tot_flt = 0.0;
1484   - double tot_dbl = 0.0;
1485   - int tot_int = 0;
1486   - long tot_lng = 0;
1487   - short tot_sht = 0;
1488   - std::string tot_str;
1489   -
1490   - //
1491   - // ===== D O U B L E =====
1492   - //
1493   -
1494   - GFitsTableDoubleCol col_dbl;
1495   -
1496   - test_try("Double");
1497   - try{
1498   - // Set string table
1499   - test_try("Set table");
1500   - try{
1501   - col_dbl = GFitsTableDoubleCol("DOUBLE", nrows);
1502   - for (int i = 0; i < nrows; ++i) {
1503   - double val_dbl = cos(double(i));
1504   - col_dbl(i) = val_dbl;
1505   - sum_dbl += val_dbl;
1506   - sum_dbl_int += int(val_dbl);
1507   - sum_dbl_str += ":"+str(val_dbl);
1508   - }
1509   - test_try_success();
1510   - }
1511   - catch(std::exception &e)
1512   - {
1513   - test_try_failure(e);
1514   - }
1515   -
1516   - // Check table (operator access)
1517   - test_try("Check table (operator access)");
1518   - try{
1519   - tot_dbl = 0.0;
1520   - for (int i = 0; i < nrows; ++i)
1521   - tot_dbl += col_dbl(i);
1522   - if (!dequal(tot_dbl, sum_dbl)) {
1523   - throw exception_failure("GFitsTableDoubleCol::operator() : Reference sum: "+str(sum_dbl)+" Derived sum: "+str(tot_dbl));
1524   - }
1525   - test_try_success();
1526   - }
1527   - catch(std::exception &e)
1528   - {
1529   - test_try_failure(e);
1530   - }
  1046 + // Test single column table
  1047 + GFitsTableUShortCol col1("USHORT", nrows);
  1048 + TEST_TABLE1_INT;
  1049 +
  1050 + // Test multiple column table
  1051 + GFitsTableUShortCol col2("USHORT10", nrows, nvec);
  1052 + TEST_TABLE2_INT;
  1053 +
  1054 + // Write tables
  1055 + TEST_WRITE_TABLES;
  1056 +
  1057 + // Read tables back
  1058 + test_try("Read Tables");
  1059 + try {
  1060 + GFits fits(filename);
  1061 + col1 = static_cast<GFitsTableUShortCol&>((*fits.table(1))["USHORT"]);
  1062 + col2 = static_cast<GFitsTableUShortCol&>((*fits.table(1))["USHORT10"]);
  1063 + fits.close();
  1064 + test_try_success();
  1065 + }
  1066 + catch(std::exception &e) {
  1067 + test_try_failure(e);
  1068 + }
1531 1069  
1532   - // Check table (real access)
1533   - test_try("Check table (real access)");
1534   - try{
1535   - tot_dbl = 0.0;
1536   - for (int i = 0; i < nrows; ++i)
1537   - tot_dbl += col_dbl.real(i);
1538   - if (!dequal(tot_dbl, sum_dbl)) {
1539   - throw exception_failure("GFitsTableDoubleCol::real() : Reference sum: "+str(sum_dbl)+"Derived sum:"+str(tot_dbl));
1540   - }
1541   - test_try_success();
1542   - }
1543   - catch(std::exception &e)
1544   - {
1545   - test_try_failure(e);
1546   - }
1547   -
1548   - // Check string table (int access)
1549   - test_try("Check table (int access)");
1550   - try{
1551   - tot_int = 0;
1552   - for (int i = 0; i < nrows; ++i)
1553   - tot_int += col_dbl.integer(i);
1554   - if (tot_int != sum_dbl_int) {
1555   - throw exception_failure("GFitsTableDoubleCol::integer() : Reference sum: "+str(sum_dbl_int)+"Derived sum:"+str(tot_int));
1556   - }
1557   - test_try_success();
1558   - }
1559   - catch(std::exception &e)
1560   - {
1561   - test_try_failure(e);
1562   - }
1563   -
1564   - // Check table (string access)
1565   - test_try("Check table (string access)");
1566   - try{
1567   - tot_str.clear();
1568   - for (int i = 0; i < nrows; ++i)
1569   - tot_str += ":"+col_dbl.string(i);
1570   - if (tot_str != sum_dbl_str) {
1571   - throw exception_failure("GFitsTableDoubleCol::string() : Reference sum: "+sum_dbl_str+"Derived sum:"+tot_str);
1572   - }
1573   - test_try_success();
1574   - }
1575   - catch(std::exception &e)
1576   - {
1577   - test_try_failure(e);
1578   - }
1579   - test_try_success();
1580   - } // End try ulong
1581   - catch(std::exception &e)
1582   - {
1583   - test_try_failure(e);
1584   - }
1585   -
1586   - //
1587   - // ===== D O U B L E 1 0 =====
1588   - //
1589   -
1590   - GFitsTableDoubleCol col_dbl10;
1591   -
1592   - test_try("Double 10");
1593   - try{
1594   -
1595   - // Set table
1596   - test_try("Set table");
1597   - try{
1598   - col_dbl10 = GFitsTableDoubleCol("DOUBLE10", nrows,nvec);
1599   - for (int i = 0; i < nrows; ++i) {
1600   - for (int j = 0; j < nvec; ++j) {
1601   - double val_dbl = cos(double(i))*cos(0.33*double(j));
1602   - col_dbl10(i,j) = val_dbl;
1603   - sum_dbl10 += val_dbl;
1604   - sum_dbl10_int += int(val_dbl);
1605   - sum_dbl10_str += ":"+str(val_dbl);
1606   - }
1607   - }
1608   - test_try_success();
1609   - }
1610   - catch(std::exception &e)
1611   - {
1612   - test_try_failure(e);
1613   - }
1614   -
1615   - // Check table (operator access)
1616   - test_try("Check table (operator access)");
1617   - try{
1618   - tot_dbl = 0.0;
1619   - for (int i = 0; i < nrows; ++i) {
1620   - for (int j = 0; j < nvec; ++j)
1621   - tot_dbl += col_dbl10(i,j);
1622   - }
1623   - if (!dequal(tot_dbl, sum_dbl10)) {
1624   - throw exception_failure("GFitsTableDoubleCol::operator() - 10 : Reference sum: "+str(sum_dbl10)+"Derived sum:"+str(tot_dbl));
1625   - }
1626   - test_try_success();
1627   - }
1628   - catch(std::exception &e)
1629   - {
1630   - test_try_failure(e);
1631   - }
1632   -
1633   - // Check table (real access)
1634   - test_try("Check table (real access)");
1635   - try{
1636   - tot_dbl = 0.0;
1637   - for (int i = 0; i < nrows; ++i) {
1638   - for (int j = 0; j < nvec; ++j)
1639   - tot_dbl += col_dbl10.real(i,j);
1640   - }
1641   - if (!dequal(tot_dbl, sum_dbl10)) {
1642   - throw exception_failure("GFitsTableDoubleCol::real() - 10 : Reference sum: "+str(sum_dbl10)+"Derived sum:"+str(tot_dbl));
1643   - }
1644   - test_try_success();
1645   - }
1646   - catch(std::exception &e)
1647   - {
1648   - test_try_failure(e);
1649   - }
1650   -
1651   - // Check table (int access)
1652   - test_try("Check table (int access)");
1653   - try{
1654   - tot_int = 0;
1655   - for (int i = 0; i < nrows; ++i) {
1656   - for (int j = 0; j < nvec; ++j)
1657   - tot_int += col_dbl10.integer(i,j);
1658   - }
1659   - if (tot_int != sum_dbl10_int) {
1660   - throw exception_failure("GFitsTableDoubleCol::integer() - 10 : Reference sum: "+str(sum_dbl10_int)+"Derived sum:"+str(tot_int));
1661   - }
1662   - test_try_success();
1663   - }
1664   - catch(std::exception &e)
1665   - {
1666   - test_try_failure(e);
1667   - }
1668   -
1669   - // Check table (string access)
1670   - test_try("Check table (string access)");
1671   - try{
1672   - tot_str.clear();
1673   - for (int i = 0; i < nrows; ++i) {
1674   - for (int j = 0; j < nvec; ++j)
1675   - tot_str += ":"+col_dbl10.string(i,j);
1676   - }
1677   - if (tot_str != sum_dbl10_str) {
1678   - throw exception_failure("GFitsTableDoubleCol::string() - 10 : Reference sum: "+sum_dbl10_str+"Derived sum:"+tot_str);
1679   - }
1680   - test_try_success();
1681   - }
1682   - catch(std::exception &e)
1683   - {
1684   - test_try_failure(e);
1685   - }
1686   - test_try_success();
1687   - } // end try double 10
1688   - catch(std::exception &e)
1689   - {
1690   - test_try_failure(e);
1691   - }
1692   -
1693   - //
1694   - // ===== W R I T E T A B L E =====
1695   - //
1696   - test_try("Write Table");
1697   - try{
1698   - // Build binary table
1699   - GFitsBinTable table = GFitsBinTable(nrows);
1700   - table.append_column(col_dbl);
1701   - table.insert_column(1, col_dbl10);
1702   -
1703   - // Append to file
1704   - fits.append(table);
1705   -
1706   - // Save FITS file
1707   - fits.save();
1708   -
1709   - test_try_success();
1710   - }
1711   - catch(std::exception &e)
1712   - {
1713   - test_try_failure(e);
1714   - }
1715   -
1716   - test_try_success();
1717   - } //end try build table
1718   - catch(std::exception &e)
1719   - {
1720   - test_try_failure(e);
1721   - }
1722   -
1723   - //================================================================
1724   - //================================================================
1725   - //================================================================
1726   - // Read tables
1727   - //================================================================
1728   - //================================================================
1729   - //================================================================
1730   -
1731   - test_try("Read Table");
1732   - try{
1733   - // Open FITS file
1734   - GFits fits;
1735   - fits.open(filename);
1736   -
1737   - // Set number of rows
1738   - int nrows = 10;
1739   - int nvec = 10;
1740   -
1741   - // Initial control sums
1742   - float tot_flt = 0.0;
1743   - double tot_dbl = 0.0;
1744   - int tot_int = 0;
1745   - std::string tot_str;
1746   -
1747   - //
1748   - // ===== D O U B L E =====
1749   - //
1750   - GFitsTableDoubleCol* col_dbl = NULL;
1751   - test_try("Double");
1752   - try {
1753   - // Get column
1754   - col_dbl = (GFitsTableDoubleCol*)&(*fits.table(1))["DOUBLE"];
1755   -
1756   - // Check table (operator access)
1757   - test_try("Check table (operator access)");
1758   - try {
1759   - tot_dbl = 0.0;
1760   - for (int i = 0; i < nrows; ++i)
1761   - tot_dbl += (*col_dbl)(i);
1762   - if (!dequal(tot_dbl, sum_dbl)) {
1763   - throw exception_failure("GFitsTableDoubleCol::operator() : Reference sum: "+str(sum_dbl)+" Derived sum: "+str(tot_dbl));
1764   - }
1765   -
1766   - test_try_success();
1767   - }
1768   - catch(std::exception &e)
1769   - {
1770   - test_try_failure(e);
1771   - }
1772   -
1773   -
1774   - // Check table (real access)
1775   - test_try("Check table (real access)");
1776   - try{
1777   - tot_dbl = 0.0;
1778   - for (int i = 0; i < nrows; ++i)
1779   - tot_dbl += (*col_dbl).real(i);
1780   - if (!dequal(tot_dbl, sum_dbl)) {
1781   - throw exception_failure("GFitsTableDoubleCol::real() : Reference sum: "+str(sum_dbl)+"Derived sum:"+str(tot_dbl));
1782   - }
1783   - test_try_success();
1784   - }
1785   - catch(std::exception &e)
1786   - {
1787   - test_try_failure(e);
1788   - }
1789   -
1790   - // Check string table (int access)
1791   - test_try("Check table (int access)");
1792   - try{
1793   - tot_int = 0;
1794   - for (int i = 0; i < nrows; ++i)
1795   - tot_int += (*col_dbl).integer(i);
1796   - if (tot_int != sum_dbl_int) {
1797   - throw exception_failure("GFitsTableDoubleCol::integer() : Reference sum: "+str(sum_dbl_int)+"Derived sum:"+str(tot_int));
1798   - }
1799   - test_try_success();
1800   - }
1801   - catch(std::exception &e)
1802   - {
1803   - test_try_failure(e);
1804   - }
1805   -
1806   - // Check table (string access)
1807   - test_try("Check table (string access)");
1808   - try{
1809   - tot_str.clear();
1810   - for (int i = 0; i < nrows; ++i)
1811   - tot_str += ":"+ (*col_dbl).string(i);
1812   - if (tot_str != sum_dbl_str) {
1813   - throw exception_failure("GFitsTableDoubleCol::string() : Reference sum: "+sum_dbl_str+"Derived sum:"+tot_str);
1814   - }
1815   - test_try_success();
1816   - }
1817   - catch(std::exception &e)
1818   - {
1819   - test_try_failure(e);
1820   - }
1821   -
1822   - test_try_success();
1823   - }// End try logical
1824   - catch(std::exception &e)
1825   - {
1826   - test_try_failure(e);
1827   - }
1828   -
1829   - //
1830   - // ===== D O U B L E 1 0 =====
1831   - //
1832   - GFitsTableDoubleCol* col_dbl10 = NULL;
1833   - test_try("Double 10");
1834   - try{
1835   - // Get column
1836   - col_dbl10 = (GFitsTableDoubleCol*)&(*fits.table(1))["DOUBLE10"];
1837   -
1838   - // Check table (operator access)
1839   - test_try("Check table (operator access)");
1840   - try{
1841   - tot_dbl = 0.0;
1842   - for (int i = 0; i < nrows; ++i) {
1843   - for (int j = 0; j < nvec; ++j)
1844   - tot_dbl += (*col_dbl10)(i,j);
1845   - }
1846   - if (!dequal(tot_dbl, sum_dbl10)) {
1847   - throw exception_failure("GFitsTableDoubleCol::operator() - 10 : Reference sum: "+str(sum_dbl10)+"Derived sum:"+str(tot_dbl));
1848   - }
1849   - test_try_success();
1850   - }
1851   - catch(std::exception &e)
1852   - {
1853   - test_try_failure(e);
1854   - }
1855   -
1856   - // Check table (real access)
1857   - test_try("Check table (real access)");
1858   - try{
1859   - tot_dbl = 0.0;
1860   - for (int i = 0; i < nrows; ++i) {
1861   - for (int j = 0; j < nvec; ++j)
1862   - tot_dbl += col_dbl10->real(i,j);
1863   - }
1864   - if (!dequal(tot_dbl, sum_dbl10)) {
1865   - throw exception_failure("GFitsTableDoubleCol::real() - 10 : Reference sum: "+str(sum_dbl10)+"Derived sum:"+str(tot_dbl));
1866   - }
1867   - test_try_success();
1868   - }
1869   - catch(std::exception &e)
1870   - {
1871   - test_try_failure(e);
1872   - }
1873   -
1874   - // Check table (int access)
1875   - test_try("Check table (int access)");
1876   - try{
1877   - tot_int = 0;
1878   - for (int i = 0; i < nrows; ++i) {
1879   - for (int j = 0; j < nvec; ++j)
1880   - tot_int += col_dbl10->integer(i,j);
1881   - }
1882   - if (tot_int != sum_dbl10_int) {
1883   - throw exception_failure("GFitsTableDoubleCol::integer() - 10 : Reference sum: "+str(sum_dbl10_int)+"Derived sum:"+str(tot_int));
1884   - }
1885   - test_try_success();
1886   - }
1887   - catch(std::exception &e)
1888   - {
1889   - test_try_failure(e);
1890   - }
1891   -
1892   - // Check table (string access)
1893   - test_try("Check table (string access)");
1894   - try{
1895   - tot_str.clear();
1896   - for (int i = 0; i < nrows; ++i) {
1897   - for (int j = 0; j < nvec; ++j)
1898   - tot_str += ":"+col_dbl10->string(i,j);
1899   - }
1900   - if (tot_str != sum_dbl10_str) {
1901   - throw exception_failure("GFitsTableDoubleCol::string() - 10 : Reference sum: "+sum_dbl10_str+"Derived sum:"+tot_str);
1902   - }
1903   - test_try_success();
1904   - }
1905   - catch(std::exception &e)
1906   - {
1907   - test_try_failure(e);
1908   - }
1909   -
1910   - test_try_success();
1911   - } //end try float 10
1912   - catch(std::exception &e)
1913   - {
1914   - test_try_failure(e);
1915   - }
1916   -
1917   - test_try_success();
1918   - } //end try read tabe
1919   - catch(std::exception &e)
1920   - {
1921   - test_try_failure(e);
1922   - }
  1070 + // Test single column table
  1071 + TEST_TABLE1_INT;
1923 1072  
  1073 + // Test multiple column table
  1074 + TEST_TABLE2_INT;
1924 1075  
  1076 + // Return
  1077 + return;
1925 1078 }
1926 1079  
  1080 +
1927 1081 /***************************************************************************
1928   - * @brief Test single precision FITS binary table
  1082 + * @brief Test long FITS binary table
1929 1083 ***************************************************************************/
1930   -
1931   -void TestGFits::test_bintable_float(void)
  1084 +void TestGFits::test_bintable_long(void)
1932 1085 {
1933   -
1934 1086 // Set filename
1935   - std::string filename = "test_bintable_float.fits";
  1087 + std::string filename = "test_bintable_long.fits";
1936 1088  
1937 1089 // Remove FITS file
1938 1090 std::string cmd = "rm -rf "+ filename;
1939 1091 int rc = system(cmd.c_str());
1940 1092  
1941   - // Allocate reference sums
1942   - float sum_flt = 0.0;
1943   - float sum_flt10 = 0.0;
1944   - int sum_flt_int = 0;
1945   - int sum_flt10_int = 0;
1946   - std::string sum_flt_str;
1947   - std::string sum_flt10_str;
1948   -
1949   - // Build tables
1950   - test_try("Build tables");
1951   - try {
1952   - // Create FITS file
1953   - GFits fits;
1954   - fits.open(filename, true);
1955   -
1956   - // Set number of rows
1957   - int nrows = 10;
1958   - int nvec = 10;
1959   -
1960   - // Initial control sums
1961   - float tot_flt = 0.0;
1962   - double tot_dbl = 0.0;
1963   - int tot_int = 0;
1964   - long tot_lng = 0;
1965   - short tot_sht = 0;
1966   - std::string tot_str;
1967   -
1968   - //
1969   - //
1970   - // ===== F L O A T =====
1971   - //
1972   -
1973   - GFitsTableFloatCol col_flt;
1974   -
1975   - test_try("Float");
1976   - try{
1977   - // Set string table
1978   - test_try("Set table");
1979   - try{
1980   - col_flt = GFitsTableFloatCol("FLOAT", nrows);
1981   - for (int i = 0; i < nrows; ++i) {
1982   - float val_flt = cos(0.1*float(i));
1983   - col_flt(i) = val_flt;
1984   - sum_flt += val_flt;
1985   - sum_flt_int += int(val_flt);
1986   - sum_flt_str += ":"+str(val_flt);
1987   - }
1988   - test_try_success();
1989   - }
1990   - catch(std::exception &e)
1991   - {
1992   - test_try_failure(e);
1993   - }
1994   -
1995   - // Check table (operator access)
1996   - test_try("Check table (operator access)");
1997   - try{
1998   - tot_flt = 0.0;
1999   - for (int i = 0; i < nrows; ++i)
2000   - tot_flt += col_flt(i);
2001   - if (!fequal(tot_flt, sum_flt)) {
2002   - throw exception_failure("GFitsTableFloatCol::operator() : Reference sum: "+str(sum_flt)+" Derived sum: "+str(tot_flt));
2003   - }
2004   - test_try_success();
2005   - }
2006   - catch(std::exception &e)
2007   - {
2008   - test_try_failure(e);
2009   - }
2010   -
2011   - // Check table (real access)
2012   - test_try("Check table (real access)");
2013   - try{
2014   - tot_flt = 0.0;
2015   - for (int i = 0; i < nrows; ++i)
2016   - tot_flt += col_flt.real(i);
2017   - if (!fequal(tot_flt, sum_flt)) {
2018   - throw exception_failure("GFitsTableFloatCol::real() : Reference sum: "+str(sum_flt)+"Derived sum:"+str(tot_dbl));
2019   - }
2020   - test_try_success();
2021   - }
2022   - catch(std::exception &e)
2023   - {
2024   - test_try_failure(e);
2025   - }
2026   -
2027   - // Check string table (int access)
2028   - test_try("Check table (int access)");
2029   - try{
2030   - tot_int = 0;
2031   - for (int i = 0; i < nrows; ++i)
2032   - tot_int += col_flt.integer(i);
2033   - if (tot_int != sum_flt_int) {
2034   - throw exception_failure("GFitsTableFloatCol::integer() : Reference sum: "+str(sum_flt_int)+"Derived sum:"+str(tot_int));
2035   - }
2036   - test_try_success();
2037   - }
2038   - catch(std::exception &e)
2039   - {
2040   - test_try_failure(e);
2041   - }
2042   -
2043   - // Check table (string access)
2044   - test_try("Check table (string access)");
2045   - try{
2046   - tot_str.clear();
2047   - for (int i = 0; i < nrows; ++i)
2048   - tot_str += ":"+col_flt.string(i);
2049   - if (tot_str != sum_flt_str) {
2050   - throw exception_failure("GFitsTableFloatCol::string() : Reference sum: "+sum_flt_str+"Derived sum:"+tot_str);
2051   - }
2052   - test_try_success();
2053   - }
2054   - catch(std::exception &e)
2055   - {
2056   - test_try_failure(e);
2057   - }
2058   - test_try_success();
2059   - } // End try ulong
2060   - catch(std::exception &e)
2061   - {
2062   - test_try_failure(e);
2063   - }
2064   -
2065   - //
2066   - // ===== F L O A T 1 0 =====
2067   - //
2068   -
2069   - GFitsTableFloatCol col_flt10;
2070   -
2071   - test_try("Float 10");
2072   - try{
2073   -
2074   - // Set table
2075   - test_try("Set table");
2076   - try{
2077   - col_flt10 = GFitsTableFloatCol("FLOAT10", nrows,nvec);
2078   - for (int i = 0; i < nrows; ++i) {
2079   - for (int j = 0; j < nvec; ++j) {
2080   - float val_flt = cos(0.1*float(i))*cos(0.33*float(j));
2081   - col_flt10(i,j) = val_flt;
2082   - sum_flt10 += val_flt;
2083   - sum_flt10_int += int(val_flt);
2084   - sum_flt10_str += ":"+str(val_flt);
2085   - }
2086   - }
2087   - test_try_success();
2088   - }
2089   - catch(std::exception &e)
2090   - {
2091   - test_try_failure(e);
2092   - }
2093   -
2094   - // Check table (operator access)
2095   - test_try("Check table (operator access)");
2096   - try{
2097   - tot_flt = 0.0;
2098   - for (int i = 0; i < nrows; ++i) {
2099   - for (int j = 0; j < nvec; ++j)
2100   - tot_flt += col_flt10(i,j);
2101   - }
2102   - if (!fequal(tot_flt, sum_flt10)) {
2103   - throw exception_failure("GFitsTableFloatCol::operator() - 10 : Reference sum: "+str(sum_flt10)+"Derived sum:"+str(tot_flt));
2104   - }
2105   - test_try_success();
2106   - }
2107   - catch(std::exception &e)
2108   - {
2109   - test_try_failure(e);
2110   - }
2111   -
2112   - // Check table (real access)
2113   - test_try("Check table (real access)");
2114   - try{
2115   - tot_flt = 0.0;
2116   - for (int i = 0; i < nrows; ++i) {
2117   - for (int j = 0; j < nvec; ++j)
2118   - tot_flt += col_flt10.real(i,j);
2119   - }
2120   - if (!fequal(tot_flt, sum_flt10)) {
2121   - throw exception_failure("GFitsTableFloatCol::real() - 10 : Reference sum: "+str(sum_flt10)+"Derived sum:"+str(tot_flt));
2122   - }
2123   - test_try_success();
2124   - }
2125   - catch(std::exception &e)
2126   - {
2127   - test_try_failure(e);
2128   - }
2129   -
2130   - // Check table (int access)
2131   - test_try("Check table (int access)");
2132   - try{
2133   - tot_int = 0;
2134   - for (int i = 0; i < nrows; ++i) {
2135   - for (int j = 0; j < nvec; ++j)
2136   - tot_int += col_flt10.integer(i,j);
2137   - }
2138   - if (tot_int != sum_flt10_int) {
2139   - throw exception_failure("GFitsTableFloatCol::integer() - 10 : Reference sum: "+str(sum_flt10_int)+"Derived sum:"+str(tot_int));
2140   - }
2141   - test_try_success();
2142   - }
2143   - catch(std::exception &e)
2144   - {
2145   - test_try_failure(e);
2146   - }
2147   -
2148   - // Check table (string access)
2149   - test_try("Check table (string access)");
2150   - try{
2151   - tot_str.clear();
2152   - for (int i = 0; i < nrows; ++i) {
2153   - for (int j = 0; j < nvec; ++j)
2154   - tot_str += ":"+col_flt10.string(i,j);
2155   - }
2156   - if (tot_str != sum_flt10_str) {
2157   - throw exception_failure("GFitsTableFloatCol::string() - 10 : Reference sum: "+sum_flt10_str+"Derived sum:"+tot_str);
2158   - }
2159   - test_try_success();
2160   - }
2161   - catch(std::exception &e)
2162   - {
2163   - test_try_failure(e);
2164   - }
2165   - test_try_success();
2166   - } // end try short 10
2167   - catch(std::exception &e)
2168   - {
2169   - test_try_failure(e);
2170   - }
  1093 + // Set number of rows and vector columns
  1094 + int nrows = 3;
  1095 + int nvec = 3;
2171 1096  
2172   - //
2173   - // ===== W R I T E T A B L E =====
2174   - //
2175   - test_try("Write Table");
2176   - try{
2177   - // Build binary table
2178   - GFitsBinTable table = GFitsBinTable(nrows);
2179   - table.append_column(col_flt);
2180   - table.insert_column(0, col_flt10);
2181   -
2182   - // Append to file
2183   - fits.append(table);
2184   -
2185   - // Save FITS file
2186   - fits.save();
2187   -
2188   - test_try_success();
2189   - }
2190   - catch(std::exception &e)
2191   - {
2192   - test_try_failure(e);
2193   - }
2194   -
2195   - test_try_success();
2196   - } //end try build table
2197   - catch(std::exception &e)
2198   - {
2199   - test_try_failure(e);
2200   - }
  1097 + // Test single column table
  1098 + GFitsTableLongCol col1("LONG", nrows);
  1099 + TEST_TABLE1_INT;
2201 1100  
2202   - //================================================================
2203   - //================================================================
2204   - //================================================================
2205   - // Read tables
2206   - //================================================================
2207   - //================================================================
2208   - //================================================================
2209   -
2210   - test_try("Read Table");
2211   - try{
2212   - // Open FITS file
2213   - GFits fits;
2214   - fits.open(filename);
  1101 + // Test multiple column table
  1102 + GFitsTableLongCol col2("LONG10", nrows, nvec);
  1103 + TEST_TABLE2_INT;
2215 1104  
2216   - // Set number of rows
2217   - int nrows = 10;
2218   - int nvec = 10;
  1105 + // Write tables
  1106 + TEST_WRITE_TABLES;
2219 1107  
2220   - // Initial control sums
2221   - float tot_flt = 0.0;
2222   - double tot_dbl = 0.0;
2223   - int tot_int = 0;
2224   - std::string tot_str;
2225   -
2226   - //
2227   - // ===== U S H O R T =====
2228   - //
2229   - GFitsTableFloatCol* col_flt = NULL;
2230   - test_try("Float");
2231   - try {
2232   - // Get column
2233   - col_flt = (GFitsTableFloatCol*)&(*fits.table(1))["FLOAT"];
2234   -
2235   - // Check table (operator access)
2236   - test_try("Check table (operator access)");
2237   - try {
2238   - tot_flt = 0.0;
2239   - for (int i = 0; i < nrows; ++i)
2240   - tot_flt += (*col_flt)(i);
2241   - if (!fequal(tot_flt, sum_flt)) {
2242   - throw exception_failure("GFitsTableFloatCol::operator() : Reference sum: "+str(sum_flt)+" Derived sum: "+str(tot_flt));
2243   - }
2244   -
2245   - test_try_success();
2246   - }
2247   - catch(std::exception &e)
2248   - {
2249   - test_try_failure(e);
2250   - }
2251   -
2252   -
2253   - // Check table (real access)
2254   - test_try("Check table (real access)");
2255   - try{
2256   - tot_flt = 0.0;
2257   - for (int i = 0; i < nrows; ++i)
2258   - tot_flt += col_flt->real(i);
2259   - if (!fequal(tot_flt, sum_flt)) {
2260   - throw exception_failure("GFitsTableFloatCol::real() : Reference sum: "+str(sum_flt)+"Derived sum:"+str(tot_flt));
2261   - }
2262   - test_try_success();
2263   - }
2264   - catch(std::exception &e)
2265   - {
2266   - test_try_failure(e);
2267   - }
2268   -
2269   - // Check string table (int access)
2270   - test_try("Check table (int access)");
2271   - try{
2272   - tot_int = 0;
2273   - for (int i = 0; i < nrows; ++i)
2274   - tot_int += col_flt->integer(i);
2275   - if (tot_int != sum_flt_int) {
2276   - throw exception_failure("GFitsTableFloatCol::integer() : Reference sum: "+str(sum_flt_int)+"Derived sum:"+str(tot_int));
2277   - }
2278   - test_try_success();
2279   - }
2280   - catch(std::exception &e)
2281   - {
2282   - test_try_failure(e);
2283   - }
2284   -
2285   - // Check table (string access)
2286   - test_try("Check table (string access)");
2287   - try{
2288   - tot_str.clear();
2289   - for (int i = 0; i < nrows; ++i)
2290   - tot_str += ":"+col_flt->string(i);
2291   - if (tot_str != sum_flt_str) {
2292   - throw exception_failure("GFitsTableFloatCol::string() : Reference sum: "+sum_flt_str+"Derived sum:"+tot_str);
2293   - }
2294   - test_try_success();
2295   - }
2296   - catch(std::exception &e)
2297   - {
2298   - test_try_failure(e);
2299   - }
2300   -
2301   - test_try_success();
2302   - }// End try logical
2303   - catch(std::exception &e)
2304   - {
2305   - test_try_failure(e);
2306   - }
2307   -
2308   - //
2309   - // ===== F L O A T 1 0 =====
2310   - //
2311   - GFitsTableFloatCol* col_flt10 = NULL;
2312   - test_try("Float 10");
2313   - try{
2314   - // Get column
2315   - col_flt10 = (GFitsTableFloatCol*)&(*fits.table(1))["FLOAT10"];
2316   - // Check table (operator access)
2317   - test_try("Check table (operator access)");
2318   - try{
2319   - tot_flt = 0.0;
2320   - for (int i = 0; i < nrows; ++i) {
2321   - for (int j = 0; j < nvec; ++j)
2322   - tot_flt += (*col_flt10)(i,j);
2323   - }
2324   - if (!fequal(tot_flt, sum_flt10)) {
2325   - throw exception_failure("GFitsTableFloatCol::operator() - 10 : Reference sum: "+str(sum_flt10)+"Derived sum:"+str(tot_flt));
2326   - }
2327   - test_try_success();
2328   - }
2329   - catch(std::exception &e)
2330   - {
2331   - test_try_failure(e);
2332   - }
2333   -
2334   - // Check table (real access)
2335   - test_try("Check table (real access)");
2336   - try{
2337   - tot_flt = 0.0;
2338   - for (int i = 0; i < nrows; ++i) {
2339   - for (int j = 0; j < nvec; ++j)
2340   - tot_flt += col_flt10->real(i,j);
2341   - }
2342   - if (!fequal(tot_flt, sum_flt10)) {
2343   - throw exception_failure("GFitsTableFloatCol::real() - 10 : Reference sum: "+str(sum_flt10)+"Derived sum:"+str(tot_flt));
2344   - }
2345   - test_try_success();
2346   - }
2347   - catch(std::exception &e)
2348   - {
2349   - test_try_failure(e);
2350   - }
2351   -
2352   - // Check table (int access)
2353   - test_try("Check table (int access)");
2354   - try{
2355   - tot_int = 0;
2356   - for (int i = 0; i < nrows; ++i) {
2357   - for (int j = 0; j < nvec; ++j)
2358   - tot_int += col_flt10->integer(i,j);
2359   - }
2360   - if (tot_int != sum_flt10_int) {
2361   - throw exception_failure("GFitsTableFloatCol::integer() - 10 : Reference sum: "+str(sum_flt10_int)+"Derived sum:"+str(tot_int));
2362   - }
2363   - test_try_success();
2364   - }
2365   - catch(std::exception &e)
2366   - {
2367   - test_try_failure(e);
2368   - }
2369   -
2370   - // Check table (string access)
2371   - test_try("Check table (string access)");
2372   - try{
2373   - tot_str.clear();
2374   - for (int i = 0; i < nrows; ++i) {
2375   - for (int j = 0; j < nvec; ++j)
2376   - tot_str += ":"+col_flt10->string(i,j);
2377   - }
2378   - if (tot_str != sum_flt10_str) {
2379   - throw exception_failure("GFitsTableFloatCol::string() - 10 : Reference sum: "+sum_flt10_str+"Derived sum:"+tot_str);
2380   - }
2381   - test_try_success();
2382   - }
2383   - catch(std::exception &e)
2384   - {
2385   - test_try_failure(e);
2386   - }
2387   -
2388   - test_try_success();
2389   - } //end try float 10
2390   - catch(std::exception &e)
2391   - {
2392   - test_try_failure(e);
2393   - }
2394   -
  1108 + // Read tables back
  1109 + test_try("Read Tables");
  1110 + try {
  1111 + GFits fits(filename);
  1112 + col1 = static_cast<GFitsTableLongCol&>((*fits.table(1))["LONG"]);
  1113 + col2 = static_cast<GFitsTableLongCol&>((*fits.table(1))["LONG10"]);
  1114 + fits.close();
2395 1115 test_try_success();
2396   - } //end try read tabe
2397   - catch(std::exception &e)
2398   - {
  1116 + }
  1117 + catch(std::exception &e) {
2399 1118 test_try_failure(e);
2400 1119 }
  1120 +
  1121 + // Test single column table
  1122 + TEST_TABLE1_INT;
2401 1123  
  1124 + // Test multiple column table
  1125 + TEST_TABLE2_INT;
2402 1126  
  1127 + // Return
  1128 + return;
2403 1129 }
2404 1130  
2405 1131  
2406 1132 /***************************************************************************
2407   - * @brief Test short FITS binary table
  1133 + * @brief Test long long FITS binary table
2408 1134 ***************************************************************************/
2409   -
2410   -void TestGFits::test_bintable_short(void)
  1135 +void TestGFits::test_bintable_longlong(void)
2411 1136 {
2412   -
2413 1137 // Set filename
2414   - std::string filename = "test_bintable_short.fits";
  1138 + std::string filename = "test_bintable_longlong.fits";
2415 1139  
2416 1140 // Remove FITS file
2417 1141 std::string cmd = "rm -rf "+ filename;
2418 1142 int rc = system(cmd.c_str());
2419 1143  
2420   - // Allocate reference sums
2421   - short sum_sht = 0;
2422   - short sum_sht10 = 0;
2423   - short sum_sht_int = 0;
2424   - short sum_sht10_int = 0;
2425   - std::string sum_sht_str;
2426   - std::string sum_sht10_str;
2427   -
2428   - // Build tables
2429   - test_try("Build tables");
2430   - try {
2431   - // Create FITS file
2432   - GFits fits;
2433   - fits.open(filename, true);
2434   -
2435   - // Set number of rows
2436   - int nrows = 10;
2437   - int nvec = 10;
2438   -
2439   - // Initial control sums
2440   - float tot_flt = 0.0;
2441   - double tot_dbl = 0.0;
2442   - int tot_int = 0;
2443   - long tot_lng = 0;
2444   - short tot_sht = 0;
2445   - std::string tot_str;
2446   -
2447   - //
2448   - //
2449   - // ===== S H O R T =====
2450   - //
2451   -
2452   - GFitsTableShortCol col_sht;
2453   -
2454   - test_try("Short");
2455   - try{
2456   - // Set string table
2457   - test_try("Set table");
2458   - try{
2459   - col_sht = GFitsTableShortCol("SHORT", nrows);
2460   - for (int i = 0; i < nrows; ++i) {
2461   - short val_sht = short(1000.0 * cos(0.1*float(i)));
2462   - col_sht(i) = val_sht;
2463   - sum_sht += val_sht;
2464   - sum_sht_int += int(val_sht);
2465   - sum_sht_str += ":"+str(val_sht);
2466   - }
2467   - test_try_success();
2468   - }
2469   - catch(std::exception &e)
2470   - {
2471   - test_try_failure(e);
2472   - }
2473   -
2474   - // Check table (operator access)
2475   - test_try("Check table (operator access)");
2476   - try{
2477   - tot_sht = 0;
2478   - for (int i = 0; i < nrows; ++i)
2479   - tot_sht += col_sht(i);
2480   - if (tot_sht != sum_sht) {
2481   - throw exception_failure("GFitsTableShortCol::operator() : Reference sum: "+str(sum_sht)+" Derived sum: "+str(tot_sht));
2482   - }
2483   - test_try_success();
2484   - }
2485   - catch(std::exception &e)
2486   - {
2487   - test_try_failure(e);
2488   - }
2489   -
2490   - // Check table (real access)
2491   - test_try("Check table (real access)");
2492   - try{
2493   - tot_dbl = 0.0;
2494   - for (int i = 0; i < nrows; ++i)
2495   - tot_dbl += col_sht.real(i);
2496   - if (!dequal(tot_dbl, double(sum_sht))) {
2497   - throw exception_failure("GFitsTableShortCol::real() : Reference sum: "+str(sum_sht)+"Derived sum:"+str(tot_dbl));
2498   - }
2499   - test_try_success();
2500   - }
2501   - catch(std::exception &e)
2502   - {
2503   - test_try_failure(e);
2504   - }
2505   -
2506   - // Check string table (int access)
2507   - test_try("Check table (int access)");
2508   - try{
2509   - tot_int = 0;
2510   - for (int i = 0; i < nrows; ++i)
2511   - tot_int += col_sht.integer(i);
2512   - if (tot_int != sum_sht_int) {
2513   - throw exception_failure("GFitsTableShortCol::integer() : Reference sum: "+str(sum_sht_int)+"Derived sum:"+str(tot_int));
2514   - }
2515   - test_try_success();
2516   - }
2517   - catch(std::exception &e)
2518   - {
2519   - test_try_failure(e);
2520   - }
2521   -
2522   - // Check table (string access)
2523   - test_try("Check table (string access)");
2524   - try{
2525   - tot_str.clear();
2526   - for (int i = 0; i < nrows; ++i)
2527   - tot_str += ":"+col_sht.string(i);
2528   - if (tot_str != sum_sht_str) {
2529   - throw exception_failure("GFitsTableShortCol::string() : Reference sum: "+sum_sht_str+"Derived sum:"+tot_str);
2530   - }
2531   - test_try_success();
2532   - }
2533   - catch(std::exception &e)
2534   - {
2535   - test_try_failure(e);
2536   - }
2537   - test_try_success();
2538   - } // End try ulong
2539   - catch(std::exception &e)
2540   - {
2541   - test_try_failure(e);
2542   - }
2543   -
2544   - //
2545   - // ===== S H O R T 1 0 =====
2546   - //
2547   -
2548   - GFitsTableShortCol col_sht10;
2549   -
2550   - test_try("Short 10");
2551   - try{
2552   -
2553   - // Set table
2554   - test_try("Set table");
2555   - try{
2556   - col_sht10 = GFitsTableShortCol("SHORT10", nrows,nvec);
2557   - for (int i = 0; i < nrows; ++i) {
2558   - for (int j = 0; j < nvec; ++j) {
2559   - short val_sht = short(100.0*cos(0.1*float(i))*
2560   - cos(0.33*float(j)));
2561   - col_sht10(i,j) = val_sht;
2562   - sum_sht10 += val_sht;
2563   - sum_sht10_int += int(val_sht);
2564   - sum_sht10_str += ":"+str(val_sht);
2565   - }
2566   - }
2567   - test_try_success();
2568   - }
2569   - catch(std::exception &e)
2570   - {
2571   - test_try_failure(e);
2572   - }
2573   -
2574   - // Check table (operator access)
2575   - test_try("Check table (operator access)");
2576   - try{
2577   - tot_sht = 0;
2578   - for (int i = 0; i < nrows; ++i) {
2579   - for (int j = 0; j < nvec; ++j)
2580   - tot_sht += col_sht10(i,j);
2581   - }
2582   - if (tot_sht != sum_sht10) {
2583   - throw exception_failure("GFitsTableShortCol::operator() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_sht));
2584   - }
2585   - test_try_success();
2586   - }
2587   - catch(std::exception &e)
2588   - {
2589   - test_try_failure(e);
2590   - }
2591   -
2592   - // Check table (real access)
2593   - test_try("Check table (real access)");
2594   - try{
2595   - tot_dbl = 0.0;
2596   - for (int i = 0; i < nrows; ++i) {
2597   - for (int j = 0; j < nvec; ++j)
2598   - tot_dbl += col_sht10.real(i,j);
2599   - }
2600   - if (!dequal(tot_dbl, sum_sht10)) {
2601   - throw exception_failure("GFitsTableShortCol::real() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_dbl));
2602   - }
2603   - test_try_success();
2604   - }
2605   - catch(std::exception &e)
2606   - {
2607   - test_try_failure(e);
2608   - }
2609   -
2610   - // Check table (int access)
2611   - test_try("Check table (int access)");
2612   - try{
2613   - tot_int = 0;
2614   - for (int i = 0; i < nrows; ++i) {
2615   - for (int j = 0; j < nvec; ++j)
2616   - tot_int += col_sht10.integer(i,j);
2617   - }
2618   - if (tot_int != sum_sht10_int) {
2619   - throw exception_failure("GFitsTableShortCol::integer() - 10 : Reference sum: "+str(sum_sht10_int)+"Derived sum:"+str(tot_int));
2620   - }
2621   - test_try_success();
2622   - }
2623   - catch(std::exception &e)
2624   - {
2625   - test_try_failure(e);
2626   - }
2627   -
2628   - // Check table (string access)
2629   - test_try("Check table (string access)");
2630   - try{
2631   - tot_str.clear();
2632   - for (int i = 0; i < nrows; ++i) {
2633   - for (int j = 0; j < nvec; ++j)
2634   - tot_str += ":"+col_sht10.string(i,j);
2635   - }
2636   - if (tot_str != sum_sht10_str) {
2637   - throw exception_failure("GFitsTableShortCol::string() - 10 : Reference sum: "+sum_sht10_str+"Derived sum:"+tot_str);
2638   - }
2639   - test_try_success();
2640   - }
2641   - catch(std::exception &e)
2642   - {
2643   - test_try_failure(e);
2644   - }
2645   - test_try_success();
2646   - } // end try short 10
2647   - catch(std::exception &e)
2648   - {
2649   - test_try_failure(e);
2650   - }
  1144 + // Set number of rows and vector columns
  1145 + int nrows = 3;
  1146 + int nvec = 3;
2651 1147  
2652   - //
2653   - // ===== W R I T E T A B L E =====
2654   - //
2655   - test_try("Write Table");
2656   - try{
2657   - // Build binary table
2658   - GFitsBinTable table = GFitsBinTable(nrows);
2659   - table.append_column(col_sht);
2660   - table.insert_column(99, col_sht10);
2661   -
2662   - // Append to file
2663   - fits.append(table);
2664   -
2665   - // Save FITS file
2666   - fits.save();
2667   -
2668   - test_try_success();
2669   - }
2670   - catch(std::exception &e)
2671   - {
2672   - test_try_failure(e);
2673   - }
2674   -
2675   - test_try_success();
2676   - } //end try build table
2677   - catch(std::exception &e)
2678   - {
2679   - test_try_failure(e);
2680   - }
  1148 + // Test single column table
  1149 + GFitsTableLongLongCol col1("LONGLONG", nrows);
  1150 + TEST_TABLE1_INT;
2681 1151  
2682   - //================================================================
2683   - //================================================================
2684   - //================================================================
2685   - // Read tables
2686   - //================================================================
2687   - //================================================================
2688   - //================================================================
2689   -
2690   - test_try("Read Table");
2691   - try{
2692   - // Open FITS file
2693   - GFits fits;
2694   - fits.open(filename);
  1152 + // Test multiple column table
  1153 + GFitsTableLongLongCol col2("LONGLONG10", nrows, nvec);
  1154 + TEST_TABLE2_INT;
2695 1155  
2696   - // Set number of rows
2697   - int nrows = 10;
2698   - int nvec = 10;
2699   -
2700   - // Initial control sums
2701   - float tot_flt = 0.0;
2702   - short tot_sht = 0;
2703   - double tot_dbl = 0.0;
2704   - int tot_int = 0;
2705   - std::string tot_str;
2706   -
2707   - //
2708   - // ===== U S H O R T =====
2709   - //
2710   - GFitsTableShortCol* col_sht = NULL;
2711   - test_try("Short");
2712   - try {
2713   - // Get column
2714   - col_sht = (GFitsTableShortCol*)&(*fits.table(1))["SHORT"];
2715   -
2716   - // Check table (operator access)
2717   - test_try("Check table (operator access)");
2718   - try {
2719   - tot_sht = 0;
2720   - for (int i = 0; i < nrows; ++i)
2721   - tot_sht += (*col_sht)(i);
2722   - if (tot_sht != sum_sht) {
2723   - throw exception_failure("GFitsTableShortCol::operator() : Reference sum: "+str(sum_sht)+" Derived sum: "+str(tot_sht));
2724   - }
2725   -
2726   - test_try_success();
2727   - }
2728   - catch(std::exception &e)
2729   - {
2730   - test_try_failure(e);
2731   - }
2732   -
2733   -
2734   - // Check table (real access)
2735   - test_try("Check table (real access)");
2736   - try{
2737   - tot_dbl = 0.0;
2738   - for (int i = 0; i < nrows; ++i)
2739   - tot_dbl += col_sht->real(i);
2740   - if (!dequal(tot_dbl, double(sum_sht))) {
2741   - throw exception_failure("GFitsTableShortCol::real() : Reference sum: "+str(sum_sht)+"Derived sum:"+str(tot_dbl));
2742   - }
2743   - test_try_success();
2744   - }
2745   - catch(std::exception &e)
2746   - {
2747   - test_try_failure(e);
2748   - }
2749   -
2750   - // Check string table (int access)
2751   - test_try("Check table (int access)");
2752   - try{
2753   - tot_int = 0;
2754   - for (int i = 0; i < nrows; ++i)
2755   - tot_int += col_sht->integer(i);
2756   - if (tot_int != sum_sht_int) {
2757   - throw exception_failure("GFitsTableShortCol::integer() : Reference sum: "+str(sum_sht_int)+"Derived sum:"+str(tot_int));
2758   - }
2759   - test_try_success();
2760   - }
2761   - catch(std::exception &e)
2762   - {
2763   - test_try_failure(e);
2764   - }
2765   -
2766   - // Check table (string access)
2767   - test_try("Check table (string access)");
2768   - try{
2769   - tot_str.clear();
2770   - for (int i = 0; i < nrows; ++i)
2771   - tot_str += ":"+col_sht->string(i);
2772   - if (tot_str != sum_sht_str) {
2773   - throw exception_failure("GFitsTableShortCol::string() : Reference sum: "+sum_sht_str+"Derived sum:"+tot_str);
2774   - }
2775   - test_try_success();
2776   - }
2777   - catch(std::exception &e)
2778   - {
2779   - test_try_failure(e);
2780   - }
2781   -
2782   - test_try_success();
2783   - }// End try logical
2784   - catch(std::exception &e)
2785   - {
2786   - test_try_failure(e);
2787   - }
2788   -
2789   - //
2790   - // ===== S H O R T 1 0 =====
2791   - //
2792   - GFitsTableShortCol* col_sht10 = NULL;
2793   - test_try("Short 10");
2794   - try{
2795   - // Get column
2796   - col_sht10 = (GFitsTableShortCol*)&(*fits.table(1))["SHORT10"];
2797   - // Check table (operator access)
2798   - test_try("Check table (operator access)");
2799   - try{
2800   - tot_sht = 0;
2801   - for (int i = 0; i < nrows; ++i) {
2802   - for (int j = 0; j < nvec; ++j)
2803   - tot_sht += (*col_sht10)(i,j);
2804   - }
2805   - if (tot_sht != sum_sht10) {
2806   - throw exception_failure("GFitsTableShortCol::operator() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_sht));
2807   - }
2808   - test_try_success();
2809   - }
2810   - catch(std::exception &e)
2811   - {
2812   - test_try_failure(e);
2813   - }
2814   -
2815   - // Check table (real access)
2816   - test_try("Check table (real access)");
2817   - try{
2818   - tot_dbl = 0.0;
2819   - for (int i = 0; i < nrows; ++i) {
2820   - for (int j = 0; j < nvec; ++j)
2821   - tot_dbl += col_sht10->real(i,j);
2822   - }
2823   - if (!dequal(tot_dbl, sum_sht10)) {
2824   - throw exception_failure("GFitsTableShortCol::real() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_dbl));
2825   - }
2826   - test_try_success();
2827   - }
2828   - catch(std::exception &e)
2829   - {
2830   - test_try_failure(e);
2831   - }
2832   -
2833   - // Check table (int access)
2834   - test_try("Check table (int access)");
2835   - try{
2836   - tot_int = 0;
2837   - for (int i = 0; i < nrows; ++i) {
2838   - for (int j = 0; j < nvec; ++j)
2839   - tot_int += col_sht10->integer(i,j);
2840   - }
2841   - if (tot_int != sum_sht10_int) {
2842   - throw exception_failure("GFitsTableShortCol::integer() - 10 : Reference sum: "+str(sum_sht10_int)+"Derived sum:"+str(tot_int));
2843   - }
2844   - test_try_success();
2845   - }
2846   - catch(std::exception &e)
2847   - {
2848   - test_try_failure(e);
2849   - }
2850   -
2851   - // Check table (string access)
2852   - test_try("Check table (string access)");
2853   - try{
2854   - tot_str.clear();
2855   - for (int i = 0; i < nrows; ++i) {
2856   - for (int j = 0; j < nvec; ++j)
2857   - tot_str += ":"+col_sht10->string(i,j);
2858   - }
2859   - if (tot_str != sum_sht10_str) {
2860   - throw exception_failure("GFitsTableShortCol::string() - 10 : Reference sum: "+sum_sht10_str+"Derived sum:"+tot_str);
2861   - }
2862   - test_try_success();
2863   - }
2864   - catch(std::exception &e)
2865   - {
2866   - test_try_failure(e);
2867   - }
2868   -
2869   - test_try_success();
2870   - } //end try logical 10
2871   - catch(std::exception &e)
2872   - {
2873   - test_try_failure(e);
2874   - }
2875   -
  1156 + // Write tables
  1157 + TEST_WRITE_TABLES;
  1158 +
  1159 + // Read tables back
  1160 + test_try("Read Tables");
  1161 + try {
  1162 + GFits fits(filename);
  1163 + col1 = static_cast<GFitsTableLongLongCol&>((*fits.table(1))["LONGLONG"]);
  1164 + col2 = static_cast<GFitsTableLongLongCol&>((*fits.table(1))["LONGLONG10"]);
  1165 + fits.close();
2876 1166 test_try_success();
2877   - } //end try read tabe
2878   - catch(std::exception &e)
2879   - {
  1167 + }
  1168 + catch(std::exception &e) {
2880 1169 test_try_failure(e);
2881 1170 }
  1171 +
  1172 + // Test single column table
  1173 + TEST_TABLE1_INT;
2882 1174  
  1175 + // Test multiple column table
  1176 + TEST_TABLE2_INT;
2883 1177  
  1178 + // Return
  1179 + return;
2884 1180 }
2885 1181  
2886   -/***************************************************************************
2887   - * @brief Test unsigned short FITS binary table
2888   - ***************************************************************************/
2889   - void TestGFits::test_bintable_ushort(void)
2890   -{
2891   -
2892   - // Set filename
2893   - std::string filename = "test_bintable_ushort.fits";
2894   -
2895   - // Remove FITS file
2896   - std::string cmd = "rm -rf "+ filename;
2897   - int rc = system(cmd.c_str());
2898   -
2899   - // Allocate reference sums
2900   - unsigned short sum_sht = 0;
2901   - unsigned short sum_sht10 = 0;
2902   - unsigned short sum_sht_int = 0;
2903   - unsigned short sum_sht10_int = 0;
2904   - std::string sum_sht_str;
2905   - std::string sum_sht10_str;
2906   -
2907   - // Build tables
2908   - test_try("Build tables");
2909   - try {
2910   - // Create FITS file
2911   - GFits fits;
2912   - fits.open(filename, true);
2913   -
2914   - // Set number of rows
2915   - int nrows = 10;
2916   - int nvec = 10;
2917   -
2918   - // Initial control sums
2919   - float tot_flt = 0.0;
2920   - double tot_dbl = 0.0;
2921   - int tot_int = 0;
2922   - long tot_lng = 0;
2923   - unsigned short tot_sht = 0;
2924   - std::string tot_str;
2925   -
2926   - //
2927   - //
2928   - // ===== U S H O R T =====
2929   - //
2930   -
2931   - GFitsTableUShortCol col_sht;
2932   -
2933   - test_try("UShort");
2934   - try{
2935   - // Set string table
2936   - test_try("Set table");
2937   - try{
2938   - col_sht = GFitsTableUShortCol("USHORT", nrows);
2939   - for (int i = 0; i < nrows; ++i) {
2940   - unsigned short val_sht = (unsigned short)std::abs(1000.0 * cos(0.1*float(i)));
2941   - col_sht(i) = val_sht;
2942   - sum_sht += val_sht;
2943   - sum_sht_int += int(val_sht);
2944   - sum_sht_str += ":"+str(val_sht);
2945   - }
2946   - test_try_success();
2947   - }
2948   - catch(std::exception &e)
2949   - {
2950   - test_try_failure(e);
2951   - }
2952   -
2953   - // Check table (operator access)
2954   - test_try("Check table (operator access)");
2955   - try{
2956   - tot_sht = 0;
2957   - for (int i = 0; i < nrows; ++i)
2958   - tot_sht += col_sht(i);
2959   - if (tot_sht != sum_sht) {
2960   - throw exception_failure("GFitsTableUShortCol::operator() : Reference sum: "+str(sum_sht)+" Derived sum: "+str(tot_sht));
2961   - }
2962   - test_try_success();
2963   - }
2964   - catch(std::exception &e)
2965   - {
2966   - test_try_failure(e);
2967   - }
2968   -
2969   - // Check table (real access)
2970   - test_try("Check table (real access)");
2971   - try{
2972   - tot_dbl = 0.0;
2973   - for (int i = 0; i < nrows; ++i)
2974   - tot_dbl += col_sht.real(i);
2975   - if (!dequal(tot_dbl, double(sum_sht))) {
2976   - throw exception_failure("GFitsTableUShortCol::real() : Reference sum: "+str(sum_sht)+"Derived sum:"+str(tot_dbl));
2977   - }
2978   - test_try_success();
2979   - }
2980   - catch(std::exception &e)
2981   - {
2982   - test_try_failure(e);
2983   - }
2984   -
2985   - // Check string table (int access)
2986   - test_try("Check table (int access)");
2987   - try{
2988   - tot_int = 0;
2989   - for (int i = 0; i < nrows; ++i)
2990   - tot_int += col_sht.integer(i);
2991   - if (tot_int != sum_sht_int) {
2992   - throw exception_failure("GFitsTableUShortCol::integer() : Reference sum: "+str(sum_sht_int)+"Derived sum:"+str(tot_int));
2993   - }
2994   - test_try_success();
2995   - }
2996   - catch(std::exception &e)
2997   - {
2998   - test_try_failure(e);
2999   - }
3000   -
3001   - // Check table (string access)
3002   - test_try("Check table (string access)");
3003   - try{
3004   - tot_str.clear();
3005   - for (int i = 0; i < nrows; ++i)
3006   - tot_str += ":"+col_sht.string(i);
3007   - if (tot_str != sum_sht_str) {
3008   - throw exception_failure("GFitsTableUShortCol::string() : Reference sum: "+sum_sht_str+"Derived sum:"+tot_str);
3009   - }
3010   - test_try_success();
3011   - }
3012   - catch(std::exception &e)
3013   - {
3014   - test_try_failure(e);
3015   - }
3016   - test_try_success();
3017   - } // End try ulong
3018   - catch(std::exception &e)
3019   - {
3020   - test_try_failure(e);
3021   - }
3022   -
3023   - //
3024   - // ===== S H O R T 1 0 =====
3025   - //
3026   -
3027   - GFitsTableUShortCol col_sht10;
3028   -
3029   - test_try("UShort 10");
3030   - try{
3031   -
3032   - // Set table
3033   - test_try("Set table");
3034   - try{
3035   - col_sht10 = GFitsTableUShortCol("USHORT10", nrows,nvec);
3036   - for (int i = 0; i < nrows; ++i) {
3037   - for (int j = 0; j < nvec; ++j) {
3038   - unsigned short val_sht =
3039   - (unsigned short)(std::abs(100.0*cos(0.1*float(i))*cos(0.33*float(j))));
3040   - col_sht10(i,j) = val_sht;
3041   - sum_sht10 += val_sht;
3042   - sum_sht10_int += int(val_sht);
3043   - sum_sht10_str += ":"+str(val_sht);
3044   - }
3045   - }
3046   - test_try_success();
3047   - }
3048   - catch(std::exception &e)
3049   - {
3050   - test_try_failure(e);
3051   - }
3052   -
3053   - // Check table (operator access)
3054   - test_try("Check table (operator access)");
3055   - try{
3056   - tot_sht = 0;
3057   - for (int i = 0; i < nrows; ++i) {
3058   - for (int j = 0; j < nvec; ++j)
3059   - tot_sht += col_sht10(i,j);
3060   - }
3061   - if (tot_sht != sum_sht10) {
3062   - throw exception_failure("GFitsTableUShortCol::operator() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_sht));
3063   - }
3064   - test_try_success();
3065   - }
3066   - catch(std::exception &e)
3067   - {
3068   - test_try_failure(e);
3069   - }
3070   -
3071   - // Check table (real access)
3072   - test_try("Check table (real access)");
3073   - try{
3074   - tot_dbl = 0.0;
3075   - for (int i = 0; i < nrows; ++i) {
3076   - for (int j = 0; j < nvec; ++j)
3077   - tot_dbl += col_sht10.real(i,j);
3078   - }
3079   - if (!dequal(tot_dbl, sum_sht10)) {
3080   - throw exception_failure("GFitsTableUShortCol::real() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_dbl));
3081   - }
3082   - test_try_success();
3083   - }
3084   - catch(std::exception &e)
3085   - {
3086   - test_try_failure(e);
3087   - }
3088   -
3089   - // Check table (int access)
3090   - test_try("Check table (int access)");
3091   - try{
3092   - tot_int = 0;
3093   - for (int i = 0; i < nrows; ++i) {
3094   - for (int j = 0; j < nvec; ++j)
3095   - tot_int += col_sht10.integer(i,j);
3096   - }
3097   - if (tot_int != sum_sht10_int) {
3098   - throw exception_failure("GFitsTableUShortCol::integer() - 10 : Reference sum: "+str(sum_sht10_int)+"Derived sum:"+str(tot_int));
3099   - }
3100   - test_try_success();
3101   - }
3102   - catch(std::exception &e)
3103   - {
3104   - test_try_failure(e);
3105   - }
3106   -
3107   - // Check table (string access)
3108   - test_try("Check table (string access)");
3109   - try{
3110   - tot_str.clear();
3111   - for (int i = 0; i < nrows; ++i) {
3112   - for (int j = 0; j < nvec; ++j)
3113   - tot_str += ":"+col_sht10.string(i,j);
3114   - }
3115   - if (tot_str != sum_sht10_str) {
3116   - throw exception_failure("GFitsTableUShortCol::string() - 10 : Reference sum: "+sum_sht10_str+"Derived sum:"+tot_str);
3117   - }
3118   - test_try_success();
3119   - }
3120   - catch(std::exception &e)
3121   - {
3122   - test_try_failure(e);
3123   - }
3124   - test_try_success();
3125   - } // end try longlong 10
3126   - catch(std::exception &e)
3127   - {
3128   - test_try_failure(e);
3129   - }
3130   -
3131   - //
3132   - // ===== W R I T E T A B L E =====
3133   - //
3134   - test_try("Write Table");
3135   - try{
3136   - // Build binary table
3137   - GFitsBinTable table = GFitsBinTable(nrows);
3138   - table.append_column(col_sht);
3139   - table.insert_column(99, col_sht10);
3140   -
3141   - // Append to file
3142   - fits.append(table);
3143   -
3144   - // Save FITS file
3145   - fits.save();
3146   -
3147   - test_try_success();
3148   - }
3149   - catch(std::exception &e)
3150   - {
3151   - test_try_failure(e);
3152   - }
3153   -
3154   - test_try_success();
3155   - } //end try build table
3156   - catch(std::exception &e)
3157   - {
3158   - test_try_failure(e);
3159   - }
3160   -
3161   - //================================================================
3162   - //================================================================
3163   - //================================================================
3164   - // Read tables
3165   - //================================================================
3166   - //================================================================
3167   - //================================================================
3168   -
3169   - test_try("Read Table");
3170   - try{
3171   - // Open FITS file
3172   - GFits fits;
3173   - fits.open(filename);
3174   -
3175   - // Set number of rows
3176   - int nrows = 10;
3177   - int nvec = 10;
3178   -
3179   - // Initial control sums
3180   - float tot_flt = 0.0;
3181   - unsigned short tot_sht = 0;
3182   - double tot_dbl = 0.0;
3183   - int tot_int = 0;
3184   - std::string tot_str;
3185   -
3186   - //
3187   - // ===== U S H O R T =====
3188   - //
3189   - GFitsTableUShortCol* col_sht = NULL;
3190   - test_try("UShort");
3191   - try {
3192   - // Get column
3193   - col_sht = (GFitsTableUShortCol*)&(*fits.table(1))["USHORT"];
3194   -
3195   - // Check table (operator access)
3196   - test_try("Check table (operator access)");
3197   - try {
3198   - tot_sht = 0;
3199   - for (int i = 0; i < nrows; ++i)
3200   - tot_sht += (*col_sht)(i);
3201   - if (tot_sht != sum_sht) {
3202   - throw exception_failure("GFitsTableUShortCol::operator() : Reference sum: "+str(sum_sht)+" Derived sum: "+str(tot_sht));
3203   - }
3204   -
3205   - test_try_success();
3206   - }
3207   - catch(std::exception &e)
3208   - {
3209   - test_try_failure(e);
3210   - }
3211   -
3212   -
3213   - // Check table (real access)
3214   - test_try("Check table (real access)");
3215   - try{
3216   - tot_dbl = 0.0;
3217   - for (int i = 0; i < nrows; ++i)
3218   - tot_dbl += col_sht->real(i);
3219   - if (!dequal(tot_dbl, double(sum_sht))) {
3220   - throw exception_failure("GFitsTableUShortCol::real() : Reference sum: "+str(sum_sht)+"Derived sum:"+str(tot_dbl));
3221   - }
3222   - test_try_success();
3223   - }
3224   - catch(std::exception &e)
3225   - {
3226   - test_try_failure(e);
3227   - }
3228   -
3229   - // Check string table (int access)
3230   - test_try("Check table (int access)");
3231   - try{
3232   - tot_int = 0;
3233   - for (int i = 0; i < nrows; ++i)
3234   - tot_int += col_sht->integer(i);
3235   - if (tot_int != sum_sht_int) {
3236   - throw exception_failure("GFitsTableUShortCol::integer() : Reference sum: "+str(sum_sht_int)+"Derived sum:"+str(tot_int));
3237   - }
3238   - test_try_success();
3239   - }
3240   - catch(std::exception &e)
3241   - {
3242   - test_try_failure(e);
3243   - }
3244   -
3245   - // Check table (string access)
3246   - test_try("Check table (string access)");
3247   - try{
3248   - tot_str.clear();
3249   - for (int i = 0; i < nrows; ++i)
3250   - tot_str += ":"+col_sht->string(i);
3251   - if (tot_str != sum_sht_str) {
3252   - throw exception_failure("GFitsTableUShortCol::string() : Reference sum: "+sum_sht_str+"Derived sum:"+tot_str);
3253   - }
3254   - test_try_success();
3255   - }
3256   - catch(std::exception &e)
3257   - {
3258   - test_try_failure(e);
3259   - }
3260   -
3261   - test_try_success();
3262   - }// End try logical
3263   - catch(std::exception &e)
3264   - {
3265   - test_try_failure(e);
3266   - }
3267   -
3268   - //
3269   - // ===== U S H O R T 1 0 =====
3270   - //
3271   - GFitsTableUShortCol* col_sht10 = NULL;
3272   - test_try("UShort 10");
3273   - try{
3274   - // Get column
3275   - col_sht10 = (GFitsTableUShortCol*)&(*fits.table(1))["USHORT10"];
3276   - // Check table (operator access)
3277   - test_try("Check table (operator access)");
3278   - try{
3279   - tot_sht = 0;
3280   - for (int i = 0; i < nrows; ++i) {
3281   - for (int j = 0; j < nvec; ++j)
3282   - tot_sht += (*col_sht10)(i,j);
3283   - }
3284   - if (tot_sht != sum_sht10) {
3285   - throw exception_failure("GFitsTableUShortCol::operator() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_sht));
3286   - }
3287   - test_try_success();
3288   - }
3289   - catch(std::exception &e)
3290   - {
3291   - test_try_failure(e);
3292   - }
3293   -
3294   - // Check table (real access)
3295   - test_try("Check table (real access)");
3296   - try{
3297   - tot_dbl = 0.0;
3298   - for (int i = 0; i < nrows; ++i) {
3299   - for (int j = 0; j < nvec; ++j)
3300   - tot_dbl += col_sht10->real(i,j);
3301   - }
3302   - if (!dequal(tot_dbl, sum_sht10)) {
3303   - throw exception_failure("GFitsTableUShortCol::real() - 10 : Reference sum: "+str(sum_sht10)+"Derived sum:"+str(tot_dbl));
3304   - }
3305   - test_try_success();
3306   - }
3307   - catch(std::exception &e)
3308   - {
3309   - test_try_failure(e);
3310   - }
3311   -
3312   - // Check table (int access)
3313   - test_try("Check table (int access)");
3314   - try{
3315   - tot_int = 0;
3316   - for (int i = 0; i < nrows; ++i) {
3317   - for (int j = 0; j < nvec; ++j)
3318   - tot_int += col_sht10->integer(i,j);
3319   - }
3320   - if (tot_int != sum_sht10_int) {
3321   - throw exception_failure("GFitsTableUShortCol::integer() - 10 : Reference sum: "+str(sum_sht10_int)+"Derived sum:"+str(tot_int));
3322   - }
3323   - test_try_success();
3324   - }
3325   - catch(std::exception &e)
3326   - {
3327   - test_try_failure(e);
3328   - }
3329   -
3330   - // Check table (string access)
3331   - test_try("Check table (string access)");
3332   - try{
3333   - tot_str.clear();
3334   - for (int i = 0; i < nrows; ++i) {
3335   - for (int j = 0; j < nvec; ++j)
3336   - tot_str += ":"+col_sht10->string(i,j);
3337   - }
3338   - if (tot_str != sum_sht10_str) {
3339   - throw exception_failure("GFitsTableUShortCol::string() - 10 : Reference sum: "+sum_sht10_str+"Derived sum:"+tot_str);
3340   - }
3341   - test_try_success();
3342   - }
3343   - catch(std::exception &e)
3344   - {
3345   - test_try_failure(e);
3346   - }
3347   -
3348   - test_try_success();
3349   - } //end try logical 10
3350   - catch(std::exception &e)
3351   - {
3352   - test_try_failure(e);
3353   - }
3354   -
3355   - test_try_success();
3356   - } //end try read tabe
3357   - catch(std::exception &e)
3358   - {
3359   - test_try_failure(e);
3360   - }
3361   -
3362   -
3363   -}
3364   -
3365   -/***************************************************************************
3366   - * @brief Test long FITS binary table
3367   - ***************************************************************************/
3368   -
3369   -void TestGFits::test_bintable_long(void)
3370   -{
3371   -
3372   - // Set filename
3373   - std::string filename = "test_bintable_long.fits";
3374   -
3375   - // Remove FITS file
3376   - std::string cmd = "rm -rf "+ filename;
3377   - int rc = system(cmd.c_str());
3378   -
3379   - // Allocate reference sums
3380   - long sum_lng = 0;
3381   - long sum_lng10 = 0;
3382   - long sum_lng_int = 0;
3383   - long sum_lng10_int = 0;
3384   - std::string sum_lng_str;
3385   - std::string sum_lng10_str;
3386   -
3387   - // Build tables
3388   - test_try("Build tables");
3389   - try {
3390   - // Create FITS file
3391   - GFits fits;
3392   - fits.open(filename, true);
3393   -
3394   - // Set number of rows
3395   - int nrows = 10;
3396   - int nvec = 10;
3397   -
3398   - // Initial control sums
3399   - float tot_flt = 0.0;
3400   - double tot_dbl = 0.0;
3401   - int tot_int = 0;
3402   - long tot_lng = 0;
3403   - short tot_sht = 0;
3404   - std::string tot_str;
3405   -
3406   - //
3407   - //
3408   - // ===== L O N G =====
3409   - //
3410   -
3411   - GFitsTableLongCol col_lng;
3412   -
3413   - test_try("Long");
3414   - try{
3415   - // Set string table
3416   - test_try("Set table");
3417   - try{
3418   - col_lng = GFitsTableLongCol("LONG", nrows);
3419   - for (int i = 0; i < nrows; ++i) {
3420   - long val_lng = long(100000.0 * cos(0.1*float(i)));
3421   - col_lng(i) = val_lng;
3422   - sum_lng += val_lng;
3423   - sum_lng_int += int(val_lng);
3424   - sum_lng_str += ":"+str((int)val_lng);
3425   - }
3426   - test_try_success();
3427   - }
3428   - catch(std::exception &e)
3429   - {
3430   - test_try_failure(e);
3431   - }
3432   -
3433   - // Check string table (operator access)
3434   - test_try("Check table (operator access)");
3435   - try{
3436   - tot_lng = 0;
3437   - for (int i = 0; i < nrows; ++i)
3438   - tot_lng += col_lng(i);
3439   - if (tot_lng != sum_lng) {
3440   - throw exception_failure("GFitsTableLongCol::operator() : Reference sum: "+str(sum_lng)+" Derived sum: "+str(tot_lng));
3441   - }
3442   - test_try_success();
3443   - }
3444   - catch(std::exception &e)
3445   - {
3446   - test_try_failure(e);
3447   - }
3448   -
3449   - // Check string table (real access)
3450   - test_try("Check table (real access)");
3451   - try{
3452   - tot_dbl = 0.0;
3453   - for (int i = 0; i < nrows; ++i)
3454   - tot_dbl += col_lng.real(i);
3455   - if (!dequal(tot_dbl, double(sum_lng))) {
3456   - throw exception_failure("GFitsTableLongCol::real() : Reference sum: "+str(sum_lng)+"Derived sum:"+str(tot_dbl));
3457   - }
3458   - test_try_success();
3459   - }
3460   - catch(std::exception &e)
3461   - {
3462   - test_try_failure(e);
3463   - }
3464   -
3465   - // Check string table (int access)
3466   - test_try("Check table (int access)");
3467   - try{
3468   - tot_int = 0;
3469   - for (int i = 0; i < nrows; ++i)
3470   - tot_int += col_lng.integer(i);
3471   - if (tot_int != sum_lng_int) {
3472   - throw exception_failure("GFitsTableLongCol::integer() : Reference sum: "+str(sum_lng_int)+"Derived sum:"+str(tot_int));
3473   - }
3474   - test_try_success();
3475   - }
3476   - catch(std::exception &e)
3477   - {
3478   - test_try_failure(e);
3479   - }
3480   -
3481   - // Check table (string access)
3482   - test_try("Check table (string access)");
3483   - try{
3484   - tot_str.clear();
3485   - for (int i = 0; i < nrows; ++i)
3486   - tot_str += ":"+col_lng.string(i);
3487   - if (tot_str != sum_lng_str) {
3488   - throw exception_failure("GFitsTableLongCol::string() : Reference sum: "+sum_lng_str+"Derived sum:"+tot_str);
3489   - }
3490   - test_try_success();
3491   - }
3492   - catch(std::exception &e)
3493   - {
3494   - test_try_failure(e);
3495   - }
3496   - test_try_success();
3497   - } // End try ulong
3498   - catch(std::exception &e)
3499   - {
3500   - test_try_failure(e);
3501   - }
3502   -
3503   - //
3504   - // ===== L O N G 1 0 =====
3505   - //
3506   -
3507   - GFitsTableLongCol col_lng10;
3508   -
3509   - test_try("Long 10");
3510   - try{
3511   -
3512   - // Set table
3513   - test_try("Set table");
3514   - try{
3515   - col_lng10 = GFitsTableLongCol("LONG10", nrows,nvec);
3516   - for (int i = 0; i < nrows; ++i) {
3517   - for (int j = 0; j < nvec; ++j) {
3518   - long val_lng = long(1000.0*cos(0.1*float(i))*
3519   - cos(0.33*float(j)));
3520   - col_lng10(i,j) = val_lng;
3521   - sum_lng10 += val_lng;
3522   - sum_lng10_int += int(val_lng);
3523   - sum_lng10_str += ":"+str((int)val_lng);
3524   - }
3525   - }
3526   - test_try_success();
3527   - }
3528   - catch(std::exception &e)
3529   - {
3530   - test_try_failure(e);
3531   - }
3532   -
3533   - // Check table (operator access)
3534   - test_try("Check table (operator access)");
3535   - try{
3536   - tot_lng = 0;
3537   - for (int i = 0; i < nrows; ++i) {
3538   - for (int j = 0; j < nvec; ++j)
3539   - tot_lng += col_lng10(i,j);
3540   - }
3541   - if (tot_lng != sum_lng10) {
3542   - throw exception_failure("GFitsTableLongCol::operator() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_lng));
3543   - }
3544   - test_try_success();
3545   - }
3546   - catch(std::exception &e)
3547   - {
3548   - test_try_failure(e);
3549   - }
3550   -
3551   - // Check table (real access)
3552   - test_try("Check table (real access)");
3553   - try{
3554   - tot_dbl = 0.0;
3555   - for (int i = 0; i < nrows; ++i) {
3556   - for (int j = 0; j < nvec; ++j)
3557   - tot_dbl += col_lng10.real(i,j);
3558   - }
3559   - if (!dequal(tot_dbl, sum_lng10)) {
3560   - throw exception_failure("GFitsTableLongCol::real() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_dbl));
3561   - }
3562   - test_try_success();
3563   - }
3564   - catch(std::exception &e)
3565   - {
3566   - test_try_failure(e);
3567   - }
3568   -
3569   - // Check table (int access)
3570   - test_try("Check table (int access)");
3571   - try{
3572   - tot_int = 0;
3573   - for (int i = 0; i < nrows; ++i) {
3574   - for (int j = 0; j < nvec; ++j)
3575   - tot_int += col_lng10.integer(i,j);
3576   - }
3577   - if (tot_int != sum_lng10_int) {
3578   - throw exception_failure("GFitsTableLongCol::integer() - 10 : Reference sum: "+str(sum_lng10_int)+"Derived sum:"+str(tot_int));
3579   - }
3580   - test_try_success();
3581   - }
3582   - catch(std::exception &e)
3583   - {
3584   - test_try_failure(e);
3585   - }
3586   -
3587   - // Check table (string access)
3588   - test_try("Check table (string access)");
3589   - try{
3590   - tot_str.clear();
3591   - for (int i = 0; i < nrows; ++i) {
3592   - for (int j = 0; j < nvec; ++j)
3593   - tot_str += ":"+col_lng10.string(i,j);
3594   - }
3595   - if (tot_str != sum_lng10_str) {
3596   - throw exception_failure("GFitsTableLongCol::string() - 10 : Reference sum: "+sum_lng10_str+"Derived sum:"+tot_str);
3597   - }
3598   - test_try_success();
3599   - }
3600   - catch(std::exception &e)
3601   - {
3602   - test_try_failure(e);
3603   - }
3604   - test_try_success();
3605   - } // end try longlong 10
3606   - catch(std::exception &e)
3607   - {
3608   - test_try_failure(e);
3609   - }
3610   -
3611   - //
3612   - // ===== W R I T E T A B L E =====
3613   - //
3614   - test_try("Write Table");
3615   - try{
3616   - // Build binary table
3617   - GFitsBinTable table = GFitsBinTable(nrows);
3618   - table.append_column(col_lng);
3619   - table.insert_column(99, col_lng10);
3620   -
3621   - // Append to file
3622   - fits.append(table);
3623   -
3624   - // Save FITS file
3625   - fits.save();
3626   -
3627   - test_try_success();
3628   - }
3629   - catch(std::exception &e)
3630   - {
3631   - test_try_failure(e);
3632   - }
3633   -
3634   - test_try_success();
3635   - } //end try build table
3636   - catch(std::exception &e)
3637   - {
3638   - test_try_failure(e);
3639   - }
3640   -
3641   - //================================================================
3642   - //================================================================
3643   - //================================================================
3644   - // Read tables
3645   - //================================================================
3646   - //================================================================
3647   - //================================================================
3648   -
3649   - test_try("Read Table");
3650   - try{
3651   - // Open FITS file
3652   - GFits fits;
3653   - fits.open(filename);
3654   -
3655   - // Set number of rows
3656   - int nrows = 10;
3657   - int nvec = 10;
3658   -
3659   - // Initial control sums
3660   - float tot_flt = 0.0;
3661   - double tot_dbl = 0.0;
3662   - int tot_int = 0;
3663   - long tot_lng = 0;
3664   - std::string tot_str;
3665   -
3666   - //
3667   - // ===== L O N G =====
3668   - //
3669   - GFitsTableLongCol* col_lng = NULL;
3670   - test_try("Long");
3671   - try {
3672   - // Get column
3673   - col_lng = (GFitsTableLongCol*)&(*fits.table(1))["LONG"];
3674   -
3675   - // Check string table (operator access)
3676   - test_try("Check table (operator access)");
3677   - try {
3678   - tot_lng = 0;
3679   - for (int i = 0; i < nrows; ++i)
3680   - tot_lng += (*col_lng)(i);
3681   - if (tot_lng != sum_lng) {
3682   - throw exception_failure("GFitsTableLongCol::operator() : Reference sum: "+str(sum_lng)+" Derived sum: "+str(tot_lng));
3683   - }
3684   -
3685   - test_try_success();
3686   - }
3687   - catch(std::exception &e)
3688   - {
3689   - test_try_failure(e);
3690   - }
3691   -
3692   -
3693   - // Check table (real access)
3694   - test_try("Check table (real access)");
3695   - try{
3696   - tot_dbl = 0.0;
3697   - for (int i = 0; i < nrows; ++i)
3698   - tot_dbl += col_lng->real(i);
3699   - if (!dequal(tot_dbl, double(sum_lng))) {
3700   - throw exception_failure("GFitsTableLongCol::real() : Reference sum: "+str(sum_lng)+"Derived sum:"+str(tot_dbl));
3701   - }
3702   - test_try_success();
3703   - }
3704   - catch(std::exception &e)
3705   - {
3706   - test_try_failure(e);
3707   - }
3708   -
3709   - // Check string table (int access)
3710   - test_try("Check table (int access)");
3711   - try{
3712   - tot_int = 0;
3713   - for (int i = 0; i < nrows; ++i)
3714   - tot_int += col_lng->integer(i);
3715   - if (tot_int != sum_lng_int) {
3716   - throw exception_failure("GFitsTableLongCol::integer() : Reference sum: "+str(sum_lng_int)+"Derived sum:"+str(tot_int));
3717   - }
3718   - test_try_success();
3719   - }
3720   - catch(std::exception &e)
3721   - {
3722   - test_try_failure(e);
3723   - }
3724   -
3725   - // Check table (string access)
3726   - test_try("Check table (string access)");
3727   - try{
3728   - tot_str.clear();
3729   - for (int i = 0; i < nrows; ++i)
3730   - tot_str += ":"+col_lng->string(i);
3731   - if (tot_str != sum_lng_str) {
3732   - throw exception_failure("GFitsTableLongCol::string() : Reference sum: "+sum_lng_str+"Derived sum:"+tot_str);
3733   - }
3734   - test_try_success();
3735   - }
3736   - catch(std::exception &e)
3737   - {
3738   - test_try_failure(e);
3739   - }
3740   -
3741   - test_try_success();
3742   - }// End try logical
3743   - catch(std::exception &e)
3744   - {
3745   - test_try_failure(e);
3746   - }
3747   -
3748   - //
3749   - // ===== L O N G 1 0 =====
3750   - //
3751   - GFitsTableLongCol* col_lng10 = NULL;
3752   - test_try("Long 10");
3753   - try{
3754   - // Get column
3755   - col_lng10 = (GFitsTableLongCol*)&(*fits.table(1))["LONG10"];
3756   - // Check table (operator access)
3757   - test_try("Check table (operator access)");
3758   - try{
3759   - tot_lng = 0;
3760   - for (int i = 0; i < nrows; ++i) {
3761   - for (int j = 0; j < nvec; ++j)
3762   - tot_lng += (*col_lng10)(i,j);
3763   - }
3764   - if (tot_lng != sum_lng10) {
3765   - throw exception_failure("GFitsTableLongCol::operator() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_lng));
3766   - }
3767   - test_try_success();
3768   - }
3769   - catch(std::exception &e)
3770   - {
3771   - test_try_failure(e);
3772   - }
3773   -
3774   - // Check table (real access)
3775   - test_try("Check table (real access)");
3776   - try{
3777   - tot_dbl = 0.0;
3778   - for (int i = 0; i < nrows; ++i) {
3779   - for (int j = 0; j < nvec; ++j)
3780   - tot_dbl += col_lng10->real(i,j);
3781   - }
3782   - if (!dequal(tot_dbl, sum_lng10)) {
3783   - throw exception_failure("GFitsTableLongCol::real() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_dbl));
3784   - }
3785   - test_try_success();
3786   - }
3787   - catch(std::exception &e)
3788   - {
3789   - test_try_failure(e);
3790   - }
3791   -
3792   - // Check table (int access)
3793   - test_try("Check table (int access)");
3794   - try{
3795   - tot_int = 0;
3796   - for (int i = 0; i < nrows; ++i) {
3797   - for (int j = 0; j < nvec; ++j)
3798   - tot_int += col_lng10->integer(i,j);
3799   - }
3800   - if (tot_int != sum_lng10_int) {
3801   - throw exception_failure("GFitsTableLongCol::integer() - 10 : Reference sum: "+str(sum_lng10_int)+"Derived sum:"+str(tot_int));
3802   - }
3803   - test_try_success();
3804   - }
3805   - catch(std::exception &e)
3806   - {
3807   - test_try_failure(e);
3808   - }
3809   -
3810   - // Check table (string access)
3811   - test_try("Check table (string access)");
3812   - try{
3813   - tot_str.clear();
3814   - for (int i = 0; i < nrows; ++i) {
3815   - for (int j = 0; j < nvec; ++j)
3816   - tot_str += ":"+col_lng10->string(i,j);
3817   - }
3818   - if (tot_str != sum_lng10_str) {
3819   - throw exception_failure("GFitsTableLongCol::string() - 10 : Reference sum: "+sum_lng10_str+"Derived sum:"+tot_str);
3820   - }
3821   - test_try_success();
3822   - }
3823   - catch(std::exception &e)
3824   - {
3825   - test_try_failure(e);
3826   - }
3827   -
3828   - test_try_success();
3829   - } //end try logical 10
3830   - catch(std::exception &e)
3831   - {
3832   - test_try_failure(e);
3833   - }
3834   -
3835   - test_try_success();
3836   - } //end try read tabe
3837   - catch(std::exception &e)
3838   - {
3839   - test_try_failure(e);
3840   - }
3841   -
3842   -
3843   -}
3844   -
3845   -/***************************************************************************
3846   - * @brief Test long long FITS binary table
3847   - ***************************************************************************/
3848   -
3849   -void TestGFits::test_bintable_longlong(void)
3850   -{
3851   -
3852   - // Set filename
3853   - std::string filename = "test_bintable_longlong.fits";
3854   -
3855   - // Remove FITS file
3856   - std::string cmd = "rm -rf "+ filename;
3857   - int rc = system(cmd.c_str());
3858   -
3859   - // Allocate reference sums
3860   - long long sum_lng = 0;
3861   - long long sum_lng10 = 0;
3862   - long long sum_lng_int = 0;
3863   - long long sum_lng10_int = 0;
3864   - std::string sum_lng_str;
3865   - std::string sum_lng10_str;
3866   -
3867   - // Build tables
3868   - test_try("Build tables");
3869   - try {
3870   - // Create FITS file
3871   - GFits fits;
3872   - fits.open(filename, true);
3873   -
3874   - // Set number of rows
3875   - int nrows = 10;
3876   - int nvec = 10;
3877   -
3878   - // Initial control sums
3879   - float tot_flt = 0.0;
3880   - double tot_dbl = 0.0;
3881   - int tot_int = 0;
3882   - long long tot_lng = 0;
3883   - short tot_sht = 0;
3884   - std::string tot_str;
3885   -
3886   - //
3887   - //
3888   - // ===== L O N G L O N G =====
3889   - //
3890   -
3891   - GFitsTableLongLongCol col_lng;
3892   -
3893   - test_try("LongLong");
3894   - try{
3895   - // Set string table
3896   - test_try("Set table");
3897   - try{
3898   - col_lng = GFitsTableLongLongCol("LONGLONG", nrows);
3899   - for (int i = 0; i < nrows; ++i) {
3900   - long val_lng = long(100000.0 * cos(0.1*float(i)));
3901   - col_lng(i) = val_lng;
3902   - sum_lng += val_lng;
3903   - sum_lng_int += int(val_lng);
3904   - sum_lng_str += ":"+str((int)val_lng);
3905   - }
3906   - test_try_success();
3907   - }
3908   - catch(std::exception &e)
3909   - {
3910   - test_try_failure(e);
3911   - }
3912   -
3913   - // Check string table (operator access)
3914   - test_try("Check table (operator access)");
3915   - try{
3916   - tot_lng = 0;
3917   - for (int i = 0; i < nrows; ++i)
3918   - tot_lng += col_lng(i);
3919   - if (tot_lng != sum_lng) {
3920   - throw exception_failure("GFitsTableLongLongCol::operator() : Reference sum: "+str(sum_lng)+" Derived sum: "+str(tot_lng));
3921   - }
3922   - test_try_success();
3923   - }
3924   - catch(std::exception &e)
3925   - {
3926   - test_try_failure(e);
3927   - }
3928   -
3929   - // Check string table (real access)
3930   - test_try("Check table (real access)");
3931   - try{
3932   - tot_dbl = 0.0;
3933   - for (int i = 0; i < nrows; ++i)
3934   - tot_dbl += col_lng.real(i);
3935   - if (!dequal(tot_dbl, double(sum_lng))) {
3936   - throw exception_failure("GFitsTableLongLongCol::real() : Reference sum: "+str(sum_lng)+"Derived sum:"+str(tot_dbl));
3937   - }
3938   - test_try_success();
3939   - }
3940   - catch(std::exception &e)
3941   - {
3942   - test_try_failure(e);
3943   - }
3944   -
3945   - // Check string table (int access)
3946   - test_try("Check table (int access)");
3947   - try{
3948   - tot_int = 0;
3949   - for (int i = 0; i < nrows; ++i)
3950   - tot_int += col_lng.integer(i);
3951   - if (tot_int != sum_lng_int) {
3952   - throw exception_failure("GFitsTableLongLongCol::integer() : Reference sum: "+str(sum_lng_int)+"Derived sum:"+str(tot_int));
3953   - }
3954   - test_try_success();
3955   - }
3956   - catch(std::exception &e)
3957   - {
3958   - test_try_failure(e);
3959   - }
3960   -
3961   - // Check table (string access)
3962   - test_try("Check table (string access)");
3963   - try{
3964   - tot_str.clear();
3965   - for (int i = 0; i < nrows; ++i)
3966   - tot_str += ":"+col_lng.string(i);
3967   - if (tot_str != sum_lng_str) {
3968   - throw exception_failure("GFitsTableLongLongCol::string() : Reference sum: "+sum_lng_str+"Derived sum:"+tot_str);
3969   - }
3970   - test_try_success();
3971   - }
3972   - catch(std::exception &e)
3973   - {
3974   - test_try_failure(e);
3975   - }
3976   - test_try_success();
3977   - } // End try ulong
3978   - catch(std::exception &e)
3979   - {
3980   - test_try_failure(e);
3981   - }
3982   -
3983   - //
3984   - // ===== L O N G L O N G 1 0 =====
3985   - //
3986   -
3987   - GFitsTableLongLongCol col_lng10;
3988   -
3989   - test_try("LongLong 10");
3990   - try{
3991   -
3992   - // Set table
3993   - test_try("Set table");
3994   - try{
3995   - col_lng10 = GFitsTableLongLongCol("LONGLONG10", nrows,nvec);
3996   - for (int i = 0; i < nrows; ++i) {
3997   - for (int j = 0; j < nvec; ++j) {
3998   - long val_lng = long(1000.0*cos(0.1*float(i))*
3999   - cos(0.33*float(j)));
4000   - col_lng10(i,j) = val_lng;
4001   - sum_lng10 += val_lng;
4002   - sum_lng10_int += int(val_lng);
4003   - sum_lng10_str += ":"+str((int)val_lng);
4004   - }
4005   - }
4006   - test_try_success();
4007   - }
4008   - catch(std::exception &e)
4009   - {
4010   - test_try_failure(e);
4011   - }
4012   -
4013   - // Check table (operator access)
4014   - test_try("Check table (operator access)");
4015   - try{
4016   - tot_lng = 0;
4017   - for (int i = 0; i < nrows; ++i) {
4018   - for (int j = 0; j < nvec; ++j)
4019   - tot_lng += col_lng10(i,j);
4020   - }
4021   - if (tot_lng != sum_lng10) {
4022   - throw exception_failure("GFitsTableLongLongCol::operator() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_lng));
4023   - }
4024   - test_try_success();
4025   - }
4026   - catch(std::exception &e)
4027   - {
4028   - test_try_failure(e);
4029   - }
4030   -
4031   - // Check table (real access)
4032   - test_try("Check table (real access)");
4033   - try{
4034   - tot_dbl = 0.0;
4035   - for (int i = 0; i < nrows; ++i) {
4036   - for (int j = 0; j < nvec; ++j)
4037   - tot_dbl += col_lng10.real(i,j);
4038   - }
4039   - if (!dequal(tot_dbl, sum_lng10)) {
4040   - throw exception_failure("GFitsTableLongLongCol::real() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_dbl));
4041   - }
4042   - test_try_success();
4043   - }
4044   - catch(std::exception &e)
4045   - {
4046   - test_try_failure(e);
4047   - }
4048   -
4049   - // Check table (int access)
4050   - test_try("Check table (int access)");
4051   - try{
4052   - tot_int = 0;
4053   - for (int i = 0; i < nrows; ++i) {
4054   - for (int j = 0; j < nvec; ++j)
4055   - tot_int += col_lng10.integer(i,j);
4056   - }
4057   - if (tot_int != sum_lng10_int) {
4058   - throw exception_failure("GFitsTableLongLongCol::integer() - 10 : Reference sum: "+str(sum_lng10_int)+"Derived sum:"+str(tot_int));
4059   - }
4060   - test_try_success();
4061   - }
4062   - catch(std::exception &e)
4063   - {
4064   - test_try_failure(e);
4065   - }
4066   -
4067   - // Check table (string access)
4068   - test_try("Check table (string access)");
4069   - try{
4070   - tot_str.clear();
4071   - for (int i = 0; i < nrows; ++i) {
4072   - for (int j = 0; j < nvec; ++j)
4073   - tot_str += ":"+col_lng10.string(i,j);
4074   - }
4075   - if (tot_str != sum_lng10_str) {
4076   - throw exception_failure("GFitsTableLongLongCol::string() - 10 : Reference sum: "+sum_lng10_str+"Derived sum:"+tot_str);
4077   - }
4078   - test_try_success();
4079   - }
4080   - catch(std::exception &e)
4081   - {
4082   - test_try_failure(e);
4083   - }
4084   - test_try_success();
4085   - } // end try longlong 10
4086   - catch(std::exception &e)
4087   - {
4088   - test_try_failure(e);
4089   - }
4090   -
4091   - //
4092   - // ===== W R I T E T A B L E =====
4093   - //
4094   - test_try("Write Table");
4095   - try{
4096   - // Build binary table
4097   - GFitsBinTable table = GFitsBinTable(nrows);
4098   - table.append_column(col_lng);
4099   - table.insert_column(99, col_lng10);
4100   -
4101   - // Append to file
4102   - fits.append(table);
4103   -
4104   - // Save FITS file
4105   - fits.save();
4106   -
4107   - test_try_success();
4108   - }
4109   - catch(std::exception &e)
4110   - {
4111   - test_try_failure(e);
4112   - }
4113   -
4114   - test_try_success();
4115   - } //end try build table
4116   - catch(std::exception &e)
4117   - {
4118   - test_try_failure(e);
4119   - }
4120   -
4121   - //================================================================
4122   - //================================================================
4123   - //================================================================
4124   - // Read tables
4125   - //================================================================
4126   - //================================================================
4127   - //================================================================
4128   -
4129   - test_try("Read Table");
4130   - try{
4131   - // Open FITS file
4132   - GFits fits;
4133   - fits.open(filename);
4134   -
4135   - // Set number of rows
4136   - int nrows = 10;
4137   - int nvec = 10;
4138   -
4139   - // Initial control sums
4140   - float tot_flt = 0.0;
4141   - double tot_dbl = 0.0;
4142   - int tot_int = 0;
4143   - long long tot_lng = 0;
4144   - std::string tot_str;
4145   -
4146   - //
4147   - // ===== L O N G L O N G =====
4148   - //
4149   - GFitsTableLongLongCol* col_lng = NULL;
4150   - test_try("LongLong");
4151   - try {
4152   - // Get column
4153   - col_lng = (GFitsTableLongLongCol*)&(*fits.table(1))["LONGLONG"];
4154   -
4155   - // Check string table (operator access)
4156   - test_try("Check table (operator access)");
4157   - try {
4158   - tot_lng = 0;
4159   - for (int i = 0; i < nrows; ++i)
4160   - tot_lng += (*col_lng)(i);
4161   - if (tot_lng != sum_lng) {
4162   - throw exception_failure("GFitsTableLongLongCol::operator() : Reference sum: "+str(sum_lng)+" Derived sum: "+str(tot_lng));
4163   - }
4164   -
4165   - test_try_success();
4166   - }
4167   - catch(std::exception &e)
4168   - {
4169   - test_try_failure(e);
4170   - }
4171   -
4172   -
4173   - // Check table (real access)
4174   - test_try("Check table (real access)");
4175   - try{
4176   - tot_dbl = 0.0;
4177   - for (int i = 0; i < nrows; ++i)
4178   - tot_dbl += col_lng->real(i);
4179   - if (!dequal(tot_dbl, double(sum_lng))) {
4180   - throw exception_failure("GFitsTableLongLongCol::real() : Reference sum: "+str(sum_lng)+"Derived sum:"+str(tot_dbl));
4181   - }
4182   - test_try_success();
4183   - }
4184   - catch(std::exception &e)
4185   - {
4186   - test_try_failure(e);
4187   - }
4188   -
4189   - // Check string table (int access)
4190   - test_try("Check table (int access)");
4191   - try{
4192   - tot_int = 0;
4193   - for (int i = 0; i < nrows; ++i)
4194   - tot_int += col_lng->integer(i);
4195   - if (tot_int != sum_lng_int) {
4196   - throw exception_failure("GFitsTableLongLongCol::integer() : Reference sum: "+str(sum_lng_int)+"Derived sum:"+str(tot_int));
4197   - }
4198   - test_try_success();
4199   - }
4200   - catch(std::exception &e)
4201   - {
4202   - test_try_failure(e);
4203   - }
4204   -
4205   - // Check table (string access)
4206   - test_try("Check table (string access)");
4207   - try{
4208   - tot_str.clear();
4209   - for (int i = 0; i < nrows; ++i)
4210   - tot_str += ":"+col_lng->string(i);
4211   - if (tot_str != sum_lng_str) {
4212   - throw exception_failure("GFitsTableLongLongCol::string() : Reference sum: "+sum_lng_str+"Derived sum:"+tot_str);
4213   - }
4214   - test_try_success();
4215   - }
4216   - catch(std::exception &e)
4217   - {
4218   - test_try_failure(e);
4219   - }
4220   -
4221   - test_try_success();
4222   - }// End try logical
4223   - catch(std::exception &e)
4224   - {
4225   - test_try_failure(e);
4226   - }
4227   -
4228   - //
4229   - // ===== L O N G L O N G 1 0 =====
4230   - //
4231   - GFitsTableLongLongCol* col_lng10 = NULL;
4232   - test_try("LongLong 10");
4233   - try{
4234   - // Get column
4235   - col_lng10 = (GFitsTableLongLongCol*)&(*fits.table(1))["LONGLONG10"];
4236   - // Check table (operator access)
4237   - test_try("Check table (operator access)");
4238   - try{
4239   - tot_lng = 0;
4240   - for (int i = 0; i < nrows; ++i) {
4241   - for (int j = 0; j < nvec; ++j)
4242   - tot_lng += (*col_lng10)(i,j);
4243   - }
4244   - if (tot_lng != sum_lng10) {
4245   - throw exception_failure("GFitsTableLongLongCol::operator() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_lng));
4246   - }
4247   - test_try_success();
4248   - }
4249   - catch(std::exception &e)
4250   - {
4251   - test_try_failure(e);
4252   - }
4253   -
4254   - // Check table (real access)
4255   - test_try("Check table (real access)");
4256   - try{
4257   - tot_dbl = 0.0;
4258   - for (int i = 0; i < nrows; ++i) {
4259   - for (int j = 0; j < nvec; ++j)
4260   - tot_dbl += col_lng10->real(i,j);
4261   - }
4262   - if (!dequal(tot_dbl, sum_lng10)) {
4263   - throw exception_failure("GFitsTableLongLongCol::real() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_dbl));
4264   - }
4265   - test_try_success();
4266   - }
4267   - catch(std::exception &e)
4268   - {
4269   - test_try_failure(e);
4270   - }
4271   -
4272   - // Check table (int access)
4273   - test_try("Check table (int access)");
4274   - try{
4275   - tot_int = 0;
4276   - for (int i = 0; i < nrows; ++i) {
4277   - for (int j = 0; j < nvec; ++j)
4278   - tot_int += col_lng10->integer(i,j);
4279   - }
4280   - if (tot_int != sum_lng10_int) {
4281   - throw exception_failure("GFitsTableLongLongCol::integer() - 10 : Reference sum: "+str(sum_lng10_int)+"Derived sum:"+str(tot_int));
4282   - }
4283   - test_try_success();
4284   - }
4285   - catch(std::exception &e)
4286   - {
4287   - test_try_failure(e);
4288   - }
4289   -
4290   - // Check table (string access)
4291   - test_try("Check table (string access)");
4292   - try{
4293   - tot_str.clear();
4294   - for (int i = 0; i < nrows; ++i) {
4295   - for (int j = 0; j < nvec; ++j)
4296   - tot_str += ":"+col_lng10->string(i,j);
4297   - }
4298   - if (tot_str != sum_lng10_str) {
4299   - throw exception_failure("GFitsTableLongLongCol::string() - 10 : Reference sum: "+sum_lng10_str+"Derived sum:"+tot_str);
4300   - }
4301   - test_try_success();
4302   - }
4303   - catch(std::exception &e)
4304   - {
4305   - test_try_failure(e);
4306   - }
4307   -
4308   - test_try_success();
4309   - } //end try logical 10
4310   - catch(std::exception &e)
4311   - {
4312   - test_try_failure(e);
4313   - }
4314   -
4315   - test_try_success();
4316   - } //end try read tabe
4317   - catch(std::exception &e)
4318   - {
4319   - test_try_failure(e);
4320   - }
4321   -
4322   -
4323   -}
4324 1182  
4325 1183 /***************************************************************************
4326 1184 * @brief Test unsigned long FITS binary table
4327 1185 ***************************************************************************/
4328   -
4329 1186 void TestGFits::test_bintable_ulong(void)
4330 1187 {
4331   -
4332 1188 // Set filename
4333 1189 std::string filename = "test_bintable_ulong.fits";
4334 1190  
4335 1191 // Remove FITS file
4336   - std::string cmd = "rm -rf "+ filename;
4337   - int rc = system(cmd.c_str());
4338   -
4339   - // Allocate reference sums
4340   - unsigned long sum_lng = 0;
4341   - unsigned long sum_lng10 = 0;
4342   - unsigned long sum_lng_int = 0;
4343   - unsigned long sum_lng10_int = 0;
4344   - std::string sum_lng_str;
4345   - std::string sum_lng10_str;
4346   -
4347   - // Build tables
4348   - test_try("Build tables");
4349   - try {
4350   - // Create FITS file
4351   - GFits fits;
4352   - fits.open(filename, true);
4353   -
4354   - // Set number of rows
4355   - int nrows = 10;
4356   - int nvec = 10;
4357   -
4358   - // Initial control sums
4359   - float tot_flt = 0.0;
4360   - double tot_dbl = 0.0;
4361   - int tot_int = 0;
4362   - unsigned long tot_lng = 0;
4363   - short tot_sht = 0;
4364   - std::string tot_str;
4365   -
4366   - //
4367   - // ===== U L O N G=====
4368   - //
4369   -
4370   - GFitsTableULongCol col_lng;
4371   -
4372   - test_try("Ulong");
4373   - try{
4374   - // Set string table
4375   - test_try("Set table");
4376   - try{
4377   - col_lng = GFitsTableULongCol("ULONG", nrows);
4378   - for (int i = 0; i < nrows; ++i) {
4379   - unsigned long val_lng = (unsigned long)std::abs(100000.0 * cos(0.1*float(i)));
4380   - col_lng(i) = val_lng;
4381   - sum_lng += val_lng;
4382   - sum_lng_int += int(val_lng);
4383   - sum_lng_str += ":"+str((int)val_lng);
4384   - }
4385   - test_try_success();
4386   - }
4387   - catch(std::exception &e)
4388   - {
4389   - test_try_failure(e);
4390   - }
4391   -
4392   - // Check string table (operator access)
4393   - test_try("Check table (operator access)");
4394   - try{
4395   - tot_lng = 0;
4396   - for (int i = 0; i < nrows; ++i)
4397   - tot_lng += col_lng(i);
4398   - if (tot_lng != sum_lng) {
4399   - throw exception_failure("GFitsTableULongCol::operator() : Reference sum: "+str(sum_lng)+" Derived sum: "+str(tot_lng));
4400   - }
4401   - test_try_success();
4402   - }
4403   - catch(std::exception &e)
4404   - {
4405   - test_try_failure(e);
4406   - }
4407   -
4408   - // Check string table (real access)
4409   - test_try("Check table (real access)");
4410   - try{
4411   - tot_dbl = 0.0;
4412   - for (int i = 0; i < nrows; ++i)
4413   - tot_dbl += col_lng.real(i);
4414   - if (!dequal(tot_dbl, double(sum_lng))) {
4415   - throw exception_failure("GFitsTableULongCol::real() : Reference sum: "+str(sum_lng)+"Derived sum:"+str(tot_dbl));
4416   - }
4417   - test_try_success();
4418   - }
4419   - catch(std::exception &e)
4420   - {
4421   - test_try_failure(e);
4422   - }
4423   -
4424   - // Check string table (int access)
4425   - test_try("Check table (int access)");
4426   - try{
4427   - tot_int = 0;
4428   - for (int i = 0; i < nrows; ++i)
4429   - tot_int += col_lng.integer(i);
4430   - if (tot_int != sum_lng_int) {
4431   - throw exception_failure("GFitsTableULongCol::integer() : Reference sum: "+str(sum_lng_int)+"Derived sum:"+str(tot_int));
4432   - }
4433   - test_try_success();
4434   - }
4435   - catch(std::exception &e)
4436   - {
4437   - test_try_failure(e);
4438   - }
4439   -
4440   - // Check table (string access)
4441   - test_try("Check table (string access)");
4442   - try{
4443   - tot_str.clear();
4444   - for (int i = 0; i < nrows; ++i)
4445   - tot_str += ":"+col_lng.string(i);
4446   - if (tot_str != sum_lng_str) {
4447   - throw exception_failure("GFitsTableULongCol::string() : Reference sum: "+sum_lng_str+"Derived sum:"+tot_str);
4448   - }
4449   - test_try_success();
4450   - }
4451   - catch(std::exception &e)
4452   - {
4453   - test_try_failure(e);
4454   - }
4455   - test_try_success();
4456   - } // End try ulong
4457   - catch(std::exception &e)
4458   - {
4459   - test_try_failure(e);
4460   - }
4461   -
4462   - //
4463   - // ===== U L O N G 1 0 =====
4464   - //
4465   -
4466   - GFitsTableULongCol col_lng10;
4467   -
4468   - test_try("Ulong 10");
4469   - try{
4470   -
4471   - // Set table
4472   - test_try("Set table");
4473   - try{
4474   - col_lng10 = GFitsTableULongCol("ULONG10", nrows,nvec);
4475   - for (int i = 0; i < nrows; ++i) {
4476   - for (int j = 0; j < nvec; ++j) {
4477   - unsigned long val_lng = (unsigned long)std::abs(1000.0*cos(0.1*float(i))*
4478   - cos(0.33*float(j)));
4479   - col_lng10(i,j) = val_lng;
4480   - sum_lng10 += val_lng;
4481   - sum_lng10_int += int(val_lng);
4482   - sum_lng10_str += ":"+str((int)val_lng);
4483   - }
4484   - }
4485   - test_try_success();
4486   - }
4487   - catch(std::exception &e)
4488   - {
4489   - test_try_failure(e);
4490   - }
4491   -
4492   - // Check table (operator access)
4493   - test_try("Check table (operator access)");
4494   - try{
4495   - tot_lng = 0;
4496   - for (int i = 0; i < nrows; ++i) {
4497   - for (int j = 0; j < nvec; ++j)
4498   - tot_lng += col_lng10(i,j);
4499   - }
4500   - if (tot_lng != sum_lng10) {
4501   - throw exception_failure("GFitsTableULongCol::operator() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_lng));
4502   - }
4503   - test_try_success();
4504   - }
4505   - catch(std::exception &e)
4506   - {
4507   - test_try_failure(e);
4508   - }
4509   -
4510   - // Check table (real access)
4511   - test_try("Check table (real access)");
4512   - try{
4513   - tot_dbl = 0.0;
4514   - for (int i = 0; i < nrows; ++i) {
4515   - for (int j = 0; j < nvec; ++j)
4516   - tot_dbl += col_lng10.real(i,j);
4517   - }
4518   - if (!dequal(tot_dbl, sum_lng10)) {
4519   - throw exception_failure("GFitsTableULongCol::real() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_dbl));
4520   - }
4521   - test_try_success();
4522   - }
4523   - catch(std::exception &e)
4524   - {
4525   - test_try_failure(e);
4526   - }
4527   -
4528   - // Check table (int access)
4529   - test_try("Check table (int access)");
4530   - try{
4531   - tot_int = 0;
4532   - for (int i = 0; i < nrows; ++i) {
4533   - for (int j = 0; j < nvec; ++j)
4534   - tot_int += col_lng10.integer(i,j);
4535   - }
4536   - if (tot_int != sum_lng10_int) {
4537   - throw exception_failure("GFitsTableULongCol::integer() - 10 : Reference sum: "+str(sum_lng10_int)+"Derived sum:"+str(tot_int));
4538   - }
4539   - test_try_success();
4540   - }
4541   - catch(std::exception &e)
4542   - {
4543   - test_try_failure(e);
4544   - }
4545   -
4546   - // Check table (string access)
4547   - test_try("Check table (string access)");
4548   - try{
4549   - tot_str.clear();
4550   - for (int i = 0; i < nrows; ++i) {
4551   - for (int j = 0; j < nvec; ++j)
4552   - tot_str += ":"+col_lng10.string(i,j);
4553   - }
4554   - if (tot_str != sum_lng10_str) {
4555   - throw exception_failure("GFitsTableULongCol::string() - 10 : Reference sum: "+sum_lng10_str+"Derived sum:"+tot_str);
4556   - }
4557   - test_try_success();
4558   - }
4559   - catch(std::exception &e)
4560   - {
4561   - test_try_failure(e);
4562   - }
4563   - test_try_success();
4564   - } // end try ulong 10
4565   - catch(std::exception &e)
4566   - {
4567   - test_try_failure(e);
4568   - }
4569   -
4570   - //
4571   - // ===== W R I T E T A B L E =====
4572   - //
4573   - test_try("Write Table");
4574   - try{
4575   - // Build binary table
4576   - GFitsBinTable table = GFitsBinTable(nrows);
4577   - table.append_column(col_lng);
4578   - table.insert_column(99, col_lng10);
4579   -
4580   - // Append to file
4581   - fits.append(table);
4582   -
4583   - // Save FITS file
4584   - fits.save();
4585   -
4586   - test_try_success();
4587   - }
4588   - catch(std::exception &e)
4589   - {
4590   - test_try_failure(e);
4591   - }
4592   -
4593   - test_try_success();
4594   - } //end try build table
4595   - catch(std::exception &e)
4596   - {
4597   - test_try_failure(e);
4598   - }
4599   -
4600   - //================================================================
4601   - //================================================================
4602   - //================================================================
4603   - // Read tables
4604   - //================================================================
4605   - //================================================================
4606   - //================================================================
4607   -
4608   - test_try("Read Table");
4609   - try{
4610   - // Open FITS file
4611   - GFits fits;
4612   - fits.open(filename);
4613   -
4614   - // Set number of rows
4615   - int nrows = 10;
4616   - int nvec = 10;
4617   -
4618   - // Initial control sums
4619   - float tot_flt = 0.0;
4620   - double tot_dbl = 0.0;
4621   - int tot_int = 0;
4622   - unsigned long tot_lng = 0;
4623   - std::string tot_str;
4624   -
4625   - //
4626   - // ===== U L O N G =====
4627   - //
4628   - GFitsTableULongCol* col_lng = NULL;
4629   - test_try("ULong");
4630   - try {
4631   - // Get column
4632   - col_lng = (GFitsTableULongCol*)&(*fits.table(1))["ULONG"];
4633   -
4634   - // Check string table (operator access)
4635   - test_try("Check table (operator access)");
4636   - try {
4637   - tot_lng = 0;
4638   - for (int i = 0; i < nrows; ++i)
4639   - tot_lng += (*col_lng)(i);
4640   - if (tot_lng != sum_lng) {
4641   - throw exception_failure("GFitsTableULongCol::operator() : Reference sum: "+str(sum_lng)+" Derived sum: "+str(tot_lng));
4642   - }
4643   -
4644   - test_try_success();
4645   - }
4646   - catch(std::exception &e)
4647   - {
4648   - test_try_failure(e);
4649   - }
4650   -
4651   -
4652   - // Check table (real access)
4653   - test_try("Check table (real access)");
4654   - try{
4655   - tot_dbl = 0.0;
4656   - for (int i = 0; i < nrows; ++i)
4657   - tot_dbl += col_lng->real(i);
4658   - if (!dequal(tot_dbl, double(sum_lng))) {
4659   - throw exception_failure("GFitsTableULongCol::real() : Reference sum: "+str(sum_lng)+"Derived sum:"+str(tot_dbl));
4660   - }
4661   - test_try_success();
4662   - }
4663   - catch(std::exception &e)
4664   - {
4665   - test_try_failure(e);
4666   - }
4667   -
4668   - // Check string table (int access)
4669   - test_try("Check table (int access)");
4670   - try{
4671   - tot_int = 0;
4672   - for (int i = 0; i < nrows; ++i)
4673   - tot_int += col_lng->integer(i);
4674   - if (tot_int != sum_lng_int) {
4675   - throw exception_failure("GFitsTableULongCol::integer() : Reference sum: "+str(sum_lng_int)+"Derived sum:"+str(tot_int));
4676   - }
4677   - test_try_success();
4678   - }
4679   - catch(std::exception &e)
4680   - {
4681   - test_try_failure(e);
4682   - }
4683   -
4684   - // Check table (string access)
4685   - test_try("Check table (string access)");
4686   - try{
4687   - tot_str.clear();
4688   - for (int i = 0; i < nrows; ++i)
4689   - tot_str += ":"+col_lng->string(i);
4690   - if (tot_str != sum_lng_str) {
4691   - throw exception_failure("GFitsTableULongCol::string() : Reference sum: "+sum_lng_str+"Derived sum:"+tot_str);
4692   - }
4693   - test_try_success();
4694   - }
4695   - catch(std::exception &e)
4696   - {
4697   - test_try_failure(e);
4698   - }
4699   -
4700   - test_try_success();
4701   - }// End try logical
4702   - catch(std::exception &e)
4703   - {
4704   - test_try_failure(e);
4705   - }
4706   -
4707   - //
4708   - // ===== U L O N G 1 0 =====
4709   - //
4710   - GFitsTableULongCol* col_lng10 = NULL;
4711   - test_try("ULong 10");
4712   - try{
4713   - // Get column
4714   - col_lng10 = (GFitsTableULongCol*)&(*fits.table(1))["ULONG10"];
4715   - // Check table (operator access)
4716   - test_try("Check table (operator access)");
4717   - try{
4718   - tot_lng = 0;
4719   - for (int i = 0; i < nrows; ++i) {
4720   - for (int j = 0; j < nvec; ++j)
4721   - tot_lng += (*col_lng10)(i,j);
4722   - }
4723   - if (tot_lng != sum_lng10) {
4724   - throw exception_failure("GFitsTableULongCol::operator() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_lng));
4725   - }
4726   - test_try_success();
4727   - }
4728   - catch(std::exception &e)
4729   - {
4730   - test_try_failure(e);
4731   - }
4732   -
4733   - // Check table (real access)
4734   - test_try("Check table (real access)");
4735   - try{
4736   - tot_dbl = 0.0;
4737   - for (int i = 0; i < nrows; ++i) {
4738   - for (int j = 0; j < nvec; ++j)
4739   - tot_dbl += col_lng10->real(i,j);
4740   - }
4741   - if (!dequal(tot_dbl, sum_lng10)) {
4742   - throw exception_failure("GFitsTableULongCol::real() - 10 : Reference sum: "+str(sum_lng10)+"Derived sum:"+str(tot_dbl));
4743   - }
4744   - test_try_success();
4745   - }
4746   - catch(std::exception &e)
4747   - {
4748   - test_try_failure(e);
4749   - }
4750   -
4751   - // Check table (int access)
4752   - test_try("Check table (int access)");
4753   - try{
4754   - tot_int = 0;
4755   - for (int i = 0; i < nrows; ++i) {
4756   - for (int j = 0; j < nvec; ++j)
4757   - tot_int += col_lng10->integer(i,j);
4758   - }
4759   - if (tot_int != sum_lng10_int) {
4760   - throw exception_failure("GFitsTableULongCol::integer() - 10 : Reference sum: "+str(sum_lng10_int)+"Derived sum:"+str(tot_int));
4761   - }
4762   - test_try_success();
4763   - }
4764   - catch(std::exception &e)
4765   - {
4766   - test_try_failure(e);
4767   - }
4768   -
4769   - // Check table (string access)
4770   - test_try("Check table (string access)");
4771   - try{
4772   - tot_str.clear();
4773   - for (int i = 0; i < nrows; ++i) {
4774   - for (int j = 0; j < nvec; ++j)
4775   - tot_str += ":"+col_lng10->string(i,j);
4776   - }
4777   - if (tot_str != sum_lng10_str) {
4778   - throw exception_failure("GFitsTableULongCol::string() - 10 : Reference sum: "+sum_lng10_str+"Derived sum:"+tot_str);
4779   - }
4780   - test_try_success();
4781   - }
4782   - catch(std::exception &e)
4783   - {
4784   - test_try_failure(e);
4785   - }
4786   -
4787   - test_try_success();
4788   - } //end try logical 10
4789   - catch(std::exception &e)
4790   - {
4791   - test_try_failure(e);
4792   - }
4793   -
  1192 + std::string cmd = "rm -rf "+ filename;
  1193 + int rc = system(cmd.c_str());
  1194 +
  1195 + // Set number of rows and vector columns
  1196 + int nrows = 3;
  1197 + int nvec = 3;
  1198 +
  1199 + // Test single column table
  1200 + GFitsTableULongCol col1("ULONG", nrows);
  1201 + TEST_TABLE1_INT;
  1202 +
  1203 + // Test multiple column table
  1204 + GFitsTableULongCol col2("ULONG10", nrows, nvec);
  1205 + TEST_TABLE2_INT;
  1206 +
  1207 + // Write tables
  1208 + TEST_WRITE_TABLES;
  1209 +
  1210 + // Read tables back
  1211 + test_try("Read Tables");
  1212 + try {
  1213 + GFits fits(filename);
  1214 + col1 = static_cast<GFitsTableULongCol&>((*fits.table(1))["ULONG"]);
  1215 + col2 = static_cast<GFitsTableULongCol&>((*fits.table(1))["ULONG10"]);
  1216 + fits.close();
4794 1217 test_try_success();
4795   - } //end try read tabe
4796   - catch(std::exception &e)
4797   - {
  1218 + }
  1219 + catch(std::exception &e) {
4798 1220 test_try_failure(e);
4799 1221 }
4800 1222  
  1223 + // Test single column table
  1224 + TEST_TABLE1_INT;
  1225 +
  1226 + // Test multiple column table
  1227 + TEST_TABLE2_INT;
4801 1228  
  1229 + // Return
  1230 + return;
4802 1231 }
4803 1232  
  1233 +
4804 1234 /***************************************************************************
4805 1235 * @brief Test string FITS binary table
4806 1236 ***************************************************************************/
4807   - void TestGFits::test_bintable_string(void)
  1237 +void TestGFits::test_bintable_string(void)
4808 1238 {
4809   -
4810 1239 // Set filename
4811 1240 std::string filename = "test_bintable_string.fits";
4812 1241  
... ... @@ -4814,475 +1243,50 @@ void TestGFits::test_bintable_ulong(void)
4814 1243 std::string cmd = "rm -rf "+ filename;
4815 1244 int rc = system(cmd.c_str());
4816 1245  
4817   - // Allocate reference sums
4818   - std::string sum_str;
4819   - std::string sum_str10;
4820   - double sum_str_dbl = 0;
4821   - double sum_str10_dbl = 0;
4822   - double sum_str_int = 0;
4823   - double sum_str10_int = 0;
4824   -
4825   - // Build tables
4826   - test_try("Build tables");
4827   - try {
4828   - // Create FITS file
4829   - GFits fits;
4830   - fits.open(filename, true);
4831   -
4832   - // Set number of rows
4833   - int nrows = 10;
4834   - int nvec = 10;
4835   -
4836   - // Initial control sums
4837   - float tot_flt = 0.0;
4838   - double tot_dbl = 0.0;
4839   - int tot_int = 0;
4840   - long tot_lng = 0;
4841   - std::string tot_str;
4842   -
4843   - //
4844   - // ===== S T R I N G =====
4845   - //
4846   -
4847   - GFitsTableStringCol col_str;
4848   -
4849   - test_try("String");
4850   - try{
4851   - // Set string table
4852   - test_try("Set table");
4853   - try{
4854   - col_str = GFitsTableStringCol("STRING", nrows, 20);
4855   - for (int i = 0; i < nrows; ++i) {
4856   - double val_dbl = 100.0 * cos(0.1*double(i));
4857   - col_str(i) = str(val_dbl);
4858   - sum_str += ":" + str(val_dbl);
4859   - sum_str_dbl += val_dbl;
4860   - sum_str_int += int(val_dbl);
4861   - }
4862   - test_try_success();
4863   - }
4864   - catch(std::exception &e)
4865   - {
4866   - test_try_failure(e);
4867   - }
4868   -
4869   - // Check string table (operator access)
4870   - test_try("Check table (operator access)");
4871   - try{
4872   - tot_str.clear();
4873   - for (int i = 0; i < nrows; ++i)
4874   - tot_str += ":" + col_str(i);
4875   - if (tot_str != sum_str) {
4876   - throw exception_failure("GFitsTableStringCol::operator() : Reference sum: "+sum_str+" Derived sum: "+tot_str);
4877   - }
4878   - test_try_success();
4879   - }
4880   - catch(std::exception &e)
4881   - {
4882   - test_try_failure(e);
4883   - }
4884   -
4885   - // Check string table (real access)
4886   - test_try("Check table (real access)");
4887   - try{
4888   - tot_dbl = 0.0;
4889   - tot_dbl = 0.0;
4890   - for (int i = 0; i < nrows; ++i)
4891   - tot_dbl += col_str.real(i);
4892   - if (!equal(tot_dbl, sum_str_dbl, 1.0e-2)) {
4893   - throw exception_failure("GFitsTableStringCol::real() : Reference sum: "+str(sum_str_dbl)+"Derived sum:"+str(tot_dbl));
4894   - }
4895   - test_try_success();
4896   - }
4897   - catch(std::exception &e)
4898   - {
4899   - test_try_failure(e);
4900   - }
4901   -
4902   - // Check string table (int access)
4903   - test_try("Check table (int access)");
4904   - try{
4905   - tot_int = 0;
4906   - for (int i = 0; i < nrows; ++i)
4907   - tot_int += col_str.integer(i);
4908   - if (tot_int != sum_str_int) {
4909   - throw exception_failure("GFitsTableStringCol::integer() : Reference sum: "+str(sum_str_int)+"Derived sum:"+str(tot_int));
4910   - }
4911   - test_try_success();
4912   - }
4913   - catch(std::exception &e)
4914   - {
4915   - test_try_failure(e);
4916   - }
4917   -
4918   - // Check table (string access)
4919   - test_try("Check table (string access)");
4920   - try{
4921   - tot_str.clear();
4922   - for (int i = 0; i < nrows; ++i)
4923   - tot_str += ":"+col_str.string(i);
4924   - if (tot_str != sum_str) {
4925   - throw exception_failure("GFitsTableBoolCol::string() : Reference sum: "+sum_str+"Derived sum:"+tot_str);
4926   - }
4927   - test_try_success();
4928   - }
4929   - catch(std::exception &e)
4930   - {
4931   - test_try_failure(e);
4932   - }
4933   - test_try_success();
4934   - } // End try logical
4935   - catch(std::exception &e)
4936   - {
4937   - test_try_failure(e);
4938   - }
4939   -
4940   - //
4941   - // ===== S T R I N G 1 0 =====
4942   - //
4943   -
4944   - GFitsTableStringCol col_str10;
4945   -
4946   - test_try("String 10");
4947   - try{
4948   -
4949   - // Set table
4950   - test_try("Set table");
4951   - try{
4952   - col_str10 = GFitsTableStringCol("STRING10", nrows, 20, nvec);
4953   - for (int i = 0; i < nrows; ++i) {
4954   - for (int j = 0; j < nvec; ++j) {
4955   - double val_dbl = 100.0 * cos(0.1*double(i)) * cos(0.3*double(j));
4956   - col_str10(i,j) = str(val_dbl);
4957   - sum_str10 += ":" + str(val_dbl);
4958   - sum_str10_dbl += val_dbl;
4959   - sum_str10_int += int(val_dbl);
4960   - }
4961   - }
4962   - test_try_success();
4963   - }
4964   - catch(std::exception &e)
4965   - {
4966   - test_try_failure(e);
4967   - }
4968   -
4969   - // Check table (operator access)
4970   - test_try("Check table (operator access)");
4971   - try{
4972   - tot_str.clear();
4973   - for (int i = 0; i < nrows; ++i) {
4974   - for (int j = 0; j < nvec; ++j)
4975   - tot_str += ":" + col_str10(i,j);
4976   - }
4977   - if (tot_str != sum_str10) {
4978   - throw exception_failure("GFitsTableStringCol::operator() - 10 : Reference sum: "+sum_str10+"Derived sum:"+tot_str);
4979   - }
4980   - test_try_success();
4981   - }
4982   - catch(std::exception &e)
4983   - {
4984   - test_try_failure(e);
4985   - }
4986   -
4987   - // Check table (real access)
4988   - test_try("Check table (real access)");
4989   - try{
4990   - tot_dbl = 0.0;
4991   - for (int i = 0; i < nrows; ++i) {
4992   - for (int j = 0; j < nvec; ++j)
4993   - tot_dbl += col_str10.real(i,j);
4994   - }
4995   - if (!equal(tot_dbl, sum_str10_dbl, 1.0e-2)) {
4996   - throw exception_failure("GFitsTableStringCol::real() - 10 : Reference sum: "+str(sum_str10_dbl)+"Derived sum:"+str(tot_dbl));
4997   - }
4998   - test_try_success();
4999   - }
5000   - catch(std::exception &e)
5001   - {
5002   - test_try_failure(e);
5003   - }
5004   -
5005   - // Check table (int access)
5006   - test_try("Check table (int access)");
5007   - try{
5008   - tot_int = 0;
5009   - for (int i = 0; i < nrows; ++i) {
5010   - for (int j = 0; j < nvec; ++j)
5011   - tot_int += col_str10.integer(i,j);
5012   - }
5013   - if (tot_int != sum_str10_int) {
5014   - throw exception_failure("GFitsTableStringCol::integer() - 10 : Reference sum: "+str(sum_str10_int)+"Derived sum:"+str(tot_int));
5015   - }
5016   - test_try_success();
5017   - }
5018   - catch(std::exception &e)
5019   - {
5020   - test_try_failure(e);
5021   - }
5022   -
5023   - // Check table (string access)
5024   - test_try("Check table (string access)");
5025   - try{
5026   - tot_str.clear();
5027   - for (int i = 0; i < nrows; ++i) {
5028   - for (int j = 0; j < nvec; ++j)
5029   - tot_str += ":"+col_str10.string(i,j);
5030   - }
5031   - if (tot_str != sum_str10) {
5032   - throw exception_failure("GFitsTableStringCol::string() - 10 : Reference sum: "+sum_str10+"Derived sum:"+tot_str);
5033   - }
5034   - test_try_success();
5035   - }
5036   - catch(std::exception &e)
5037   - {
5038   - test_try_failure(e);
5039   - }
5040   - test_try_success();
5041   - } // end try string 10
5042   - catch(std::exception &e)
5043   - {
5044   - test_try_failure(e);
5045   - }
  1246 + // Set number of rows and vector columns
  1247 + int nrows = 3;
  1248 + int nvec = 3;
5046 1249  
5047   - //
5048   - // ===== W R I T E T A B L E =====
5049   - //
5050   - test_try("Write Table");
5051   - try{
5052   - // Build binary table
5053   - GFitsBinTable table = GFitsBinTable(nrows);
5054   - table.append_column(col_str);
5055   - table.insert_column(0, col_str10);
5056   -
5057   - // Append to file
5058   - fits.append(table);
5059   -
5060   - // Save FITS file
5061   - fits.save();
5062   -
5063   - test_try_success();
5064   - }
5065   - catch(std::exception &e)
5066   - {
5067   - test_try_failure(e);
5068   - }
5069   -
5070   - test_try_success();
5071   - } //end try build table
5072   - catch(std::exception &e)
5073   - {
5074   - test_try_failure(e);
5075   - }
  1250 + // Test single column table
  1251 + GFitsTableStringCol col1("STRING", nrows, 20);
  1252 + TEST_TABLE1_STRING;
5076 1253  
5077   - //================================================================
5078   - //================================================================
5079   - //================================================================
5080   - // Read tables
5081   - //================================================================
5082   - //================================================================
5083   - //================================================================
5084   -
5085   - test_try("Read Table");
5086   - try{
5087   - // Open FITS file
5088   - GFits fits;
5089   - fits.open(filename);
  1254 + // Test multiple column table
  1255 + GFitsTableStringCol col2("STRING10", nrows, 20, nvec);
  1256 + TEST_TABLE2_STRING;
5090 1257  
5091   - // Set number of rows
5092   - int nrows = 10;
5093   - int nvec = 10;
  1258 + // Write tables
  1259 + TEST_WRITE_TABLES;
5094 1260  
5095   - // Initial control sums
5096   - float tot_flt = 0.0;
5097   - double tot_dbl = 0.0;
5098   - int tot_int = 0;
5099   - std::string tot_str;
5100   -
5101   - //
5102   - // ===== L O G I C A L =====
5103   - //
5104   - GFitsTableStringCol* col_str = NULL;
5105   - test_try("String");
5106   - try {
5107   - // Get column
5108   - col_str = (GFitsTableStringCol*)&(*fits.table(1))["STRING"];
5109   -
5110   - // Check string table (operator access)
5111   - test_try("Check table (operator access)");
5112   - try {
5113   - tot_str.clear();
5114   - for (int i = 0; i < nrows; ++i)
5115   - tot_str += ":" + (*col_str)(i);
5116   - if (tot_str != sum_str) {
5117   - throw exception_failure("GFitsTableStringCol::operator() : Reference sum: "+sum_str+" Derived sum: "+tot_str);
5118   - }
5119   -
5120   - test_try_success();
5121   - }
5122   - catch(std::exception &e)
5123   - {
5124   - test_try_failure(e);
5125   - }
5126   -
5127   -
5128   - // Check table (real access)
5129   - test_try("Check table (real access)");
5130   - try{
5131   - tot_dbl = 0.0;
5132   - for (int i = 0; i < nrows; ++i)
5133   - tot_dbl += col_str->real(i);
5134   - if (!equal(tot_dbl, sum_str_dbl, 1.0e-2)) {
5135   - throw exception_failure("GFitsTableStringCol::real() : Reference sum: "+str(sum_str_dbl)+"Derived sum:"+str(tot_dbl));
5136   - }
5137   - test_try_success();
5138   - }
5139   - catch(std::exception &e)
5140   - {
5141   - test_try_failure(e);
5142   - }
5143   -
5144   - // Check string table (int access)
5145   - test_try("Check table (int access)");
5146   - try{
5147   - tot_int = 0;
5148   - for (int i = 0; i < nrows; ++i)
5149   - tot_int += col_str->integer(i);
5150   - if (tot_int != sum_str_int) {
5151   - throw exception_failure("GFitsTableStringCol::integer() : Reference sum: "+str(sum_str_int)+"Derived sum:"+str(tot_int));
5152   - }
5153   - test_try_success();
5154   - }
5155   - catch(std::exception &e)
5156   - {
5157   - test_try_failure(e);
5158   - }
5159   -
5160   - // Check table (string access)
5161   - test_try("Check table (string access)");
5162   - try{
5163   - tot_str.clear();
5164   - for (int i = 0; i < nrows; ++i)
5165   - tot_str += ":"+col_str->string(i);
5166   - if (tot_str != sum_str) {
5167   - throw exception_failure("GFitsTableStringCol::string() : Reference sum: "+sum_str+"Derived sum:"+tot_str);
5168   - }
5169   - test_try_success();
5170   - }
5171   - catch(std::exception &e)
5172   - {
5173   - test_try_failure(e);
5174   - }
5175   -
5176   - test_try_success();
5177   - }// End try logical
5178   - catch(std::exception &e)
5179   - {
5180   - test_try_failure(e);
5181   - }
5182   -
5183   - //
5184   - // ===== S T R I N G 1 0 =====
5185   - //
5186   - GFitsTableStringCol* col_str10 = NULL;
5187   - test_try("String 10");
5188   - try{
5189   - // Get column
5190   - col_str10 = (GFitsTableStringCol*)&(*fits.table(1))["STRING10"];
5191   - // Check table (operator access)
5192   - test_try("Check table (operator access)");
5193   - try{
5194   - tot_str.clear();
5195   - for (int i = 0; i < nrows; ++i) {
5196   - for (int j = 0; j < nvec; ++j)
5197   - tot_str += ":" + (*col_str10)(i,j);
5198   - }
5199   - if (tot_str != sum_str10) {
5200   - throw exception_failure("GFitsTableStringCol::operator() - 10 : Reference sum: "+sum_str10+"Derived sum:"+tot_str);
5201   - }
5202   - test_try_success();
5203   - }
5204   - catch(std::exception &e)
5205   - {
5206   - test_try_failure(e);
5207   - }
5208   -
5209   - // Check string table (real access)
5210   - test_try("Check table (real access)");
5211   - try{
5212   - tot_dbl = 0.0;
5213   - for (int i = 0; i < nrows; ++i) {
5214   - for (int j = 0; j < nvec; ++j)
5215   - tot_dbl += col_str10->real(i,j);
5216   - }
5217   - if (!equal(tot_dbl, sum_str10_dbl, 1.0e-2)) {
5218   - throw exception_failure("GFitsTableStringCol::real() - 10 : Reference sum: "+str(sum_str10_dbl)+"Derived sum:"+str(tot_dbl));
5219   - }
5220   - test_try_success();
5221   - }
5222   - catch(std::exception &e)
5223   - {
5224   - test_try_failure(e);
5225   - }
5226   -
5227   - // Check table (int access)
5228   - test_try("Check table (int access)");
5229   - try{
5230   - tot_int = 0;
5231   - for (int i = 0; i < nrows; ++i) {
5232   - for (int j = 0; j < nvec; ++j)
5233   - tot_int += col_str10->integer(i,j);
5234   - }
5235   - if (tot_int != sum_str10_int) {
5236   - throw exception_failure("GFitsTableStringCol::integer() - 10 : Reference sum: "+str(sum_str10_int)+"Derived sum:"+str(tot_int));
5237   - }
5238   - test_try_success();
5239   - }
5240   - catch(std::exception &e)
5241   - {
5242   - test_try_failure(e);
5243   - }
5244   -
5245   - // Check table (string access)
5246   - test_try("Check table (string access)");
5247   - try{
5248   - tot_str.clear();
5249   - for (int i = 0; i < nrows; ++i) {
5250   - for (int j = 0; j < nvec; ++j)
5251   - tot_str += ":"+col_str10->string(i,j);
5252   - }
5253   - if (tot_str != sum_str10) {
5254   - throw exception_failure("GFitsTableStringCol::string() - 10 : Reference sum: "+sum_str10+"Derived sum:"+tot_str);
5255   - }
5256   - test_try_success();
5257   - }
5258   - catch(std::exception &e)
5259   - {
5260   - test_try_failure(e);
5261   - }
5262   -
5263   - test_try_success();
5264   - } //end try logical 10
5265   - catch(std::exception &e)
5266   - {
5267   - test_try_failure(e);
5268   - }
5269   -
  1261 + // Read tables back
  1262 + test_try("Read Tables");
  1263 + try {
  1264 + GFits fits(filename);
  1265 + col1 = static_cast<GFitsTableStringCol&>((*fits.table(1))["STRING"]);
  1266 + col2 = static_cast<GFitsTableStringCol&>((*fits.table(1))["STRING10"]);
  1267 + fits.close();
5270 1268 test_try_success();
5271   - } //end try read tabe
5272   - catch(std::exception &e)
5273   - {
  1269 + }
  1270 + catch(std::exception &e) {
5274 1271 test_try_failure(e);
5275 1272 }
5276 1273  
  1274 + // Test single column table
  1275 + TEST_TABLE1_STRING;
5277 1276  
  1277 + // Test multiple column table
  1278 + TEST_TABLE2_STRING;
  1279 +
  1280 + // Return
  1281 + return;
5278 1282 }
5279 1283  
  1284 +
5280 1285 /***************************************************************************
5281 1286 * @brief Test boolean FITS binary table
5282 1287 ***************************************************************************/
5283 1288 void TestGFits::test_bintable_logical(void)
5284 1289 {
5285   -
5286 1290 // Set filename
5287 1291 std::string filename = "test_bintable_logical.fits";
5288 1292  
... ... @@ -5290,477 +1294,45 @@ void TestGFits::test_bintable_logical(void)
5290 1294 std::string cmd = "rm -rf "+ filename;
5291 1295 int rc = system(cmd.c_str());
5292 1296  
5293   - // Allocate reference sums
5294   - int sum = 0;
5295   - int sum10 = 0;
5296   - int sum_int = 0;
5297   - int sum10_int = 0;
5298   - std::string sum_str;
5299   - std::string sum10_str;
5300   -
5301   - // Build tables
5302   - test_try("Build tables");
5303   - try {
5304   - // Create FITS file
5305   - GFits fits;
5306   - fits.open(filename, true);
5307   -
5308   - // Set number of rows
5309   - int nrows = 10;
5310   - int nvec = 10;
5311   -
5312   - // Initial control sums
5313   - float tot_flt = 0.0;
5314   - double tot_dbl = 0.0;
5315   - int tot_int = 0;
5316   - long tot_lng = 0;
5317   - std::string tot_str;
5318   -
5319   - //
5320   - // ===== L O G I C A L =====
5321   - //
5322   -
5323   - GFitsTableBoolCol col;
5324   -
5325   - test_try("Logical");
5326   - try{
5327   - // Set table
5328   - test_try("Set table");
5329   - try{
5330   - col = GFitsTableBoolCol("LOGICAL", nrows);
5331   - for (int i = 0; i < nrows; ++i) {
5332   - bool val = (i % 2) ? true : false;
5333   - col(i) = val;
5334   - sum += val;
5335   - sum_int += int(val);
5336   - if (val)
5337   - sum_str += ":T";
5338   - else
5339   - sum_str += ":F";
5340   - }
5341   - test_try_success();
5342   - }
5343   - catch(std::exception &e)
5344   - {
5345   - test_try_failure(e);
5346   - }
5347   -
5348   - // Check table (operator access)
5349   - test_try("Check table (operator access)");
5350   - try{
5351   - tot_int = 0;
5352   - for (int i = 0; i < nrows; ++i)
5353   - tot_int += col(i);
5354   - if (tot_int != sum) {
5355   - throw exception_failure("GFitsTableBoolCol::operator() : Reference sum: "+str(sum)+" Derived sum: "+str(tot_int));
5356   - }
5357   - test_try_success();
5358   - }
5359   - catch(std::exception &e)
5360   - {
5361   - test_try_failure(e);
5362   - }
5363   -
5364   - // Check table (real access)
5365   - test_try("Check table (real access)");
5366   - try{
5367   - tot_dbl = 0.0;
5368   - for (int i = 0; i < nrows; ++i)
5369   - tot_dbl += col.real(i);
5370   - if (!dequal(tot_dbl, double(sum))) {
5371   - throw exception_failure("GFitsTableBoolCol::real() : Reference sum: "+str(sum)+"Derived sum:"+str(tot_dbl));
5372   - }
5373   - test_try_success();
5374   - }
5375   - catch(std::exception &e)
5376   - {
5377   - test_try_failure(e);
5378   - }
5379   -
5380   - // Check table (int access)
5381   - test_try("Check table (int access)");
5382   - try{
5383   - tot_int = 0;
5384   - for (int i = 0; i < nrows; ++i)
5385   - tot_int += col.integer(i);
5386   - if (tot_int != sum_int) {
5387   - throw exception_failure("GFitsTableBoolCol::integer() : Reference sum: "+str(sum_int)+"Derived sum:"+str(tot_int));
5388   - }
5389   - test_try_success();
5390   - }
5391   - catch(std::exception &e)
5392   - {
5393   - test_try_failure(e);
5394   - }
5395   -
5396   - // Check table (string access)
5397   - test_try("Check table (string access)");
5398   - try{
5399   - tot_str.clear();
5400   - for (int i = 0; i < nrows; ++i)
5401   - tot_str += ":"+col.string(i);
5402   - if (tot_str != sum_str) {
5403   - throw exception_failure("GFitsTableBoolCol::string() : Reference sum: "+sum_str+"Derived sum:"+tot_str);
5404   - }
5405   - test_try_success();
5406   - }
5407   - catch(std::exception &e)
5408   - {
5409   - test_try_failure(e);
5410   - }
5411   - test_try_success();
5412   - } // End try logical
5413   - catch(std::exception &e)
5414   - {
5415   - test_try_failure(e);
5416   - }
5417   -
5418   - //
5419   - // ===== L O G I C A L 1 0 =====
5420   - //
5421   -
5422   - GFitsTableBoolCol col10;
5423   -
5424   - test_try("Logical 10");
5425   - try{
5426   -
5427   - // Set table
5428   - test_try("Set table");
5429   - try{
5430   - col10 = GFitsTableBoolCol("LOGICAL10", nrows, nvec);
5431   - for (int i = 0; i < nrows; ++i) {
5432   - for (int j = 0; j < nvec; ++j) {
5433   - char val = (i % 2) * (j % 2);
5434   - col10(i,j) = val;
5435   - sum10 += val;
5436   - sum10_int += int(val);
5437   - if (val)
5438   - sum10_str += ":T";
5439   - else
5440   - sum10_str += ":F";
5441   - }
5442   - }
5443   - test_try_success();
5444   - }
5445   - catch(std::exception &e)
5446   - {
5447   - test_try_failure(e);
5448   - }
5449   -
5450   - // Check table (operator access)
5451   - test_try("Check table (operator access)");
5452   - try{
5453   - tot_int = 0;
5454   - for (int i = 0; i < nrows; ++i) {
5455   - for (int j = 0; j < nvec; ++j)
5456   - tot_int += col10(i,j);
5457   - }
5458   - if (tot_int != sum10) {
5459   - throw exception_failure("GFitsTableBoolCol::operator() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_int));
5460   - }
5461   - test_try_success();
5462   - }
5463   - catch(std::exception &e)
5464   - {
5465   - test_try_failure(e);
5466   - }
5467   -
5468   - // Check table (real access)
5469   - test_try("Check table (real access)");
5470   - try{
5471   - tot_dbl = 0.0;
5472   - for (int i = 0; i < nrows; ++i) {
5473   - for (int j = 0; j < nvec; ++j)
5474   - tot_dbl += col10.real(i,j);
5475   - }
5476   - if (!dequal(tot_dbl, sum10)) {
5477   - throw exception_failure("GFitsTableBoolCol::real() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_dbl));
5478   - }
5479   - test_try_success();
5480   - }
5481   - catch(std::exception &e)
5482   - {
5483   - test_try_failure(e);
5484   - }
5485   -
5486   - // Check table (int access)
5487   - test_try("Check table (int access)");
5488   - try{
5489   - tot_int = 0;
5490   - for (int i = 0; i < nrows; ++i) {
5491   - for (int j = 0; j < nvec; ++j)
5492   - tot_int += col10.integer(i,j);
5493   - }
5494   - if (tot_int != sum10_int) {
5495   - throw exception_failure("GFitsTableBoolCol::integer() - 10 : Reference sum: "+str(sum10_int)+"Derived sum:"+str(tot_int));
5496   - }
5497   - test_try_success();
5498   - }
5499   - catch(std::exception &e)
5500   - {
5501   - test_try_failure(e);
5502   - }
5503   -
5504   - // Check table (string access)
5505   - test_try("Check table (string access)");
5506   - try{
5507   - tot_str.clear();
5508   - for (int i = 0; i < nrows; ++i) {
5509   - for (int j = 0; j < nvec; ++j)
5510   - tot_str += ":"+col10.string(i,j);
5511   - }
5512   - if (tot_str != sum10_str) {
5513   - throw exception_failure("GFitsTableBoolCol::string() - 10 : Reference sum: "+sum10_str+"Derived sum:"+tot_str);
5514   - }
5515   - test_try_success();
5516   - }
5517   - catch(std::exception &e)
5518   - {
5519   - test_try_failure(e);
5520   - }
5521   - test_try_success();
5522   - } // end try logical 10
5523   - catch(std::exception &e)
5524   - {
5525   - test_try_failure(e);
5526   - }
  1297 + // Set number of rows and vector columns
  1298 + int nrows = 3;
  1299 + int nvec = 3;
5527 1300  
5528   - //
5529   - // ===== W R I T E T A B L E =====
5530   - //
5531   - test_try("Write Table");
5532   - try{
5533   - // Build binary table
5534   - GFitsBinTable table = GFitsBinTable(nrows);
5535   - table.append_column(col);
5536   - table.insert_column(0, col10);
5537   -
5538   - // Append to file
5539   - fits.append(table);
5540   -
5541   - // Save FITS file
5542   - fits.save();
5543   -
5544   - test_try_success();
5545   - }
5546   - catch(std::exception &e)
5547   - {
5548   - test_try_failure(e);
5549   - }
5550   -
5551   - test_try_success();
5552   - } //end try build table
5553   - catch(std::exception &e)
5554   - {
5555   - test_try_failure(e);
5556   - }
  1301 + // Test single column table
  1302 + GFitsTableBoolCol col1("LOGICAL", nrows);
  1303 + TEST_TABLE1_BOOL;
5557 1304  
5558   - //================================================================
5559   - //================================================================
5560   - //================================================================
5561   - // Read tables
5562   - //================================================================
5563   - //================================================================
5564   - //================================================================
5565   -
5566   - test_try("Read Table");
5567   - try{
5568   - // Open FITS file
5569   - GFits fits;
5570   - fits.open(filename);
  1305 + // Test multiple column table
  1306 + GFitsTableBoolCol col2("LOGICAL10", nrows, nvec);
  1307 + TEST_TABLE2_BOOL;
5571 1308  
5572   - // Set number of rows
5573   - int nrows = 10;
5574   - int nvec = 10;
5575   -
5576   - // Initial control sums
5577   - float tot_flt = 0.0;
5578   - short tot_sht = 0;
5579   - double tot_dbl = 0.0;
5580   - int tot_int = 0;
5581   - std::string tot_str;
5582   -
5583   - //
5584   - // ===== L O G I C A L =====
5585   - //
5586   - GFitsTableBoolCol* col = NULL;
5587   - test_try("Logical");
5588   - try {
5589   - // Get column
5590   - col = (GFitsTableBoolCol*)&(*fits.table(1))["LOGICAL"];
5591   -
5592   - // Check table (operator access)
5593   - test_try("Check table (operator access)");
5594   - try {
5595   -
5596   - tot_int = 0;
5597   -
5598   - for (int i = 0; i < nrows; ++i)
5599   - tot_int += (*col)(i);
5600   - if (tot_int != sum) {
5601   - throw exception_failure("GFitsTableBoolCol::operator() : Reference sum: "+str(sum)+" Derived sum: "+str(tot_int));
5602   - }
5603   -
5604   - test_try_success();
5605   - }
5606   - catch(std::exception &e)
5607   - {
5608   - test_try_failure(e);
5609   - }
5610   -
5611   -
5612   - // Check table (real access)
5613   - test_try("Check table (real access)");
5614   - try{
5615   - tot_dbl = 0.0;
5616   - for (int i = 0; i < nrows; ++i)
5617   - tot_dbl += col->real(i);
5618   - if (!dequal(tot_dbl, double(sum))) {
5619   - throw exception_failure("GFitsTableBoolCol::real() : Reference sum: "+str(sum)+"Derived sum:"+str(tot_dbl));
5620   - }
5621   - test_try_success();
5622   - }
5623   - catch(std::exception &e)
5624   - {
5625   - test_try_failure(e);
5626   - }
5627   -
5628   - // Check table (int access)
5629   - test_try("Check table (int access)");
5630   - try{
5631   - tot_int = 0;
5632   - for (int i = 0; i < nrows; ++i)
5633   - tot_int += col->integer(i);
5634   - if (tot_int != sum_int) {
5635   - throw exception_failure("GFitsTableBoolCol::integer() : Reference sum: "+str(sum_int)+"Derived sum:"+str(tot_int));
5636   - }
5637   - test_try_success();
5638   - }
5639   - catch(std::exception &e)
5640   - {
5641   - test_try_failure(e);
5642   - }
5643   -
5644   - // Check table (string access)
5645   - test_try("Check table (string access)");
5646   - try{
5647   - tot_str.clear();
5648   - for (int i = 0; i < nrows; ++i)
5649   - tot_str += ":"+col->string(i);
5650   - if (tot_str != sum_str) {
5651   - throw exception_failure("GFitsTableBoolCol::string() : Reference sum: "+sum_str+"Derived sum:"+tot_str);
5652   - }
5653   - test_try_success();
5654   - }
5655   - catch(std::exception &e)
5656   - {
5657   - test_try_failure(e);
5658   - }
5659   -
5660   - test_try_success();
5661   - }// End try logical
5662   - catch(std::exception &e)
5663   - {
5664   - test_try_failure(e);
5665   - }
5666   -
5667   - //
5668   - // ===== L O G I C A L 1 0 =====
5669   - //
5670   - GFitsTableBoolCol* col10 = NULL;
5671   - test_try("Logical 10");
5672   - try{
5673   - // Get column
5674   - col10 = (GFitsTableBoolCol*)&(*fits.table(1))["LOGICAL10"];
5675   - // Check table (operator access)
5676   - test_try("Check table (operator access)");
5677   - try{
5678   - tot_int = 0;
5679   - for (int i = 0; i < nrows; ++i) {
5680   - for (int j = 0; j < nvec; ++j)
5681   - tot_int += (*col10)(i,j);
5682   - }
5683   - if (tot_int != sum10) {
5684   - throw exception_failure("GFitsTableBoolCol::operator() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_int));
5685   - }
5686   - test_try_success();
5687   - }
5688   - catch(std::exception &e)
5689   - {
5690   - test_try_failure(e);
5691   - }
5692   -
5693   - // Check table (real access)
5694   - test_try("Check table (real access)");
5695   - try{
5696   - tot_dbl = 0.0;
5697   - for (int i = 0; i < nrows; ++i) {
5698   - for (int j = 0; j < nvec; ++j)
5699   - tot_dbl += col10->real(i,j);
5700   - }
5701   - if (!dequal(tot_dbl, sum10)) {
5702   - throw exception_failure("GFitsTableBoolCol::real() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_dbl));
5703   - }
5704   - test_try_success();
5705   - }
5706   - catch(std::exception &e)
5707   - {
5708   - test_try_failure(e);
5709   - }
5710   -
5711   - // Check table (int access)
5712   - test_try("Check table (int access)");
5713   - try{
5714   - tot_int = 0;
5715   - for (int i = 0; i < nrows; ++i) {
5716   - for (int j = 0; j < nvec; ++j)
5717   - tot_int += col10->integer(i,j);
5718   - }
5719   - if (tot_int != sum10_int) {
5720   - throw exception_failure("GFitsTableBoolCol::integer() - 10 : Reference sum: "+str(sum10_int)+"Derived sum:"+str(tot_int));
5721   - }
5722   - test_try_success();
5723   - }
5724   - catch(std::exception &e)
5725   - {
5726   - test_try_failure(e);
5727   - }
5728   -
5729   - // Check table (string access)
5730   - test_try("Check table (string access)");
5731   - try{
5732   - tot_str.clear();
5733   - for (int i = 0; i < nrows; ++i) {
5734   - for (int j = 0; j < nvec; ++j)
5735   - tot_str += ":"+col10->string(i,j);
5736   - }
5737   - if (tot_str != sum10_str) {
5738   - throw exception_failure("GFitsTableBoolCol::string() - 10 : Reference sum: "+sum10_str+"Derived sum:"+tot_str);
5739   - }
5740   - test_try_success();
5741   - }
5742   - catch(std::exception &e)
5743   - {
5744   - test_try_failure(e);
5745   - }
5746   -
5747   - test_try_success();
5748   - } //end try logical 10
5749   - catch(std::exception &e)
5750   - {
5751   - test_try_failure(e);
5752   - }
5753   -
  1309 + // Write tables
  1310 + TEST_WRITE_TABLES;
  1311 +
  1312 + // Read tables back
  1313 + test_try("Read Tables");
  1314 + try {
  1315 + GFits fits(filename);
  1316 + col1 = static_cast<GFitsTableBoolCol&>((*fits.table(1))["LOGICAL"]);
  1317 + col2 = static_cast<GFitsTableBoolCol&>((*fits.table(1))["LOGICAL10"]);
  1318 + fits.close();
5754 1319 test_try_success();
5755   - } //end try read tabe
5756   - catch(std::exception &e)
5757   - {
  1320 + }
  1321 + catch(std::exception &e) {
5758 1322 test_try_failure(e);
5759 1323 }
5760 1324  
  1325 + // Test single column table
  1326 + TEST_TABLE1_BOOL;
5761 1327  
  1328 + // Test multiple column table
  1329 + TEST_TABLE2_BOOL;
  1330 +
  1331 + // Return
  1332 + return;
5762 1333 }
5763 1334  
  1335 +
5764 1336 /***************************************************************************
5765 1337 * @brief Test bit FITS binary table
5766 1338 ***************************************************************************/
... ... @@ -5773,469 +1345,42 @@ void TestGFits::test_bintable_bit(void)
5773 1345 std::string cmd = "rm -rf "+ filename;
5774 1346 int rc = system(cmd.c_str());
5775 1347  
5776   - // Allocate reference sums
5777   - int sum = 0;
5778   - int sum10 = 0;
5779   - int sum_int = 0;
5780   - int sum10_int = 0;
5781   - std::string sum_str;
5782   - std::string sum10_str;
5783   -
5784   - // Build tables
5785   - test_try("Build tables");
5786   - try {
5787   - // Create FITS file
5788   - GFits fits;
5789   - fits.open(filename, true);
5790   -
5791   - // Set number of rows
5792   - int nrows = 10;
5793   - int nvec = 10;
5794   -
5795   - // Initial control sums
5796   - float tot_flt = 0.0;
5797   - double tot_dbl = 0.0;
5798   - int tot_int = 0;
5799   - long tot_lng = 0;
5800   - std::string tot_str;
5801   -
5802   - //
5803   - // ===== B I T =====
5804   - //
5805   -
5806   - GFitsTableBitCol col;
  1348 + // Set number of rows and vector columns
  1349 + int nrows = 3;
  1350 + int nvec = 3;
5807 1351  
5808   - test_try("BIT");
5809   - try{
5810   - // Set table
5811   - test_try("Set table");
5812   - try{
5813   - col = GFitsTableBitCol("BIT", nrows);
5814   - for (int i = 0; i < nrows; ++i) {
5815   - char val = (i % 2) ? 1 : 0;
5816   - col(i) = val;
5817   - sum += val;
5818   - sum_int += int(val);
5819   - if (val)
5820   - sum_str += ":T";
5821   - else
5822   - sum_str += ":F";
5823   - }
5824   - test_try_success();
5825   - }
5826   - catch(std::exception &e)
5827   - {
5828   - test_try_failure(e);
5829   - }
5830   -
5831   - // Check table (operator access)
5832   - test_try("Check table (operator access)");
5833   - try{
5834   - tot_int = 0;
5835   - for (int i = 0; i < nrows; ++i)
5836   - tot_int += col(i);
5837   - if (tot_int != sum) {
5838   - throw exception_failure("GFitsTableBitCol::operator() : Reference sum: "+str(sum)+" Derived sum: "+str(tot_int));
5839   - }
5840   - test_try_success();
5841   - }
5842   - catch(std::exception &e)
5843   - {
5844   - test_try_failure(e);
5845   - }
5846   -
5847   - // Check table (real access)
5848   - test_try("Check table (real access)");
5849   - try{
5850   - tot_dbl = 0.0;
5851   - for (int i = 0; i < nrows; ++i)
5852   - tot_dbl += col.real(i);
5853   - if (!dequal(tot_dbl, double(sum))) {
5854   - throw exception_failure("GFitsTableBitCol::real() : Reference sum: "+str(sum)+"Derived sum:"+str(tot_dbl));
5855   - }
5856   - test_try_success();
5857   - }
5858   - catch(std::exception &e)
5859   - {
5860   - test_try_failure(e);
5861   - }
5862   -
5863   - // Check table (int access)
5864   - test_try("Check table (int access)");
5865   - try{
5866   - tot_int = 0;
5867   - for (int i = 0; i < nrows; ++i)
5868   - tot_int += col.integer(i);
5869   - if (tot_int != sum_int) {
5870   - throw exception_failure("GFitsTableBitCol::integer() : Reference sum: "+str(sum_int)+"Derived sum:"+str(tot_int));
5871   - }
5872   - test_try_success();
5873   - }
5874   - catch(std::exception &e)
5875   - {
5876   - test_try_failure(e);
5877   - }
5878   -
5879   - // Check table (string access)
5880   - test_try("Check table (string access)");
5881   - try{
5882   - tot_str.clear();
5883   - for (int i = 0; i < nrows; ++i)
5884   - tot_str += ":"+col.string(i);
5885   - if (tot_str != sum_str) {
5886   - throw exception_failure("GFitsTableBitCol::string() : Reference sum: "+sum_str+"Derived sum:"+tot_str);
5887   - }
5888   - test_try_success();
5889   - }
5890   - catch(std::exception &e)
5891   - {
5892   - test_try_failure(e);
5893   - }
5894   - test_try_success();
5895   - } // End try bit
5896   - catch(std::exception &e)
5897   - {
5898   - test_try_failure(e);
5899   - }
5900   -
5901   - //
5902   - // ===== B I T 1 0 =====
5903   - //
5904   -
5905   - GFitsTableBitCol col10;
5906   -
5907   - test_try("Bit 10");
5908   - try{
5909   -
5910   - // Set table
5911   - test_try("Set table");
5912   - try{
5913   - col10 = GFitsTableBitCol("BIT10", nrows, nvec);
5914   - for (int i = 0; i < nrows; ++i) {
5915   - for (int j = 0; j < nvec; ++j) {
5916   - char val = (i % 2) * (j % 2);
5917   - col10(i,j) = val;
5918   - sum10 += val;
5919   - sum10_int += int(val);
5920   - if (val)
5921   - sum10_str += ":T";
5922   - else
5923   - sum10_str += ":F";
5924   - }
5925   - }
5926   - test_try_success();
5927   - }
5928   - catch(std::exception &e)
5929   - {
5930   - test_try_failure(e);
5931   - }
5932   -
5933   - // Check table (operator access)
5934   - test_try("Check table (operator access)");
5935   - try{
5936   - tot_int = 0;
5937   - for (int i = 0; i < nrows; ++i) {
5938   - for (int j = 0; j < nvec; ++j)
5939   - tot_int += col10(i,j);
5940   - }
5941   - if (tot_int != sum10) {
5942   - throw exception_failure("GFitsTableBitCol::operator() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_int));
5943   - }
5944   - test_try_success();
5945   - }
5946   - catch(std::exception &e)
5947   - {
5948   - test_try_failure(e);
5949   - }
5950   -
5951   - // Check table (real access)
5952   - test_try("Check table (real access)");
5953   - try{
5954   - tot_dbl = 0.0;
5955   - for (int i = 0; i < nrows; ++i) {
5956   - for (int j = 0; j < nvec; ++j)
5957   - tot_dbl += col10.real(i,j);
5958   - }
5959   - if (!dequal(tot_dbl, sum10)) {
5960   - throw exception_failure("GFitsTableBitCol::real() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_dbl));
5961   - }
5962   - test_try_success();
5963   - }
5964   - catch(std::exception &e)
5965   - {
5966   - test_try_failure(e);
5967   - }
5968   -
5969   - // Check table (int access)
5970   - test_try("Check table (int access)");
5971   - try{
5972   - tot_int = 0;
5973   - for (int i = 0; i < nrows; ++i) {
5974   - for (int j = 0; j < nvec; ++j)
5975   - tot_int += col10.integer(i,j);
5976   - }
5977   - if (tot_int != sum10_int) {
5978   - throw exception_failure("GFitsTableBitCol::integer() - 10 : Reference sum: "+str(sum10_int)+"Derived sum:"+str(tot_int));
5979   - }
5980   - test_try_success();
5981   - }
5982   - catch(std::exception &e)
5983   - {
5984   - test_try_failure(e);
5985   - }
5986   -
5987   - // Check table (string access)
5988   - test_try("Check table (string access)");
5989   - try{
5990   - tot_str.clear();
5991   - for (int i = 0; i < nrows; ++i) {
5992   - for (int j = 0; j < nvec; ++j)
5993   - tot_str += ":"+col10.string(i,j);
5994   - }
5995   - if (tot_str != sum10_str) {
5996   - throw exception_failure("GFitsTableBitCol::string() - 10 : Reference sum: "+sum10_str+"Derived sum:"+tot_str);
5997   - }
5998   - test_try_success();
5999   - }
6000   - catch(std::exception &e)
6001   - {
6002   - test_try_failure(e);
6003   - }
6004   - test_try_success();
6005   - } // end try bit 10
6006   - catch(std::exception &e)
6007   - {
6008   - test_try_failure(e);
6009   - }
6010   -
6011   - //
6012   - // ===== W R I T E T A B L E =====
6013   - //
6014   - test_try("Write Table");
6015   - try{
6016   - // Build binary table
6017   - GFitsBinTable table = GFitsBinTable(nrows);
6018   - table.append_column(col);
6019   - table.insert_column(0, col10);
6020   -
6021   - // Append to file
6022   - fits.append(table);
6023   -
6024   - // Save FITS file
6025   - fits.save();
6026   -
6027   - test_try_success();
6028   - }
6029   - catch(std::exception &e)
6030   - {
6031   - test_try_failure(e);
6032   - }
6033   -
6034   - test_try_success();
6035   - } //end try build table
6036   - catch(std::exception &e)
6037   - {
6038   - test_try_failure(e);
6039   - }
  1352 + // Test single column table
  1353 + GFitsTableBitCol col1("BIT", nrows);
  1354 + TEST_TABLE1_BOOL;
6040 1355  
6041   - //================================================================
6042   - //================================================================
6043   - //================================================================
6044   - // Read tables
6045   - //================================================================
6046   - //================================================================
6047   - //================================================================
6048   -
6049   - test_try("Read Table");
6050   - try{
6051   - // Open FITS file
6052   - GFits fits;
6053   - fits.open(filename);
  1356 + // Test multiple column table
  1357 + GFitsTableBitCol col2("BIT10", nrows, nvec);
  1358 + TEST_TABLE2_BOOL;
6054 1359  
6055   - // Set number of rows
6056   - int nrows = 10;
6057   - int nvec = 10;
6058   -
6059   - // Initial control sums
6060   - float tot_flt = 0.0;
6061   - short tot_sht = 0;
6062   - double tot_dbl = 0.0;
6063   - int tot_int = 0;
6064   - std::string tot_str;
6065   -
6066   - //
6067   - // ===== B I T =====
6068   - //
6069   - GFitsTableBitCol* col = NULL;
6070   - test_try("Bit");
6071   - try {
6072   - // Get column
6073   - col = (GFitsTableBitCol*)&(*fits.table(1))["BIT"];
6074   -
6075   - // Check table (operator access)
6076   - test_try("Check table (operator access)");
6077   - try {
6078   - tot_int = 0;
6079   - for (int i = 0; i < nrows; ++i)
6080   - tot_int += (*col)(i);
6081   - if (tot_int != sum) {
6082   - throw exception_failure("GFitsTableBitCol::operator() : Reference sum: "+str(sum)+" Derived sum: "+str(tot_int));
6083   - }
6084   - test_try_success();
6085   - }
6086   - catch(std::exception &e)
6087   - {
6088   - test_try_failure(e);
6089   - }
6090   -
6091   - // Check table (real access)
6092   - test_try("Check table (real access)");
6093   - try{
6094   - tot_dbl = 0.0;
6095   - for (int i = 0; i < nrows; ++i)
6096   - tot_dbl += col->real(i);
6097   - if (!dequal(tot_dbl, double(sum))) {
6098   - throw exception_failure("GFitsTableBitCol::real() : Reference sum: "+str(sum)+"Derived sum:"+str(tot_dbl));
6099   - }
6100   - test_try_success();
6101   - }
6102   - catch(std::exception &e)
6103   - {
6104   - test_try_failure(e);
6105   - }
6106   -
6107   - // Check table (int access)
6108   - test_try("Check table (int access)");
6109   - try{
6110   - tot_int = 0;
6111   - for (int i = 0; i < nrows; ++i)
6112   - tot_int += col->integer(i);
6113   - if (tot_int != sum_int) {
6114   - throw exception_failure("GFitsTableBitCol::integer() : Reference sum: "+str(sum_int)+"Derived sum:"+str(tot_int));
6115   - }
6116   - test_try_success();
6117   - }
6118   - catch(std::exception &e)
6119   - {
6120   - test_try_failure(e);
6121   - }
6122   -
6123   - // Check table (string access)
6124   - test_try("Check table (string access)");
6125   - try{
6126   - tot_str.clear();
6127   - for (int i = 0; i < nrows; ++i)
6128   - tot_str += ":"+col->string(i);
6129   - if (tot_str != sum_str) {
6130   - throw exception_failure("GFitsTableBitCol::string() : Reference sum: "+sum_str+"Derived sum:"+tot_str);
6131   - }
6132   - test_try_success();
6133   - }
6134   - catch(std::exception &e)
6135   - {
6136   - test_try_failure(e);
6137   - }
6138   - test_try_success();
6139   - }// End try bit
6140   - catch(std::exception &e)
6141   - {
6142   - test_try_failure(e);
6143   - }
  1360 + // Write tables
  1361 + TEST_WRITE_TABLES;
6144 1362  
6145   - //
6146   - // ===== B I T 1 0 =====
6147   - //
6148   - GFitsTableBitCol* col10 = NULL;
6149   - test_try("Bit 10");
6150   - try{
6151   - // Get column
6152   - col10 = (GFitsTableBitCol*)&(*fits.table(1))["BIT10"];
6153   - // Check table (operator access)
6154   - test_try("Check table (operator access)");
6155   - try{
6156   - tot_int = 0;
6157   - for (int i = 0; i < nrows; ++i) {
6158   - for (int j = 0; j < nvec; ++j)
6159   - tot_int += (*col10)(i,j);
6160   - }
6161   - if (tot_int != sum10) {
6162   - throw exception_failure("GFitsTableBitCol::operator() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_int));
6163   - }
6164   - test_try_success();
6165   - }
6166   - catch(std::exception &e)
6167   - {
6168   - test_try_failure(e);
6169   - }
6170   -
6171   - // Check table (real access)
6172   - test_try("Check table (real access)");
6173   - try{
6174   - tot_dbl = 0.0;
6175   - for (int i = 0; i < nrows; ++i) {
6176   - for (int j = 0; j < nvec; ++j)
6177   - tot_dbl += col10->real(i,j);
6178   - }
6179   - if (!dequal(tot_dbl, sum10)) {
6180   - throw exception_failure("GFitsTableBitCol::real() - 10 : Reference sum: "+str(sum10)+"Derived sum:"+str(tot_dbl));
6181   - }
6182   - test_try_success();
6183   - }
6184   - catch(std::exception &e)
6185   - {
6186   - test_try_failure(e);
6187   - }
6188   -
6189   - // Check table (int access)
6190   - test_try("Check table (int access)");
6191   - try{
6192   - tot_int = 0;
6193   - for (int i = 0; i < nrows; ++i) {
6194   - for (int j = 0; j < nvec; ++j)
6195   - tot_int += col10->integer(i,j);
6196   - }
6197   - if (tot_int != sum10_int) {
6198   - throw exception_failure("GFitsTableBitCol::integer() - 10 : Reference sum: "+str(sum10_int)+"Derived sum:"+str(tot_int));
6199   - }
6200   - test_try_success();
6201   - }
6202   - catch(std::exception &e)
6203   - {
6204   - test_try_failure(e);
6205   - }
6206   -
6207   - // Check table (string access)
6208   - test_try("Check table (string access)");
6209   - try{
6210   - tot_str.clear();
6211   - for (int i = 0; i < nrows; ++i) {
6212   - for (int j = 0; j < nvec; ++j)
6213   - tot_str += ":"+col10->string(i,j);
6214   - }
6215   - if (tot_str != sum10_str) {
6216   - throw exception_failure("GFitsTableBitCol::string() - 10 : Reference sum: "+sum10_str+"Derived sum:"+tot_str);
6217   - }
6218   - test_try_success();
6219   - }
6220   - catch(std::exception &e)
6221   - {
6222   - test_try_failure(e);
6223   - }
6224   -
6225   - test_try_success();
6226   - } //end try bit 10
6227   - catch(std::exception &e)
6228   - {
6229   - test_try_failure(e);
6230   - }
6231   -
  1363 + // Read tables back
  1364 + test_try("Read Tables");
  1365 + try {
  1366 + GFits fits(filename);
  1367 + col1 = static_cast<GFitsTableBitCol&>((*fits.table(1))["BIT"]);
  1368 + col2 = static_cast<GFitsTableBitCol&>((*fits.table(1))["BIT10"]);
  1369 + fits.close();
6232 1370 test_try_success();
6233   - } //end try read tabe
6234   - catch(std::exception &e)
6235   - {
  1371 + }
  1372 + catch(std::exception &e) {
6236 1373 test_try_failure(e);
6237 1374 }
  1375 +
  1376 + // Test single column table
  1377 + TEST_TABLE1_BOOL;
  1378 +
  1379 + // Test multiple column table
  1380 + TEST_TABLE2_BOOL;
6238 1381  
  1382 + // Return
  1383 + return;
6239 1384 }
6240 1385  
6241 1386  
... ... @@ -6245,7 +1390,7 @@ void TestGFits::test_bintable_bit(void)
6245 1390 int main(void)
6246 1391 {
6247 1392 // Allocate test suit container
6248   - GTestSuites testsuites("GFits");
  1393 + GTestSuites testsuites("FITS module");
6249 1394  
6250 1395 // Initially assume that we pass all tests
6251 1396 bool success = true;
... ...
test/test_GFits.hpp
... ... @@ -29,7 +29,6 @@
29 29  
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include "GammaLib.hpp"
32   -#include <iostream> // cout, cerr
33 32  
34 33  
35 34 /***********************************************************************//**
... ... @@ -65,12 +64,6 @@ public:
65 64 void test_bintable_ulong(void);
66 65 void test_bintable_long(void);
67 66 void test_bintable_longlong(void);
68   -
69   -private:
70   - // Private methods
71   - int equal(double val, double ref, double eps);
72   - int fequal(double val, double ref);
73   - int dequal(double val, double ref);
74 67 };
75 68  
76 69 #endif /* TEST_GFITS_HPP */
... ...