Commit 1fff8b907ae230b360d833ae0e09cbccfd1662f4

Authored by knodlseder
1 parent a235d9c7

evening save

include/GFitsDblImage.hpp
... ... @@ -50,9 +50,12 @@ public:
50 50 double& operator() (const int& ix, const int& iy);
51 51 const double& operator() (const int& ix, const int& iy) const;
52 52 double& operator() (const int& ix, const int& iy, const int& iz);
53   - const double& operator() (const int& ix, const int& iy, const int& iz) const;
54   - double& operator() (const int& ix, const int& iy, const int& iz, const int& it);
55   - const double& operator() (const int& ix, const int& iy, const int& iz, const int& it) const;
  53 + const double& operator() (const int& ix, const int& iy, const int& iz)
  54 + const;
  55 + double& operator() (const int& ix, const int& iy, const int& iz,
  56 + const int& it);
  57 + const double& operator() (const int& ix, const int& iy, const int& iz,
  58 + const int& it) const;
56 59  
57 60  
58 61 // Methods
... ...
include/GFitsTableCol.hpp
... ... @@ -30,7 +30,7 @@
30 30 *
31 31 * @brief Abstract interface for FITS table column
32 32 *
33   - * This class implements a FITS table column.
  33 + * This class implements a FITS table column. Vector columns are supported.
34 34 ***************************************************************************/
35 35 class GFitsTableCol {
36 36  
... ... @@ -43,6 +43,7 @@ class GFitsTableCol {
43 43 public:
44 44 // Constructors and destructors
45 45 GFitsTableCol();
  46 + GFitsTableCol(const int& length, const int& size = 1);
46 47 GFitsTableCol(const GFitsTableCol& column);
47 48 virtual ~GFitsTableCol();
48 49  
... ... @@ -50,23 +51,13 @@ public:
50 51 GFitsTableCol& operator= (const GFitsTableCol& column);
51 52  
52 53 // Virtual Methods
53   - virtual std::string string(const int& row, const int& col = 0) = 0;
54   - virtual double real(const int& row, const int& col = 0) = 0;
55   - virtual int integer(const int& row, const int& col = 0) = 0;
  54 + virtual std::string string(const int& row, const int& inx = 0) = 0;
  55 + virtual double real(const int& row, const int& inx = 0) = 0;
  56 + virtual int integer(const int& row, const int& inx = 0) = 0;
56 57 virtual GFitsTableCol* clone(void) const = 0;
57   - virtual double* ptr_double(void) = 0;
58   - virtual float* ptr_float(void) = 0;
59   - virtual short* ptr_short(void) = 0;
60   - virtual long* ptr_long(void) = 0;
61   - virtual int* ptr_int(void) = 0;
62 58  
63 59 // Base class Methods
64 60 void name(const std::string& name);
65   - //void colnum(const int& colnum); //!< DO WE REALLY NEED THIS???
66   - //void type(const int& type); //!< DO WE REALLY NEED THIS???
67   - //void repeat(const int repeat); //!< DO WE REALLY NEED THIS???
68   - //void width(const int width); //!< DO WE REALLY NEED THIS???
69   - //void length(const int& length); //!< DO WE REALLY NEED THIS???
70 61 std::string name(void);
71 62 int colnum(void);
72 63 int type(void);
... ... @@ -94,9 +85,4 @@ private:
94 85 void connect(__fitsfile* fptr);
95 86 };
96 87  
97   -
98   -/***************************************************************************
99   - * Inline methods *
100   - ***************************************************************************/
101   -
102 88 #endif /* GFITSTABLECOL_HPP */
... ...
include/GFitsTableDblCol.hpp
... ... @@ -10,6 +10,11 @@
10 10 * (at your option) any later version. *
11 11 * *
12 12 ***************************************************************************/
  13 +/**
  14 + * @file GFitsTableDblCol.hpp
  15 + * @brief GFitsTableDblCol class definition.
  16 + * @author J. Knodlseder
  17 + */
13 18  
14 19 #ifndef GFITSTABLEDBLCOL_HPP
15 20 #define GFITSTABLEDBLCOL_HPP
... ... @@ -24,30 +29,33 @@
24 29 /* __ Structures _________________________________________________________ */
25 30  
26 31  
27   -/***************************************************************************
28   - * GFitsTableDblCol class definition *
  32 +/***********************************************************************//**
  33 + * @class GFitsTableDblCol
  34 + *
  35 + * @brief Interface for FITS table double precision column
  36 + *
  37 + * This class implements a FITS table double precision column.
29 38 ***************************************************************************/
30 39 class GFitsTableDblCol : public GFitsTableCol {
31 40  
32 41 public:
33 42 // Constructors and destructors
34 43 GFitsTableDblCol();
  44 + GFitsTableDblCol(const int& length, const int& size = 1);
35 45 GFitsTableDblCol(const GFitsTableDblCol& column);
36 46 virtual ~GFitsTableDblCol();
37 47  
38 48 // Operators
39 49 GFitsTableDblCol& operator= (const GFitsTableDblCol& column);
  50 + double& operator() (const int& row, const int& inx = 0);
  51 + const double& operator() (const int& row, const int& inx = 0) const;
40 52  
41 53 // Methods
42   - std::string string(const int& row, const int& col = 0);
43   - double real(const int& row, const int& col = 0);
44   - int integer(const int& row, const int& col = 0);
  54 + std::string string(const int& row, const int& inx = 0);
  55 + double real(const int& row, const int& inx = 0);
  56 + int integer(const int& row, const int& inx = 0);
45 57 GFitsTableDblCol* clone(void) const;
46   - double* ptr_double(void);
47   - float* ptr_float(void);
48   - short* ptr_short(void);
49   - long* ptr_long(void);
50   - int* ptr_int(void);
  58 + double* data(void);
51 59 void set_nullval(const double* value);
52 60  
53 61 private:
... ... @@ -55,24 +63,13 @@ private:
55 63 void init_members(void);
56 64 void copy_members(const GFitsTableDblCol& column);
57 65 void free_members(void);
58   - void load(void);
  66 + void fetch_data(void);
59 67  
60 68 // Private data area
61   - int m_size; // Size of data area
62   - double* m_data; // Data area
63   - double* m_nulval; // NULL value
64   - int m_anynul; // Number of NULLs encountered
  69 + int m_size; //!< Size of data area
  70 + double* m_data; //!< Data area
  71 + double* m_nulval; //!< NULL value
  72 + int m_anynul; //!< Number of NULLs encountered
65 73 };
66 74  
67   -
68   -/***************************************************************************
69   - * Inline methods *
70   - ***************************************************************************/
71   -inline double* GFitsTableDblCol::ptr_double(void) { return m_data; }
72   -inline
73   -GFitsTableDblCol* GFitsTableDblCol::clone(void) const
74   -{
75   - return new GFitsTableDblCol(*this);
76   -}
77   -
78 75 #endif /* GFITSTABLEDBLCOL_HPP */
... ...
include/GFitsTableFltCol.hpp
... ... @@ -10,6 +10,11 @@
10 10 * (at your option) any later version. *
11 11 * *
12 12 ***************************************************************************/
  13 +/**
  14 + * @file GFitsTableFltCol.hpp
  15 + * @brief GFitsTableFltCol class definition.
  16 + * @author J. Knodlseder
  17 + */
13 18  
14 19 #ifndef GFITSTABLEFLTCOL_HPP
15 20 #define GFITSTABLEFLTCOL_HPP
... ... @@ -24,8 +29,12 @@
24 29 /* __ Structures _________________________________________________________ */
25 30  
26 31  
27   -/***************************************************************************
28   - * GFitsTableFltCol class definition *
  32 +/***********************************************************************//**
  33 + * @class GFitsTableFltCol
  34 + *
  35 + * @brief Interface for FITS table floating point column
  36 + *
  37 + * This class implements a FITS table floating point column.
29 38 ***************************************************************************/
30 39 class GFitsTableFltCol : public GFitsTableCol {
31 40  
... ... @@ -43,11 +52,7 @@ public:
43 52 double real(const int& row, const int& col = 0);
44 53 int integer(const int& row, const int& col = 0);
45 54 GFitsTableFltCol* clone(void) const;
46   - double* ptr_double(void);
47   - float* ptr_float(void);
48   - short* ptr_short(void);
49   - long* ptr_long(void);
50   - int* ptr_int(void);
  55 + float* data(void);
51 56 void set_nullval(const float* value);
52 57  
53 58 private:
... ... @@ -58,21 +63,15 @@ private:
58 63 void load(void);
59 64  
60 65 // Private data area
61   - int m_size; // Size of data area
62   - float* m_data; // Data area
63   - float* m_nulval; // NULL value
64   - int m_anynul; // Number of NULLs encountered
  66 + int m_size; //!< Size of data area
  67 + float* m_data; //!< Data area
  68 + float* m_nulval; //!< NULL value
  69 + int m_anynul; //!< Number of NULLs encountered
65 70 };
66 71  
67 72  
68 73 /***************************************************************************
69 74 * Inline methods *
70 75 ***************************************************************************/
71   -inline float* GFitsTableFltCol::ptr_float(void) { return m_data; }
72   -inline
73   -GFitsTableFltCol* GFitsTableFltCol::clone(void) const
74   -{
75   - return new GFitsTableFltCol(*this);
76   -}
77 76  
78 77 #endif /* GFITSTABLEFLTCOL_HPP */
... ...
include/GFitsTableLngCol.hpp
... ... @@ -10,6 +10,11 @@
10 10 * (at your option) any later version. *
11 11 * *
12 12 ***************************************************************************/
  13 +/**
  14 + * @file GFitsTableLngCol.hpp
  15 + * @brief GFitsTableLngCol class definition.
  16 + * @author J. Knodlseder
  17 + */
13 18  
14 19 #ifndef GFITSTABLELNGCOL_HPP
15 20 #define GFITSTABLELNGCOL_HPP
... ... @@ -24,8 +29,12 @@
24 29 /* __ Structures _________________________________________________________ */
25 30  
26 31  
27   -/***************************************************************************
28   - * GFitsTableLngCol class definition *
  32 +/***********************************************************************//**
  33 + * @class GFitsTableLngCol
  34 + *
  35 + * @brief Interface for FITS table long integer column
  36 + *
  37 + * This class implements a FITS table long integer column.
29 38 ***************************************************************************/
30 39 class GFitsTableLngCol : public GFitsTableCol {
31 40  
... ... @@ -37,17 +46,15 @@ public:
37 46  
38 47 // Operators
39 48 GFitsTableLngCol& operator= (const GFitsTableLngCol& column);
  49 + long& operator() (const int& row, const int& inx = 0);
  50 + const long& operator() (const int& row, const int& inx = 0) const;
40 51  
41 52 // Methods
42 53 std::string string(const int& row, const int& col = 0);
43 54 double real(const int& row, const int& col = 0);
44 55 int integer(const int& row, const int& col = 0);
45 56 GFitsTableLngCol* clone(void) const;
46   - double* ptr_double(void);
47   - float* ptr_float(void);
48   - short* ptr_short(void);
49   - long* ptr_long(void);
50   - int* ptr_int(void);
  57 + long* data(void);
51 58 void set_nullval(const long* value);
52 59  
53 60 private:
... ... @@ -55,24 +62,13 @@ private:
55 62 void init_members(void);
56 63 void copy_members(const GFitsTableLngCol& column);
57 64 void free_members(void);
58   - void load(void);
  65 + void fetch_data(void);
59 66  
60 67 // Private data area
61   - int m_size; // Size of data area
62   - long* m_data; // Data area
63   - long* m_nulval; // NULL value
64   - int m_anynul; // Number of NULLs encountered
  68 + int m_size; //!< Size of data area
  69 + long* m_data; //!< Data area
  70 + long* m_nulval; //!< NULL value
  71 + int m_anynul; //!< Number of NULLs encountered
65 72 };
66 73  
67   -
68   -/***************************************************************************
69   - * Inline methods *
70   - ***************************************************************************/
71   -inline long* GFitsTableLngCol::ptr_long(void) { return m_data; }
72   -inline
73   -GFitsTableLngCol* GFitsTableLngCol::clone(void) const
74   -{
75   - return new GFitsTableLngCol(*this);
76   -}
77   -
78 74 #endif /* GFITSTABLELNGCOL_HPP */
... ...
src/fits/GFitsHDU.cpp
... ... @@ -337,41 +337,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
337 337 ***************************************************************************/
338 338 void GFitsHDU::save(void)
339 339 {
340   -//cout << "GFitsHDU::save " << m_fitsfile.Fptr << " " << m_hdunum << endl;
341   - // Move to HDU
342   -// int status = 0;
343   -// status = __ffmahd(&m_fitsfile, m_hdunum, NULL, &status);
344   -
345   - // If HDU does not yet exist in file then create it now. This works even
346   - // in the case that the actual HDU has no associated header and/or data
347   - // (these will be created automatically). However, to make this work we have
348   - // to set the fitsfile HDU position to the position we want to go. In that
349   - // was the save members will know that they have to create the HDU ...
350   -/*
351   - if (status == 107) {
352   - m_fitsfile.HDUposition = m_hdunum-1;
353   - status = 0;
354   - if (m_data != NULL) {
355   - switch (m_type) {
356   - case HT_IMAGE: // Image HDU
357   - m_data->connect(&m_fitsfile);
358   - //m_data->save();
359   - break;
360   - case HT_ASCII_TABLE: // ASCII Table HDU
361   - m_data->connect(&m_fitsfile);
362   - //m_data->save();
363   - break;
364   - case HT_BIN_TABLE: // Binary Table HDU
365   - m_data->connect(&m_fitsfile);
366   - //m_data->save();
367   - break;
368   - default:
369   - throw GException::fits_unknown_HDU_type(G_SAVE, m_type);
370   - break;
371   - }
372   - }
373   - }
374   -*/
  340 +//cout << "GFitsHDU::save entry" << endl;
375 341  
376 342 // Save data and header if they exist
377 343 if (m_data != NULL) {
... ... @@ -398,6 +364,7 @@ void GFitsHDU::save(void)
398 364  
399 365 } // endelse: no data were available
400 366  
  367 +//cout << "GFitsHDU::save exit" << endl;
401 368 // Return
402 369 return;
403 370 }
... ...
src/fits/GFitsHeader.cpp
... ... @@ -174,6 +174,7 @@ void GFitsHeader::open(__fitsfile* fptr)
174 174 ***************************************************************************/
175 175 void GFitsHeader::save(__fitsfile* fptr)
176 176 {
  177 +//cout << "GFitsHeader::save entry" << endl;
177 178 // Move to HDU
178 179 int status = 0;
179 180 status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
... ... @@ -193,6 +194,7 @@ void GFitsHeader::save(__fitsfile* fptr)
193 194 }
194 195 }
195 196  
  197 +//cout << "GFitsHeader::save exit" << endl;
