Commit 56d87b7ad30800c7d8df486c910dfb0592139f33

Authored by knodlseder
1 parent d111479a

enhance column table handling and testing suite

include/GFitsData.hpp
... ... @@ -46,7 +46,7 @@ public:
46 46 protected:
47 47 // Protected methods
48 48 virtual void connect(__fitsfile* fptr);
49   -
  49 +
50 50 // Protected data area
51 51 __fitsfile m_fitsfile; //!< FITS file
52 52 };
... ...
include/GFitsImage.hpp
... ... @@ -66,7 +66,8 @@ protected:
66 66 void copy_members(const GFitsImage& image);
67 67 void free_members(void);
68 68 void open_image(__fitsfile* fptr);
69   - void load_image(int datatype, const void* pixels, const void* nulval, int* anynul);
  69 + void load_image(int datatype, const void* pixels, const void* nulval,
  70 + int* anynul);
70 71 void save_image(int datatype, const void* pixels);
71 72  
72 73 // Private data area
... ...
include/GFitsTableCol.hpp
... ... @@ -37,9 +37,6 @@ class GFitsTableCol {
37 37 // Friend classes
38 38 friend class GFitsTable;
39 39  
40   - // I/O friends
41   -// friend ostream& operator<< (ostream& os, const GFitsTableCol& column);
42   -
43 40 public:
44 41 // Constructors and destructors
45 42 GFitsTableCol();
... ... @@ -70,24 +67,36 @@ public:
70 67  
71 68 protected:
72 69 // Protected data area
73   - std::string m_name; //!< Column name
74   - std::string m_unit; //!< Column unit
75   - int m_colnum; //!< @brief Column number (starting from 1).
76   - //!< This parameter is used to signal if a
77   - //!< table column corresponds to a FITS file
78   - //!< column. If it is set to 0 there is no
79   - //!< correspondance.
80   - int m_type; //!< Column type
81   - int m_repeat; //!< Repeat value of column
82   - int m_width; //!< Width of single column element
83   - int m_number; //!< Number of elements in column
84   - //!< m_number = m_repeat / m_width
85   - int m_length; //!< Length of column
86   - __fitsfile m_fitsfile; //!< FITS file associated with column
  70 + std::string m_name; //!< Column name
  71 + std::string m_unit; //!< Column unit
  72 + int m_colnum; //!< @brief Column number (starting from 1).
  73 + //!< This parameter is used to signal if a
  74 + //!< table column corresponds to a FITS file
  75 + //!< column. If it is set to 0 there is no
  76 + //!< correspondance.
  77 + int m_type; //!< Column type
  78 + int m_repeat; //!< Repeat value of column
  79 + int m_width; //!< Width of single column element
  80 + int m_number; //!< @brief Number of elements in column.
  81 + //!< m_number = m_repeat / m_width
  82 + int m_length; //!< Length of column
  83 + int m_size; //!< Size of allocated data area (0 if not loaded)
  84 + int m_anynul; //!< Number of NULLs encountered
  85 + __fitsfile m_fitsfile; //!< FITS file associated with column
87 86  
88   - // Protected methods
  87 + // Protected virtual methods
89 88 virtual std::string ascii_format(void) const = 0;
90 89 virtual std::string binary_format(void) const = 0;
  90 + virtual void alloc_data(void) = 0;
  91 + virtual void init_data(void) = 0;
  92 + virtual void fetch_data(void) = 0;
  93 + virtual void* ptr_data(void) = 0;
  94 + virtual void* ptr_nulval(void) = 0;
  95 +
  96 + // Protected methods
  97 + void load_column(void);
  98 + void save_column(void);
  99 + void dump_column(ostream& os, void* data) const;
91 100  
92 101 private:
93 102 // Private methods
... ...
include/GFitsTableDblCol.hpp
... ... @@ -68,15 +68,17 @@ private:
68 68 void init_members(void);
69 69 void copy_members(const GFitsTableDblCol& column);
70 70 void free_members(void);
71   - void fetch_data(void);
72 71 std::string ascii_format(void) const;
73 72 std::string binary_format(void) const;
  73 + void alloc_data(void);
  74 + void init_data(void);
  75 + void fetch_data(void);
  76 + void* ptr_data(void) { return m_data; }
  77 + void* ptr_nulval(void) { return m_nulval; }
74 78  
75 79 // Private data area
76   - int m_size; //!< Size of allocated data area (0 if not loaded)
77 80 double* m_data; //!< Data area
78 81 double* m_nulval; //!< NULL value
79   - int m_anynul; //!< Number of NULLs encountered
80 82 };
81 83  
82 84 #endif /* GFITSTABLEDBLCOL_HPP */
... ...
include/GFitsTableFltCol.hpp
... ... @@ -68,15 +68,17 @@ private:
68 68 void init_members(void);
69 69 void copy_members(const GFitsTableFltCol& column);
70 70 void free_members(void);
71   - void fetch_data(void);
72 71 std::string ascii_format(void) const;
73 72 std::string binary_format(void) const;
  73 + void alloc_data(void);
  74 + void init_data(void);
  75 + void fetch_data(void);
  76 + void* ptr_data(void) { return m_data; }
  77 + void* ptr_nulval(void) { return m_nulval; }
74 78  
75 79 // Private data area
76   - int m_size; //!< Size of allocated data area (0 if not loaded)
77 80 float* m_data; //!< Data area
78 81 float* m_nulval; //!< NULL value
79   - int m_anynul; //!< Number of NULLs encountered
80 82 };
81 83  
82 84 #endif /* GFITSTABLEFLTCOL_HPP */
... ...
include/GFitsTableLngCol.hpp
... ... @@ -38,6 +38,9 @@
38 38 ***************************************************************************/
39 39 class GFitsTableLngCol : public GFitsTableCol {
40 40  
  41 + // I/O friends
  42 + friend ostream& operator<< (ostream& os, const GFitsTableLngCol& column);
  43 +
41 44 public:
42 45 // Constructors and destructors
43 46 GFitsTableLngCol();
... ... @@ -65,15 +68,17 @@ private:
65 68 void init_members(void);
66 69 void copy_members(const GFitsTableLngCol& column);
67 70 void free_members(void);
68   - void fetch_data(void);
69 71 std::string ascii_format(void) const;
70 72 std::string binary_format(void) const;
  73 + void alloc_data(void);
  74 + void init_data(void);
  75 + void fetch_data(void);
  76 + void* ptr_data(void) { return m_data; }
  77 + void* ptr_nulval(void) { return m_nulval; }
71 78  
72 79 // Private data area
73   - int m_size; //!< Size of data area
74 80 long* m_data; //!< Data area
75 81 long* m_nulval; //!< NULL value
76   - int m_anynul; //!< Number of NULLs encountered
77 82 };
78 83  
79 84 #endif /* GFITSTABLELNGCOL_HPP */
... ...
include/GFitsTableShtCol.hpp
... ... @@ -10,6 +10,11 @@
10 10 * (at your option) any later version. *
11 11 * *
12 12 ***************************************************************************/
  13 +/**
  14 + * @file GFitsTableShtCol.hpp
  15 + * @brief GFitsTableShtCol class definition.
  16 + * @author J. Knodlseder
  17 + */
13 18  
14 19 #ifndef GFITSTABLESHTCOL_HPP
15 20 #define GFITSTABLESHTCOL_HPP
... ... @@ -24,21 +29,30 @@
24 29 /* __ Structures _________________________________________________________ */
25 30  
26 31  
27   -/***************************************************************************
28   - * GFitsTableShtCol class definition *
  32 +/***********************************************************************//**
  33 + * @class GFitsTableShtCol
  34 + *
  35 + * @brief Interface for FITS table short integer column
  36 + *
  37 + * This class implements a FITS table short integer column.
29 38 ***************************************************************************/
30 39 class GFitsTableShtCol : public GFitsTableCol {
31 40  
  41 + // I/O friends
  42 + friend ostream& operator<< (ostream& os, const GFitsTableShtCol& column);
  43 +
32 44 public:
33 45 // Constructors and destructors
34 46 GFitsTableShtCol();
35 47 GFitsTableShtCol(const std::string& name, const int& length,
36   - const int& size = 1);
  48 + const int& size = 1);
37 49 GFitsTableShtCol(const GFitsTableShtCol& column);
38 50 virtual ~GFitsTableShtCol();
39 51  
40 52 // Operators
41 53 GFitsTableShtCol& operator= (const GFitsTableShtCol& column);
  54 + short& operator() (const int& row, const int& inx = 0);
  55 + const short& operator() (const int& row, const int& inx = 0) const;
42 56  
43 57 // Methods
44 58 void save(void);
... ... @@ -46,11 +60,7 @@ public:
46 60 double real(const int& row, const int& col = 0);
47 61 int integer(const int& row, const int& col = 0);
48 62 GFitsTableShtCol* clone(void) const;
49   - double* ptr_double(void);
50   - float* ptr_float(void);
51   - short* ptr_short(void);
52   - long* ptr_long(void);
53   - int* ptr_int(void);
  63 + short* data(void);
54 64 void set_nullval(const short* value);
55 65  
56 66 private:
... ... @@ -58,26 +68,17 @@ private:
58 68 void init_members(void);
59 69 void copy_members(const GFitsTableShtCol& column);
60 70 void free_members(void);
61   - void load(void);
62 71 std::string ascii_format(void) const;
63 72 std::string binary_format(void) const;
  73 + void alloc_data(void);
  74 + void init_data(void);
  75 + void fetch_data(void);
  76 + void* ptr_data(void) { return m_data; }
  77 + void* ptr_nulval(void) { return m_nulval; }
64 78  
65 79 // Private data area
66   - int m_size; // Size of data area
67   - short* m_data; // Data area
68   - short* m_nulval; // NULL value
69   - int m_anynul; // Number of NULLs encountered
  80 + short* m_data; //!< Data area
  81 + short* m_nulval; //!< NULL value
70 82 };
71 83  
72   -
73   -/***************************************************************************
74   - * Inline methods *
75   - ***************************************************************************/
76   -inline short* GFitsTableShtCol::ptr_short(void) { return m_data; }
77   -inline
78   -GFitsTableShtCol* GFitsTableShtCol::clone(void) const
79   -{
80   - return new GFitsTableShtCol(*this);
81   -}
82   -
83 84 #endif /* GFITSTABLESHTCOL_HPP */
... ...
include/GFitsTableStrCol.hpp
... ... @@ -10,6 +10,11 @@
10 10 * (at your option) any later version. *
11 11 * *
12 12 ***************************************************************************/
  13 +/**
  14 + * @file GFitsTableStrCol.hpp
  15 + * @brief GFitsTableStrCol class definition.
  16 + * @author J. Knodlseder
  17 + */
13 18  
14 19 #ifndef GFITSTABLESTRCOL_HPP
15 20 #define GFITSTABLESTRCOL_HPP
... ... @@ -24,21 +29,30 @@
24 29 /* __ Structures _________________________________________________________ */
25 30  
26 31  
27   -/***************************************************************************
28   - * GFitsTableStrCol class definition *
  32 +/***********************************************************************//**
  33 + * @class GFitsTableStrCol
  34 + *
  35 + * @brief Interface for FITS table string column
  36 + *
  37 + * This class implements a FITS table string column.
29 38 ***************************************************************************/
30 39 class GFitsTableStrCol : public GFitsTableCol {
31 40  
  41 + // I/O friends
  42 + friend ostream& operator<< (ostream& os, const GFitsTableStrCol& column);
  43 +
32 44 public:
33 45 // Constructors and destructors
34 46 GFitsTableStrCol();
35 47 GFitsTableStrCol(const std::string& name, const int& length,
36   - const int& size = 1);
  48 + const int& width, const int& size = 1);
37 49 GFitsTableStrCol(const GFitsTableStrCol& column);
38 50 ~GFitsTableStrCol();
39 51  
40 52 // Operators
41   - GFitsTableStrCol& operator= (const GFitsTableStrCol& column);
  53 + GFitsTableStrCol& operator= (const GFitsTableStrCol& column);
  54 + std::string& operator() (const int& row, const int& inx = 0);
  55 + const std::string& operator() (const int& row, const int& inx = 0) const;
42 56  
43 57 // Methods
44 58 void save(void);
... ... @@ -46,37 +60,28 @@ public:
46 60 double real(const int& row, const int& col = 0);
47 61 int integer(const int& row, const int& col = 0);
48 62 GFitsTableStrCol* clone(void) const;
49   - float* ptr_float(void);
50   - double* ptr_double(void);
51   - short* ptr_short(void);
52   - long* ptr_long(void);
53   - int* ptr_int(void);
54   - void set_nullstr(const std::string string);
  63 + std::string* data(void);
  64 + void set_nullval(const std::string string);
55 65  
56 66 private:
57 67 // Private methods
58 68 void init_members(void);
59 69 void copy_members(const GFitsTableStrCol& column);
60 70 void free_members(void);
61   - void load(void);
62 71 std::string ascii_format(void) const;
63 72 std::string binary_format(void) const;
  73 + void alloc_data(void);
  74 + void init_data(void);
  75 + void fetch_data(void);
  76 + void* ptr_data(void) { return m_buffer; }
  77 + void* ptr_nulval(void) { return m_nulval; }
  78 + void alloc_buffer(void);
  79 + void free_buffer(void);
64 80  
65 81 // Private data area
66   - int m_size; // Total number of strings
67   - char** m_data; // Data area
68   - char* m_nulstr; // NULL string
69   - int m_anynul; // Number of NULLs encountered
  82 + std::string* m_data; //!< Data area
  83 + char** m_buffer; //!< Data area for CFITSIO transfer
  84 + char* m_nulval; //!< NULL string
