diff --git a/include/GFitsTableBitCol.hpp b/include/GFitsTableBitCol.hpp index 0ee23d6..68823e4 100644 --- a/include/GFitsTableBitCol.hpp +++ b/include/GFitsTableBitCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableBitCol.hpp - FITS table bit column class * + * GFitsTableBitCol.hpp - FITS table bit column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2012 by Juergen Knoedlseder * + * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -75,24 +75,24 @@ private: void init_members(void); void copy_members(const GFitsTableBitCol& column); void free_members(void); + void alloc_nulval(const unsigned char* value); + void get_bit(const int& row, const int& inx); + void set_pending(void); - // Implemented pure virtual methods - virtual std::string ascii_format(void) const; - virtual void alloc_data(void); - virtual void init_data(void); - virtual void* ptr_data(const int& index = 0) { return m_data+index; } - virtual void* ptr_nulval(void) { return m_nulval; } + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Overloaded virtual methods virtual void load_column(void); virtual void save_column(void); - // Other private methods - void release_data(void); - void alloc_nulval(const unsigned char* value); - void get_bit(const int& row, const int& inx); - void set_pending(void); - // Private data area int m_bits; //!< Total number of Bits in column int m_bytes_per_row; //!< Number of Bytes per row diff --git a/include/GFitsTableBoolCol.hpp b/include/GFitsTableBoolCol.hpp index f26ea41..c4a7544 100644 --- a/include/GFitsTableBoolCol.hpp +++ b/include/GFitsTableBoolCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableBoolCol.hpp - FITS table boolean column class * + * GFitsTableBoolCol.hpp - FITS table boolean column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2012 by Juergen Knoedlseder * + * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -73,25 +73,30 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableBoolCol& column); - void free_members(void); - void save(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const bool* value); - void init_data(void); - void fetch_data(void) const; - void alloc_buffer(void); - void free_buffer(void); - void* ptr_data(const int& index = 0) { return m_buffer+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableBoolCol& column); + void free_members(void); + void alloc_nulval(const bool* value); + void alloc_buffer(void) const; + void free_buffer(void) const; + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; + + // Overloaded base class methods + virtual void save(void); // Private data area - bool* m_data; //!< Data area - char* m_buffer; //!< Data area for CFITSIO transfer - bool* m_nulval; //!< NULL value + bool* m_data; //!< Data area + bool* m_nulval; //!< NULL value + mutable char* m_buffer; //!< Data area for CFITSIO transfer }; #endif /* GFITSTABLEBOOLCOL_HPP */ diff --git a/include/GFitsTableByteCol.hpp b/include/GFitsTableByteCol.hpp index 3145a71..fad3282 100644 --- a/include/GFitsTableByteCol.hpp +++ b/include/GFitsTableByteCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableByteCol.hpp - FITS table Byte column class * + * GFitsTableByteCol.hpp - FITS table Byte column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2012 by Juergen Knoedlseder * + * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableByteCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const unsigned char* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableByteCol& column); + void free_members(void); + void alloc_nulval(const unsigned char* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area unsigned char* m_data; //!< Data vector diff --git a/include/GFitsTableCDoubleCol.hpp b/include/GFitsTableCDoubleCol.hpp index 3aaf4be..93c0b5a 100644 --- a/include/GFitsTableCDoubleCol.hpp +++ b/include/GFitsTableCDoubleCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableCDoubleCol.hpp - FITS table double precision complex column * + * GFitsTableCDoubleCol.hpp - FITS table double precision complex column * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2012 by Juergen Knoedlseder * + * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -71,16 +71,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableCDoubleCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const GFits::cdouble* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableCDoubleCol& column); + void free_members(void); + void alloc_nulval(const GFits::cdouble* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area GFits::cdouble* m_data; //!< Data vector diff --git a/include/GFitsTableCFloatCol.hpp b/include/GFitsTableCFloatCol.hpp index 872a2e3..2951826 100644 --- a/include/GFitsTableCFloatCol.hpp +++ b/include/GFitsTableCFloatCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableCFloatCol.hpp - FITS table single precision complex column * + * GFitsTableCFloatCol.hpp - FITS table single precision complex column * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2012 by Juergen Knoedlseder * + * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -71,16 +71,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableCFloatCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const GFits::cfloat* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableCFloatCol& column); + void free_members(void); + void alloc_nulval(const GFits::cfloat* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area GFits::cfloat* m_data; //!< Data vector diff --git a/include/GFitsTableCol.hpp b/include/GFitsTableCol.hpp index 70b351d..653ebc5 100644 --- a/include/GFitsTableCol.hpp +++ b/include/GFitsTableCol.hpp @@ -95,6 +95,7 @@ public: void anynul(const int& anynul); const int& anynul(void) const; std::string tform_binary(void) const; + bool isloaded(void) const; std::string print(const GChatter& chatter = NORMAL) const; protected: @@ -107,17 +108,22 @@ protected: // Protected pure virtual methods virtual void alloc_data(void) = 0; virtual void init_data(void) = 0; + virtual void fetch_data(void) const = 0; + virtual void copy_data(const GFitsTableCol& column) = 0; + virtual void release_data(void) = 0; virtual void* ptr_data(const int& index = 0) = 0; virtual void* ptr_nulval(void) = 0; virtual std::string ascii_format(void) const = 0; // Protected virtual methods virtual void save(void); - virtual void fetch_data(void) const; + //virtual void fetch_data(void) const; virtual void load_column(void); virtual void load_column_fixed(void); virtual void load_column_variable(void); virtual void save_column(void); + virtual void save_column_fixed(void); + virtual void save_column_variable(void); virtual int offset(const int& row, const int& inx) const; // Protected data area diff --git a/include/GFitsTableDoubleCol.hpp b/include/GFitsTableDoubleCol.hpp index 416486e..d66f597 100644 --- a/include/GFitsTableDoubleCol.hpp +++ b/include/GFitsTableDoubleCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableDoubleCol.hpp - FITS table double column class * + * GFitsTableDoubleCol.hpp - FITS table double column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2012 by Juergen Knoedlseder * + * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableDoubleCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const double* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableDoubleCol& column); + void free_members(void); + void alloc_nulval(const double* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area double* m_data; //!< Data vector diff --git a/include/GFitsTableFloatCol.hpp b/include/GFitsTableFloatCol.hpp index d83982a..264f541 100644 --- a/include/GFitsTableFloatCol.hpp +++ b/include/GFitsTableFloatCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableFloatCol.hpp - FITS table float column class * + * GFitsTableFloatCol.hpp - FITS table float column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2012 by Juergen Knoedlseder * + * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableFloatCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const float* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableFloatCol& column); + void free_members(void); + void alloc_nulval(const float* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area float* m_data; //!< Data vector diff --git a/include/GFitsTableLongCol.hpp b/include/GFitsTableLongCol.hpp index 4ccab65..39d1924 100644 --- a/include/GFitsTableLongCol.hpp +++ b/include/GFitsTableLongCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableLongCol.hpp - FITS table long column class * + * GFitsTableLongCol.hpp - FITS table long column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2011 by Jurgen Knodlseder * + * copyright (C) 2010-2013 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -50,7 +50,7 @@ public: virtual ~GFitsTableLongCol(void); // Operators - GFitsTableLongCol& operator= (const GFitsTableLongCol& column); + GFitsTableLongCol& operator=(const GFitsTableLongCol& column); long& operator()(const int& row, const int& inx = 0); const long& operator()(const int& row, const int& inx = 0) const; @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableLongCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const long* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableLongCol& column); + void free_members(void); + void alloc_nulval(const long* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area long* m_data; //!< Data vector diff --git a/include/GFitsTableLongLongCol.hpp b/include/GFitsTableLongLongCol.hpp index e519340..6e6cc9f 100644 --- a/include/GFitsTableLongLongCol.hpp +++ b/include/GFitsTableLongLongCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableLongLongCol.hpp - FITS table long long column class * + * GFitsTableLongLongCol.hpp - FITS table long long column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2012 by Juergen Knoedlseder * + * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableLongLongCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const long long* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableLongLongCol& column); + void free_members(void); + void alloc_nulval(const long long* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area long long* m_data; //!< Data vector diff --git a/include/GFitsTableShortCol.hpp b/include/GFitsTableShortCol.hpp index 3fcd26f..1410540 100644 --- a/include/GFitsTableShortCol.hpp +++ b/include/GFitsTableShortCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableShortCol.hpp - FITS table short column class * + * GFitsTableShortCol.hpp - FITS table short column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2012 by Juergen Knoedlseder * + * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableShortCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const short* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableShortCol& column); + void free_members(void); + void alloc_nulval(const short* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area short* m_data; //!< Data vector diff --git a/include/GFitsTableStringCol.hpp b/include/GFitsTableStringCol.hpp index f379682..081f88f 100644 --- a/include/GFitsTableStringCol.hpp +++ b/include/GFitsTableStringCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableStringCol.hpp - FITS table string column class * + * GFitsTableStringCol.hpp - FITS table string column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2012 by Juergen Knoedlseder * + * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -50,7 +50,7 @@ public: virtual ~GFitsTableStringCol(void); // Operators - GFitsTableStringCol& operator= (const GFitsTableStringCol& column); + GFitsTableStringCol& operator=(const GFitsTableStringCol& column); std::string& operator()(const int& row, const int& inx = 0); const std::string& operator()(const int& row, const int& inx = 0) const; @@ -70,20 +70,25 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableStringCol& column); - void free_members(void); - void save(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const std::string& value); - void init_data(void); - void fetch_data(void) const; - void alloc_buffer(void) const; - void free_buffer(void) const; - void* ptr_data(const int& index = 0) { return m_buffer+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableStringCol& column); + void free_members(void); + void alloc_nulval(const std::string& value); + void alloc_buffer(void) const; + void free_buffer(void) const; + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; + + // Overloaded base class methods + virtual void save(void); // Private data area std::string* m_data; //!< Data area diff --git a/include/GFitsTableULongCol.hpp b/include/GFitsTableULongCol.hpp index 584846b..2c369bf 100644 --- a/include/GFitsTableULongCol.hpp +++ b/include/GFitsTableULongCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableULongCol.hpp - FITS table unsigned long column class * + * GFitsTableULongCol.hpp - FITS table unsigned long column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2012 by Juergen Knoedlseder * + * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableULongCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const unsigned long* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableULongCol& column); + void free_members(void); + void alloc_nulval(const unsigned long* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area unsigned long* m_data; //!< Data vector diff --git a/include/GFitsTableUShortCol.hpp b/include/GFitsTableUShortCol.hpp index 4de5712..7f629ab 100644 --- a/include/GFitsTableUShortCol.hpp +++ b/include/GFitsTableUShortCol.hpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GFitsTableUShortCol.hpp - FITS table unsigned short column class * + * GFitsTableUShortCol.hpp - FITS table unsigned short column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2012 by Juergen Knoedlseder * + * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,16 +70,20 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableUShortCol& column); - void free_members(void); - std::string ascii_format(void) const; - void alloc_data(void); - void release_data(void); - void alloc_nulval(const unsigned short* value); - void init_data(void); - void* ptr_data(const int& index = 0) { return m_data+index; } - void* ptr_nulval(void) { return m_nulval; } + void init_members(void); + void copy_members(const GFitsTableUShortCol& column); + void free_members(void); + void alloc_nulval(const unsigned short* value); + + // Implemented virtual base class methods + virtual void alloc_data(void); + virtual void init_data(void); + virtual void fetch_data(void) const; + virtual void copy_data(const GFitsTableCol& column); + virtual void release_data(void); + virtual void* ptr_data(const int& index = 0) { return m_data+index; } + virtual void* ptr_nulval(void) { return m_nulval; } + virtual std::string ascii_format(void) const; // Private data area unsigned short* m_data; //!< Data vector diff --git a/pyext/GFitsTableCol.i b/pyext/GFitsTableCol.i index 496cbd1..712778c 100644 --- a/pyext/GFitsTableCol.i +++ b/pyext/GFitsTableCol.i @@ -96,6 +96,8 @@ public: const bool& isvariable(void) const; void anynul(const int& anynul); const int& anynul(void) const; + std::string tform_binary(void) const; + bool isloaded(void) const; }; diff --git a/src/fits/GFits.cpp b/src/fits/GFits.cpp index 815c4c1..9d3bfd4 100644 --- a/src/fits/GFits.cpp +++ b/src/fits/GFits.cpp @@ -499,7 +499,7 @@ void GFits::append(const GFitsHDU& hdu) // Debug header #if DEBUG std::cout << "GFits::append("; - switch (hdu->exttype()) { + switch (hdu.exttype()) { case GFitsHDU::HT_IMAGE: std::cout << "GFitsImage"; break; diff --git a/src/fits/GFitsTable.cpp b/src/fits/GFitsTable.cpp index ebb4b80..b136353 100644 --- a/src/fits/GFitsTable.cpp +++ b/src/fits/GFitsTable.cpp @@ -67,7 +67,7 @@ /* __ Coding definitions _________________________________________________ */ /* __ Debug definitions __________________________________________________ */ -//#define G_DEBUG_SAVE //!< Debug data_save() method +//#define G_DEBUG_SAVE //!< Debug data_save() method /*========================================================================== @@ -848,6 +848,9 @@ void GFitsTable::data_save(void) // Debug definition: Dump method entry #if defined(G_DEBUG_SAVE) std::cout << "GFitsTable::save: entry" << std::endl; + for (int i = 0; i < m_cols; ++i) { + std::cout << m_columns[i]->print() << std::endl; + } #endif // Make sure that column lengths are consistent with table length. @@ -901,8 +904,9 @@ void GFitsTable::data_save(void) // Create FITS table status = __ffcrtb(FPTR(m_fitsfile), m_type, m_rows, tfields, ttype, tform, tunit, NULL, &status); - if (status != 0) + if (status != 0) { throw GException::fits_error(G_DATA_SAVE, status); + } // De-allocate column definition arrays if (m_cols > 0) { @@ -1016,6 +1020,11 @@ void GFitsTable::data_save(void) #endif } + + // Debug option: Show where we are + #if defined(G_DEBUG_SAVE) + std::cout << "GFitsTable::save: Now update all columns." << std::endl; + #endif // Update all columns. The 'm_colnum' field specifies where in the // FITS file the column resides. If 'm_colnum=0' then we have a new @@ -1049,13 +1058,24 @@ void GFitsTable::data_save(void) // Now write column into FITS file (only if length is positive) if (m_columns[i]->length() > 0) { + // Debug option: Show which column we're going to write + #if defined(G_DEBUG_SAVE) + std::cout << "GFitsTable::save: Write column " << i; + std::cout << "." << std::endl; + #endif m_columns[i]->save(); } } // endif: column was valid } // endfor: looped over all table columns - // Delete all unused columns from FITS file. We do this from last to + // Debug option: Show where we are + #if defined(G_DEBUG_SAVE) + std::cout << "GFitsTable::save: Now delete all obsolete columns."; + std::cout << std::endl; + #endif + + // Delete all obsolete columns from FITS file. We do this from last to // first so that the column numbers remain valid. Also note that // FITS column counting starts from 1. for (int colnum = num_cols; colnum > 0; --colnum) { @@ -1103,6 +1123,12 @@ void GFitsTable::data_save(void) } // endelse: FITS table has been updated + // Debug option: Show where we are + #if defined(G_DEBUG_SAVE) + std::cout << "GFitsTable::save: Now update the FITS header for all columns."; + std::cout << std::endl; + #endif + // Now update the header for all columns (unit and TDIM information) for (int i = 0; i < m_cols; ++i) { diff --git a/src/fits/GFitsTableBitCol.cpp b/src/fits/GFitsTableBitCol.cpp index fd48d10..76abc65 100644 --- a/src/fits/GFitsTableBitCol.cpp +++ b/src/fits/GFitsTableBitCol.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableBitCol.cpp - FITS table Bit column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2012 by Juergen Knoedlseder * + * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ /* __ Coding definitions _________________________________________________ */ /* __ Debug definitions __________________________________________________ */ +//#define G_CALL_GRAPH //!< Dump call graph in console /*========================================================================== @@ -162,10 +163,10 @@ GFitsTableBitCol& GFitsTableBitCol::operator= (const GFitsTableBitCol& column) * * Provides access to data in a column. ***************************************************************************/ -bool& GFitsTableBitCol::operator() (const int& row, const int& inx) +bool& GFitsTableBitCol::operator()(const int& row, const int& inx) { // If data are not available then load them now - if (m_data == NULL) fetch_data(); + if (m_data == NULL) this->fetch_data(); // Set any pending Bit set_pending(); @@ -192,7 +193,7 @@ bool& GFitsTableBitCol::operator() (const int& row, const int& inx) * * Provides access to data in a column. ***************************************************************************/ -const bool& GFitsTableBitCol::operator() (const int& row, const int& inx) const +const bool& GFitsTableBitCol::operator()(const int& row, const int& inx) const { // Circumvent const correctness GFitsTableBitCol* ptr = const_cast(this); @@ -537,6 +538,11 @@ void GFitsTableBitCol::nulval(const unsigned char* value) ***************************************************************************/ void GFitsTableBitCol::init_members(void) { + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("GFitsTableBitCol::init_members\n"); + #endif + // Initialise members m_type = __TBIT; m_bits = 0; @@ -549,6 +555,11 @@ void GFitsTableBitCol::init_members(void) m_bit_byte = 0; m_bit_mask = 0; + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("exit GFitsTableBitCol::init_members\n"); + #endif + // Return return; } @@ -561,7 +572,6 @@ void GFitsTableBitCol::init_members(void) ***************************************************************************/ void GFitsTableBitCol::copy_members(const GFitsTableBitCol& column) { - // Fetch column data if not yet fetched. The casting circumvents the // const correctness bool not_loaded = (column.m_data == NULL); if (not_loaded) { @@ -571,6 +581,8 @@ void GFitsTableBitCol::copy_members(const GFitsTableBitCol& column) // Copy attributes m_type = column.m_type; m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; m_bits = column.m_bits; m_bytes_per_row = column.m_bytes_per_row; m_bits_per_row = column.m_bits_per_row; @@ -587,9 +599,6 @@ void GFitsTableBitCol::copy_members(const GFitsTableBitCol& column) } // Copy NULL value - alloc_nulval(column.m_nulval); - - // Small memory option: release column if it was fetch above #if defined(G_SMALL_MEMORY) if (not_loaded) { const_cast(&column)->release_data(); @@ -606,6 +615,11 @@ void GFitsTableBitCol::copy_members(const GFitsTableBitCol& column) ***************************************************************************/ void GFitsTableBitCol::free_members(void) { + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("GFitsTableBitCol::free_members\n"); + #endif + // Free memory if (m_data != NULL) delete [] m_data; if (m_nulval != NULL) delete m_nulval; @@ -617,6 +631,11 @@ void GFitsTableBitCol::free_members(void) // Reset load flag m_size = 0; + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("exit GFitsTableBitCol::free_members\n"); + #endif + // Return return; } @@ -646,6 +665,11 @@ std::string GFitsTableBitCol::ascii_format(void) const ***************************************************************************/ void GFitsTableBitCol::alloc_data(void) { + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("GFitsTableBitCol::alloc_data(%d)\n", m_size); + #endif + // Free any existing memory if (m_data != NULL) delete [] m_data; @@ -657,6 +681,63 @@ void GFitsTableBitCol::alloc_data(void) m_data = new unsigned char[m_size]; } + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("exit GFitsTableBitCol::alloc_data(m_data=%x)\n", m_data); + #endif + + // Return + return; +} + + +/***********************************************************************//** + * @brief Fetch column data + * + * This method fetches column data when needed. It is declared const, so + * that const data access methods can be implemented. + * + * If a FITS file is attached to the column the data are loaded into memory + * from the FITS file. If no FITS file is attached, memory is allocated + * to hold the column data and all cells are initialised. + * + * This method calls GFitsTableCol::load_column to do the job. + ***************************************************************************/ +void GFitsTableBitCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableBitCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableBitCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + // Return return; } diff --git a/src/fits/GFitsTableBoolCol.cpp b/src/fits/GFitsTableBoolCol.cpp index ffefdf0..77396df 100644 --- a/src/fits/GFitsTableBoolCol.cpp +++ b/src/fits/GFitsTableBoolCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableBoolCol.cpp - FITS table boolean column class * + * GFitsTableBoolCol.cpp - FITS table boolean column class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -521,8 +521,10 @@ void GFitsTableBoolCol::copy_members(const GFitsTableBoolCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -645,6 +647,75 @@ void GFitsTableBoolCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + * + * If a FITS file is attached to the column the data are loaded into memory + * from the FITS file. If no FITS file is attached, memory is allocated + * to hold the column data and all cells are set to 0. + * + * Refer to GFitsTableCol::load_column for more information. + ***************************************************************************/ +void GFitsTableBoolCol::fetch_data(void) const +{ + // Calculate size of memory + m_size = m_number * m_length; + + // Free old buffer memory + free_buffer(); + //const_cast(this)->free_buffer(); + + // Allocate buffer memory + //const_cast(this)->alloc_buffer(); + alloc_buffer(); + + // Save column + const_cast(this)->load_column(); + + // Extract values from buffer + for (int i = 0; i < m_size; ++i) { + m_data[i] = (bool)m_buffer[i]; + } + + // Free buffer memory + //const_cast(this)->free_buffer(); + free_buffer(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableBoolCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableBoolCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableBoolCol::release_data(void) @@ -701,48 +772,12 @@ void GFitsTableBoolCol::init_data(void) /***********************************************************************//** - * @brief Fetch column data - * - * If a FITS file is attached to the column the data are loaded into memory - * from the FITS file. If no FITS file is attached, memory is allocated - * to hold the column data and all cells are set to 0. - * - * Refer to GFitsTableCol::load_column for more information. - ***************************************************************************/ -void GFitsTableBoolCol::fetch_data(void) const -{ - // Calculate size of memory - m_size = m_number * m_length; - - // Free old buffer memory - const_cast(this)->free_buffer(); - - // Allocate buffer memory - const_cast(this)->alloc_buffer(); - - // Save column - const_cast(this)->load_column(); - - // Extract values from buffer - for (int i = 0; i < m_size; ++i) { - m_data[i] = (bool)m_buffer[i]; - } - - // Free buffer memory - const_cast(this)->free_buffer(); - - // Return - return; -} - - -/***********************************************************************//** * @brief Allocate CFITSIO transfer buffer * * The CFITSIO transfer buffer allows transparent conversion from the CFITSIO * storage format to a vector of bool values. ***************************************************************************/ -void GFitsTableBoolCol::alloc_buffer(void) +void GFitsTableBoolCol::alloc_buffer(void) const { // Allocate and initialise buffer memory if (m_size > 0) { @@ -762,7 +797,7 @@ void GFitsTableBoolCol::alloc_buffer(void) * * Release memory that has been allocated for the CFITSIO transfer buffer. ***************************************************************************/ -void GFitsTableBoolCol::free_buffer(void) +void GFitsTableBoolCol::free_buffer(void) const { // Free buffer if (m_buffer != NULL) delete [] m_buffer; @@ -773,10 +808,3 @@ void GFitsTableBoolCol::free_buffer(void) // Return return; } - - -/*========================================================================== - = = - = Friends = - = = - ==========================================================================*/ diff --git a/src/fits/GFitsTableByteCol.cpp b/src/fits/GFitsTableByteCol.cpp index f31bd0e..bb66423 100644 --- a/src/fits/GFitsTableByteCol.cpp +++ b/src/fits/GFitsTableByteCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableByteCol.cpp - FITS table Byte column class * + * GFitsTableByteCol.cpp - FITS table Byte column class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -526,8 +526,10 @@ void GFitsTableByteCol::copy_members(const GFitsTableByteCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -611,6 +613,49 @@ void GFitsTableByteCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableByteCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableByteCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableByteCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableByteCol::release_data(void) diff --git a/src/fits/GFitsTableCDoubleCol.cpp b/src/fits/GFitsTableCDoubleCol.cpp index a584a36..944693e 100644 --- a/src/fits/GFitsTableCDoubleCol.cpp +++ b/src/fits/GFitsTableCDoubleCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableCDoubleCol.cpp - FITS table double precision complex column * + * GFitsTableCDoubleCol.cpp - FITS table double precision complex column * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -528,8 +528,10 @@ void GFitsTableCDoubleCol::copy_members(const GFitsTableCDoubleCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -616,6 +618,49 @@ void GFitsTableCDoubleCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableCDoubleCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableCDoubleCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableCDoubleCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableCDoubleCol::release_data(void) diff --git a/src/fits/GFitsTableCFloatCol.cpp b/src/fits/GFitsTableCFloatCol.cpp index dccb3d1..9ff34a8 100644 --- a/src/fits/GFitsTableCFloatCol.cpp +++ b/src/fits/GFitsTableCFloatCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableCFloatCol.cpp - FITS table single precision complex column * + * GFitsTableCFloatCol.cpp - FITS table single precision complex column * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -528,8 +528,10 @@ void GFitsTableCFloatCol::copy_members(const GFitsTableCFloatCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -616,6 +618,49 @@ void GFitsTableCFloatCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableCFloatCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableCFloatCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableCFloatCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableCFloatCol::release_data(void) diff --git a/src/fits/GFitsTableCol.cpp b/src/fits/GFitsTableCol.cpp index cb28d7e..7894074 100644 --- a/src/fits/GFitsTableCol.cpp +++ b/src/fits/GFitsTableCol.cpp @@ -44,6 +44,7 @@ /* __ Coding definitions _________________________________________________ */ /* __ Debug definitions __________________________________________________ */ +//#define G_CALL_GRAPH //!< Dump call graph in console /*========================================================================== @@ -309,6 +310,21 @@ std::string GFitsTableCol::tform_binary(void) const /***********************************************************************//** + * @brief Signals if column has already been loaded + * + * @return True if column has been loaded, false otherwise. + ***************************************************************************/ +bool GFitsTableCol::isloaded(void) const +{ + // Circumvent const correctness + GFitsTableCol* column = const_cast(this); + + // Return flag + return (column->ptr_data() != NULL); +} + + +/***********************************************************************//** * @brief Print column information * * @param[in] chatter Chattiness (defaults to NORMAL). @@ -431,6 +447,7 @@ void GFitsTableCol::save(void) * * This method calls GFitsTableCol::load_column to do the job. ***************************************************************************/ +/* void GFitsTableCol::fetch_data(void) const { // Save column (circumvent const correctness) @@ -439,14 +456,18 @@ void GFitsTableCol::fetch_data(void) const // Return return; } - +*/ /***********************************************************************//** * @brief Load table column from FITS file + * + * Loads table column from FITS file by calling the load_column_variable() + * method for variable-length columns and load_column_fixed() for fixed- + * length columns. ***************************************************************************/ void GFitsTableCol::load_column(void) { - // Load variable-length of fixed-length column + // Load variable-length or fixed-length column from FITS file if (isvariable()) { load_column_variable(); } @@ -664,6 +685,28 @@ void GFitsTableCol::load_column_variable(void) /***********************************************************************//** * @brief Save table column into FITS file * + * Save table column into FITS file by calling the save_column_variable() + * method for variable-length columns and save_column_fixed() for fixed- + * length columns. + ***************************************************************************/ +void GFitsTableCol::save_column(void) +{ + // Save variable-length or fixed-length column into FITS file + if (isvariable()) { + save_column_variable(); + } + else { + save_column_fixed(); + } + + // Return + return; +} + + +/***********************************************************************//** + * @brief Save table column into FITS file + * * @exception GException::fits_hdu_not_found * Specified HDU not found in FITS file. * @exception GException::fits_error @@ -679,7 +722,7 @@ void GFitsTableCol::load_column_variable(void) * These methods are implemented by the derived column classes which * implement a specific storage class (i.e. float, double, short, ...). ***************************************************************************/ -void GFitsTableCol::save_column(void) +void GFitsTableCol::save_column_fixed(void) { // Continue only if a FITS file is connected and data have been loaded if (FPTR(m_fitsfile)->Fptr != NULL && m_colnum > 0 && ptr_data() != NULL) { @@ -710,6 +753,67 @@ void GFitsTableCol::save_column(void) /***********************************************************************//** + * @brief Save table column into FITS file + * + * @exception GException::fits_hdu_not_found + * Specified HDU not found in FITS file. + * @exception GException::fits_error + * Error occured during writing of the column data. + * + * The table column is only saved if it is linked to a FITS file and if the + * data are indeed present in the class instance. This avoids saving of data + * that have not been modified. + * + * The method make use of the virtual methods + * GFitsTableCol::ptr_data and + * GFitsTableCol::ptr_nulval. + * These methods are implemented by the derived column classes which + * implement a specific storage class (i.e. float, double, short, ...). + ***************************************************************************/ +void GFitsTableCol::save_column_variable(void) +{ + // Continue only if a FITS file is connected and data have been loaded + if (FPTR(m_fitsfile)->Fptr != NULL && m_colnum > 0 && ptr_data() != NULL) { + + // Move to the HDU + int status = 0; + status = __ffmahd(FPTR(m_fitsfile), + (FPTR(m_fitsfile)->HDUposition)+1, NULL, + &status); + if (status != 0) { + throw GException::fits_hdu_not_found(G_SAVE_COLUMN, + (FPTR(m_fitsfile)->HDUposition)+1, + status); + } + + // Save the column data row-by-row + for (int row = 0; row < m_length; ++row) { + + // Save row data + status = __ffpcn(FPTR(m_fitsfile), + std::abs(m_type), + m_colnum, + row+1, + 1, + elements(row), + ptr_data(m_rowstart[row]), + ptr_nulval(), + &status); + if (status != 0) { + throw GException::fits_error(G_SAVE_COLUMN, status, + "for column \""+m_name+"\"."); + } + + } // endfor: looped over rows + + } // endif: FITS file was connected + + // Return + return; +} + + +/***********************************************************************//** * @brief Compute offset of column element in memory * * @param[in] row Row of column. @@ -757,6 +861,11 @@ int GFitsTableCol::offset(const int& row, const int& inx) const ***************************************************************************/ void GFitsTableCol::init_members(void) { + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("GFitsTableCol::init_members\n"); + #endif + // Allocate FITS file pointer m_fitsfile = new __fitsfile; FPTR(m_fitsfile)->HDUposition = 0; @@ -778,6 +887,11 @@ void GFitsTableCol::init_members(void) m_size = 0; m_anynul = 0; + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("exit GFitsTableCol::init_members\n"); + #endif + // Return return; } @@ -817,12 +931,22 @@ void GFitsTableCol::copy_members(const GFitsTableCol& column) ***************************************************************************/ void GFitsTableCol::free_members(void) { + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("GFitsTableCol::free_members\n"); + #endif + // Free memory if (m_fitsfile != NULL) delete FPTR(m_fitsfile); // Mark memory as free m_fitsfile = NULL; + // Optionally print call graph + #if defined(G_CALL_GRAPH) + printf("exit GFitsTableCol::free_members\n"); + #endif + // Return return; } diff --git a/src/fits/GFitsTableDoubleCol.cpp b/src/fits/GFitsTableDoubleCol.cpp index 9d45001..0999c00 100644 --- a/src/fits/GFitsTableDoubleCol.cpp +++ b/src/fits/GFitsTableDoubleCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableDoubleCol.cpp - FITS table double column class * + * GFitsTableDoubleCol.cpp - FITS table double column class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -526,8 +526,10 @@ void GFitsTableDoubleCol::copy_members(const GFitsTableDoubleCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -614,6 +616,49 @@ void GFitsTableDoubleCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableDoubleCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableDoubleCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableDoubleCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableDoubleCol::release_data(void) diff --git a/src/fits/GFitsTableFloatCol.cpp b/src/fits/GFitsTableFloatCol.cpp index 0f03b0f..155d620 100644 --- a/src/fits/GFitsTableFloatCol.cpp +++ b/src/fits/GFitsTableFloatCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableFloatCol.cpp - FITS table float column class * + * GFitsTableFloatCol.cpp - FITS table float column class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -127,7 +127,7 @@ GFitsTableFloatCol::~GFitsTableFloatCol(void) * * @param[in] column Table column. ***************************************************************************/ -GFitsTableFloatCol& GFitsTableFloatCol::operator= (const GFitsTableFloatCol& column) +GFitsTableFloatCol& GFitsTableFloatCol::operator=(const GFitsTableFloatCol& column) { // Execute only if object is not identical if (this != &column) { @@ -526,8 +526,10 @@ void GFitsTableFloatCol::copy_members(const GFitsTableFloatCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -614,6 +616,49 @@ void GFitsTableFloatCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableFloatCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableFloatCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableFloatCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableFloatCol::release_data(void) diff --git a/src/fits/GFitsTableLongCol.cpp b/src/fits/GFitsTableLongCol.cpp index 9ff2ca3..d3a4787 100644 --- a/src/fits/GFitsTableLongCol.cpp +++ b/src/fits/GFitsTableLongCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableLongCol.cpp - FITS table long integer column class * + * GFitsTableLongCol.cpp - FITS table long integer column class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -526,8 +526,10 @@ void GFitsTableLongCol::copy_members(const GFitsTableLongCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -614,6 +616,49 @@ void GFitsTableLongCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableLongCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableLongCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableLongCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableLongCol::release_data(void) diff --git a/src/fits/GFitsTableLongLongCol.cpp b/src/fits/GFitsTableLongLongCol.cpp index d321caa..4d5e56e 100644 --- a/src/fits/GFitsTableLongLongCol.cpp +++ b/src/fits/GFitsTableLongLongCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableLongLongCol.cpp - FITS table long long integer column class * + * GFitsTableLongLongCol.cpp - FITS table long long integer column class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -526,8 +526,10 @@ void GFitsTableLongLongCol::copy_members(const GFitsTableLongLongCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -614,6 +616,49 @@ void GFitsTableLongLongCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableLongLongCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableLongLongCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableLongLongCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableLongLongCol::release_data(void) diff --git a/src/fits/GFitsTableShortCol.cpp b/src/fits/GFitsTableShortCol.cpp index a819c9b..ddc4a1b 100644 --- a/src/fits/GFitsTableShortCol.cpp +++ b/src/fits/GFitsTableShortCol.cpp @@ -526,8 +526,10 @@ void GFitsTableShortCol::copy_members(const GFitsTableShortCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -614,6 +616,49 @@ void GFitsTableShortCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableShortCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableShortCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableShortCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableShortCol::release_data(void) diff --git a/src/fits/GFitsTableStringCol.cpp b/src/fits/GFitsTableStringCol.cpp index 52bc5e9..2f0e2d2 100644 --- a/src/fits/GFitsTableStringCol.cpp +++ b/src/fits/GFitsTableStringCol.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GFitsTableStringCol.cpp - FITS table string column class * + * GFitsTableStringCol.cpp - FITS table string column class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -532,8 +532,10 @@ void GFitsTableStringCol::copy_members(const GFitsTableStringCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -666,6 +668,78 @@ void GFitsTableStringCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + * + * If a FITS file is attached to the column the data are loaded into memory + * from the FITS file. If no FITS file is attached, memory is allocated + * to hold the column data and all cells are set to 0. + * + * Refer to GFitsTableCol::load_column for more information. + ***************************************************************************/ +void GFitsTableStringCol::fetch_data(void) const +{ + // Calculate size of memory + m_size = m_number * m_length; + + // Free old buffer memory + free_buffer(); + + // Allocate buffer memory + alloc_buffer(); + + // Load column + const_cast(this)->load_column(); + + // Extract string from buffer + for (int i = 0; i < m_size; ++i) { + if (m_buffer[i] != NULL) { + m_data[i].assign(m_buffer[i]); + } + } + + // Free buffer memory + free_buffer(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableStringCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableStringCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + if (ptr->m_nulval != NULL) { + if (m_nulval != NULL) delete [] m_nulval; + m_nulval = new char[m_width+1]; + std::strncpy(m_nulval, ptr->m_nulval, m_width); + } + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableStringCol::release_data(void) @@ -727,44 +801,6 @@ void GFitsTableStringCol::init_data(void) /***********************************************************************//** - * @brief Fetch column data - * - * If a FITS file is attached to the column the data are loaded into memory - * from the FITS file. If no FITS file is attached, memory is allocated - * to hold the column data and all cells are set to 0. - * - * Refer to GFitsTableCol::load_column for more information. - ***************************************************************************/ -void GFitsTableStringCol::fetch_data(void) const -{ - // Calculate size of memory - m_size = m_number * m_length; - - // Free old buffer memory - free_buffer(); - - // Allocate buffer memory - alloc_buffer(); - - // Load column - const_cast(this)->load_column(); - - // Extract string from buffer - for (int i = 0; i < m_size; ++i) { - if (m_buffer[i] != NULL) { - m_data[i].assign(m_buffer[i]); - } - } - - // Free buffer memory - free_buffer(); - - // Return - return; -} - - -/***********************************************************************//** * @brief Allocate CFITSIO transfer buffer * * The CFITSIO transfer buffer allows transparent conversion from the CFITSIO diff --git a/src/fits/GFitsTableULongCol.cpp b/src/fits/GFitsTableULongCol.cpp index 0317124..9761b70 100644 --- a/src/fits/GFitsTableULongCol.cpp +++ b/src/fits/GFitsTableULongCol.cpp @@ -526,8 +526,10 @@ void GFitsTableULongCol::copy_members(const GFitsTableULongCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -611,6 +613,49 @@ void GFitsTableULongCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableULongCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableULongCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableULongCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableULongCol::release_data(void) diff --git a/src/fits/GFitsTableUShortCol.cpp b/src/fits/GFitsTableUShortCol.cpp index 2ebbbe6..8fb4c72 100644 --- a/src/fits/GFitsTableUShortCol.cpp +++ b/src/fits/GFitsTableUShortCol.cpp @@ -526,8 +526,10 @@ void GFitsTableUShortCol::copy_members(const GFitsTableUShortCol& column) } // Copy attributes - m_type = column.m_type; - m_size = column.m_size; + m_type = column.m_type; + m_size = column.m_size; + m_varlen = column.m_varlen; + m_rowstart = column.m_rowstart; // Copy column data if (column.m_data != NULL && m_size > 0) { @@ -611,6 +613,49 @@ void GFitsTableUShortCol::alloc_data(void) /***********************************************************************//** + * @brief Fetch column data + ***************************************************************************/ +void GFitsTableUShortCol::fetch_data(void) const +{ + // Save column (circumvent const correctness) + const_cast(this)->load_column(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy column data + * + * @param[in] column Column. + * + * Copies all data from a column. This method is called from the base class + * copy constructor. + ***************************************************************************/ +void GFitsTableUShortCol::copy_data(const GFitsTableCol& column) +{ + // Type-cast to the correct column type + const GFitsTableUShortCol* ptr = static_cast(&column); + + // Copy column data (only if column contains data) + if (ptr->m_data != NULL && ptr->m_size > 0) { + m_size = ptr->m_size; + alloc_data(); + for (int i = 0; i < ptr->m_size; ++i) { + m_data[i] = ptr->m_data[i]; + } + } + + // Copy NULL value + alloc_nulval(ptr->m_nulval); + + // Return + return; +} + + +/***********************************************************************//** * @brief Release column data ***************************************************************************/ void GFitsTableUShortCol::release_data(void) diff --git a/test/test_GFits.cpp b/test/test_GFits.cpp index 1109003..d41a8ed 100644 --- a/test/test_GFits.cpp +++ b/test/test_GFits.cpp @@ -1394,7 +1394,7 @@ void TestGFits::test_bintable_bit(void) catch(std::exception &e) { test_try_failure(e); } - + // Test single column table TEST_TABLE1_BOOL;