196 198 // Return
197 199 return;
198 200 }
... ...
src/fits/GFitsTable.cpp
... ... @@ -301,7 +301,7 @@ void GFitsTable::save(void)
301 301 }
302 302  
303 303 // Create FITS table
304   - status = __ffcrtb(&m_fitsfile, m_type, m_rows, tfields, ttype, tform,
  304 + status = __ffcrtb(&m_fitsfile, m_type, m_rows, tfields, ttype, tform,
305 305 tunit, NULL, &status);
306 306 if (status != 0)
307 307 throw GException::fits_error(G_SAVE, status);
... ... @@ -322,6 +322,7 @@ void GFitsTable::save(void)
322 322 else if (status != 0)
323 323 throw GException::fits_error(G_SAVE, status);
324 324  
  325 +//cout << "GFitsTable::save exit" << endl;
325 326 // Return
326 327 return;
327 328 }
... ... @@ -370,6 +371,7 @@ void GFitsTable::append_column(GFitsTableCol* column)
370 371 return;
371 372 }
372 373  
  374 +
373 375 /***********************************************************************//**
374 376 * @brief Insert column into the table
375 377 *
... ... @@ -455,11 +457,17 @@ void GFitsTable::insert_column(int colnum, GFitsTableCol* column)
455 457 // Connect new memory
456 458 m_columns = tmp;
457 459  
  460 + // Increment column counter
  461 + m_cols++;
  462 +
458 463 } // endelse: we made space to insert a column
459 464  
460 465 // Insert column pointer
461 466 m_columns[colnum] = column;
462 467  
  468 + // Set column attributes
  469 + m_columns[colnum]->m_colnum = colnum + 1; // IS THIS REALLY NEEDED???
  470 +
463 471 // Return
464 472 return;
465 473 }
... ... @@ -613,10 +621,7 @@ void GFitsTable::copy_members(const GFitsTable&amp; table)
613 621 ***************************************************************************/
614 622 void GFitsTable::free_members(void)
615 623 {
616   - // Free memory
617   - for (int i = 0; i < m_cols; ++i) {
618   - if (m_columns[i] != NULL) delete m_columns[i];
619   - }
  624 + // Free memory (don't free associated column pointers explicitely!!!)
620 625 if (m_columns != NULL) delete [] m_columns;
621 626  
622 627 // Mark memory as freed
... ... @@ -664,15 +669,16 @@ char* GFitsTable::get_ttype(const int&amp; colnum) const
664 669 {
665 670 // Initialise result with NULL pointer
666 671 char* ptr = NULL;
667   -
  672 +
668 673 // Get type only if column exists
669 674 if (m_columns != NULL && colnum >=0 && colnum < m_cols &&
670 675 m_columns[colnum] != NULL) {
671   - int size = m_columns[colnum]->m_name.length() + 1;
672   - ptr = new char[size];
673   - strncpy(ptr, m_columns[colnum]->m_name.c_str(), size-1);
674   - }
675   -
  676 + int size = m_columns[colnum]->m_name.length();
  677 + ptr = new char[size+1];
  678 + strncpy(ptr, m_columns[colnum]->m_name.c_str(), size);
  679 + ptr[size] = '\0';
  680 + }
  681 +
676 682 // Return result
677 683 return ptr;
678 684 }
... ... @@ -691,15 +697,16 @@ char* GFitsTable::get_tform(const int&amp; colnum) const
691 697 {
692 698 // Initialise result with NULL pointer
693 699 char* ptr = NULL;
694   -
  700 +
695 701 // Get type only if column exists
696 702 if (m_columns != NULL && colnum >=0 && colnum < m_cols &&
697 703 m_columns[colnum] != NULL) {
698   - int size = m_columns[colnum]->m_format.length() + 1;
699   - ptr = new char[size];
700   - strncpy(ptr, m_columns[colnum]->m_format.c_str(), size-1);
  704 + int size = m_columns[colnum]->m_format.length();
  705 + ptr = new char[size+1];
  706 + strncpy(ptr, m_columns[colnum]->m_format.c_str(), size);
  707 + ptr[size] = '\0';
701 708 }
702   -
  709 +
703 710 // Return result
704 711 return ptr;
705 712 }
... ... @@ -718,15 +725,16 @@ char* GFitsTable::get_tunit(const int&amp; colnum) const
718 725 {
719 726 // Initialise result with NULL pointer
720 727 char* ptr = NULL;
721   -
  728 +
722 729 // Get type only if column exists
723 730 if (m_columns != NULL && colnum >=0 && colnum < m_cols &&
724 731 m_columns[colnum] != NULL) {
725   - int size = m_columns[colnum]->m_unit.length() + 1;
726   - ptr = new char[size];
727   - strncpy(ptr, m_columns[colnum]->m_unit.c_str(), size-1);
  732 + int size = m_columns[colnum]->m_unit.length();
  733 + ptr = new char[size+1];
  734 + strncpy(ptr, m_columns[colnum]->m_unit.c_str(), size);
  735 + ptr[size] = '\0';
728 736 }
729   -
  737 +
730 738 // Return result
731 739 return ptr;
732 740 }
... ...
src/fits/GFitsTableCol.cpp
... ... @@ -48,6 +48,26 @@ GFitsTableCol::GFitsTableCol()
48 48  
49 49  
50 50 /***********************************************************************//**
  51 + * @brief Constructor
  52 + *
  53 + * @param[in] length Length of column.
  54 + * @param[in] size Vector size of column.
  55 + ***************************************************************************/
  56 +GFitsTableCol::GFitsTableCol(const int& length, const int& size)
  57 +{
  58 + // Initialise class members for clean destruction
  59 + init_members();
  60 +
  61 + // Set column length and vector size
  62 + m_length = length;
  63 + m_repeat = size;
  64 +
  65 + // Return
  66 + return;
  67 +}
  68 +
  69 +
  70 +/***********************************************************************//**
51 71 * @brief Copy constructor
52 72 *
53 73 * @param[in] column Column from which the class instance should be built
... ...
src/fits/GFitsTableDblCol.cpp
... ... @@ -23,12 +23,7 @@
23 23 #define G_STRING "GFitsTableDblCol::string(const int&, const int&)"
24 24 #define G_REAL "GFitsTableDblCol::real(const int&, const int&)"
25 25 #define G_INTEGER "GFitsTableDblCol::integer(const int&, const int&)"
26   -#define G_PTR_FLOAT "GFitsTableDblCol::ptr_float()"
27   -#define G_PTR_DOUBLE "GFitsTableDblCol::ptr_double()"
28   -#define G_PTR_SHORT "GFitsTableDblCol::ptr_short()"
29   -#define G_PTR_LONG "GFitsTableDblCol::ptr_long()"
30   -#define G_PTR_INT "GFitsTableDblCol::ptr_int()"
31   -#define G_LOAD "GFitsTableDblCol::load()"
  26 +#define G_FETCH_DATA "GFitsTableDblCol::fetch_data()"
32 27  
33 28 /* __ Macros _____________________________________________________________ */
34 29  
... ... @@ -43,9 +38,8 @@
43 38 = =
44 39 ==========================================================================*/
45 40  
46   -/***************************************************************************
47   - * Constructor *
48   - * ----------------------------------------------------------------------- *
  41 +/***********************************************************************//**
  42 + * @brief Constructor
49 43 ***************************************************************************/
50 44 GFitsTableDblCol::GFitsTableDblCol() : GFitsTableCol()
51 45 {
... ... @@ -57,11 +51,35 @@ GFitsTableDblCol::GFitsTableDblCol() : GFitsTableCol()
57 51 }
58 52  
59 53  
60   -/***************************************************************************
61   - * Copy constructor *
62   - * ----------------------------------------------------------------------- *
  54 +/***********************************************************************//**
  55 + * @brief Constructor
  56 + *
  57 + * @param[in] length Length of column.
  58 + * @param[in] size Vector size of column.
63 59 ***************************************************************************/
64   -GFitsTableDblCol::GFitsTableDblCol(const GFitsTableDblCol& column) : GFitsTableCol(column)
  60 +GFitsTableDblCol::GFitsTableDblCol(const int& length, const int& size)
  61 + : GFitsTableCol(length, size)
  62 +{
  63 + // Initialise class members for clean destruction
  64 + init_members();
  65 +
  66 + // Setup format
  67 + //m_name = "Test";
  68 + m_format = "1D";
  69 + //m_unit = "deg";
  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 +GFitsTableDblCol::GFitsTableDblCol(const GFitsTableDblCol& column) :
  82 + GFitsTableCol(column)
65 83 {
66 84 // Initialise class members for clean destruction
67 85 init_members();
... ... @@ -74,9 +92,8 @@ GFitsTableDblCol::GFitsTableDblCol(const GFitsTableDblCol&amp; column) : GFitsTableC
74 92 }
75 93  
76 94  
77   -/***************************************************************************
78   - * Destructor *
79   - * ----------------------------------------------------------------------- *
  95 +/***********************************************************************//**
  96 + * @brief Destructor
80 97 ***************************************************************************/
81 98 GFitsTableDblCol::~GFitsTableDblCol()
82 99 {
... ... @@ -94,9 +111,10 @@ GFitsTableDblCol::~GFitsTableDblCol()
94 111 = =
95 112 ==========================================================================*/
96 113  
97   -/***************************************************************************
98   - * Assignment operator *
99   - * ----------------------------------------------------------------------- *
  114 +/***********************************************************************//**
  115 + * @brief Assignment operator
  116 + *
  117 + * @param[in] column Column which should be assigned
100 118 ***************************************************************************/
101 119 GFitsTableDblCol& GFitsTableDblCol::operator= (const GFitsTableDblCol& column)
102 120 {
... ... @@ -122,126 +140,193 @@ GFitsTableDblCol&amp; GFitsTableDblCol::operator= (const GFitsTableDblCol&amp; column)
122 140 }
123 141  
124 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 + * GFitsTableDblCol::string(ix,iy),
  152 + * GFitsTableDblCol::real(ix;iy) or
  153 + * GFitsTableDblCol::integer(ix;iy)
  154 + * if range checking is required.
  155 + ***************************************************************************/
  156 +double& GFitsTableDblCol::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_repeat + inx;
  163 +
  164 + // Return image pixel
  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 + * GFitsTableDblCol::string(ix,iy),
  178 + * GFitsTableDblCol::real(ix;iy) or
  179 + * GFitsTableDblCol::integer(ix;iy)
  180 + * if range checking is required.
  181 + ***************************************************************************/
  182 +const double& GFitsTableDblCol::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) ((GFitsTableDblCol*)this)->fetch_data();
  187 +
  188 + // Calculate pixel offset
  189 + int offset = row * m_repeat + inx;
  190 +
  191 + // Return image pixel
  192 + return m_data[offset];
  193 +}
  194 +
  195 +