70 85 };
71 86  
72   -
73   -/***************************************************************************
74   - * Inline methods *
75   - ***************************************************************************/
76   -inline
77   -GFitsTableStrCol* GFitsTableStrCol::clone(void) const
78   -{
79   - return new GFitsTableStrCol(*this);
80   -}
81   -
82 87 #endif /* GFITSTABLESTRCOL_HPP */
... ...
src/fits/GFitsTable.cpp
... ... @@ -917,16 +917,20 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsTable&amp; table)
917 917 if (table.m_columns[i] != NULL) {
918 918 switch (table.m_columns[i]->type()) {
919 919 case __TSTRING:
920   - os << " column " << i << " no << operator" << endl;
  920 + os << " " << *((GFitsTableStrCol*)table.m_columns[i])
  921 + << endl;
921 922 break;
922 923 case __TSHORT:
923   - os << " column " << i << " no << operator" << endl;
  924 + os << " " << *((GFitsTableShtCol*)table.m_columns[i])
  925 + << endl;
924 926 break;
925 927 case __TLONG:
926   - os << " column " << i << " no << operator" << endl;
  928 + os << " " << *((GFitsTableLngCol*)table.m_columns[i])
  929 + << endl;
927 930 break;
928 931 case __TFLOAT:
929   - os << " column " << i << " no << operator" << endl;
  932 + os << " " << *((GFitsTableFltCol*)table.m_columns[i])
  933 + << endl;
930 934 break;
931 935 case __TDOUBLE:
932 936 os << " " << *((GFitsTableDblCol*)table.m_columns[i])
... ...
src/fits/GFitsTableCol.cpp
... ... @@ -20,6 +20,8 @@
20 20 /* __ Namespaces _________________________________________________________ */
21 21  
22 22 /* __ Method name definitions ____________________________________________ */
  23 +#define G_LOAD_COLUMN "GFitsTableCol::load_column(void*, void*)"
  24 +#define G_SAVE_COLUMN "GFitsTableCol::save_column(void*, void*)"
23 25  
24 26 /* __ Macros _____________________________________________________________ */
25 27  
... ... @@ -268,6 +270,8 @@ void GFitsTableCol::init_members(void)
268 270 m_width = 0;
269 271 m_number = 0;
270 272 m_length = 0;
  273 + m_size = 0;
  274 + m_anynul = 0;
271 275 m_fitsfile.HDUposition = 0;
272 276 m_fitsfile.Fptr = NULL;
273 277  
... ... @@ -292,6 +296,8 @@ void GFitsTableCol::copy_members(const GFitsTableCol&amp; column)
292 296 m_width = column.m_width;
293 297 m_number = column.m_number;
294 298 m_length = column.m_length;
  299 + m_size = column.m_size;
  300 + m_anynul = column.m_anynul;
295 301 m_fitsfile = column.m_fitsfile;
296 302  
297 303 // Return
... ... @@ -329,6 +335,159 @@ void GFitsTableCol::connect(__fitsfile* fptr)
329 335 }
330 336  
331 337  
  338 +/***********************************************************************//**
  339 + * @brief Load table column from FITS file
  340 + *
  341 + * @exception GException::fits_hdu_not_found
  342 + * Specified HDU not found in FITS file.
  343 + * @exception GException::fits_error
  344 + * An error occured while loading column data from FITS file.
  345 + *
  346 + * If a FITS file is attached to the column the data are loaded into memory
  347 + * from the FITS file. If no FITS file is attached, memory is allocated
  348 + * to hold the column data and all cells are set to 0.
  349 + *
  350 + * The method make use of the virtual methods
  351 + * GFitsTableCol::alloc_data,
  352 + * GFitsTableCol::init_data,
  353 + * GFitsTableCol::ptr_data, and
  354 + * GFitsTableCol::ptr_nulval.
  355 + * These methods are implemented by the derived column classes which
  356 + * implement a specific storage class (i.e. float, double, short, ...).
  357 + ***************************************************************************/
  358 +void GFitsTableCol::load_column(void)
  359 +{
  360 + // Calculate size of memory
  361 + m_size = m_number * m_length;
  362 +
  363 + // Load only if the column has a positive size
  364 + if (m_size > 0) {
  365 +
  366 + // Allocate fresh memory
  367 + alloc_data();
  368 +
  369 + // If a FITS file is attached then load column data from the FITS
  370 + // file
  371 + if (m_fitsfile.Fptr != NULL) {
  372 +
  373 + // Move to the HDU
  374 + int status = 0;
  375 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1,
  376 + NULL, &status);
  377 + if (status != 0)
  378 + throw GException::fits_hdu_not_found(G_LOAD_COLUMN,
  379 + (m_fitsfile.HDUposition)+1,
  380 + status);
  381 +
  382 + // Load data
  383 + status = __ffgcv(&m_fitsfile, m_type, m_colnum, 1, 1, m_size,
  384 + ptr_nulval(), ptr_data(), &m_anynul, &status);
  385 + if (status != 0)
  386 + throw GException::fits_error(G_LOAD_COLUMN, status);
  387 + }
  388 +
  389 + // ... otherwise initialise all column values
  390 + else
  391 + init_data();
  392 +
  393 + } // endif: column has a positive size
  394 +
  395 + // Return
  396 + return;
  397 +}
  398 +
  399 +
  400 +/***********************************************************************//**
  401 + * @brief Save table column into FITS file
  402 + *
  403 + * @exception GException::fits_hdu_not_found
  404 + * Specified HDU not found in FITS file.
  405 + * @exception GException::fits_error
  406 + * Error occured during writing of the column data.
  407 + *
  408 + * The table column is only saved if it is linked to a FITS file and if the
  409 + * data are indeed present in the class instance. This avoids saving of data
  410 + * that have not been modified.
  411 + *
  412 + * The method make use of the virtual methods
  413 + * GFitsTableCol::ptr_data and
  414 + * GFitsTableCol::ptr_nulval.
  415 + * These methods are implemented by the derived column classes which
  416 + * implement a specific storage class (i.e. float, double, short, ...).
  417 + ***************************************************************************/
  418 +void GFitsTableCol::save_column(void)
  419 +{
  420 + // Continue only if a FITS file is connected and data have been loaded
  421 + if (m_fitsfile.Fptr != NULL && m_colnum > 0 && ptr_data() != NULL) {
  422 +
  423 + // Move to the HDU
  424 + int status = 0;
  425 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
  426 + &status);
  427 + if (status != 0)
  428 + throw GException::fits_hdu_not_found(G_SAVE_COLUMN,
  429 + (m_fitsfile.HDUposition)+1,
  430 + status);
  431 + // Save the column data
  432 + status = __ffpcn(&m_fitsfile, m_type, m_colnum, 1, 1,
  433 + (long)m_size, ptr_data(), ptr_nulval(), &status);
  434 + if (status != 0)
  435 + throw GException::fits_error(G_SAVE_COLUMN, status);
  436 +
  437 + } // endif: FITS file was connected
  438 +
  439 + // Return
  440 + return;
  441 +}
  442 +
  443 +
  444 +/***********************************************************************//**
  445 + * @brief Put column information in output stream
  446 + *
  447 + * @param[in] os Output stream
  448 + * @param[in] column Column to put in output stream
  449 + ***************************************************************************/
  450 +void GFitsTableCol::dump_column(ostream& os, void* data) const
  451 +{
  452 + // Put column name in stream
  453 + os << "'" << m_name << "'";
  454 +
  455 + // Put FITS column number in stream
  456 + if (m_colnum > 0)
  457 + os << " [fits_colnum=" << m_colnum << "]";
  458 + else
  459 + os << " [not linked to FITS file]";
  460 +
  461 + // Put column type in stream
  462 + os << " " << ascii_format();
  463 + os << " " << binary_format();
  464 +
  465 + // Put data loading in stream
  466 + if (data == NULL)
  467 + os << " (not loaded)";
  468 + else
  469 + os << " (loaded in memory)";
  470 +
  471 + // Set data area size
  472 + os << " size=" << m_size;
  473 +
  474 + // Set vector length
  475 + os << " repeat=" << m_repeat;
  476 +
  477 + // Set width
  478 + os << " width=" << m_width;
  479 +
  480 + // Set number
  481 + os << " number=" << m_number;
  482 +
  483 + // Set length
  484 + os << " length=" << m_length;
  485 +
  486 + // Return
  487 + return;
  488 +}
  489 +
  490 +
332 491 /*==========================================================================
333 492 = =
334 493 = GFitsTableCol friends =
... ...
src/fits/GFitsTableDblCol.cpp
... ... @@ -21,11 +21,9 @@
21 21 /* __ Namespaces _________________________________________________________ */
22 22  
23 23 /* __ Method name definitions ____________________________________________ */
24   -#define G_SAVE "GFitsTableDblCol::save(void)"
25   -#define G_STRING "GFitsTableDblCol::string(const int&, const int&)"
26   -#define G_REAL "GFitsTableDblCol::real(const int&, const int&)"
27   -#define G_INTEGER "GFitsTableDblCol::integer(const int&, const int&)"
28   -#define G_FETCH_DATA "GFitsTableDblCol::fetch_data()"
  24 +#define G_STRING "GFitsTableDblCol::string(const int&, const int&)"
  25 +#define G_REAL "GFitsTableDblCol::real(const int&, const int&)"
  26 +#define G_INTEGER "GFitsTableDblCol::integer(const int&, const int&)"
29 27  
30 28 /* __ Macros _____________________________________________________________ */
31 29  
... ... @@ -161,7 +159,7 @@ double&amp; GFitsTableDblCol::operator() (const int&amp; row, const int&amp; inx)
161 159 // Calculate pixel offset
162 160 int offset = row * m_number + inx;
163 161  
164   - // Return image pixel
  162 + // Return data bin
165 163 return m_data[offset];
166 164 }
167 165  
... ... @@ -180,7 +178,7 @@ double&amp; GFitsTableDblCol::operator() (const int&amp; row, const int&amp; inx)
180 178 * if range checking is required.
181 179 ***************************************************************************/
182 180 const double& GFitsTableDblCol::operator() (const int& row, const int& inx)
183   - const
  181 + const
184 182 {
185 183 // If data are not available then load them now
186 184 if (m_data == NULL) ((GFitsTableDblCol*)this)->fetch_data();
... ... @@ -188,7 +186,7 @@ const double&amp; GFitsTableDblCol::operator() (const int&amp; row, const int&amp; inx)
188 186 // Calculate pixel offset
189 187 int offset = row * m_number + inx;
190 188  
191   - // Return image pixel
  189 + // Return data bin
192 190 return m_data[offset];
193 191 }
194 192  
... ... @@ -202,35 +200,16 @@ const double&amp; GFitsTableDblCol::operator() (const int&amp; row, const int&amp; inx)
202 200 /***********************************************************************//**
203 201 * @brief Save table column into FITS file
204 202 *
205   - * @exception GException::fits_hdu_not_found
206   - * Specified HDU not found in FITS file.
207   - * @exception GException::fits_error
208   - * Error occured during writing of the column data.
209   - *
210 203 * The table column is only saved if it is linked to a FITS file and if the
211 204 * data are indeed present in the class instance. This avoids saving of data
212 205 * that have not been modified.
  206 + *
  207 + * Refer to GFitsTableCol::save_column() for more information.
213 208 ***************************************************************************/
214 209 void GFitsTableDblCol::save(void)
215 210 {
216   - // Continue only if a FITS file is connected and data have been loaded
217   - if (m_fitsfile.Fptr != NULL && m_colnum > 0 && m_data != NULL) {
218   -
219   - // Move to the HDU
220   - int status = 0;
221   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
222   - &status);
223   - if (status != 0)
224   - throw GException::fits_hdu_not_found(G_SAVE,
225   - (m_fitsfile.HDUposition)+1,
226   - status);
227   - // Save the column data
228   - status = __ffpcn(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1,
229   - (long)m_size, m_data, m_nulval, &status);
230   - if (status != 0)
231   - throw GException::fits_error(G_SAVE, status);
232   -
233   - } // endif: FITS file was connected
  211 + // Save column
  212 + save_column();