125 196 /*==========================================================================
126 197 = =
127 198 = GFitsTableDblCol public methods =
128 199 = =
129 200 ==========================================================================*/
130 201  
131   -/***************************************************************************
132   - * Get string value *
133   - * ----------------------------------------------------------------------- *
  202 +/***********************************************************************//**
  203 + * @brief Get string value
  204 + *
  205 + * @param[in] row Table row.
  206 + * @param[in] inx Table column vector index.
  207 + *
  208 + * @exception GException::out_of_range
  209 + * Table row or vector index are out of valid range.
  210 + *
  211 + * Returns value of specified row and vector index as string.
134 212 ***************************************************************************/
135   -std::string GFitsTableDblCol::string(const int& row, const int& col)
  213 +std::string GFitsTableDblCol::string(const int& row, const int& inx)
136 214 {
137   - // Make sure that data are loaded
138   - if (m_data == NULL)
139   - load();
  215 + // If data are not available then load them now
  216 + if (m_data == NULL) fetch_data();
140 217  
141 218 // Check row value
142 219 if (row < 0 || row >= m_length)
143 220 throw GException::out_of_range(G_STRING, row, 0, m_length-1);
144 221  
145   - // Check col value
146   - if (col < 0 || col >= m_repeat)
147   - throw GException::out_of_range(G_STRING, col, 0, m_repeat-1);
  222 + // Check inx value
  223 + if (inx < 0 || inx >= m_repeat)
  224 + throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1);
148 225  
149 226 // Get index
150   - int inx = row * m_repeat + col;
  227 + int offset = row * m_repeat + inx;
151 228  
152 229 // Convert double into string
153 230 ostringstream s_value;
154   - s_value << scientific << m_data[inx];
  231 + s_value << scientific << m_data[offset];
155 232  
156 233 // Return value
157 234 return s_value.str();
158 235 }
159 236  
160 237  
161   -/***************************************************************************
162   - * Get real value *
163   - * ----------------------------------------------------------------------- *
  238 +/***********************************************************************//**
  239 + * @brief Get double precision value
  240 + *
  241 + * @param[in] row Table row.
  242 + * @param[in] inx Table column vector index.
  243 + *
  244 + * @exception GException::out_of_range
  245 + * Table row or vector index are out of valid range.
  246 + *
  247 + * Returns value of specified row and vector index as double precision.
164 248 ***************************************************************************/
165   -double GFitsTableDblCol::real(const int& row, const int& col)
  249 +double GFitsTableDblCol::real(const int& row, const int& inx)
166 250 {
167   - // Make sure that data are loaded
168   - if (m_data == NULL)
169   - load();
  251 + // If data are not available then load them now
  252 + if (m_data == NULL) fetch_data();
170 253  
171 254 // Check row value
172 255 if (row < 0 || row >= m_length)
173 256 throw GException::out_of_range(G_REAL, row, 0, m_length-1);
174 257  
175   - // Check col value
176   - if (col < 0 || col >= m_repeat)
177   - throw GException::out_of_range(G_REAL, col, 0, m_repeat-1);
  258 + // Check inx value
  259 + if (inx < 0 || inx >= m_repeat)
  260 + throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1);
178 261  
179 262 // Get index
180   - int inx = row * m_repeat + col;
  263 + int offset = row * m_repeat + inx;
181 264  
182 265 // Return value
183   - return m_data[inx];
  266 + return m_data[offset];
184 267 }
185 268  
186 269  
187   -/***************************************************************************
188   - * Get int value *
189   - * ----------------------------------------------------------------------- *
  270 +/***********************************************************************//**
  271 + * @brief Get integer value
  272 + *
  273 + * @param[in] row Table row.
  274 + * @param[in] inx Table column vector index.
  275 + *
  276 + * @exception GException::out_of_range
  277 + * Table row or vector index are out of valid range.
  278 + *
  279 + * Returns value of specified row and vector index as integer.
190 280 ***************************************************************************/
191   -int GFitsTableDblCol::integer(const int& row, const int& col)
  281 +int GFitsTableDblCol::integer(const int& row, const int& inx)
192 282 {
193   - // Make sure that data are loaded
194   - if (m_data == NULL)
195   - load();
  283 + // If data are not available then load them now
  284 + if (m_data == NULL) fetch_data();
196 285  
197 286 // Check row value
198 287 if (row < 0 || row >= m_length)
199 288 throw GException::out_of_range(G_INTEGER, row, 0, m_length-1);
200 289  
201 290 // Check col value
202   - if (col < 0 || col >= m_repeat)
203   - throw GException::out_of_range(G_INTEGER, col, 0, m_repeat-1);
  291 + if (inx < 0 || inx >= m_repeat)
  292 + throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1);
204 293  
205 294 // Get index
206   - int inx = row * m_repeat + col;
  295 + int offset = row * m_repeat + inx;
207 296  
208 297 // Convert double into int
209   - int value = (int)m_data[inx];
  298 + int value = (int)m_data[offset];
210 299  
211 300 // Return value
212 301 return value;
213 302 }
214 303  
215 304  
216   -/***************************************************************************
217   - * Access to invalid data pointers *
218   - * ----------------------------------------------------------------------- *
  305 +/***********************************************************************//**
  306 + * @brief Clone column
219 307 ***************************************************************************/
220   -float* GFitsTableDblCol::ptr_float(void)
221   -{
222   - throw GException::fits_invalid_type(G_PTR_FLOAT,
223   - "No <float> pointer allowed to <double> array");
224   -}
225   -short* GFitsTableDblCol::ptr_short(void)
226   -{
227   - throw GException::fits_invalid_type(G_PTR_SHORT,
228   - "No <short> pointer allowed to <double> array");
229   -}
230   -long* GFitsTableDblCol::ptr_long(void)
  308 +GFitsTableDblCol* GFitsTableDblCol::clone(void) const
231 309 {
232   - throw GException::fits_invalid_type(G_PTR_LONG,
233   - "No <long> pointer allowed to <double> array");
  310 + return new GFitsTableDblCol(*this);
234 311 }
235   -int* GFitsTableDblCol::ptr_int(void)
  312 +
  313 +
  314 +/***********************************************************************//**
  315 + * @brief Return pointer to double precision column
  316 + ***************************************************************************/
  317 +double* GFitsTableDblCol::data(void)
236 318 {
237   - throw GException::fits_invalid_type(G_PTR_INT,
238   - "No <int> pointer allowed to <double> array");
  319 + return m_data;
239 320 }
240 321  
241 322  
242   -/***************************************************************************
243   - * Set NULL value *
244   - * ----------------------------------------------------------------------- *
  323 +/***********************************************************************//**
  324 + * @brief Set NULL value
  325 + *
  326 + * @param[in] value Pointer on NULL value
  327 + *
  328 + * Allows the specification of the FITS table NULL value. If value=NULL the
  329 + * data will not be screened for NULL values.
245 330 ***************************************************************************/
246 331 void GFitsTableDblCol::set_nullval(const double* value)
247 332 {
... ... @@ -258,13 +343,13 @@ void GFitsTableDblCol::set_nullval(const double* value)
258 343 *m_nulval = *value;
259 344 }
260 345  
261   - // Re-load column
262   - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!!
  346 + // Re-load column
  347 +/*
263 348 if (m_data != NULL) {
264   - //save();
  349 + save();
265 350 load();
266 351 }
267   -
  352 +*/