234 213  
235 214 // Return
236 215 return;
... ... @@ -406,8 +385,6 @@ void GFitsTableDblCol::init_members(void)
406 385 {
407 386 // Initialise members
408 387 m_type = __TDOUBLE;
409   - m_size = 0;
410   - m_anynul = 0;
411 388 m_data = NULL;
412 389 m_nulval = NULL;
413 390  
... ... @@ -424,8 +401,6 @@ void GFitsTableDblCol::init_members(void)
424 401 void GFitsTableDblCol::copy_members(const GFitsTableDblCol& column)
425 402 {
426 403 // Copy attributes
427   - m_size = column.m_size;
428   - m_anynul = column.m_anynul;
429 404  
430 405 // Copy column data
431 406 if (column.m_data != NULL && m_size > 0) {
... ... @@ -465,53 +440,6 @@ void GFitsTableDblCol::free_members(void)
465 440  
466 441  
467 442 /***********************************************************************//**
468   - * @brief Fetch column data
469   - *
470   - * @exception GException::fits_error
471   - * An error occured while loading column data from FITS file.
472   - *
473   - * If a FITS file is attached to the column the data are loaded into memory
474   - * from the FITS file. If no FITS file is attached, memory is allocated
475   - * to hold the column data and all cells are set to 0.
476   - ***************************************************************************/
477   -void GFitsTableDblCol::fetch_data(void)
478   -{
479   - // Calculate size of memory
480   - m_size = m_number * m_length;
481   -
482   - // Load only if the column has a positive size
483   - if (m_size > 0) {
484   -
485   - // Allocate fresh memory
486   - if (m_data != NULL) delete [] m_data;
487   - m_data = new double[m_size];
488   -
489   - // If a FITS file is attached then load column data from the FITS
490   - // file
491   - if (m_fitsfile.Fptr != NULL) {
492   - int status = 0;
493   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
494   - &status);
495   - status = __ffgcv(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size,
496   - m_nulval, m_data, &m_anynul, &status);
497   - if (status != 0)
498   - throw GException::fits_error(G_FETCH_DATA, status);
499   - }
500   -
501   - // ... otherwise initialise all column values to 0
502   - else {
503   - for (int i = 0; i < m_size; ++i)
504   - m_data[i] = 0.0;
505   - }
506   -
507   - } // endif: column has a positive size
508   -
509   - // Return
510   - return;
511   -}
512   -
513   -
514   -/***********************************************************************//**
515 443 * @brief Returns format string of ASCII table
516 444 ***************************************************************************/
517 445 std::string GFitsTableDblCol::ascii_format(void) const
... ... @@ -549,6 +477,61 @@ std::string GFitsTableDblCol::binary_format(void) const
549 477 }
550 478  
551 479  
  480 +/***********************************************************************//**
  481 + * @brief Allocates column data
  482 + ***************************************************************************/
  483 +void GFitsTableDblCol::alloc_data(void)
  484 +{
  485 + // Free any existing memory
  486 + if (m_data != NULL) delete [] m_data;
  487 +
  488 + // Mark pointer as free
  489 + m_data = NULL;
  490 +
  491 + // Allocate new data
  492 + if (m_size > 0)
  493 + m_data = new double[m_size];
  494 +
  495 + // Return
  496 + return;
  497 +}
  498 +
  499 +
  500 +/***********************************************************************//**
  501 + * @brief Initialise column data
  502 + ***************************************************************************/
  503 +void GFitsTableDblCol::init_data(void)
  504 +{
  505 + // Initialise data if they exist
  506 + if (m_data != NULL) {
  507 + for (int i = 0; i < m_size; ++i)
  508 + m_data[i] = 0.0;
  509 + }
  510 +
  511 + // Return
  512 + return;
  513 +}
  514 +
  515 +
  516 +/***********************************************************************//**
  517 + * @brief Fetch column data
  518 + *
  519 + * If a FITS file is attached to the column the data are loaded into memory
  520 + * from the FITS file. If no FITS file is attached, memory is allocated
  521 + * to hold the column data and all cells are set to 0.
  522 + *
  523 + * Refer to GFitsTableCol::load_column for more information.
  524 + ***************************************************************************/
  525 +void GFitsTableDblCol::fetch_data(void)
  526 +{
  527 + // Save column
  528 + load_column();
  529 +
  530 + // Return
  531 + return;
  532 +}
  533 +
  534 +
552 535 /*==========================================================================
553 536 = =
554 537 = GFitsTableDblCol friends =
... ... @@ -563,39 +546,8 @@ std::string GFitsTableDblCol::binary_format(void) const
563 546 ***************************************************************************/
564 547 ostream& operator<< (ostream& os, const GFitsTableDblCol& column)
565 548 {
566   - // Put column name in stream
567   - os << "'" << column.m_name << "'";
568   -
569   - // Put FITS column number in stream
570   - if (column.m_colnum > 0)
571   - os << " [fits_colnum=" << column.m_colnum << "]";
572   - else
573   - os << " [not linked to FITS file]";
574   -
575   - // Put column type in stream
576   - os << " " << column.ascii_format();
577   - os << " " << column.binary_format();
578   -
579   - // Put data loading in stream
580   - if (column.m_data == NULL)
581   - os << " (not loaded)";
582   - else
583   - os << " (loaded in memory)";
584   -
585   - // Set data area size
586   - os << " size=" << column.m_size;
587   -
588   - // Set vector length
589   - os << " repeat=" << column.m_repeat;
590   -
591   - // Set width
592   - os << " width=" << column.m_width;
593   -
594   - // Set number
595   - os << " number=" << column.m_number;
596   -
597   - // Set length
598   - os << " length=" << column.m_length;
  549 + // Dump column in output stream
  550 + column.dump_column(os, column.m_data);
599 551  
600 552 // Return output stream
601 553 return os;
... ...
src/fits/GFitsTableFltCol.cpp
... ... @@ -21,11 +21,9 @@
21 21 /* __ Namespaces _________________________________________________________ */
22 22  
23 23 /* __ Method name definitions ____________________________________________ */
24   -#define G_SAVE "GFitsTableFltCol::save()"
25   -#define G_STRING "GFitsTableFltCol::string(const int&, const int&)"
26   -#define G_REAL "GFitsTableFltCol::real(const int&, const int&)"
27   -#define G_INTEGER "GFitsTableFltCol::integer(const int&, const int&)"
28   -#define G_FETCH_DATA "GFitsTableFltCol::fetch_data()"
  24 +#define G_STRING "GFitsTableFltCol::string(const int&, const int&)"
  25 +#define G_REAL "GFitsTableFltCol::real(const int&, const int&)"
  26 +#define G_INTEGER "GFitsTableFltCol::integer(const int&, const int&)"
29 27  
30 28 /* __ Macros _____________________________________________________________ */
31 29  
... ... @@ -202,35 +200,16 @@ const float&amp; GFitsTableFltCol::operator() (const int&amp; row, const int&amp; inx)
202 200 /***********************************************************************//**
203 201 * @brief Save table column into FITS file
204 202 *
205   - * @exception GException::fits_hdu_not_found
206   - * Specified HDU not found in FITS file.
207   - * @exception GException::fits_error
208   - * Error occured during writing of the column data.
209   - *
210 203 * The table column is only saved if it is linked to a FITS file and if the
211 204 * data are indeed present in the class instance. This avoids saving of data
212 205 * that have not been modified.
  206 + *
  207 + * Refer to GFitsTableCol::save_column() for more information.
213 208 ***************************************************************************/
214 209 void GFitsTableFltCol::save(void)
215 210 {
216   - // Continue only if a FITS file is connected and data have been loaded
217   - if (m_fitsfile.Fptr != NULL && m_colnum > 0 && m_data != NULL) {
218   -
219   - // Move to the HDU
220   - int status = 0;
221   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
222   - &status);
223   - if (status != 0)
224   - throw GException::fits_hdu_not_found(G_SAVE,
225   - (m_fitsfile.HDUposition)+1,
226   - status);
227   - // Save the column data
228   - status = __ffpcn(&m_fitsfile, __TFLOAT, m_colnum, 1, 1,
229   - (long)m_size, m_data, m_nulval, &status);
230   - if (status != 0)
231   - throw GException::fits_error(G_SAVE, status);
232   -
233   - } // endif: FITS file was connected
  211 + // Save column
  212 + save_column();
234 213  
235 214 // Return
236 215 return;
... ... @@ -410,8 +389,6 @@ void GFitsTableFltCol::init_members(void)
410 389 {
411 390 // Initialise members
412 391 m_type = __TFLOAT;
413   - m_size = 0;
414   - m_anynul = 0;
415 392 m_data = NULL;
416 393 m_nulval = NULL;
417 394  
... ... @@ -428,8 +405,6 @@ void GFitsTableFltCol::init_members(void)
428 405 void GFitsTableFltCol::copy_members(const GFitsTableFltCol& column)
429 406 {
430 407 // Copy attributes
431   - m_size = column.m_size;
432   - m_anynul = column.m_anynul;
433 408  
434 409 // Copy column data
435 410 if (column.m_data != NULL && m_size > 0) {
... ... @@ -469,55 +444,6 @@ void GFitsTableFltCol::free_members(void)
469 444  
470 445  
471 446 /***********************************************************************//**
472   - * @brief Fetch column data
473   - *
474   - * @exception GException::fits_error
475   - * An error occured while loading column data from FITS file.
476   - *
477   - * If a FITS file is attached to the column the data are loaded into memory
478   - * from the FITS file. If no FITS file is attached, memory is allocated
479   - * to hold the column data and all cells are set to 0.
480   - ***************************************************************************/
481   -void GFitsTableFltCol::fetch_data(void)
482   -{
483   - // Calculate size of memory
484   - m_size = m_number * m_length;
485   -
486   - // Load only if the column has a positive size
487   - if (m_size > 0) {
488   -
489   - // Allocate fresh memory
490   - if (m_data != NULL) delete [] m_data;
491   - m_data = new float[m_size];
492   -
493   - // If a FITS file is attached then load column data from the FITS
494   - // file
495   - if (m_fitsfile.Fptr != NULL) {
496   - int status = 0;
497   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
498   - &status);
499   - status = __ffgcv(&m_fitsfile, __TFLOAT, m_colnum, 1, 1, m_size,
500   - m_nulval, m_data, &m_anynul, &status);
501   - if (status != 0)
502   - throw GException::fits_error(G_FETCH_DATA, status);
503   - }
504   -
505   - // ... otherwise initialise all column values to 0
506   - else {
507   - for (int i = 0; i < m_size; ++i)
508   - m_data[i] = 0.0;
509   - }
510   -
511   - } // endif: column has a positive size
512   -
513   - // Return
514   - return;
515   -}
516   -
517   -
518   -
519   -
520   -/***********************************************************************//**
521 447 * @brief Returns format string of ASCII table
522 448 ***************************************************************************/
523 449 std::string GFitsTableFltCol::ascii_format(void) const
... ... @@ -555,6 +481,61 @@ std::string GFitsTableFltCol::binary_format(void) const
555 481 }
556 482  
557 483  
  484 +/***********************************************************************//**
  485 + * @brief Allocates column data
  486 + ***************************************************************************/
  487 +void GFitsTableFltCol::alloc_data(void)
  488 +{
  489 + // Free any existing memory
  490 + if (m_data != NULL) delete [] m_data;
  491 +
  492 + // Mark pointer as free
  493 + m_data = NULL;
  494 +
  495 + // Allocate new data
  496 + if (m_size > 0)
  497 + m_data = new float[m_size];
  498 +
  499 + // Return
  500 + return;
  501 +}
  502 +
  503 +
  504 +/***********************************************************************//**
  505 + * @brief Initialise column data
  506 + ***************************************************************************/
  507 +void GFitsTableFltCol::init_data(void)
  508 +{
  509 + // Initialise data if they exist
  510 + if (m_data != NULL) {
  511 + for (int i = 0; i < m_size; ++i)
  512 + m_data[i] = 0.0;
  513 + }
  514 +
  515 + // Return
  516 + return;
  517 +}
  518 +
  519 +
  520 +/***********************************************************************//**
  521 + * @brief Fetch column data
  522 + *
  523 + * If a FITS file is attached to the column the data are loaded into memory
  524 + * from the FITS file. If no FITS file is attached, memory is allocated
  525 + * to hold the column data and all cells are set to 0.
  526 + *
  527 + * Refer to GFitsTableCol::load_column for more information.
  528 + ***************************************************************************/
  529 +void GFitsTableFltCol::fetch_data(void)
  530 +{
  531 + // Save column
  532 + load_column();
  533 +
  534 + // Return
  535 + return;
  536 +}
  537 +
  538 +
558 539 /*==========================================================================
559 540 = =
560 541 = GFitsTableFltCol friends =
... ... @@ -569,39 +550,8 @@ std::string GFitsTableFltCol::binary_format(void) const
569 550 ***************************************************************************/
570 551 ostream& operator<< (ostream& os, const GFitsTableFltCol& column)
571 552 {
572   - // Put column name in stream
573   - os << "'" << column.m_name << "'";
574   -
575   - // Put FITS column number in stream
576   - if (column.m_colnum > 0)
577   - os << " [fits_colnum=" << column.m_colnum << "]";
578   - else
579   - os << " [not linked to FITS file]";
580   -
581   - // Put column type in stream
582   - os << " " << column.ascii_format();
583   - os << " " << column.binary_format();
584   -
585   - // Put data loading in stream
586   - if (column.m_data == NULL)
587   - os << " (not loaded)";
588   - else
589   - os << " (loaded in memory)";
590   -
591   - // Set data area size
592   - os << " size=" << column.m_size;
593   -
594   - // Set vector length
595   - os << " repeat=" << column.m_repeat;
596   -
597   - // Set width
598   - os << " width=" << column.m_width;
599   -
600   - // Set number
601   - os << " number=" << column.m_number;
602   -
603   - // Set length
604   - os << " length=" << column.m_length;
  553 + // Dump column in output stream
  554 + column.dump_column(os, column.m_data);
605 555  
606 556 // Return output stream
607 557 return os;
... ...
src/fits/GFitsTableLngCol.cpp
... ... @@ -21,11 +21,9 @@
21 21 /* __ Namespaces _________________________________________________________ */
22 22  
23 23 /* __ Method name definitions ____________________________________________ */
24   -#define G_SAVE "GFitsTableLngCol::save()"
25   -#define G_STRING "GFitsTableLngCol::string(const int&, const int&)"
26   -#define G_REAL "GFitsTableLngCol::real(const int&, const int&)"
27   -#define G_INTEGER "GFitsTableLngCol::integer(const int&, const int&)"
28   -#define G_FETCH_DATA "GFitsTableLngCol::fetch_data()"
  24 +#define G_STRING "GFitsTableLngCol::string(const int&, const int&)"
  25 +#define G_REAL "GFitsTableLngCol::real(const int&, const int&)"
  26 +#define G_INTEGER "GFitsTableLngCol::integer(const int&, const int&)"
29 27  
30 28 /* __ Macros _____________________________________________________________ */
31 29  
... ... @@ -78,8 +76,8 @@ GFitsTableLngCol::GFitsTableLngCol(const std::string&amp; name,
78 76 *
79 77 * @param[in] column Column from which class instance should be built.
80 78 ***************************************************************************/
81   -GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol& column) :
82   - GFitsTableCol(column)
  79 +GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol& column)
  80 + : GFitsTableCol(column)
83 81 {
84 82 // Initialise class members for clean destruction
85 83 init_members();
... ... @@ -159,7 +157,7 @@ long&amp; GFitsTableLngCol::operator() (const int&amp; row, const int&amp; inx)
159 157 if (m_data == NULL) fetch_data();
160 158  
161 159 // Calculate pixel offset
162   - int offset = row * m_repeat + inx;
  160 + int offset = row * m_number + inx;
163 161  
164 162 // Return image pixel
165 163 return m_data[offset];
... ... @@ -180,13 +178,13 @@ long&amp; GFitsTableLngCol::operator() (const int&amp; row, const int&amp; inx)
180 178 * if range checking is required.
181 179 ***************************************************************************/
182 180 const long& GFitsTableLngCol::operator() (const int& row, const int& inx)
183   - const
  181 + const
184 182 {
185 183 // If data are not available then load them now
186 184 if (m_data == NULL) ((GFitsTableLngCol*)this)->fetch_data();
187 185  
188 186 // Calculate pixel offset
189   - int offset = row * m_repeat + inx;
  187 + int offset = row * m_number + inx;
190 188  
191 189 // Return image pixel
192 190 return m_data[offset];
... ... @@ -202,27 +200,16 @@ const long&amp; GFitsTableLngCol::operator() (const int&amp; row, const int&amp; inx)
202 200 /***********************************************************************//**
203 201 * @brief Save table column into FITS file
204 202 *
205   - * @exception GException::fits_hdu_not_found
206   - * Specified HDU not found in FITS file.
  203 + * The table column is only saved if it is linked to a FITS file and if the
  204 + * data are indeed present in the class instance. This avoids saving of data
  205 + * that have not been modified.
  206 + *
  207 + * Refer to GFitsTableCol::save_column() for more information.
207 208 ***************************************************************************/
208 209 void GFitsTableLngCol::save(void)
209 210 {
210   - // Continue only if a FITS file is connected
211   - if (m_fitsfile.Fptr != NULL) {
212   -
213   - // Move to the HDU
214   - int status = 0;
215   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
216   - &status);
217   - if (status != 0)
218   - throw GException::fits_hdu_not_found(G_SAVE,
219   - (m_fitsfile.HDUposition)+1,
220   - status);
221   -
222   - // Save the column data
223   - // TBD
224   -
225   - } // endif: FITS file was connected
  211 + // Save column
  212 + save_column();
226 213  
227 214 // Return
228 215 return;
... ... @@ -254,7 +241,7 @@ std::string GFitsTableLngCol::string(const int&amp; row, const int&amp; inx)
254 241 throw GException::out_of_range(G_STRING, inx, 0, m_number-1);
255 242  
256 243 // Get index
257   - int offset = row * m_repeat + inx;
  244 + int offset = row * m_number + inx;
258 245  
259 246 // Convert long into string
260 247 ostringstream s_value;
... ... @@ -290,7 +277,7 @@ double GFitsTableLngCol::real(const int&amp; row, const int&amp; inx)
290 277 throw GException::out_of_range(G_REAL, inx, 0, m_number-1);
291 278  
292 279 // Get index
293   - int offset = row * m_repeat + inx;
  280 + int offset = row * m_number + inx;
294 281  
295 282 // Convert long into double
296 283 double value = (double)m_data[offset];
... ... @@ -325,7 +312,7 @@ int GFitsTableLngCol::integer(const int&amp; row, const int&amp; inx)
325 312 throw GException::out_of_range(G_INTEGER, inx, 0, m_number-1);
326 313  
327 314 // Get index
328   - int offset = row * m_repeat + inx;
  315 + int offset = row * m_number + inx;
329 316  
330 317 // Convert long into int
331 318 int value = (int)m_data[offset];
... ... @@ -402,8 +389,6 @@ void GFitsTableLngCol::init_members(void)
402 389 {
403 390 // Initialise members
404 391 m_type = __TLONG;
405   - m_size = 0;
406   - m_anynul = 0;
407 392 m_data = NULL;
408 393 m_nulval = NULL;
409 394  
... ... @@ -420,8 +405,6 @@ void GFitsTableLngCol::init_members(void)
420 405 void GFitsTableLngCol::copy_members(const GFitsTableLngCol& column)
421 406 {
422 407 // Copy attributes
423   - m_size = column.m_size;
424   - m_anynul = column.m_anynul;
425 408  
426 409 // Copy column data
427 410 if (column.m_data != NULL && m_size > 0) {
... ... @@ -461,53 +444,6 @@ void GFitsTableLngCol::free_members(void)
461 444  
462 445  
463 446 /***********************************************************************//**
464   - * @brief Fetch column data
465   - *
466   - * @exception GException::fits_error
467   - * An error occured while loading column data from FITS file.
468   - *
469   - * If a FITS file is attached to the column the data are loaded into memory
470   - * from the FITS file. If no FITS file is attached, memory is allocated
471   - * to hold the column data and all cells are set to 0.
472   - ***************************************************************************/
473   -void GFitsTableLngCol::fetch_data(void)
474   -{
475   - // Calculate size of memory
476   - m_size = m_number * m_length;
477   -
478   - // Load only if the column has a positive size
479   - if (m_size > 0) {
480   -
481   - // Allocate fresh memory
482   - if (m_data != NULL) delete [] m_data;
483   - m_data = new long[m_size];
484   -
485   - // If a FITS file is attached then load column data from the FITS
486   - // file
487   - if (m_fitsfile.Fptr != NULL) {
488   - int status = 0;
489   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
490   - &status);
491   - status = __ffgcv(&m_fitsfile, __TLONG, m_colnum, 1, 1, m_size,
492   - m_nulval, m_data, &m_anynul, &status);
493   - if (status != 0)
494   - throw GException::fits_error(G_FETCH_DATA, status);
495   - }
496   -
497   - // ... otherwise initialise all column values to 0
498   - else {
499   - for (int i = 0; i < m_size; ++i)
500   - m_data[i] = 0;
501   - }
502   -
503   - } // endif: column has a positive size
504   -
505   - // Return
506   - return;
507   -}
508   -
509   -
510   -/***********************************************************************//**
511 447 * @brief Returns format string of ASCII table
512 448 ***************************************************************************/
513 449 std::string GFitsTableLngCol::ascii_format(void) const
... ... @@ -545,12 +481,82 @@ std::string GFitsTableLngCol::binary_format(void) const
545 481 }
546 482  
547 483  
  484 +/***********************************************************************//**
  485 + * @brief Allocates column data
  486 + ***************************************************************************/
  487 +void GFitsTableLngCol::alloc_data(void)
  488 +{
  489 + // Free any existing memory
  490 + if (m_data != NULL) delete [] m_data;
  491 +
  492 + // Mark pointer as free
  493 + m_data = NULL;
  494 +
  495 + // Allocate new data
  496 + if (m_size > 0)
  497 + m_data = new long[m_size];
  498 +
  499 + // Return
  500 + return;
  501 +}
  502 +
  503 +
  504 +/***********************************************************************//**
  505 + * @brief Initialise column data
  506 + ***************************************************************************/
  507 +void GFitsTableLngCol::init_data(void)
  508 +{
  509 + // Initialise data if they exist
  510 + if (m_data != NULL) {
  511 + for (int i = 0; i < m_size; ++i)
  512 + m_data[i] = 0;
  513 + }
  514 +
  515 + // Return
  516 + return;
  517 +}
  518 +
  519 +
  520 +/***********************************************************************//**
  521 + * @brief Fetch column data
  522 + *
  523 + * If a FITS file is attached to the column the data are loaded into memory
  524 + * from the FITS file. If no FITS file is attached, memory is allocated
  525 + * to hold the column data and all cells are set to 0.
  526 + *
  527 + * Refer to GFitsTableCol::load_column for more information.
  528 + ***************************************************************************/
  529 +void GFitsTableLngCol::fetch_data(void)
  530 +{
  531 + // Save column
  532 + load_column();
  533 +
  534 + // Return
  535 + return;
  536 +}
  537 +
  538 +
548 539 /*==========================================================================
549 540 = =
550 541 = GFitsTableLngCol friends =
551 542 = =
552 543 ==========================================================================*/
553 544  
  545 +/***********************************************************************//**
  546 + * @brief Output operator
  547 + *
  548 + * @param[in] os Output stream
  549 + * @param[in] column Column to put in output stream
  550 + ***************************************************************************/
  551 +ostream& operator<< (ostream& os, const GFitsTableLngCol& column)
  552 +{
  553 + // Dump column in output stream
  554 + column.dump_column(os, column.m_data);
  555 +
  556 + // Return output stream
  557 + return os;
  558 +}
  559 +
554 560  
555 561 /*==========================================================================
556 562 = =
... ...
src/fits/GFitsTableShtCol.cpp
... ... @@ -21,16 +21,9 @@
21 21 /* __ Namespaces _________________________________________________________ */
22 22  
23 23 /* __ Method name definitions ____________________________________________ */
24   -#define G_SAVE "GFitsTableShtCol::save()"
25   -#define G_STRING "GFitsTableShtCol::string(const int&, const int&)"
26   -#define G_REAL "GFitsTableShtCol::real(const int&, const int&)"
27   -#define G_INTEGER "GFitsTableShtCol::integer(const int&, const int&)"
28   -#define G_PTR_FLOAT "GFitsTableShtCol::ptr_float()"
29   -#define G_PTR_DOUBLE "GFitsTableShtCol::ptr_double()"
30   -#define G_PTR_SHORT "GFitsTableShtCol::ptr_short()"
31   -#define G_PTR_LONG "GFitsTableShtCol::ptr_long()"
32   -#define G_PTR_INT "GFitsTableShtCol::ptr_int()"
33   -#define G_LOAD "GFitsTableShtCol::load()"
  24 +#define G_STRING "GFitsTableShtCol::string(const int&, const int&)"
  25 +#define G_REAL "GFitsTableShtCol::real(const int&, const int&)"
  26 +#define G_INTEGER "GFitsTableShtCol::integer(const int&, const int&)"
34 27  
35 28 /* __ Macros _____________________________________________________________ */
36 29  
... ... @@ -45,9 +38,8 @@
45 38 = =
46 39 ==========================================================================*/
47 40  
48   -/***************************************************************************
49   - * Constructor *
50   - * ----------------------------------------------------------------------- *
  41 +/***********************************************************************//**
  42 + * @brief Constructor
51 43 ***************************************************************************/
52 44 GFitsTableShtCol::GFitsTableShtCol() : GFitsTableCol()
53 45 {
... ... @@ -79,9 +71,10 @@ GFitsTableShtCol::GFitsTableShtCol(const std::string&amp; name,
79 71 }
80 72  
81 73  
82   -/***************************************************************************
83   - * Copy constructor *
84   - * ----------------------------------------------------------------------- *
  74 +/***********************************************************************//**
  75 + * @brief Copy constructor
  76 + *
  77 + * @param[in] column Column from which class instance should be built.
85 78 ***************************************************************************/
86 79 GFitsTableShtCol::GFitsTableShtCol(const GFitsTableShtCol& column) : GFitsTableCol(column)
87 80 {
... ... @@ -96,9 +89,8 @@ GFitsTableShtCol::GFitsTableShtCol(const GFitsTableShtCol&amp; column) : GFitsTableC
96 89 }
97 90  
98 91  
99   -/***************************************************************************
100   - * Destructor *
101   - * ----------------------------------------------------------------------- *
  92 +/***********************************************************************//**
  93 + * @brief Destructor
102 94 ***************************************************************************/
103 95 GFitsTableShtCol::~GFitsTableShtCol()
104 96 {
... ... @@ -116,9 +108,10 @@ GFitsTableShtCol::~GFitsTableShtCol()
116 108 = =
117 109 ==========================================================================*/
118 110  
119   -/***************************************************************************
120   - * Assignment operator *
121   - * ----------------------------------------------------------------------- *
  111 +/***********************************************************************//**
  112 + * @brief Assignment operator
  113 + *
  114 + * @param[in] column Column which should be assigned
122 115 ***************************************************************************/
123 116 GFitsTableShtCol& GFitsTableShtCol::operator= (const GFitsTableShtCol& column)
124 117 {
... ... @@ -144,6 +137,59 @@ GFitsTableShtCol&amp; GFitsTableShtCol::operator= (const GFitsTableShtCol&amp; column)
144 137 }
145 138  
146 139  
  140 +/***********************************************************************//**
  141 + * @brief Column data access operator
  142 + *
  143 + * @param[in] row Row of column to access.
  144 + * @param[in] inx Vector index in column row to access
  145 + *
  146 + * Provides access to data in a column. No range checking is performed.
  147 + * Use one of
  148 + * GFitsTableShtCol::string(ix,iy),
  149 + * GFitsTableShtCol::real(ix;iy) or
  150 + * GFitsTableShtCol::integer(ix;iy)
  151 + * if range checking is required.
  152 + ***************************************************************************/
  153 +short& GFitsTableShtCol::operator() (const int& row, const int& inx)
  154 +{
  155 + // If data are not available then load them now
  156 + if (m_data == NULL) fetch_data();
  157 +
  158 + // Calculate pixel offset
  159 + int offset = row * m_number + inx;
  160 +
  161 + // Return data bin
  162 + return m_data[offset];
  163 +}
  164 +
  165 +
  166 +/***********************************************************************//**
  167 + * @brief Column data access operator (const variant)
  168 + *
  169 + * @param[in] row Row of column to access.
  170 + * @param[in] inx Vector index in column row to access
  171 + *
  172 + * Provides access to data in a column. No range checking is performed.
  173 + * Use one of
  174 + * GFitsTableDblCol::string(ix,iy),
  175 + * GFitsTableShtCol::real(ix;iy) or
  176 + * GFitsTableShtCol::integer(ix;iy)
  177 + * if range checking is required.
  178 + ***************************************************************************/
  179 +const short& GFitsTableShtCol::operator() (const int& row, const int& inx)
  180 + const
  181 +{
  182 + // If data are not available then load them now
  183 + if (m_data == NULL) ((GFitsTableShtCol*)this)->fetch_data();
  184 +
  185 + // Calculate pixel offset
  186 + int offset = row * m_number + inx;
  187 +
  188 + // Return data bin
  189 + return m_data[offset];
  190 +}
  191 +
  192 +
147 193 /*==========================================================================
148 194 = =
149 195 = GFitsTableShtCol public methods =
... ... @@ -153,149 +199,153 @@ GFitsTableShtCol&amp; GFitsTableShtCol::operator= (const GFitsTableShtCol&amp; column)
153 199 /***********************************************************************//**
154 200 * @brief Save table column into FITS file
155 201 *
156   - * @exception GException::fits_hdu_not_found
157   - * Specified HDU not found in FITS file.
  202 + * The table column is only saved if it is linked to a FITS file and if the
  203 + * data are indeed present in the class instance. This avoids saving of data
  204 + * that have not been modified.
  205 + *
  206 + * Refer to GFitsTableCol::save_column() for more information.
158 207 ***************************************************************************/
159 208 void GFitsTableShtCol::save(void)
160 209 {
161   - // Continue only if a FITS file is connected
162   - if (m_fitsfile.Fptr != NULL) {
163   -
164   - // Move to the HDU
165   - int status = 0;
166   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
167   - &status);
168   - if (status != 0)
169   - throw GException::fits_hdu_not_found(G_SAVE,
170   - (m_fitsfile.HDUposition)+1,
171   - status);
172   -
173   - // Save the column data
174   - // TBD
175   -
176   - } // endif: FITS file was connected
  210 + // Save column
  211 + save_column();
177 212  
178 213 // Return
179 214 return;
180 215 }
181 216  
182   -/***************************************************************************
183   - * Get string value *
184   - * ----------------------------------------------------------------------- *
  217 +
  218 +/***********************************************************************//**
  219 + * @brief Get string value
  220 + *
  221 + * @param[in] row Table row.
  222 + * @param[in] inx Table column vector index.
  223 + *
  224 + * @exception GException::out_of_range
  225 + * Table row or vector index are out of valid range.
  226 + *
  227 + * Returns value of specified row and vector index as string.
185 228 ***************************************************************************/
186   -std::string GFitsTableShtCol::string(const int& row, const int& col)
  229 +std::string GFitsTableShtCol::string(const int& row, const int& inx)
187 230 {
188   - // Make sure that data are loaded
189   - if (m_data == NULL)
190   - load();
  231 + // If data are not available then load them now
  232 + if (m_data == NULL) fetch_data();
191 233  
192 234 // Check row value
193 235 if (row < 0 || row >= m_length)
194 236 throw GException::out_of_range(G_STRING, row, 0, m_length-1);
195 237  
196   - // Check col value
197   - if (col < 0 || col >= m_number)
198   - throw GException::out_of_range(G_STRING, col, 0, m_number-1);
  238 + // Check inx value
  239 + if (inx < 0 || inx >= m_number)
  240 + throw GException::out_of_range(G_STRING, inx, 0, m_number-1);
199 241  
200 242 // Get index
201   - int inx = row * m_repeat + col;
  243 + int offset = row * m_number + inx;
202 244  
203   - // Convert short into string
  245 + // Convert double into string
204 246 ostringstream s_value;
205   - s_value << m_data[inx];
  247 + s_value << m_data[offset];
206 248  
207 249 // Return value
208 250 return s_value.str();
209 251 }
210 252  
211 253  
212   -/***************************************************************************
213   - * Get real value *
214   - * ----------------------------------------------------------------------- *
  254 +/***********************************************************************//**
  255 + * @brief Get double precision value
  256 + *
  257 + * @param[in] row Table row.
  258 + * @param[in] inx Table column vector index.
  259 + *
  260 + * @exception GException::out_of_range
  261 + * Table row or vector index are out of valid range.
  262 + *
  263 + * Returns value of specified row and vector index as double precision.
215 264 ***************************************************************************/
216   -double GFitsTableShtCol::real(const int& row, const int& col)
  265 +double GFitsTableShtCol::real(const int& row, const int& inx)
217 266 {
218   - // Make sure that data are loaded
219   - if (m_data == NULL)
220   - load();
  267 + // If data are not available then load them now
  268 + if (m_data == NULL) fetch_data();
221 269  
222 270 // Check row value
223 271 if (row < 0 || row >= m_length)
224 272 throw GException::out_of_range(G_REAL, row, 0, m_length-1);
225 273  
226   - // Check col value
227   - if (col < 0 || col >= m_number)
228   - throw GException::out_of_range(G_REAL, col, 0, m_number-1);
  274 + // Check inx value
  275 + if (inx < 0 || inx >= m_number)
  276 + throw GException::out_of_range(G_REAL, inx, 0, m_number-1);
229 277  
230 278 // Get index
231   - int inx = row * m_repeat + col;
  279 + int offset = row * m_number + inx;
232 280  
233 281 // Convert short into double
234   - double value = (double)m_data[inx];
  282 + double value = (double)m_data[offset];
235 283  
236 284 // Return value
237 285 return value;
238 286 }
239 287  
240 288  
241   -/***************************************************************************
242   - * Get int value *
243   - * ----------------------------------------------------------------------- *
  289 +/***********************************************************************//**
  290 + * @brief Get integer value
  291 + *
  292 + * @param[in] row Table row.
  293 + * @param[in] inx Table column vector index.
  294 + *
  295 + * @exception GException::out_of_range
  296 + * Table row or vector index are out of valid range.
  297 + *
  298 + * Returns value of specified row and vector index as integer.
244 299 ***************************************************************************/
245   -int GFitsTableShtCol::integer(const int& row, const int& col)
  300 +int GFitsTableShtCol::integer(const int& row, const int& inx)
246 301 {
247   - // Make sure that data are loaded
248   - if (m_data == NULL)
249   - load();
  302 + // If data are not available then load them now
  303 + if (m_data == NULL) fetch_data();
250 304  
251 305 // Check row value
252 306 if (row < 0 || row >= m_length)
253 307 throw GException::out_of_range(G_INTEGER, row, 0, m_length-1);
254 308  
255 309 // Check col value
256   - if (col < 0 || col >= m_number)
257   - throw GException::out_of_range(G_INTEGER, col, 0, m_number-1);
  310 + if (inx < 0 || inx >= m_number)
  311 + throw GException::out_of_range(G_INTEGER, inx, 0, m_number-1);
258 312  
259 313 // Get index
260   - int inx = row * m_repeat + col;
  314 + int offset = row * m_number + inx;
261 315  
262 316 // Convert short into int
263   - int value = (int)m_data[inx];
  317 + int value = (int)m_data[offset];
264 318  
265 319 // Return value
266 320 return value;
267 321 }
268 322  
269 323  
270   -/***************************************************************************
271   - * Access to invalid data pointers *
272   - * ----------------------------------------------------------------------- *
  324 +/***********************************************************************//**
  325 + * @brief Clone column
273 326 ***************************************************************************/
274   -float* GFitsTableShtCol::ptr_float(void)
  327 +GFitsTableShtCol* GFitsTableShtCol::clone(void) const
275 328 {
276   - throw GException::fits_invalid_type(G_PTR_FLOAT,
277   - "No <float> pointer allowed to <short> array");
  329 + return new GFitsTableShtCol(*this);
278 330 }
279   -double* GFitsTableShtCol::ptr_double(void)
280   -{
281   - throw GException::fits_invalid_type(G_PTR_DOUBLE,
282   - "No <double> pointer allowed to <short> array");
283   -}
284   -long* GFitsTableShtCol::ptr_long(void)
285   -{
286   - throw GException::fits_invalid_type(G_PTR_LONG,
287   - "No <long> pointer allowed to <short> array");
288   -}
289   -int* GFitsTableShtCol::ptr_int(void)
  331 +
  332 +
  333 +/***********************************************************************//**
  334 + * @brief Return pointer to short integer column
  335 + ***************************************************************************/
  336 +short* GFitsTableShtCol::data(void)
290 337 {
291   - throw GException::fits_invalid_type(G_PTR_INT,
292   - "No <int> pointer allowed to <short> array");
  338 + return m_data;
293 339 }
294 340  
295 341  
296   -/***************************************************************************
297   - * Set NULL string *
298   - * ----------------------------------------------------------------------- *
  342 +/***********************************************************************//**
  343 + * @brief Set NULL value
  344 + *
  345 + * @param[in] value Pointer on NULL value
  346 + *
  347 + * Allows the specification of the FITS table NULL value. If value=NULL the
  348 + * data will not be screened for NULL values.
299 349 ***************************************************************************/
300 350 void GFitsTableShtCol::set_nullval(const short* value)
301 351 {
... ... @@ -312,13 +362,13 @@ void GFitsTableShtCol::set_nullval(const short* value)
312 362 *m_nulval = *value;
313 363 }
314 364  
315   - // Re-load column
316   - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!!
  365 + // Re-load column
  366 +/*
317 367 if (m_data != NULL) {
318   - //save();
  368 + save();
319 369 load();
320 370 }
321   -
  371 +*/
322 372 // Return
323 373 return;
324 374 }
... ... @@ -330,16 +380,13 @@ void GFitsTableShtCol::set_nullval(const short* value)
330 380 = =
331 381 ==========================================================================*/
332 382  
333   -/***************************************************************************
334   - * Initialise class members *
335   - * ----------------------------------------------------------------------- *
  383 +/***********************************************************************//**
  384 + * @brief Initialise class members
336 385 ***************************************************************************/
337 386 void GFitsTableShtCol::init_members(void)
338 387 {
339 388 // Initialise members
340 389 m_type = __TSHORT;
341   - m_size = 0;
342   - m_anynul = 0;
343 390 m_data = NULL;
344 391 m_nulval = NULL;
345 392  
... ... @@ -348,15 +395,14 @@ void GFitsTableShtCol::init_members(void)
348 395 }
349 396  
350 397  
351   -/***************************************************************************
352   - * Copy class members *
353   - * ----------------------------------------------------------------------- *
  398 +/***********************************************************************//**
  399 + * @brief Copy class members
  400 + *
  401 + * @param[in] column Column for which members should be copied.
354 402 ***************************************************************************/
355 403 void GFitsTableShtCol::copy_members(const GFitsTableShtCol& column)
356 404 {
357 405 // Copy attributes
358   - m_size = column.m_size;
359   - m_anynul = column.m_anynul;
360 406  
361 407 // Copy column data
362 408 if (column.m_data != NULL && m_size > 0) {
... ... @@ -377,9 +423,8 @@ void GFitsTableShtCol::copy_members(const GFitsTableShtCol&amp; column)
377 423 }
378 424  
379 425  
380   -/***************************************************************************
381   - * Delete class members *
382   - * ----------------------------------------------------------------------- *
  426 +/***********************************************************************//**
  427 + * @brief Delete class members
383 428 ***************************************************************************/
384 429 void GFitsTableShtCol::free_members(void)
385 430 {
... ... @@ -396,32 +441,6 @@ void GFitsTableShtCol::free_members(void)
396 441 }
397 442  
398 443  
399   -/***************************************************************************
400   - * Load column data *
401   - * ----------------------------------------------------------------------- *
402   - ***************************************************************************/
403   -void GFitsTableShtCol::load(void)
404   -{
405   - // Calculate size of memory
406   - m_size = m_number * m_length;
407   -
408   - // Allocate memory
409   - if (m_data != NULL) delete [] m_data;
410   - m_data = new short[m_size];
411   -
412   - // Load column data
413   - int status = 0;
414   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
415   - status = __ffgcv(&m_fitsfile, __TSHORT, m_colnum, 1, 1, m_size,
416   - m_nulval, m_data, &m_anynul, &status);
417   - if (status != 0)
418   - throw GException::fits_error(G_LOAD, status);
419   -
420   - // Return
421   - return;
422   -}
423   -
424   -
425 444 /***********************************************************************//**
426 445 * @brief Returns format string of ASCII table
427 446 ***************************************************************************/
... ... @@ -460,12 +479,82 @@ std::string GFitsTableShtCol::binary_format(void) const
460 479 }
461 480  
462 481  
  482 +/***********************************************************************//**
  483 + * @brief Allocates column data
  484 + ***************************************************************************/
  485 +void GFitsTableShtCol::alloc_data(void)
  486 +{
  487 + // Free any existing memory
  488 + if (m_data != NULL) delete [] m_data;
  489 +
  490 + // Mark pointer as free
  491 + m_data = NULL;
  492 +
  493 + // Allocate new data
  494 + if (m_size > 0)
  495 + m_data = new short[m_size];
  496 +
  497 + // Return
  498 + return;
  499 +}
  500 +
  501 +
  502 +/***********************************************************************//**
  503 + * @brief Initialise column data
  504 + ***************************************************************************/
  505 +void GFitsTableShtCol::init_data(void)
  506 +{
  507 + // Initialise data if they exist
  508 + if (m_data != NULL) {
  509 + for (int i = 0; i < m_size; ++i)
  510 + m_data[i] = 0;
  511 + }
  512 +
  513 + // Return
  514 + return;
  515 +}
  516 +
  517 +
  518 +/***********************************************************************//**
  519 + * @brief Fetch column data
  520 + *
  521 + * If a FITS file is attached to the column the data are loaded into memory
  522 + * from the FITS file. If no FITS file is attached, memory is allocated
  523 + * to hold the column data and all cells are set to 0.
  524 + *
  525 + * Refer to GFitsTableCol::load_column for more information.
  526 + ***************************************************************************/
  527 +void GFitsTableShtCol::fetch_data(void)
  528 +{
  529 + // Save column
  530 + load_column();
  531 +
  532 + // Return
  533 + return;
  534 +}
  535 +
  536 +
463 537 /*==========================================================================
464 538 = =
465 539 = GFitsTableShtCol friends =
466 540 = =
467 541 ==========================================================================*/
468 542  
  543 +/***********************************************************************//**
  544 + * @brief Output operator
  545 + *
  546 + * @param[in] os Output stream
  547 + * @param[in] column Column to put in output stream
  548 + ***************************************************************************/
  549 +ostream& operator<< (ostream& os, const GFitsTableShtCol& column)
  550 +{
  551 + // Dump column in output stream
  552 + column.dump_column(os, column.m_data);
  553 +
  554 + // Return output stream
  555 + return os;
  556 +}
  557 +
469 558  
470 559 /*==========================================================================
471 560 = =
... ...
src/fits/GFitsTableStrCol.cpp
... ... @@ -21,17 +21,9 @@
21 21 /* __ Namespaces _________________________________________________________ */
22 22  
23 23 /* __ Method name definitions ____________________________________________ */
24   -#define G_SAVE "GFitsTableStrCol::save()"
25   -#define G_STRING "GFitsTableStrCol::string(const int&, const int&)"
26   -#define G_REAL "GFitsTableStrCol::real(const int&, const int&)"
27   -#define G_INTEGER "GFitsTableStrCol::integer(const int&, const int&)"
28   -#define G_PTR_STRING "GFitsTableStrCol::ptr_string()"
29   -#define G_PTR_FLOAT "GFitsTableStrCol::ptr_float()"
30   -#define G_PTR_DOUBLE "GFitsTableStrCol::ptr_double()"
31   -#define G_PTR_SHORT "GFitsTableStrCol::ptr_short()"
32   -#define G_PTR_LONG "GFitsTableStrCol::ptr_long()"
33   -#define G_PTR_INT "GFitsTableStrCol::ptr_int()"
34   -#define G_LOAD "GFitsTableStrCol::load()"
  24 +#define G_STRING "GFitsTableStrCol::string(const int&, const int&)"
  25 +#define G_REAL "GFitsTableStrCol::real(const int&, const int&)"
  26 +#define G_INTEGER "GFitsTableStrCol::integer(const int&, const int&)"
35 27  
36 28 /* __ Macros _____________________________________________________________ */
37 29  
... ... @@ -46,9 +38,8 @@
46 38 = =
47 39 ==========================================================================*/
48 40  
49   -/***************************************************************************
50   - * Constructor *
51   - * ----------------------------------------------------------------------- *
  41 +/***********************************************************************//**
  42 + * @brief Constructor
52 43 ***************************************************************************/
53 44 GFitsTableStrCol::GFitsTableStrCol() : GFitsTableCol()
54 45 {
... ... @@ -60,11 +51,35 @@ GFitsTableStrCol::GFitsTableStrCol() : GFitsTableCol()
60 51 }
61 52  
62 53  
63   -/***************************************************************************
64   - * Copy constructor *
65   - * ----------------------------------------------------------------------- *
  54 +/***********************************************************************//**
  55 + * @brief Constructor
  56 + *
  57 + * @param[in] name Name of column.
  58 + * @param[in] length Length of column.
  59 + * @param[in] width Length of individual string.
  60 + * @param[in] size Number of strings in each column.
66 61 ***************************************************************************/
67   -GFitsTableStrCol::GFitsTableStrCol(const GFitsTableStrCol& column) : GFitsTableCol(column)
  62 +GFitsTableStrCol::GFitsTableStrCol(const std::string& name,
  63 + const int& length,
  64 + const int& width,
  65 + const int& size)
  66 + : GFitsTableCol(name, length, size, width)
  67 +{
  68 + // Initialise class members for clean destruction
  69 + init_members();
  70 +
  71 + // Return
  72 + return;
  73 +}
  74 +
  75 +
  76 +/***********************************************************************//**
  77 + * @brief Copy constructor
  78 + *
  79 + * @param[in] column Column from which class instance should be built.
  80 + ***************************************************************************/
  81 +GFitsTableStrCol::GFitsTableStrCol(const GFitsTableStrCol& column)
  82 + : GFitsTableCol(column)
68 83 {
69 84 // Initialise class members for clean destruction
70 85 init_members();
... ... @@ -77,9 +92,8 @@ GFitsTableStrCol::GFitsTableStrCol(const GFitsTableStrCol&amp; column) : GFitsTableC
77 92 }
78 93  
79 94  
80   -/***************************************************************************
81   - * Destructor *
82   - * ----------------------------------------------------------------------- *
  95 +/***********************************************************************//**
  96 + * @brief Destructor
83 97 ***************************************************************************/
84 98 GFitsTableStrCol::~GFitsTableStrCol()
85 99 {
... ... @@ -97,9 +111,10 @@ GFitsTableStrCol::~GFitsTableStrCol()
97 111 = =
98 112 ==========================================================================*/
99 113  
100   -/***************************************************************************
101   - * Assignment operator *
102   - * ----------------------------------------------------------------------- *
  114 +/***********************************************************************//**
  115 + * @brief Assignment operator
  116 + *
  117 + * @param[in] column Column which should be assigned
103 118 ***************************************************************************/
104 119 GFitsTableStrCol& GFitsTableStrCol::operator= (const GFitsTableStrCol& column)
105 120 {
... ... @@ -125,6 +140,59 @@ GFitsTableStrCol&amp; GFitsTableStrCol::operator= (const GFitsTableStrCol&amp; column)
125 140 }
126 141  
127 142  
  143 +/***********************************************************************//**
  144 + * @brief Column data access operator
  145 + *
  146 + * @param[in] row Row of column to access.
  147 + * @param[in] inx Vector index in column row to access
  148 + *
  149 + * Provides access to data in a column. No range checking is performed.
  150 + * Use one of
  151 + * GFitsTableStrCol::string(ix,iy),
  152 + * GFitsTableStrCol::real(ix;iy) or
  153 + * GFitsTableStrCol::integer(ix;iy)
  154 + * if range checking is required.
  155 + ***************************************************************************/
  156 +std::string& GFitsTableStrCol::operator() (const int& row, const int& inx)
  157 +{
  158 + // If data are not available then load them now
  159 + if (m_data == NULL) fetch_data();
  160 +
  161 + // Calculate pixel offset
  162 + int offset = row * m_number + inx;
  163 +
  164 + // Return data bin
  165 + return m_data[offset];
  166 +}
  167 +
  168 +
  169 +/***********************************************************************//**
  170 + * @brief Column data access operator (const variant)
  171 + *
  172 + * @param[in] row Row of column to access.
  173 + * @param[in] inx Vector index in column row to access
  174 + *
  175 + * Provides access to data in a column. No range checking is performed.
  176 + * Use one of
  177 + * GFitsTableStrCol::string(ix,iy),
  178 + * GFitsTableStrCol::real(ix;iy) or
  179 + * GFitsTableStrCol::integer(ix;iy)
  180 + * if range checking is required.
  181 + ***************************************************************************/
  182 +const std::string& GFitsTableStrCol::operator() (const int& row, const int& inx)
  183 + const
  184 +{
  185 + // If data are not available then load them now
  186 + if (m_data == NULL) ((GFitsTableStrCol*)this)->fetch_data();
  187 +
  188 + // Calculate pixel offset
  189 + int offset = row * m_number + inx;
  190 +
  191 + // Return data bin
  192 + return m_data[offset];
  193 +}
  194 +
  195 +
128 196 /*==========================================================================
129 197 = =
130 198 = GFitsTableStrCol public methods =
... ... @@ -134,171 +202,186 @@ GFitsTableStrCol&amp; GFitsTableStrCol::operator= (const GFitsTableStrCol&amp; column)
134 202 /***********************************************************************//**
135 203 * @brief Save table column into FITS file
136 204 *
137   - * @exception GException::fits_hdu_not_found
138   - * Specified HDU not found in FITS file.
  205 + * The table column is only saved if it is linked to a FITS file and if the
  206 + * data are indeed present in the class instance. This avoids saving of data
  207 + * that have not been modified.
  208 + *
  209 + * Refer to GFitsTableCol::save_column() for more information.
139 210 ***************************************************************************/
140 211 void GFitsTableStrCol::save(void)
141 212 {
142   - // Continue only if a FITS file is connected
143   - if (m_fitsfile.Fptr != NULL) {
  213 + // Free buffer
  214 + free_buffer();
144 215  
145   - // Move to the HDU
146   - int status = 0;
147   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
148   - &status);
149   - if (status != 0)
150   - throw GException::fits_hdu_not_found(G_SAVE,
151   - (m_fitsfile.HDUposition)+1,
152   - status);
  216 + // Allocate buffer
  217 + alloc_buffer();
153 218  
154   - // Save the column data
155   - // TBD
  219 + // Transfer string into buffer
  220 + for (int i = 0; i < m_size; ++i)
  221 + strncpy(m_buffer[i], m_data[i].c_str(), m_width);
156 222  
157   - } // endif: FITS file was connected
  223 + // Save column
  224 + save_column();
  225 +
  226 + // Free buffer
  227 + free_buffer();
158 228  
159 229 // Return
160 230 return;
161 231 }
162 232  
163   -/***************************************************************************
164   - * Get string value *
165   - * ----------------------------------------------------------------------- *
  233 +
  234 +/***********************************************************************//**
  235 + * @brief Get string value
  236 + *
  237 + * @param[in] row Table row.
  238 + * @param[in] inx Table column vector index.
  239 + *
  240 + * @exception GException::out_of_range
  241 + * Table row or vector index are out of valid range.
  242 + *
  243 + * Returns value of specified row and vector index as string.
166 244 ***************************************************************************/
167   -std::string GFitsTableStrCol::string(const int& row, const int& col)
  245 +std::string GFitsTableStrCol::string(const int& row, const int& inx)
168 246 {
169   - // Make sure that data are loaded
170   - if (m_data == NULL)
171   - load();
  247 + // If data are not available then load them now
  248 + if (m_data == NULL) fetch_data();
172 249  
173 250 // Check row value
174 251 if (row < 0 || row >= m_length)
175 252 throw GException::out_of_range(G_STRING, row, 0, m_length-1);
176 253  
177   - // Check col value
178   - if (col < 0 || col >= m_number)
179   - throw GException::out_of_range(G_STRING, col, 0, m_number-1);
  254 + // Check inx value
  255 + if (inx < 0 || inx >= m_number)
  256 + throw GException::out_of_range(G_STRING, inx, 0, m_number-1);
180 257  
181   - // Get string index
182   - int inx = row * m_repeat + col;
183   -
184   - // Assign C string to C++ std::string
185   - std::string value;
186   - value.assign(m_data[inx]);
  258 + // Get index
  259 + int offset = row * m_number + inx;
187 260  
188 261 // Return value
189   - return value;
  262 + return m_data[offset];
190 263 }
191 264  
192 265  
193   -/***************************************************************************
194   - * Get real value *
195   - * ----------------------------------------------------------------------- *
  266 +/***********************************************************************//**
  267 + * @brief Get double precision value
  268 + *
  269 + * @param[in] row Table row.
  270 + * @param[in] inx Table column vector index.
  271 + *
  272 + * @exception GException::out_of_range
  273 + * Table row or vector index are out of valid range.
  274 + *
  275 + * Returns value of specified row and vector index as double precision.
196 276 ***************************************************************************/
197   -double GFitsTableStrCol::real(const int& row, const int& col)
  277 +double GFitsTableStrCol::real(const int& row, const int& inx)
198 278 {
199   - // Make sure that data are loaded
200   - if (m_data == NULL)
201   - load();
  279 + // If data are not available then load them now
  280 + if (m_data == NULL) fetch_data();
202 281  
203 282 // Check row value
204 283 if (row < 0 || row >= m_length)
205   - throw GException::out_of_range(G_STRING, row, 0, m_length-1);
  284 + throw GException::out_of_range(G_REAL, row, 0, m_length-1);
206 285  
207   - // Check col value
208   - if (col < 0 || col >= m_number)
209   - throw GException::out_of_range(G_STRING, col, 0, m_number-1);
  286 + // Check inx value
  287 + if (inx < 0 || inx >= m_number)
  288 + throw GException::out_of_range(G_REAL, inx, 0, m_number-1);
210 289  
211   - // Get string index
212   - int inx = row * m_repeat + col;
  290 + // Get index
  291 + int offset = row * m_number + inx;
213 292  
214 293 // Assign C string to double
215   - double value = atof(m_data[inx]);
  294 + double value = atof(m_data[offset].c_str());
216 295  
217 296 // Return value
218 297 return value;
219 298 }
220 299  
221 300  
222   -/***************************************************************************
223   - * Get int value *
224   - * ----------------------------------------------------------------------- *
  301 +/***********************************************************************//**
  302 + * @brief Get integer value
  303 + *
  304 + * @param[in] row Table row.
  305 + * @param[in] inx Table column vector index.
  306 + *
  307 + * @exception GException::out_of_range
  308 + * Table row or vector index are out of valid range.
  309 + *
  310 + * Returns value of specified row and vector index as integer.
225 311 ***************************************************************************/
226   -int GFitsTableStrCol::integer(const int& row, const int& col)
  312 +int GFitsTableStrCol::integer(const int& row, const int& inx)
227 313 {
228   - // Make sure that data are loaded
229   - if (m_data == NULL)
230   - load();
  314 + // If data are not available then load them now
  315 + if (m_data == NULL) fetch_data();
231 316  
232 317 // Check row value
233 318 if (row < 0 || row >= m_length)
234   - throw GException::out_of_range(G_STRING, row, 0, m_length-1);
  319 + throw GException::out_of_range(G_INTEGER, row, 0, m_length-1);
235 320  
236 321 // Check col value
237   - if (col < 0 || col >= m_number)
238   - throw GException::out_of_range(G_STRING, col, 0, m_number-1);
  322 + if (inx < 0 || inx >= m_number)
  323 + throw GException::out_of_range(G_INTEGER, inx, 0, m_number-1);
239 324  
240   - // Get string index
241   - int inx = row * m_repeat + col;
  325 + // Get index
  326 + int offset = row * m_number + inx;
242 327  
243 328 // Assign C string to int
244   - int value = atoi(m_data[inx]);
  329 + int value = atoi(m_data[offset].c_str());
245 330  
246 331 // Return value
247 332 return value;
248 333 }
249 334  
250 335  
251   -/***************************************************************************
252   - * Access to invalid data pointers *
253   - * ----------------------------------------------------------------------- *
  336 +/***********************************************************************//**
  337 + * @brief Clone column
254 338 ***************************************************************************/
255   -float* GFitsTableStrCol::ptr_float(void)
  339 +GFitsTableStrCol* GFitsTableStrCol::clone(void) const
256 340 {
257   - throw GException::fits_invalid_type(G_PTR_FLOAT, "No <float> pointer allowed to <string> array");
  341 + return new GFitsTableStrCol(*this);
258 342 }
259   -double* GFitsTableStrCol::ptr_double(void)
260   -{
261   - throw GException::fits_invalid_type(G_PTR_FLOAT, "No <double> pointer allowed to <string> array");
262   -}
263   -short* GFitsTableStrCol::ptr_short(void)
264   -{
265   - throw GException::fits_invalid_type(G_PTR_SHORT, "No <short> pointer allowed to <string> array");
266   -}
267   -long* GFitsTableStrCol::ptr_long(void)
268   -{
269   - throw GException::fits_invalid_type(G_PTR_LONG, "No <long> pointer allowed to <string> array");
270   -}
271   -int* GFitsTableStrCol::ptr_int(void)
  343 +
  344 +
  345 +/***********************************************************************//**
  346 + * @brief Return pointer to std::string column
  347 + ***************************************************************************/
  348 +std::string* GFitsTableStrCol::data(void)
272 349 {
273   - throw GException::fits_invalid_type(G_PTR_INT, "No <int> pointer allowed to <string> array");
  350 + return m_data;
274 351 }
275 352  
276 353  
277   -/***************************************************************************
278   - * Set NULL string *
279   - * ----------------------------------------------------------------------- *
  354 +
  355 +/***********************************************************************//**
  356 + * @brief Set NULL string
  357 + *
  358 + * @param[in] value Pointer on NULL string
  359 + *
  360 + * Allows the specification of the FITS table NULL string. If the string
  361 + * is empty the data will not be screened for NULL values.
280 362 ***************************************************************************/
281   -void GFitsTableStrCol::set_nullstr(const std::string string)
  363 +void GFitsTableStrCol::set_nullval(const std::string string)
282 364 {
283 365 // If NULL string is empty then reset the NULL string
284 366 if (string.empty()) {
285   - if (m_nulstr != NULL) delete [] m_nulstr;
286   - m_nulstr = NULL;
  367 + if (m_nulval != NULL) delete [] m_nulval;
  368 + m_nulval = NULL;
287 369 }
288 370  
289 371 // ... otherwise copy string into NULL string
290 372 else {
291   - if (m_nulstr != NULL) delete [] m_nulstr;
292   - m_nulstr = new char[m_width+1];
293   - strncpy(m_nulstr, string.c_str(), m_width);
  373 + if (m_nulval != NULL) delete [] m_nulval;
  374 + m_nulval = new char[m_width+1];
  375 + strncpy(m_nulval, string.c_str(), m_width);
294 376 }
295 377  
296   - // Re-load column
297   - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!!
  378 + // Re-load column
  379 +/*
298 380 if (m_data != NULL) {
299   - //save();
  381 + save();
300 382 load();
301 383 }
  384 +*/
302 385  
303 386 // Return
304 387 return;
... ... @@ -311,53 +394,40 @@ void GFitsTableStrCol::set_nullstr(const std::string string)
311 394 = =
312 395 ==========================================================================*/
313 396  
314   -/***************************************************************************
315   - * Initialise class members *
316   - * ----------------------------------------------------------------------- *
  397 +/***********************************************************************//**
  398 + * @brief Initialise class members
317 399 ***************************************************************************/
318 400 void GFitsTableStrCol::init_members(void)
319 401 {
320 402 // Initialise members
321 403 m_type = __TSTRING;
322   - m_size = 0;
323   - m_data = NULL;
324   - m_nulstr = NULL;
325   - m_anynul = 0;
  404 + m_data = NULL;
  405 + m_buffer = NULL;
  406 + m_nulval = NULL;
326 407  
327 408 // Return
328 409 return;
329 410 }
330 411  
331 412  
332   -/***************************************************************************
333   - * Copy class members *
334   - * ----------------------------------------------------------------------- *
335   - * Note: it is assumed that no memory has been allocated so far for the *
336   - * actual instance. *
  413 +/***********************************************************************//**
  414 + * @brief Copy class members
  415 + *
  416 + * @param[in] column Column for which members should be copied.
337 417 ***************************************************************************/
338 418 void GFitsTableStrCol::copy_members(const GFitsTableStrCol& column)
339 419 {
340   - // Copy string size
341   - m_size = column.m_size;
342   - m_anynul = column.m_anynul;
343   -
344 420 // Copy column data
345 421 if (column.m_data != NULL && m_size > 0) {
346   - m_data = new char*[m_size];
347   - for (int i = 0; i < m_size; ++i) {
348   - if (column.m_data[i] != NULL) {
349   - m_data[i] = new char[m_width+1];
350   - memcpy(m_data[i], column.m_data[i], m_width);
351   - }
352   - else
353   - m_data[i] = NULL;
354   - }
  422 + m_data = new std::string[m_size];
  423 + for (int i = 0; i < m_size; ++i)
  424 + m_data[i] = column.m_data[i];
355 425 }
356 426  
357   - // Copy nulstr data
358   - if (column.m_nulstr != NULL) {
359   - m_nulstr = new char[m_width+1];
360   - strncpy(m_nulstr, column.m_nulstr, m_width);
  427 + // Copy nulval data
  428 + if (column.m_nulval != NULL) {
  429 + m_nulval = new char[m_width+1];
  430 + strncpy(m_nulval, column.m_nulval, m_width);
361 431 }
362 432  
363 433 // Return
... ... @@ -365,65 +435,21 @@ void GFitsTableStrCol::copy_members(const GFitsTableStrCol&amp; column)
365 435 }
366 436  
367 437  
368   -/***************************************************************************
369   - * Delete class members *
370   - * ----------------------------------------------------------------------- *
  438 +/***********************************************************************//**
  439 + * @brief Delete class members
371 440 ***************************************************************************/
372 441 void GFitsTableStrCol::free_members(void)
373 442 {
374 443 // Free memory
375   - if (m_data != NULL) {
376   - for (int i = 0; i < m_size; ++i) {
377   - if (m_data[i] != NULL) delete [] m_data[i];
378   - }
379   - delete [] m_data;
380   - }
  444 + if (m_data != NULL) delete [] m_data;
  445 + if (m_nulval != NULL) delete m_nulval;
381 446  
382 447 // Mark memory as freed
383   - m_data = NULL;
384   -
385   - // Return
386   - return;
387   -}
388   -
389   -
390   -/***************************************************************************
391   - * Load column data *
392   - * ----------------------------------------------------------------------- *
393   - * The string column is read in a list of character buffers. The length of *
394   - * each character buffer is 'm_width+1' to hold the final '\0'. The number *
395   - * of strings is given by the number of rows of the table times the number *
396   - * of substrings. *
397   - ***************************************************************************/
398   -void GFitsTableStrCol::load(void)
399   -{
400   - // Calculate total number of strings
401   - m_size = m_number * m_length;
402   -
403   - // Free memory
404   - free_members();
405   -
406   - // Reset number of NULLs
407   - m_anynul = 0;
408   -
409   - // Load data only if some are available
410   - if (m_size > 0) {
411   -
412   - // Allocate memory
413   - m_data = new char*[m_size];
414   - for (int i = 0; i < m_size; ++i)
415   - m_data[i] = new char[m_width+1];
  448 + m_data = NULL;
  449 + m_nulval = NULL;
416 450  
417   - // Load column data
418   - int status = 0;
419   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
420   - &status);
421   - status = __ffgcvs(&m_fitsfile, m_colnum, 1, 1, m_size, m_nulstr, m_data,
422   - &m_anynul, &status);
423   - if (status != 0)
424   - throw GException::fits_error(G_LOAD, status);
425   -
426   - } // endif: data were available
  451 + // Free buffer
  452 + free_buffer();
427 453  
428 454 // Return
429 455 return;
... ... @@ -472,12 +498,144 @@ std::string GFitsTableStrCol::binary_format(void) const
472 498 }
473 499  
474 500  
  501 +/***********************************************************************//**
  502 + * @brief Allocates column data
  503 + ***************************************************************************/
  504 +void GFitsTableStrCol::alloc_data(void)
  505 +{
  506 + // Free memory
  507 + if (m_data != NULL) delete [] m_data;
  508 +
  509 + // Mark pointer as free
  510 + m_data = NULL;
  511 +
  512 + // Allocate new data
  513 + if (m_size > 0)
  514 + m_data = new std::string[m_size];
  515 +
  516 + // Return
  517 + return;
  518 +}
  519 +
  520 +
  521 +/***********************************************************************//**
  522 + * @brief Initialise column data
  523 + ***************************************************************************/
  524 +void GFitsTableStrCol::init_data(void)
  525 +{
  526 + // Initialise data if they exist
  527 + if (m_data != NULL) {
  528 + for (int i = 0; i < m_size; ++i)
  529 + m_data[i].clear();
  530 + }
  531 +
  532 + // Return
  533 + return;
  534 +}
  535 +
  536 +
  537 +/***********************************************************************//**
  538 + * @brief Fetch column data
  539 + *
  540 + * If a FITS file is attached to the column the data are loaded into memory
  541 + * from the FITS file. If no FITS file is attached, memory is allocated
  542 + * to hold the column data and all cells are set to 0.
  543 + *
  544 + * Refer to GFitsTableCol::load_column for more information.
  545 + ***************************************************************************/
  546 +void GFitsTableStrCol::fetch_data(void)
  547 +{
  548 + // Calculate size of memory
  549 + m_size = m_number * m_length;
  550 +
  551 + // Free old buffer memory
  552 + free_buffer();
  553 +
  554 + // Allocate buffer memory
  555 + alloc_buffer();
  556 +
  557 + // Save column
  558 + load_column();
  559 +
  560 + // Extract string from buffer
  561 + for (int i = 0; i < m_size; ++i) {
  562 + if (m_buffer[i] != NULL)
  563 + m_data[i].assign(m_buffer[i]);
  564 + }
  565 +
  566 + // Free buffer memory
  567 + free_buffer();
  568 +
  569 + // Return
  570 + return;
  571 +}
  572 +
  573 +
  574 +/***********************************************************************//**
  575 + * @brief Allocate buffer memory
  576 + ***************************************************************************/
  577 +void GFitsTableStrCol::alloc_buffer(void)
  578 +{
  579 + // Allocate buffer memory
  580 + if (m_size > 0) {
  581 + m_buffer = new char*[m_size];
  582 + for (int i = 0; i < m_size; ++i)
  583 + m_buffer[i] = new char[m_width+1];
  584 + }
  585 +
  586 + // Initialise buffer
  587 + if (m_buffer != NULL) {
  588 + for (int i = 0; i < m_size; ++i) {
  589 + for (int j = 0; j <= m_width; ++j)
  590 + (m_buffer[i])[j] = '\0';
  591 + }
  592 + }
  593 +
  594 + // Return
  595 + return;
  596 +}
  597 +
  598 +
  599 +/***********************************************************************//**
  600 + * @brief Free buffer memory
  601 + ***************************************************************************/
  602 +void GFitsTableStrCol::free_buffer(void)
  603 +{
  604 + // If there was a buffer allocated then free it
  605 + if (m_buffer != NULL) {
  606 + for (int i = 0; i < m_size; ++i) {
  607 + if (m_buffer[i] != NULL) delete [] m_buffer[i];
  608 + }
  609 + delete [] m_buffer;
  610 + m_buffer = NULL;
  611 + }
  612 +
  613 + // Return
  614 + return;
  615 +}
  616 +
  617 +
475 618 /*==========================================================================
476 619 = =
477 620 = GFitsTableStrCol friends =
478 621 = =
479 622 ==========================================================================*/
480 623  
  624 +/***********************************************************************//**
  625 + * @brief Output operator
  626 + *
  627 + * @param[in] os Output stream
  628 + * @param[in] column Column to put in output stream
  629 + ***************************************************************************/
  630 +ostream& operator<< (ostream& os, const GFitsTableStrCol& column)
  631 +{
  632 + // Dump column in output stream
  633 + column.dump_column(os, column.m_data);
  634 +
  635 + // Return output stream
  636 + return os;
  637 +}
  638 +
481 639  
482 640 /*==========================================================================
483 641 = =
... ...
test/test_GFits.cpp
... ... @@ -82,8 +82,8 @@ void test_columns(void)
82 82 }
83 83 else
84 84 std::cout << ".";
85   - std::string nullstr = "empty";
86   - str.set_nullstr(nullstr);
  85 + std::string nullval = "empty";
  86 + str.set_nullval(nullval);
87 87 if (str.string(2) != "empty") {
88 88 cout << endl << "TEST ERROR: Bad single TSTRING NULL value read ("
89 89 << str.string(2) << ")." << endl;
... ... @@ -508,13 +508,31 @@ void test_bin_table(void)
508 508 system("rm -rf test_bintables.fits");
509 509  
510 510 // Allocate reference sums
511   - double sum_dbl = 0.0;
512   - int sum_dbl_int = 0;
  511 + double sum_dbl = 0.0;
  512 + double sum_dbl10 = 0.0;
  513 + int sum_dbl_int = 0;
  514 + int sum_dbl10_int = 0;
513 515 std::string sum_dbl_str;
514   - float sum_flt = 0.0;
515   - int sum_flt_int = 0;
  516 + std::string sum_dbl10_str;
  517 + float sum_flt = 0.0;
  518 + float sum_flt10 = 0.0;
  519 + int sum_flt_int = 0;
  520 + int sum_flt10_int = 0;
516 521 std::string sum_flt_str;
517   -
  522 + std::string sum_flt10_str;
  523 + short sum_sht = 0;
  524 + short sum_sht10 = 0;
  525 + short sum_sht_int = 0;
  526 + short sum_sht10_int = 0;
  527 + std::string sum_sht_str;
  528 + std::string sum_sht10_str;
  529 + long sum_lng = 0;
  530 + long sum_lng10 = 0;
  531 + long sum_lng_int = 0;
  532 + long sum_lng10_int = 0;
  533 + std::string sum_lng_str;
  534 + std::string sum_lng10_str;
  535 +
518 536 // Build tables
519 537 try {
520 538 // Open FITS file
... ... @@ -523,17 +541,20 @@ void test_bin_table(void)
523 541  
524 542 // Set number of rows
525 543 int nrows = 10;
  544 + int nvec = 10;
526 545  
527 546 // Initial control sums
528 547 float tot_flt = 0.0;
529 548 double tot_dbl = 0.0;
530 549 int tot_int = 0;
  550 + long tot_lng = 0;
  551 + short tot_sht = 0;
531 552 std::string tot_str;
532 553  
533 554 //
534 555 // ===== D O U B L E =====
535 556 //
536   -
  557 +
537 558 // Set double precision table
538 559 GFitsTableDblCol col_dbl = GFitsTableDblCol("DOUBLE", nrows);
539 560 for (int i = 0; i < nrows; ++i) {
... ... @@ -546,14 +567,15 @@ void test_bin_table(void)
546 567 sum_dbl_str += ":"+s_value.str();
547 568 }
548 569 cout << ".";
549   -
  570 +
550 571 // Check double precision table (operator access)
551 572 tot_dbl = 0.0;
552 573 for (int i = 0; i < nrows; ++i)
553 574 tot_dbl += col_dbl(i);
554 575 if (!dequal(tot_dbl, sum_dbl)) {
555   - cout << endl << "TEST ERROR: GFitsTableDblCol::operator()"
556   - << endl;
  576 + cout << endl << "TEST ERROR: GFitsTableDblCol::operator()";
  577 + cout << endl << " Reference sum: " << sum_dbl;
  578 + cout << endl << " Derived sum: " << tot_dbl << endl;
557 579 throw;
558 580 }
559 581 cout << ".";
... ... @@ -563,19 +585,21 @@ void test_bin_table(void)
563 585 for (int i = 0; i < nrows; ++i)
564 586 tot_dbl += col_dbl.real(i);
565 587 if (!dequal(tot_dbl, sum_dbl)) {
566   - cout << endl << "TEST ERROR: GFitsTableDblCol::real()"
567   - << endl;
  588 + cout << endl << "TEST ERROR: GFitsTableDblCol::real()";
  589 + cout << endl << " Reference sum: " << sum_dbl;
  590 + cout << endl << " Derived sum: " << tot_dbl << endl;
568 591 throw;
569 592 }
570 593 cout << ".";
571 594  
572 595 // Check double precision table (int access)
573   - tot_int = 0.0;
  596 + tot_int = 0;
574 597 for (int i = 0; i < nrows; ++i)
575 598 tot_int += col_dbl.integer(i);
576 599 if (tot_int != sum_dbl_int) {
577   - cout << endl << "TEST ERROR: GFitsTableDblCol::integer()"
578   - << endl;
  600 + cout << endl << "TEST ERROR: GFitsTableDblCol::integer()";
  601 + cout << endl << " Reference sum: " << sum_dbl_int;
  602 + cout << endl << " Derived sum: " << tot_int << endl;
579 603 throw;
580 604 }
581 605 cout << ".";
... ... @@ -585,8 +609,84 @@ void test_bin_table(void)
585 609 for (int i = 0; i < nrows; ++i)
586 610 tot_str += ":"+col_dbl.string(i);
587 611 if (tot_str != sum_dbl_str) {
588   - cout << endl << "TEST ERROR: GFitsTableDblCol::string()"
589   - << endl;
  612 + cout << endl << "TEST ERROR: GFitsTableDblCol::string()";
  613 + cout << endl << " Reference sum: " << sum_dbl_str;
  614 + cout << endl << " Derived sum: " << tot_str << endl;
  615 + throw;
  616 + }
  617 + cout << ".";
  618 +
  619 + //
  620 + // ===== D O U B L E 1 0 =====
  621 + //
  622 +
  623 + // Set double precision table
  624 + GFitsTableDblCol col_dbl10 = GFitsTableDblCol("DOUBLE10", nrows, nvec);
  625 + for (int i = 0; i < nrows; ++i) {
  626 + for (int j = 0; j < nvec; ++j) {
  627 + double val_dbl = cos(double(i))*cos(0.33*double(j));
  628 + col_dbl10(i,j) = val_dbl;
  629 + sum_dbl10 += val_dbl;
  630 + sum_dbl10_int += int(val_dbl);
  631 + ostringstream s_value;
  632 + s_value << scientific << val_dbl;
  633 + sum_dbl10_str += ":"+s_value.str();
  634 + }
  635 + }
  636 + cout << ".";
  637 +
  638 + // Check double precision table (operator access)
  639 + tot_dbl = 0.0;
  640 + for (int i = 0; i < nrows; ++i) {
  641 + for (int j = 0; j < nvec; ++j)
  642 + tot_dbl += col_dbl10(i,j);
  643 + }
  644 + if (!dequal(tot_dbl, sum_dbl10)) {
  645 + cout << endl << "TEST ERROR: GFitsTableDblCol::operator() - 10";
  646 + cout << endl << " Reference sum: " << sum_dbl10;
  647 + cout << endl << " Derived sum: " << tot_dbl << endl;
  648 + throw;
  649 + }
  650 + cout << ".";
  651 +
  652 + // Check double precision table (real access)
  653 + tot_dbl = 0.0;
  654 + for (int i = 0; i < nrows; ++i) {
  655 + for (int j = 0; j < nvec; ++j)
  656 + tot_dbl += col_dbl10.real(i,j);
  657 + }
  658 + if (!dequal(tot_dbl, sum_dbl10)) {
  659 + cout << endl << "TEST ERROR: GFitsTableDblCol::real() - 10";
  660 + cout << endl << " Reference sum: " << sum_dbl10;
  661 + cout << endl << " Derived sum: " << tot_dbl << endl;
  662 + throw;
  663 + }
  664 + cout << ".";
  665 +
  666 + // Check double precision table (int access)
  667 + tot_int = 0;
  668 + for (int i = 0; i < nrows; ++i) {
  669 + for (int j = 0; j < nvec; ++j)
  670 + tot_int += col_dbl10.integer(i,j);
  671 + }
  672 + if (tot_int != sum_dbl10_int) {
  673 + cout << endl << "TEST ERROR: GFitsTableDblCol::integer() - 10";
  674 + cout << endl << " Reference sum: " << sum_dbl10_int;
  675 + cout << endl << " Derived sum: " << tot_int << endl;
  676 + throw;
  677 + }
  678 + cout << ".";
  679 +
  680 + // Check double precision table (string access)
  681 + tot_str.clear();
  682 + for (int i = 0; i < nrows; ++i) {
  683 + for (int j = 0; j < nvec; ++j)
  684 + tot_str += ":"+col_dbl10.string(i,j);
  685 + }
  686 + if (tot_str != sum_dbl10_str) {
  687 + cout << endl << "TEST ERROR: GFitsTableDblCol::string() - 10";
  688 + cout << endl << " Reference sum: " << sum_dbl10_str;
  689 + cout << endl << " Derived sum: " << tot_str << endl;
590 690 throw;
591 691 }
592 692 cout << ".";
... ... @@ -613,8 +713,9 @@ void test_bin_table(void)
613 713 for (int i = 0; i < nrows; ++i)
614 714 tot_flt += col_flt(i);
615 715 if (!fequal(tot_flt, sum_flt)) {
616   - cout << endl << "TEST ERROR: GFitsTableFltCol::operator()"
617   - << endl;
  716 + cout << endl << "TEST ERROR: GFitsTableFltCol::operator()";
  717 + cout << endl << " Reference sum: " << sum_flt;
  718 + cout << endl << " Derived sum: " << tot_flt << endl;
618 719 throw;
619 720 }
620 721 cout << ".";
... ... @@ -624,19 +725,21 @@ void test_bin_table(void)
624 725 for (int i = 0; i < nrows; ++i)
625 726 tot_flt += col_flt.real(i);
626 727 if (!fequal(tot_flt, sum_flt)) {
627   - cout << endl << "TEST ERROR: GFitsTableFltCol::real()"
628   - << endl;
  728 + cout << endl << "TEST ERROR: GFitsTableFltCol::real()";
  729 + cout << endl << " Reference sum: " << sum_flt;
  730 + cout << endl << " Derived sum: " << tot_flt << endl;
629 731 throw;
630 732 }
631 733 cout << ".";
632 734  
633 735 // Check single precision table (int access)
634   - tot_int = 0.0;
  736 + tot_int = 0;
635 737 for (int i = 0; i < nrows; ++i)
636 738 tot_int += col_flt.integer(i);
637 739 if (tot_int != sum_flt_int) {
638   - cout << endl << "TEST ERROR: GFitsTableFltCol::integer()"
639   - << endl;
  740 + cout << endl << "TEST ERROR: GFitsTableFltCol::integer()";
  741 + cout << endl << " Reference sum: " << sum_flt_int;
  742 + cout << endl << " Derived sum: " << tot_int << endl;
640 743 throw;
641 744 }
642 745 cout << ".";
... ... @@ -646,27 +749,493 @@ void test_bin_table(void)
646 749 for (int i = 0; i < nrows; ++i)
647 750 tot_str += ":"+col_flt.string(i);
648 751 if (tot_str != sum_flt_str) {
649   - cout << endl << "TEST ERROR: GFitsTableFltCol::string()"
650   - << endl;
  752 + cout << endl << "TEST ERROR: GFitsTableFltCol::string()";
  753 + cout << endl << " Reference sum: " << sum_flt_str;
  754 + cout << endl << " Derived sum: " << tot_str << endl;
651 755 throw;
652 756 }
653 757 cout << ".";
654 758  
655 759 //
  760 + // ===== F L O A T 1 0 =====
  761 + //
  762 +
  763 + // Set single precision table
  764 + GFitsTableFltCol col_flt10 = GFitsTableFltCol("FLOAT10", nrows, nvec);
  765 + for (int i = 0; i < nrows; ++i) {
  766 + for (int j = 0; j < nvec; ++j) {
  767 + float val_flt = cos(0.1*float(i))*cos(0.33*float(j));
  768 + col_flt10(i,j) = val_flt;
  769 + sum_flt10 += val_flt;
  770 + sum_flt10_int += int(val_flt);
  771 + ostringstream s_value;
  772 + s_value << scientific << val_flt;
  773 + sum_flt10_str += ":"+s_value.str();
  774 + }
  775 + }
  776 + cout << ".";
  777 +
  778 + // Check single precision table (operator access)
  779 + tot_flt = 0.0;
  780 + for (int i = 0; i < nrows; ++i) {
  781 + for (int j = 0; j < nvec; ++j)
  782 + tot_flt += col_flt10(i,j);
  783 + }
  784 + if (!fequal(tot_flt, sum_flt10)) {
  785 + cout << endl << "TEST ERROR: GFitsTableFltCol::operator() - 10";
  786 + cout << endl << " Reference sum: " << sum_flt10;
  787 + cout << endl << " Derived sum: " << tot_flt << endl;
  788 + throw;
  789 + }
  790 + cout << ".";
  791 +
  792 + // Check single precision table (real access)
  793 + tot_flt = 0.0;
  794 + for (int i = 0; i < nrows; ++i) {
  795 + for (int j = 0; j < nvec; ++j)
  796 + tot_flt += col_flt10.real(i,j);
  797 + }
  798 + if (!fequal(tot_flt, sum_flt10)) {
  799 + cout << endl << "TEST ERROR: GFitsTableFltCol::real() - 10";
  800 + cout << endl << " Reference sum: " << sum_flt10;
  801 + cout << endl << " Derived sum: " << tot_flt << endl;
  802 + throw;
  803 + }
  804 + cout << ".";
  805 +
  806 + // Check double precision table (int access)
  807 + tot_int = 0;
  808 + for (int i = 0; i < nrows; ++i) {
  809 + for (int j = 0; j < nvec; ++j)
  810 + tot_int += col_flt10.integer(i,j);
  811 + }
  812 + if (tot_int != sum_flt10_int) {
  813 + cout << endl << "TEST ERROR: GFitsTableFltCol::integer() - 10";
  814 + cout << endl << " Reference sum: " << sum_flt10_int;
  815 + cout << endl << " Derived sum: " << tot_int << endl;
  816 + throw;
  817 + }
  818 + cout << ".";
  819 +
  820 + // Check single precision table (string access)
  821 + tot_str.clear();
  822 + for (int i = 0; i < nrows; ++i) {
  823 + for (int j = 0; j < nvec; ++j)
  824 + tot_str += ":"+col_flt10.string(i,j);
  825 + }
  826 + if (tot_str != sum_flt10_str) {
  827 + cout << endl << "TEST ERROR: GFitsTableFltCol::string() - 10";
  828 + cout << endl << " Reference sum: " << sum_flt10_str;
  829 + cout << endl << " Derived sum: " << tot_str << endl;
  830 + throw;
  831 + }
  832 + cout << ".";
  833 +
  834 + //
  835 + // ===== S H O R T =====
  836 + //
  837 +
  838 + // Set short table
  839 + GFitsTableShtCol col_sht = GFitsTableShtCol("SHORT", nrows);
  840 + for (int i = 0; i < nrows; ++i) {
  841 + short val_sht = short(1000.0 * cos(0.1*float(i)));
  842 + col_sht(i) = val_sht;
  843 + sum_sht += val_sht;
  844 + sum_sht_int += int(val_sht);
  845 + ostringstream s_value;
  846 + s_value << val_sht;
  847 + sum_sht_str += ":"+s_value.str();
  848 + }
  849 + cout << ".";
  850 +
  851 + // Check short table (operator access)
  852 + tot_sht = 0;
  853 + for (int i = 0; i < nrows; ++i)
  854 + tot_sht += col_sht(i);
  855 + if (tot_sht != sum_sht) {
  856 + cout << endl << "TEST ERROR: GFitsTableShtCol::operator()";
  857 + cout << endl << " Reference sum: " << sum_sht;
  858 + cout << endl << " Derived sum: " << tot_sht << endl;
  859 + throw;
  860 + }
  861 + cout << ".";
  862 +
  863 + // Check short table (real access)
  864 + tot_dbl = 0.0;
  865 + for (int i = 0; i < nrows; ++i)
  866 + tot_dbl += col_sht.real(i);
  867 + if (!dequal(tot_dbl, double(sum_sht))) {
  868 + cout << endl << "TEST ERROR: GFitsTableShtCol::real()";
  869 + cout << endl << " Reference sum: " << sum_sht;
  870 + cout << endl << " Derived sum: " << tot_dbl << endl;
  871 + throw;
  872 + }
  873 + cout << ".";
  874 +
  875 + // Check short table (int access)
  876 + tot_int = 0;
  877 + for (int i = 0; i < nrows; ++i)
  878 + tot_int += col_sht.integer(i);
  879 + if (tot_int != sum_sht_int) {
  880 + cout << endl << "TEST ERROR: GFitsTableShtCol::integer()";
  881 + cout << endl << " Reference sum: " << sum_sht_int;
  882 + cout << endl << " Derived sum: " << tot_int << endl;
  883 + throw;
  884 + }
  885 + cout << ".";
  886 +
  887 + // Check single precision table (string access)
  888 + tot_str.clear();
  889 + for (int i = 0; i < nrows; ++i)
  890 + tot_str += ":"+col_sht.string(i);
  891 + if (tot_str != sum_sht_str) {
  892 + cout << endl << "TEST ERROR: GFitsTableShtCol::string()";
  893 + cout << endl << " Reference sum: " << sum_sht_str;
  894 + cout << endl << " Derived sum: " << tot_str << endl;
  895 + throw;
  896 + }
  897 + cout << ".";
  898 +
  899 + //
  900 + // ===== S H O R T 1 0 =====
  901 + //
  902 +
  903 + // Set short table
  904 + GFitsTableShtCol col_sht10 = GFitsTableShtCol("SHORT10", nrows, nvec);
  905 + for (int i = 0; i < nrows; ++i) {
  906 + for (int j = 0; j < nvec; ++j) {
  907 + short val_sht = short(100.0*cos(0.1*float(i))*
  908 + cos(0.33*float(j)));
  909 + col_sht10(i,j) = val_sht;
  910 + sum_sht10 += val_sht;
  911 + sum_sht10_int += int(val_sht);
  912 + ostringstream s_value;
  913 + s_value << val_sht;
  914 + sum_sht10_str += ":"+s_value.str();
  915 + }
  916 + }
  917 + cout << ".";
  918 +
  919 + // Check short table (operator access)
  920 + tot_sht = 0;
  921 + for (int i = 0; i < nrows; ++i) {
  922 + for (int j = 0; j < nvec; ++j)
  923 + tot_sht += col_sht10(i,j);
  924 + }
  925 + if (tot_sht != sum_sht10) {
  926 + cout << endl << "TEST ERROR: GFitsTableShtCol::operator() - 10";
  927 + cout << endl << " Reference sum: " << sum_sht10;
  928 + cout << endl << " Derived sum: " << tot_sht << endl;
  929 + throw;
  930 + }
  931 + cout << ".";
  932 +
  933 + // Check short table (real access)
  934 + tot_dbl = 0.0;
  935 + for (int i = 0; i < nrows; ++i) {
  936 + for (int j = 0; j < nvec; ++j)
  937 + tot_dbl += col_sht10.real(i,j);
  938 + }
  939 + if (!dequal(tot_dbl, sum_sht10)) {
  940 + cout << endl << "TEST ERROR: GFitsTableShtCol::real() - 10";
  941 + cout << endl << " Reference sum: " << sum_sht10;
  942 + cout << endl << " Derived sum: " << tot_dbl << endl;
  943 + throw;
  944 + }
  945 + cout << ".";
  946 +
  947 + // Check short table (int access)
  948 + tot_int = 0;
  949 + for (int i = 0; i < nrows; ++i) {
  950 + for (int j = 0; j < nvec; ++j)
  951 + tot_int += col_sht10.integer(i,j);
  952 + }
  953 + if (tot_int != sum_sht10_int) {
  954 + cout << endl << "TEST ERROR: GFitsTableShtCol::integer() - 10";
  955 + cout << endl << " Reference sum: " << sum_sht10_int;
  956 + cout << endl << " Derived sum: " << tot_int << endl;
  957 + throw;
  958 + }
  959 + cout << ".";
  960 +
  961 + // Check single precision table (string access)
  962 + tot_str.clear();
  963 + for (int i = 0; i < nrows; ++i) {
  964 + for (int j = 0; j < nvec; ++j)
  965 + tot_str += ":"+col_sht10.string(i,j);
  966 + }
  967 + if (tot_str != sum_sht10_str) {
  968 + cout << endl << "TEST ERROR: GFitsTableShtCol::string() - 10";
  969 + cout << endl << " Reference sum: " << sum_sht10_str;
  970 + cout << endl << " Derived sum: " << tot_str << endl;
  971 + throw;
  972 + }
  973 + cout << ".";
  974 +
  975 + //
  976 + // ===== L O N G =====
  977 + //
  978 +
  979 + // Set long table
  980 + GFitsTableLngCol col_lng = GFitsTableLngCol("LONG", nrows);
  981 + for (int i = 0; i < nrows; ++i) {
  982 + long val_lng = long(100000.0 * cos(0.1*float(i)));
  983 + col_lng(i) = val_lng;
  984 + sum_lng += val_lng;
  985 + sum_lng_int += int(val_lng);
  986 + ostringstream s_value;
  987 + s_value << val_lng;
  988 + sum_lng_str += ":"+s_value.str();
  989 + }
  990 + cout << ".";
  991 +
  992 + // Check long table (operator access)
  993 + tot_lng = 0;
  994 + for (int i = 0; i < nrows; ++i)
  995 + tot_lng += col_lng(i);
  996 + if (tot_lng != sum_lng) {
  997 + cout << endl << "TEST ERROR: GFitsTableLngCol::operator()";
  998 + cout << endl << " Reference sum: " << sum_lng;
  999 + cout << endl << " Derived sum: " << tot_lng << endl;
  1000 + throw;
  1001 + }
  1002 + cout << ".";
  1003 +
  1004 + // Check long table (real access)
  1005 + tot_dbl = 0.0;
  1006 + for (int i = 0; i < nrows; ++i)
  1007 + tot_dbl += col_lng.real(i);
  1008 + if (!dequal(tot_dbl, double(sum_lng))) {
  1009 + cout << endl << "TEST ERROR: GFitsTableLngCol::real()";
  1010 + cout << endl << " Reference sum: " << sum_lng;
  1011 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1012 + throw;
  1013 + }
  1014 + cout << ".";
  1015 +
  1016 + // Check long table (int access)
  1017 + tot_int = 0;
  1018 + for (int i = 0; i < nrows; ++i)
  1019 + tot_int += col_lng.integer(i);
  1020 + if (tot_int != sum_lng_int) {
  1021 + cout << endl << "TEST ERROR: GFitsTableLngCol::integer()";
  1022 + cout << endl << " Reference sum: " << sum_lng_int;
  1023 + cout << endl << " Derived sum: " << tot_int << endl;
  1024 + throw;
  1025 + }
  1026 + cout << ".";
  1027 +
  1028 + // Check long table (string access)
  1029 + tot_str.clear();
  1030 + for (int i = 0; i < nrows; ++i)
  1031 + tot_str += ":"+col_lng.string(i);
  1032 + if (tot_str != sum_lng_str) {
  1033 + cout << endl << "TEST ERROR: GFitsTableLngCol::string()";
  1034 + cout << endl << " Reference sum: " << sum_lng_str;
  1035 + cout << endl << " Derived sum: " << tot_str << endl;
  1036 + throw;
  1037 + }
  1038 + cout << ".";
  1039 +
  1040 + //
  1041 + // ===== L O N G 1 0 =====
  1042 + //
  1043 +
  1044 + // Set long table
  1045 + GFitsTableLngCol col_lng10 = GFitsTableLngCol("LONG10", nrows, nvec);
  1046 + for (int i = 0; i < nrows; ++i) {
  1047 + for (int j = 0; j < nvec; ++j) {
  1048 + long val_lng = long(1000.0*cos(0.1*float(i))*
  1049 + cos(0.33*float(j)));
  1050 + col_lng10(i,j) = val_lng;
  1051 + sum_lng10 += val_lng;
  1052 + sum_lng10_int += int(val_lng);
  1053 + ostringstream s_value;
  1054 + s_value << val_lng;
  1055 + sum_lng10_str += ":"+s_value.str();
  1056 + }
  1057 + }
  1058 + cout << ".";
  1059 +
  1060 + // Check long table (operator access)
  1061 + tot_lng = 0;
  1062 + for (int i = 0; i < nrows; ++i) {
  1063 + for (int j = 0; j < nvec; ++j)
  1064 + tot_lng += col_lng10(i,j);
  1065 + }
  1066 + if (tot_lng != sum_lng10) {
  1067 + cout << endl << "TEST ERROR: GFitsTableLngCol::operator() - 10";
  1068 + cout << endl << " Reference sum: " << sum_lng10;
  1069 + cout << endl << " Derived sum: " << tot_lng << endl;
  1070 + throw;
  1071 + }
  1072 + cout << ".";
  1073 +
  1074 + // Check long table (real access)
  1075 + tot_dbl = 0.0;
  1076 + for (int i = 0; i < nrows; ++i) {
  1077 + for (int j = 0; j < nvec; ++j)
  1078 + tot_dbl += col_lng10.real(i,j);
  1079 + }
  1080 + if (!dequal(tot_dbl, sum_lng10)) {
  1081 + cout << endl << "TEST ERROR: GFitsTableLngCol::real() - 10";
  1082 + cout << endl << " Reference sum: " << sum_lng10;
  1083 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1084 + throw;
  1085 + }
  1086 + cout << ".";
  1087 +
  1088 + // Check long table (int access)
  1089 + tot_int = 0;
  1090 + for (int i = 0; i < nrows; ++i) {
  1091 + for (int j = 0; j < nvec; ++j)
  1092 + tot_int += col_lng10.integer(i,j);
  1093 + }
  1094 + if (tot_int != sum_lng10_int) {
  1095 + cout << endl << "TEST ERROR: GFitsTableLngCol::integer() - 10";
  1096 + cout << endl << " Reference sum: " << sum_lng10_int;
  1097 + cout << endl << " Derived sum: " << tot_int << endl;
  1098 + throw;
  1099 + }
  1100 + cout << ".";
  1101 +
  1102 + // Check single precision table (string access)
  1103 + tot_str.clear();
  1104 + for (int i = 0; i < nrows; ++i) {
  1105 + for (int j = 0; j < nvec; ++j)
  1106 + tot_str += ":"+col_lng10.string(i,j);
  1107 + }
  1108 + if (tot_str != sum_lng10_str) {
  1109 + cout << endl << "TEST ERROR: GFitsTableLngCol::string() - 10";
  1110 + cout << endl << " Reference sum: " << sum_lng10_str;
  1111 + cout << endl << " Derived sum: " << tot_str << endl;
  1112 + throw;
  1113 + }
  1114 + cout << ".";
  1115 +
  1116 + //
  1117 + // ===== S T R I N G =====
  1118 + //
  1119 +
  1120 + // Set string table
  1121 + GFitsTableStrCol col_str = GFitsTableStrCol("STRING", nrows, 20);
  1122 + for (int i = 0; i < nrows; ++i) {
  1123 + double val_dbl = cos(0.1*double(i));
  1124 + ostringstream s_value;
  1125 + s_value << scientific << val_dbl;
  1126 + col_str(i) = s_value.str();
  1127 + }
  1128 + cout << ".";
  1129 +
  1130 + //
656 1131 // ===== W R I T E T A B L E =====
657 1132 //
658   -
  1133 +
659 1134 // Build binary table
660 1135 GFitsBinTable table = GFitsBinTable(nrows);
661 1136 table.append_column(col_dbl);
662 1137 table.append_column(col_flt);
663   -
  1138 + table.append_column(col_sht);
  1139 + table.append_column(col_lng);
  1140 + table.append_column(col_str);
  1141 + table.insert_column(1, col_dbl10);
  1142 + table.insert_column(1, col_flt10);
  1143 + table.insert_column(0, col_sht10);
  1144 + table.insert_column(99, col_lng10);
  1145 +
664 1146 // Create HDU and append to FILE file
665 1147 GFitsHDU hdu(table);
666 1148 fits.append_hdu(hdu);
667 1149  
668 1150 // Save FITS file
669 1151 fits.save();
  1152 + //cout << fits;
  1153 + cout << ".";
  1154 + }
  1155 + catch (exception &e) {
  1156 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  1157 + cout << e.what() << endl;
  1158 + throw;
  1159 + }
  1160 + cout << ".";
  1161 +
  1162 +
  1163 + //================================================================
  1164 + //================================================================
  1165 + //================================================================
  1166 + // Read tables
  1167 + //================================================================
  1168 + //================================================================
  1169 + //================================================================
  1170 + try {
  1171 + // Open FITS file
  1172 + GFits fits;
  1173 + fits.open("test_bintables.fits");
  1174 +
  1175 + // Set number of rows
  1176 + int nrows = 10;
  1177 + int nvec = 10;
  1178 +
  1179 + // Initial control sums
  1180 + float tot_flt = 0.0;
  1181 + double tot_dbl = 0.0;
  1182 + int tot_int = 0;
  1183 + std::string tot_str;
  1184 +
  1185 + //
  1186 + // ===== D O U B L E =====
  1187 + //
  1188 +
  1189 + // Get column
  1190 + GFitsTableDblCol* col_dbl =
  1191 + (GFitsTableDblCol*)fits.hdu(2)->column("DOUBLE");
  1192 +
  1193 + // Check double precision table (operator access)
  1194 + tot_dbl = 0.0;
  1195 + for (int i = 0; i < nrows; ++i)
  1196 + tot_dbl += (*col_dbl)(i);
  1197 + if (!dequal(tot_dbl, sum_dbl)) {
  1198 + cout << endl << "TEST ERROR: GFitsTableDblCol::operator()";
  1199 + cout << endl << " Reference sum: " << sum_dbl;
  1200 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1201 + throw;
  1202 + }
  1203 + cout << ".";
  1204 +
  1205 + // Check double precision table (real access)
  1206 + tot_dbl = 0.0;
  1207 + for (int i = 0; i < nrows; ++i)
  1208 + tot_dbl += (*col_dbl).real(i);
  1209 + if (!dequal(tot_dbl, sum_dbl)) {
  1210 + cout << endl << "TEST ERROR: GFitsTableDblCol::real()";
  1211 + cout << endl << " Reference sum: " << sum_dbl;
  1212 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1213 + throw;
  1214 + }
  1215 + cout << ".";
  1216 +
  1217 + // Check double precision table (int access)
  1218 + tot_int = 0;
  1219 + for (int i = 0; i < nrows; ++i)
  1220 + tot_int += (*col_dbl).integer(i);
  1221 + if (tot_int != sum_dbl_int) {
  1222 + cout << endl << "TEST ERROR: GFitsTableDblCol::integer()";
  1223 + cout << endl << " Reference sum: " << sum_dbl_int;
  1224 + cout << endl << " Derived sum: " << tot_int << endl;
  1225 + throw;
  1226 + }
  1227 + cout << ".";
  1228 +
  1229 + // Check double precision table (string access)
  1230 + tot_str.clear();
  1231 + for (int i = 0; i < nrows; ++i)
  1232 + tot_str += ":"+ (*col_dbl).string(i);
  1233 + if (tot_str != sum_dbl_str) {
  1234 + cout << endl << "TEST ERROR: GFitsTableDblCol::string()";
  1235 + cout << endl << " Reference sum: " << sum_dbl_str;
  1236 + cout << endl << " Derived sum: " << tot_str << endl;
  1237 + throw;
  1238 + }
670 1239 cout << ".";
671 1240 }
672 1241 catch (exception &e) {
... ... @@ -675,8 +1244,7 @@ void test_bin_table(void)
675 1244 throw;
676 1245 }
677 1246 cout << ". ok." << endl;
678   -
679   -
  1247 +
680 1248 }
681 1249  
682 1250 /***************************************************************************
... ...