268 353 // Return
269 354 return;
270 355 }
... ... @@ -276,9 +361,8 @@ void GFitsTableDblCol::set_nullval(const double* value)
276 361 = =
277 362 ==========================================================================*/
278 363  
279   -/***************************************************************************
280   - * Initialise class members *
281   - * ----------------------------------------------------------------------- *
  364 +/***********************************************************************//**
  365 + * @brief Initialise class members
282 366 ***************************************************************************/
283 367 void GFitsTableDblCol::init_members(void)
284 368 {
... ... @@ -293,9 +377,10 @@ void GFitsTableDblCol::init_members(void)
293 377 }
294 378  
295 379  
296   -/***************************************************************************
297   - * Copy class members *
298   - * ----------------------------------------------------------------------- *
  380 +/***********************************************************************//**
  381 + * @brief Copy class members
  382 + *
  383 + * @param[in] column Column for which members should be copied.
299 384 ***************************************************************************/
300 385 void GFitsTableDblCol::copy_members(const GFitsTableDblCol& column)
301 386 {
... ... @@ -322,9 +407,8 @@ void GFitsTableDblCol::copy_members(const GFitsTableDblCol&amp; column)
322 407 }
323 408  
324 409  
325   -/***************************************************************************
326   - * Delete class members *
327   - * ----------------------------------------------------------------------- *
  410 +/***********************************************************************//**
  411 + * @brief Delete class members
328 412 ***************************************************************************/
329 413 void GFitsTableDblCol::free_members(void)
330 414 {
... ... @@ -341,26 +425,47 @@ void GFitsTableDblCol::free_members(void)
341 425 }
342 426  
343 427  
344   -/***************************************************************************
345   - * Load column data *
346   - * ----------------------------------------------------------------------- *
  428 +/***********************************************************************//**
  429 + * @brief Fetch column data
  430 + *
  431 + * @exception GException::fits_error
  432 + * An error occured while loading column data from FITS file.
  433 + *
  434 + * If a FITS file is attached to the column the data are loaded into memory
  435 + * from the FITS file. If no FITS file is attached, memory is allocated
  436 + * to hold the column data and all cells are set to 0.
347 437 ***************************************************************************/
348   -void GFitsTableDblCol::load(void)
  438 +void GFitsTableDblCol::fetch_data(void)
349 439 {
350 440 // Calculate size of memory
351 441 m_size = m_repeat * m_length;
352 442  
353   - // Allocate memory
354   - if (m_data != NULL) delete [] m_data;
355   - m_data = new double[m_size];
356   -
357   - // Load column data
358   - int status = 0;
359   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
360   - status = __ffgcv(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size,
361   - m_nulval, m_data, &m_anynul, &status);
362   - if (status != 0)
363   - throw GException::fits_error(G_LOAD, status);
  443 + // Load only if the column has a positive size
  444 + if (m_size > 0) {
  445 +
  446 + // Allocate fresh memory
  447 + if (m_data != NULL) delete [] m_data;
  448 + m_data = new double[m_size];
  449 +
  450 + // If a FITS file is attached then load column data from the FITS
  451 + // file
  452 + if (m_fitsfile.Fptr != NULL) {
  453 + int status = 0;
  454 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
  455 + &status);
  456 + status = __ffgcv(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size,
  457 + m_nulval, m_data, &m_anynul, &status);
  458 + if (status != 0)
  459 + throw GException::fits_error(G_FETCH_DATA, status);
  460 + }
  461 +
  462 + // ... otherwise initialise all column values to 0
  463 + else {
  464 + for (int i = 0; i < m_size; ++i)
  465 + m_data[i] = 0.0;
  466 + }
  467 +
  468 + } // endif: column has a positive size
364 469  
365 470 // Return
366 471 return;
... ...
src/fits/GFitsTableFltCol.cpp
... ... @@ -43,9 +43,8 @@
43 43 = =
44 44 ==========================================================================*/
45 45  
46   -/***************************************************************************
47   - * Constructor *
48   - * ----------------------------------------------------------------------- *
  46 +/***********************************************************************//**
  47 + * @brief Constructor
49 48 ***************************************************************************/
50 49 GFitsTableFltCol::GFitsTableFltCol() : GFitsTableCol()
51 50 {
... ... @@ -57,11 +56,13 @@ GFitsTableFltCol::GFitsTableFltCol() : GFitsTableCol()
57 56 }
58 57  
59 58  
60   -/***************************************************************************
61   - * Copy constructor *
62   - * ----------------------------------------------------------------------- *
  59 +/***********************************************************************//**
  60 + * @brief Copy constructor
  61 + *
  62 + * @param[in] column Column from which class instance should be built.
63 63 ***************************************************************************/
64   -GFitsTableFltCol::GFitsTableFltCol(const GFitsTableFltCol& column) : GFitsTableCol(column)
  64 +GFitsTableFltCol::GFitsTableFltCol(const GFitsTableFltCol& column) :
  65 + GFitsTableCol(column)
65 66 {
66 67 // Initialise class members for clean destruction
67 68 init_members();
... ... @@ -74,9 +75,8 @@ GFitsTableFltCol::GFitsTableFltCol(const GFitsTableFltCol&amp; column) : GFitsTableC
74 75 }
75 76  
76 77  
77   -/***************************************************************************
78   - * Destructor *
79   - * ----------------------------------------------------------------------- *
  78 +/***********************************************************************//**
  79 + * @brief Destructor
80 80 ***************************************************************************/
81 81 GFitsTableFltCol::~GFitsTableFltCol()
82 82 {
... ... @@ -94,9 +94,10 @@ GFitsTableFltCol::~GFitsTableFltCol()
94 94 = =
95 95 ==========================================================================*/
96 96  
97   -/***************************************************************************
98   - * Assignment operator *
99   - * ----------------------------------------------------------------------- *
  97 +/***********************************************************************//**
  98 + * @brief Assignment operator
  99 + *
  100 + * @param[in] column Column which should be assigned
100 101 ***************************************************************************/
101 102 GFitsTableFltCol& GFitsTableFltCol::operator= (const GFitsTableFltCol& column)
102 103 {
... ... @@ -128,9 +129,13 @@ GFitsTableFltCol&amp; GFitsTableFltCol::operator= (const GFitsTableFltCol&amp; column)
128 129 = =
129 130 ==========================================================================*/
130 131  
131   -/***************************************************************************
132   - * Get string value *
133   - * ----------------------------------------------------------------------- *
  132 +/***********************************************************************//**
  133 + * @brief Get string value
  134 + *
  135 + * @param[in] row Table row.
  136 + * @param[in] col Table column vector index.
  137 + *
  138 + * Returns value of specified row and vector index as string.
134 139 ***************************************************************************/
135 140 std::string GFitsTableFltCol::string(const int& row, const int& col)
136 141 {
... ... @@ -158,9 +163,13 @@ std::string GFitsTableFltCol::string(const int&amp; row, const int&amp; col)
158 163 }
159 164  
160 165  
161   -/***************************************************************************
162   - * Get real value *
163   - * ----------------------------------------------------------------------- *
  166 +/***********************************************************************//**
  167 + * @brief Get double precision value
  168 + *
  169 + * @param[in] row Table row.
  170 + * @param[in] col Table column vector index.
  171 + *
  172 + * Returns value of specified row and vector index as double precision.
164 173 ***************************************************************************/
165 174 double GFitsTableFltCol::real(const int& row, const int& col)
166 175 {
... ... @@ -187,9 +196,13 @@ double GFitsTableFltCol::real(const int&amp; row, const int&amp; col)
187 196 }
188 197  
189 198  
190   -/***************************************************************************
191   - * Get int value *
192   - * ----------------------------------------------------------------------- *
  199 +/***********************************************************************//**
  200 + * @brief Get integer value
  201 + *
  202 + * @param[in] row Table row.
  203 + * @param[in] col Table column vector index.
  204 + *
  205 + * Returns value of specified row and vector index as integer.
193 206 ***************************************************************************/
194 207 int GFitsTableFltCol::integer(const int& row, const int& col)
195 208 {
... ... @@ -216,35 +229,31 @@ int GFitsTableFltCol::integer(const int&amp; row, const int&amp; col)
216 229 }
217 230  
218 231  
219   -/***************************************************************************
220   - * Access to invalid data pointers *
221   - * ----------------------------------------------------------------------- *
  232 +/***********************************************************************//**
  233 + * @brief Clone column
222 234 ***************************************************************************/
223   -double* GFitsTableFltCol::ptr_double(void)
  235 +GFitsTableFltCol* GFitsTableFltCol::clone(void) const
224 236 {
225   - throw GException::fits_invalid_type(G_PTR_DOUBLE,
226   - "No <double> pointer allowed to <float> array");
  237 + return new GFitsTableFltCol(*this);
227 238 }
228   -short* GFitsTableFltCol::ptr_short(void)
229   -{
230   - throw GException::fits_invalid_type(G_PTR_SHORT,
231   - "No <short> pointer allowed to <float> array");
232   -}
233   -long* GFitsTableFltCol::ptr_long(void)
234   -{
235   - throw GException::fits_invalid_type(G_PTR_LONG,
236   - "No <long> pointer allowed to <float> array");
237   -}
238   -int* GFitsTableFltCol::ptr_int(void)
  239 +
  240 +
  241 +/***********************************************************************//**
  242 + * @brief Return pointer to floating point column
  243 + ***************************************************************************/
  244 +float* GFitsTableFltCol::data(void)
239 245 {
240   - throw GException::fits_invalid_type(G_PTR_INT,
241   - "No <int> pointer allowed to <float> array");
  246 + return m_data;
242 247 }
243 248  
244 249  
245   -/***************************************************************************
246   - * Set NULL string *
247   - * ----------------------------------------------------------------------- *
  250 +/***********************************************************************//**
  251 + * @brief Set NULL value
  252 + *
  253 + * @param[in] value Pointer on NULL value
  254 + *
  255 + * Allows the specification of the FITS table NULL value. If value=NULL the
  256 + * data will not be screened for NULL values.
248 257 ***************************************************************************/
249 258 void GFitsTableFltCol::set_nullval(const float* value)
250 259 {
... ... @@ -261,12 +270,13 @@ void GFitsTableFltCol::set_nullval(const float* value)
261 270 *m_nulval = *value;
262 271 }
263 272  
264   - // Re-load column
265   - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!!
  273 + // Re-load column
  274 +/*
266 275 if (m_data != NULL) {
267   - //save();
  276 + save();
268 277 load();
269 278 }
  279 +*/
270 280  
271 281 // Return
272 282 return;
... ... @@ -279,9 +289,8 @@ void GFitsTableFltCol::set_nullval(const float* value)
279 289 = =
280 290 ==========================================================================*/
281 291  
282   -/***************************************************************************
283   - * Initialise class members *
284   - * ----------------------------------------------------------------------- *
  292 +/***********************************************************************//**
  293 + * @brief Initialise class members
285 294 ***************************************************************************/
286 295 void GFitsTableFltCol::init_members(void)
287 296 {
... ... @@ -296,9 +305,10 @@ void GFitsTableFltCol::init_members(void)
296 305 }
297 306  
298 307  
299   -/***************************************************************************
300   - * Copy class members *
301   - * ----------------------------------------------------------------------- *
  308 +/***********************************************************************//**
  309 + * @brief Copy class members
  310 + *
  311 + * @param[in] column Column for which members should be copied.
302 312 ***************************************************************************/
303 313 void GFitsTableFltCol::copy_members(const GFitsTableFltCol& column)
304 314 {
... ... @@ -325,9 +335,8 @@ void GFitsTableFltCol::copy_members(const GFitsTableFltCol&amp; column)
325 335 }
326 336  
327 337  
328   -/***************************************************************************
329   - * Delete class members *
330   - * ----------------------------------------------------------------------- *
  338 +/***********************************************************************//**
  339 + * @brief Delete class members
331 340 ***************************************************************************/
332 341 void GFitsTableFltCol::free_members(void)
333 342 {
... ... @@ -344,9 +353,8 @@ void GFitsTableFltCol::free_members(void)
344 353 }
345 354  
346 355  
347   -/***************************************************************************
348   - * Load column data *
349   - * ----------------------------------------------------------------------- *
  356 +/***********************************************************************//**
  357 + * @brief Load column data
350 358 ***************************************************************************/
351 359 void GFitsTableFltCol::load(void)
352 360 {
... ...
src/fits/GFitsTableLngCol.cpp
... ... @@ -23,12 +23,7 @@
23 23 #define G_STRING "GFitsTableLngCol::string(const int&, const int&)"
24 24 #define G_REAL "GFitsTableLngCol::real(const int&, const int&)"
25 25 #define G_INTEGER "GFitsTableLngCol::integer(const int&, const int&)"
26   -#define G_PTR_FLOAT "GFitsTableLngCol::ptr_float()"
27   -#define G_PTR_DOUBLE "GFitsTableLngCol::ptr_double()"
28   -#define G_PTR_SHORT "GFitsTableLngCol::ptr_short()"
29   -#define G_PTR_LONG "GFitsTableLngCol::ptr_long()"
30   -#define G_PTR_INT "GFitsTableLngCol::ptr_int()"
31   -#define G_LOAD "GFitsTableLngCol::load()"
  26 +#define G_FETCH_DATA "GFitsTableLngCol::fetch_data()"
32 27  
33 28 /* __ Macros _____________________________________________________________ */
34 29  
... ... @@ -43,9 +38,8 @@
43 38 = =
44 39 ==========================================================================*/
45 40  
46   -/***************************************************************************
47   - * Constructor *
48   - * ----------------------------------------------------------------------- *
  41 +/***********************************************************************//**
  42 + * @brief Constructor
49 43 ***************************************************************************/
50 44 GFitsTableLngCol::GFitsTableLngCol() : GFitsTableCol()
51 45 {
... ... @@ -57,11 +51,13 @@ GFitsTableLngCol::GFitsTableLngCol() : GFitsTableCol()
57 51 }
58 52  
59 53  
60   -/***************************************************************************
61   - * Copy constructor *
62   - * ----------------------------------------------------------------------- *
  54 +/***********************************************************************//**
  55 + * @brief Copy constructor
  56 + *
  57 + * @param[in] column Column from which class instance should be built.
63 58 ***************************************************************************/
64   -GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol& column) : GFitsTableCol(column)
  59 +GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol& column) :
  60 + GFitsTableCol(column)
65 61 {
66 62 // Initialise class members for clean destruction
67 63 init_members();
... ... @@ -74,9 +70,8 @@ GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol&amp; column) : GFitsTableC
74 70 }
75 71  
76 72  
77   -/***************************************************************************
78   - * Destructor *
79   - * ----------------------------------------------------------------------- *
  73 +/***********************************************************************//**
  74 + * @brief Destructor
80 75 ***************************************************************************/
81 76 GFitsTableLngCol::~GFitsTableLngCol()
82 77 {
... ... @@ -94,9 +89,10 @@ GFitsTableLngCol::~GFitsTableLngCol()
94 89 = =
95 90 ==========================================================================*/
96 91  
97   -/***************************************************************************
98   - * Assignment operator *
99   - * ----------------------------------------------------------------------- *
  92 +/***********************************************************************//**
  93 + * @brief Assignment operator
  94 + *
  95 + * @param[in] column Column which should be assigned
100 96 ***************************************************************************/
101 97 GFitsTableLngCol& GFitsTableLngCol::operator= (const GFitsTableLngCol& column)
102 98 {
... ... @@ -122,129 +118,196 @@ GFitsTableLngCol&amp; GFitsTableLngCol::operator= (const GFitsTableLngCol&amp; column)
122 118 }
123 119  
124 120  
  121 +/***********************************************************************//**
  122 + * @brief Column data access operator
  123 + *
  124 + * @param[in] row Row of column to access.
  125 + * @param[in] inx Vector index in column row to access
  126 + *
  127 + * Provides access to data in a column. No range checking is performed.
  128 + * Use one of
  129 + * GFitsTableLngCol::string(ix,iy),
  130 + * GFitsTableLngCol::real(ix;iy) or
  131 + * GFitsTableLngCol::integer(ix;iy)
  132 + * if range checking is required.
  133 + ***************************************************************************/
  134 +long& GFitsTableLngCol::operator() (const int& row, const int& inx)
  135 +{
  136 + // If data are not available then load them now
  137 + if (m_data == NULL) fetch_data();
  138 +
  139 + // Calculate pixel offset
  140 + int offset = row * m_repeat + inx;
  141 +
  142 + // Return image pixel
  143 + return m_data[offset];
  144 +}
  145 +
  146 +
  147 +/***********************************************************************//**
  148 + * @brief Column data access operator (const variant)
  149 + *
  150 + * @param[in] row Row of column to access.
  151 + * @param[in] inx Vector index in column row to access
  152 + *
  153 + * Provides access to data in a column. No range checking is performed.
  154 + * Use one of
  155 + * GFitsTableLngCol::string(ix,iy),
  156 + * GFitsTableLngCol::real(ix;iy) or
  157 + * GFitsTableLngCol::integer(ix;iy)
  158 + * if range checking is required.
  159 + ***************************************************************************/
  160 +const long& GFitsTableLngCol::operator() (const int& row, const int& inx)
  161 + const
  162 +{
  163 + // If data are not available then load them now
  164 + if (m_data == NULL) ((GFitsTableLngCol*)this)->fetch_data();
  165 +
  166 + // Calculate pixel offset
  167 + int offset = row * m_repeat + inx;
  168 +
  169 + // Return image pixel
  170 + return m_data[offset];
  171 +}
  172 +
  173 +
125 174 /*==========================================================================
126 175 = =
127 176 = GFitsTableLngCol public methods =
128 177 = =
129 178 ==========================================================================*/
130 179  
131   -/***************************************************************************
132   - * Get string value *
133   - * ----------------------------------------------------------------------- *
  180 +/***********************************************************************//**
  181 + * @brief Get string value
  182 + *
  183 + * @param[in] row Table row.
  184 + * @param[in] inx Table column vector index.
  185 + *
  186 + * @exception GException::out_of_range
  187 + * Table row or vector index are out of valid range.
  188 + *
  189 + * Returns value of specified row and vector index as string.
134 190 ***************************************************************************/
135   -std::string GFitsTableLngCol::string(const int& row, const int& col)
  191 +std::string GFitsTableLngCol::string(const int& row, const int& inx)
136 192 {
137   - // Make sure that data are loaded
138   - if (m_data == NULL)
139   - load();
  193 + // If data are not available then load them now
  194 + if (m_data == NULL) fetch_data();
140 195  
141 196 // Check row value
142 197 if (row < 0 || row >= m_length)
143 198 throw GException::out_of_range(G_STRING, row, 0, m_length-1);
144 199  
145   - // Check col value
146   - if (col < 0 || col >= m_repeat)
147   - throw GException::out_of_range(G_STRING, col, 0, m_repeat-1);
  200 + // Check inx value
  201 + if (inx < 0 || inx >= m_repeat)
  202 + throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1);
148 203  
149 204 // Get index
150   - int inx = row * m_repeat + col;
  205 + int offset = row * m_repeat + inx;
151 206  
152 207 // Convert long into string
153 208 ostringstream s_value;
154   - s_value << m_data[inx];
  209 + s_value << m_data[offset];
155 210  
156 211 // Return value
157 212 return s_value.str();
158 213 }
159 214  
160 215  
161   -/***************************************************************************
162   - * Get real value *
163   - * ----------------------------------------------------------------------- *
  216 +/***********************************************************************//**
  217 + * @brief Get double precision value
  218 + *
  219 + * @param[in] row Table row.
  220 + * @param[in] inx Table column vector index.
  221 + *
  222 + * @exception GException::out_of_range
  223 + * Table row or vector index are out of valid range.
  224 + *
  225 + * Returns value of specified row and vector index as double precision.
164 226 ***************************************************************************/
165   -double GFitsTableLngCol::real(const int& row, const int& col)
  227 +double GFitsTableLngCol::real(const int& row, const int& inx)
166 228 {
167   - // Make sure that data are loaded
168   - if (m_data == NULL)
169   - load();
  229 + // If data are not available then load them now
  230 + if (m_data == NULL) fetch_data();
170 231  
171 232 // Check row value
172 233 if (row < 0 || row >= m_length)
173 234 throw GException::out_of_range(G_REAL, row, 0, m_length-1);
174 235  
175   - // Check col value
176   - if (col < 0 || col >= m_repeat)
177   - throw GException::out_of_range(G_REAL, col, 0, m_repeat-1);
  236 + // Check inx value
  237 + if (inx < 0 || inx >= m_repeat)
  238 + throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1);
178 239  
179 240 // Get index
180   - int inx = row * m_repeat + col;
  241 + int offset = row * m_repeat + inx;
181 242  
182 243 // Convert long into double
183   - double value = (double)m_data[inx];
  244 + double value = (double)m_data[offset];
184 245  
185 246 // Return value
186 247 return value;
187 248 }
188 249  
189 250  
190   -/***************************************************************************
191   - * Get int value *
192   - * ----------------------------------------------------------------------- *
  251 +/***********************************************************************//**
  252 + * @brief Get integer value
  253 + *
  254 + * @param[in] row Table row.
  255 + * @param[in] inx Table column vector index.
  256 + *
  257 + * @exception GException::out_of_range
  258 + * Table row or vector index are out of valid range.
  259 + *
  260 + * Returns value of specified row and vector index as integer.
193 261 ***************************************************************************/
194   -int GFitsTableLngCol::integer(const int& row, const int& col)
  262 +int GFitsTableLngCol::integer(const int& row, const int& inx)
195 263 {
196   - // Make sure that data are loaded
197   - if (m_data == NULL)
198   - load();
  264 + // If data are not available then load them now
  265 + if (m_data == NULL) fetch_data();
199 266  
200 267 // Check row value
201 268 if (row < 0 || row >= m_length)
202 269 throw GException::out_of_range(G_INTEGER, row, 0, m_length-1);
203 270  
204   - // Check col value
205   - if (col < 0 || col >= m_repeat)
206   - throw GException::out_of_range(G_INTEGER, col, 0, m_repeat-1);
  271 + // Check inx value
  272 + if (inx < 0 || inx >= m_repeat)
  273 + throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1);
207 274  
208 275 // Get index
209   - int inx = row * m_repeat + col;
  276 + int offset = row * m_repeat + inx;
210 277  
211 278 // Convert long into int
212   - int value = (int)m_data[inx];
  279 + int value = (int)m_data[offset];
213 280  
214 281 // Return value
215 282 return value;
216 283 }
217 284  
218 285  
219   -/***************************************************************************
220   - * Access to invalid data pointers *
221   - * ----------------------------------------------------------------------- *
  286 +/***********************************************************************//**
  287 + * @brief Clone column
222 288 ***************************************************************************/
223   -float* GFitsTableLngCol::ptr_float(void)
  289 +GFitsTableLngCol* GFitsTableLngCol::clone(void) const
224 290 {
225   - throw GException::fits_invalid_type(G_PTR_FLOAT,
226   - "No <float> pointer allowed to <long> array");
  291 + return new GFitsTableLngCol(*this);
227 292 }
228   -double* GFitsTableLngCol::ptr_double(void)
229   -{
230   - throw GException::fits_invalid_type(G_PTR_DOUBLE,
231   - "No <double> pointer allowed to <long> array");
232   -}
233   -short* GFitsTableLngCol::ptr_short(void)
234   -{
235   - throw GException::fits_invalid_type(G_PTR_SHORT,
236   - "No <short> pointer allowed to <long> array");
237   -}
238   -int* GFitsTableLngCol::ptr_int(void)
  293 +
  294 +
  295 +/***********************************************************************//**
  296 + * @brief Return pointer to long integer column
  297 + ***************************************************************************/
  298 +long* GFitsTableLngCol::data(void)
239 299 {
240   - throw GException::fits_invalid_type(G_PTR_INT,
241   - "No <int> pointer allowed to <long> array");
  300 + return m_data;
242 301 }
243 302  
244 303  
245   -/***************************************************************************
246   - * Set NULL string *
247   - * ----------------------------------------------------------------------- *
  304 +/***********************************************************************//**
  305 + * @brief Set NULL value
  306 + *
  307 + * @param[in] value Pointer on NULL value
  308 + *
  309 + * Allows the specification of the FITS table NULL value. If value=NULL the
  310 + * data will not be screened for NULL values.
248 311 ***************************************************************************/
249 312 void GFitsTableLngCol::set_nullval(const long* value)
250 313 {
... ... @@ -261,12 +324,13 @@ void GFitsTableLngCol::set_nullval(const long* value)
261 324 *m_nulval = *value;
262 325 }
263 326  
264   - // Re-load column
265   - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!!
  327 + // Re-load column
  328 +/*
266 329 if (m_data != NULL) {
267   - //save();
  330 + save();
268 331 load();
269 332 }
  333 +*/
270 334  
271 335 // Return
272 336 return;
... ... @@ -279,9 +343,8 @@ void GFitsTableLngCol::set_nullval(const long* value)
279 343 = =
280 344 ==========================================================================*/
281 345  
282   -/***************************************************************************
283   - * Initialise class members *
284   - * ----------------------------------------------------------------------- *
  346 +/***********************************************************************//**
  347 + * @brief Initialise class members
285 348 ***************************************************************************/
286 349 void GFitsTableLngCol::init_members(void)
287 350 {
... ... @@ -296,9 +359,10 @@ void GFitsTableLngCol::init_members(void)
296 359 }
297 360  
298 361  
299   -/***************************************************************************
300   - * Copy class members *
301   - * ----------------------------------------------------------------------- *
  362 +/***********************************************************************//**
  363 + * @brief Copy class members
  364 + *
  365 + * @param[in] column Column for which members should be copied.
302 366 ***************************************************************************/
303 367 void GFitsTableLngCol::copy_members(const GFitsTableLngCol& column)
304 368 {
... ... @@ -325,9 +389,8 @@ void GFitsTableLngCol::copy_members(const GFitsTableLngCol&amp; column)
325 389 }
326 390  
327 391  
328   -/***************************************************************************
329   - * Delete class members *
330   - * ----------------------------------------------------------------------- *
  392 +/***********************************************************************//**
  393 + * @brief Delete class members
331 394 ***************************************************************************/
332 395 void GFitsTableLngCol::free_members(void)
333 396 {
... ... @@ -344,26 +407,47 @@ void GFitsTableLngCol::free_members(void)
344 407 }
345 408  
346 409  
347   -/***************************************************************************
348   - * Load column data *
349   - * ----------------------------------------------------------------------- *
  410 +/***********************************************************************//**
  411 + * @brief Fetch column data
  412 + *
  413 + * @exception GException::fits_error
  414 + * An error occured while loading column data from FITS file.
  415 + *
  416 + * If a FITS file is attached to the column the data are loaded into memory
  417 + * from the FITS file. If no FITS file is attached, memory is allocated
  418 + * to hold the column data and all cells are set to 0.
350 419 ***************************************************************************/
351   -void GFitsTableLngCol::load(void)
  420 +void GFitsTableLngCol::fetch_data(void)
352 421 {
353 422 // Calculate size of memory
354 423 m_size = m_repeat * m_length;
355 424  
356   - // Allocate memory
357   - if (m_data != NULL) delete [] m_data;
358   - m_data = new long[m_size];
  425 + // Load only if the column has a positive size
  426 + if (m_size > 0) {
  427 +
  428 + // Allocate fresh memory
  429 + if (m_data != NULL) delete [] m_data;
  430 + m_data = new long[m_size];
359 431  
360   - // Load column data
361   - int status = 0;
362   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
363   - status = __ffgcv(&m_fitsfile, __TLONG, m_colnum, 1, 1, m_size,
364   - m_nulval, m_data, &m_anynul, &status);
365   - if (status != 0)
366   - throw GException::fits_error(G_LOAD, status);
  432 + // If a FITS file is attached then load column data from the FITS
  433 + // file
  434 + if (m_fitsfile.Fptr != NULL) {
  435 + int status = 0;
  436 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL,
  437 + &status);
  438 + status = __ffgcv(&m_fitsfile, __TLONG, m_colnum, 1, 1, m_size,
  439 + m_nulval, m_data, &m_anynul, &status);
  440 + if (status != 0)
  441 + throw GException::fits_error(G_FETCH_DATA, status);
  442 + }
  443 +
  444 + // ... otherwise initialise all column values to 0
  445 + else {
  446 + for (int i = 0; i < m_size; ++i)
  447 + m_data[i] = 0;
  448 + }
  449 +
  450 + } // endif: column has a positive size
367 451  
368 452 // Return
369 453 return;
... ... @@ -372,13 +456,13 @@ void GFitsTableLngCol::load(void)
372 456  
373 457 /*==========================================================================
374 458 = =
375   - = GFitsTableShtCol friends =
  459 + = GFitsTableLngCol friends =
376 460 = =
377 461 ==========================================================================*/
378 462  
379 463  
380 464 /*==========================================================================
381 465 = =
382   - = Other functions used by GFitsTableShtCol =
  466 + = Other functions used by GFitsTableLngCol =
383 467 = =
384 468 ==========================================================================*/
... ...
src/rsp/GLATResponse.cpp
... ... @@ -425,10 +425,12 @@ void GLATResponse::psf_init(void)
425 425  
426 426 // Evaluate ntail
427 427 double denom = psf_base_value(10.0, gtail);
428   - double ntail = (denom != 0.0) ? ncore * psf_base_value(10.0, gcore) / denom : 0.0;
  428 + double ntail = (denom != 0.0)
  429 + ? ncore * psf_base_value(10.0, gcore) / denom : 0.0;
429 430  
430 431 // Calculate PSF dependence
431   - GVector psf = ncore * psf_base_vector(u, gcore) + ntail * psf_base_vector(u, gtail);
  432 + GVector psf = ncore * psf_base_vector(u, gcore) +
  433 + ntail * psf_base_vector(u, gtail);
432 434  
433 435 // Normalize PSF vector to identical amplitudes at smallest angular
434 436 // distance. This allows for accurate interpolation afterwards
... ... @@ -555,7 +557,7 @@ double GLATResponse::psf_base_value(const double&amp; u, const double&amp; gamma)
555 557 double c0 = 1.0 - invgamma;
556 558 double c1 = 1.0 + u * invgamma;
557 559 double result = c0 * pow(c1,-gamma);
558   -
  560 +
559 561 // Return result
560 562 return result;
561 563 }
... ... @@ -567,7 +569,7 @@ GVector GLATResponse::psf_base_vector(const GVector&amp; u, const double&amp; gamma)
567 569 double c0 = 1.0 - invgamma;
568 570 GVector c1 = 1.0 + u * invgamma;
569 571 GVector result = c0 * pow(c1,-gamma);
570   -
  572 +
571 573 // Return result
572 574 return result;
573 575 }
... ... @@ -631,7 +633,7 @@ void GLATResponse::init_members(void)
631 633 //m_aeff_name.clear();
632 634 //m_psf_name.clear();
633 635 //m_edisp_name.clear();
634   -
  636 +
635 637 // Initialise PSF members
636 638 m_psf_angle_num = 0;
637 639 m_psf_angle_min = 0.0;
... ... @@ -703,7 +705,7 @@ GVector GLATResponse::get_fits_vector(const GFitsHDU* hdu, const std::string&amp; co
703 705 GFitsTableCol* ptr = hdu->column(colname);
704 706 if (ptr == NULL)
705 707 throw GException::fits_column_not_found(G_GET_FITS_VECTOR, colname);
706   -
  708 +
707 709 // Determine number of entries
708 710 int num = ptr->repeat();
709 711  
... ...
test/test_GFits.cpp
... ... @@ -373,14 +373,25 @@ void test_create(void)
373 373  
374 374 // Attach binary table
375 375 try {
  376 + // Re-open FITS file
376 377 GFits fits;
377 378 fits.open("test.fits");
  379 +
  380 + // Create binary Table with 10 rows
378 381 int nrows = 10;
379   - int ncols = 5;
380   - GFitsBinTable table(nrows);
  382 + GFitsBinTable table = GFitsBinTable(nrows);
  383 + GFitsTableDblCol first = GFitsTableDblCol(nrows);
  384 + GFitsTableDblCol second = GFitsTableDblCol(nrows);
  385 + table.append_column(&first);
  386 + table.append_column(&second);
  387 + cout << table;
  388 +
  389 + // Create HDU and append to FILE file
381 390 GFitsHDU hdu(table);
382 391 fits.append(&hdu);
383   - cout << fits;
  392 +// cout << fits;
  393 +
  394 + // Save FITS file
384 395 fits.save();
385 396 }
386 397 catch (exception &e) {
... ...