Column.h
// Astrophysics Science Division,
// NASA/ Goddard Space Flight Center
// HEASARC
// http://heasarc.gsfc.nasa.gov
// e-mail: ccfits@legacy.gsfc.nasa.gov
//
// Original author: Ben Dorman
#ifndef COLUMN_H
#define COLUMN_H 1
#include <iostream>
// CCfitsHeader
#include "CCfits.h"
// Table
#include "Table.h"
// FitsError
#include "FitsError.h"
// FITSUtil
#include "FITSUtil.h"
#include <complex>
namespace CCfits {
class Column
{
public:
class RangeError : public FitsException //## Inherits: <unnamed>%3946526D031A
{
public:
RangeError (const String& msg, bool silent = true);
protected:
private:
private: //## implementation
};
class InvalidDataType : public FitsException //## Inherits: <unnamed>%3947CF30033E
{
public:
InvalidDataType (const String& str = string(), bool silent = true);
protected:
private:
private: //## implementation
};
class InvalidRowParameter : public FitsException //## Inherits: <unnamed>%39B5310F01A0
{
public:
InvalidRowParameter (const String& diag, bool silent = true);
protected:
private:
private: //## implementation
};
class WrongColumnType : public FitsException //## Inherits: <unnamed>%39B545780082
{
public:
WrongColumnType (const String& diag, bool silent = true);
protected:
private:
private: //## implementation
};
class UnspecifiedLengths : public FitsException //## Inherits: <unnamed>%3A018C9D007D
{
public:
UnspecifiedLengths (const String& diag, bool silent = true);
protected:
private:
private: //## implementation
};
class InvalidRowNumber : public FitsException //## Inherits: <unnamed>%3B0A850F0307
{
public:
InvalidRowNumber (const String& diag, bool silent = true);
protected:
private:
private: //## implementation
};
class InsufficientElements : public FitsException //## Inherits: <unnamed>%3B0BE611010A
{
public:
InsufficientElements (const String& msg, bool silent = true);
protected:
private:
private: //## implementation
};
class NoNullValue : public FitsException //## Inherits: <unnamed>%3B0D589A0092
{
public:
NoNullValue (const String& diag, bool silent = true);
protected:
private:
private: //## implementation
};
class InvalidNumberOfRows : public FitsException //## Inherits: <unnamed>%3B20EB8B0205
{
public:
InvalidNumberOfRows (int number, bool silent = true);
protected:
private:
private: //## implementation
};
Column(const Column &right);
virtual ~Column();
bool operator==(const Column &right) const;
bool operator!=(const Column &right) const;
virtual void readData (long firstRow, long nelements, long firstElem = 1) = 0;
// Virtual copy constructor.
virtual Column * clone () const = 0;
int rows () const;
void setDisplay ();
virtual void setDimen ();
friend std::ostream& operator << (std::ostream& s, const Column& right);
// The parent SET function is needed by Table classes, but
// should not be part of the user interface. It is deliberately left
// out of the document section up top.
Table* parent () const;
void setParent(Table* parent);
// Inequality operators for imposing sort order on columns.
friend bool operator < (const Column& left, const Column& right);
// Inequality operators for imposing sort order on columns.
friend bool operator > (const Column& left, const Column& right);
void setLimits (ValueType type);
void unit (const String& value);
void resetRead ();
int index () const;
void index (int value);
bool isRead () const;
void isRead (bool value);
long width () const;
void width (long value);
size_t repeat () const;
bool varLength () const;
double scale () const;
void scale (double value);
double zero () const;
void zero (double value);
const String& display () const;
const String& dimen () const;
void dimen (const String& value);
ValueType type () const;
void type (ValueType value);
static const String& TFORM ();
static const String& TDISP ();
static const String& TSCAL ();
static const String& TZERO ();
static const String& TDIM ();
const String& format () const;
const String& unit () const;
const String& name () const;
public:
// Additional Public Declarations
// scalar column interface. Column's Data Member is a std::vector<T>,
// input data is std::vector<S>, std::valarray<S> or S* where S is not
// in general the same as T.
template <typename S>
void write (const std::vector<S>& indata, long firstRow);
void write (const std::vector<std::complex<float> >& indata, long firstRow);
void write (const std::vector<std::complex<double> >& indata, long firstRow);
template <typename S>
void write (const std::valarray<S>& indata, long firstRow);
void write (const std::valarray<std::complex<float> >& indata, long firstRow);
void write (const std::valarray<std::complex<double> >& indata, long firstRow);
template <typename S>
void write (S* indata, long nRows, long firstRow);
template <typename S>
void write (const std::vector<S>& indata, long firstRow, S* nullValue);
template <typename S>
void write (const std::valarray<S>& indata, long firstRow, S* nullValue);
template <typename S>
void write (S* indata, long nRows, long firstRow, S* nullValue);
// vector column interface. We provide an interface that allows input of a vector, valarray and C-array.
// there are versions that write variable numbers of elements per row as specified
// in the vectorLengths argument. The user also can directly write a vector<valarray<T> >
// object which is how the data are stored in the ColumnVectorData object.
// this last one is also used internally to implement the variable lengths versions.
// fixed length write to binary table from valarray.
template <typename S>
void write (const std::valarray<S>& indata, long nRows, long firstRow);
void write (const std::valarray<std::complex<float> >& indata, long nRows, long firstRow);
void write (const std::valarray<std::complex<double> >& indata, long nRows, long firstRow);
template <typename S>
void write (const std::vector<S>& indata, long nRows, long firstRow);
void write (const std::vector<std::complex<float> >& indata, long nRows, long firstRow);
void write (const std::vector<std::complex<double> >& indata, long nRows, long firstRow);
template <typename S>
void write (S* indata, long nElements, long nRows, long firstRow);
template <typename S>
void write (const std::valarray<S>& indata, long nRows, long firstRow, S* nullValue);
template <typename S>
void write (const std::vector<S>& indata, long nRows, long firstRow, S* nullValue);
template <typename S>
void write (S* indata, long nElements, long nRows, long firstRow, S* nullValue);
// variable-length write to vector column from valarray or vector.
template <typename S>
void write (const std::valarray<S>& indata,
const std::vector<long>& vectorLengths,
long firstRow);
void write (const std::valarray<std::complex<float> >& indata,
const std::vector<long>& vectorLengths,
long firstRow);
void write (const std::valarray<std::complex<double> >& indata,
const std::vector<long>& vectorLengths,
long firstRow);
template <typename S>
void write (const std::vector<S>& indata,
const std::vector<long>& vectorLengths,
long firstRow);
void write (const std::vector<std::complex<float> >& indata,
const std::vector<long>& vectorLengths,
long firstRow);
void write (const std::vector<std::complex<double> >& indata,
const std::vector<long>& vectorLengths,
long firstRow);
template <typename S>
void write (S* indata, long nElements,
const std::vector<long>& vectorLengths,
long firstRow);
template <typename S>
void writeArrays (const std::vector<std::valarray<S> >& indata, long firstRow);
void writeArrays (const std::vector<std::valarray<std::complex<float> > >& indata, long firstRow);
void writeArrays (const std::vector<std::valarray<std::complex<double> > >& indata, long firstRow);
template <typename S>
void writeArrays (const std::vector<std::valarray<S> >& indata, long firstRow, S* nullValue);
// get specified elements of a scalar column, returned as a std::vector
// S is NOT the type of the column data itself, it is the type of the returned
// data.
template <typename S>
void read(std::vector<S>& vals, long first, long last) ;
// VC++, at least, won't compile these as template covering std::complex instances.
void read(std::vector< std::complex<float> >& , long first, long last);
void read(std::vector< std::complex<double> >& , long first, long last);
void read(std::vector<String>& vals, long first, long last);
// return a set of rows from a scalar column as a valarray.
template <typename S>
void read(std::valarray<S>& vals, long first, long last) ;
void read(std::valarray<std::complex<float> >& vals, long first, long last) ;
void read(std::valarray<std::complex<double> >& vals, long first, long last) ;
// return a single row of a vector column.
template <typename S>
void read(std::valarray<S>& vals, long rows) ;
template <typename S>
void read(std::vector<S>& vals, long rows);
void read(std::valarray<std::complex<float> >& vals, long rows) ;
void read(std::valarray<std::complex<double> >& vals, long rows) ;
void read(std::vector<std::complex<float> >& vals, long rows) ;
void read(std::vector<std::complex<double> >& vals, long rows) ;
// get a set of rows from a vector column.
template <typename S>
void readArrays(std::vector<std::valarray<S> >& vals, long first, long last) ;
void readArrays(std::vector<std::valarray<std::complex<float> > >& vals, long first, long last) ;
void readArrays(std::vector<std::valarray<std::complex<double> > >& vals, long first, long last) ;
// nullValue has no meaning when the target column has floating point/std::complex
// type. Also, implict conversion of std::complex to pure real is not supported
// by cfitsio.
template <typename S>
void read(std::vector<S>& vals, long first, long last, S* nullValue) ;
// return a set of rows from a scalar column as a valarray.
template <typename S>
void read(std::valarray<S>& vals, long first, long last, S* nullValue);
// return a single row of a vector column.
template <typename S>
void read(std::valarray<S>& vals, long rows, S* nullValue) ;
template <typename S>
void read(std::vector<S>& vals, long rows, S* nullValue) ;
// get a set of rows from a vector column.
template <typename S>
void readArrays(std::vector<std::valarray<S> >& vals, long first, long last, S* nullValue);
// add a null value to the column
template <typename T>
void addNullValue(T nullVal);
// get the TNULL setting
template <typename T>
bool getNullValue(T* nullVal) const;
void write (const std::vector<String>& indata, long firstRow);
friend void Table::insertRows(long first, long number);
friend void Table::deleteRows(long first, long number);
friend void Table::deleteRows(const std::vector<long>& rowList);
friend void Table::initRead();
friend void Table::reindex(int startNum, bool isInsert);
friend void Table::updateRows();
protected:
Column (int columnIndex, // The column index, i.e. the integer n in the keyword TCOLn
const String &columnName, // The column name, curiously TTYPEn
ValueType type, const String &format, // The TFORMn keyword.
const String &unit, // The TUNITn keyword
Table* p, // ! The Table containing the Column object
int rpt = 1, long w = 1, const String &comment = "");
Column (Table* p = 0);
virtual bool compare (const Column &right) const;
fitsfile* fitsPointer ();
// Protected method to set the current HDU to be the one containing this Column object. For use in
// public read/write methods to ensure that data regarding numbers of rows and width relate to the
// right HDU
void makeHDUCurrent ();
virtual std::ostream& put (std::ostream& s) const;
void varLength (bool value);
static const String& TBCOL ();
static const String& TTYPE ();
static const String& TUNIT ();
static const String& TNULL ();
static const String& TLMIN ();
static const String& TLMAX ();
static const String& TDMAX ();
static const String& TDMIN ();
static const std::vector<String>& columnKeys ();
const String& comment () const;
// Additional Protected Declarations
private:
Column & operator=(const Column &right);
// Insert one or more blank rows into a FITS column.
virtual void insertRows (long first, long number = 1) = 0;
virtual void deleteRows (long first, long number = 1) = 0;
virtual size_t getStoredDataSize() const = 0;
static void loadColumnKeys ();
void name (const String& value);
void format (const String& value);
long numberOfElements (long& first, long& last);
// Data Members for Class Attributes
static const String s_TBCOL;
static const String s_TTYPE;
static const String s_TFORM;
static const String s_TDISP;
static const String s_TUNIT;
static const String s_TSCAL;
static const String s_TZERO;
static const String s_TDIM;
static const String s_TNULL;
static const String s_TLMIN;
static const String s_TLMAX;
static const String s_TDMAX;
static const String s_TDMIN;
// Additional Private Declarations
private: //## implementation
// Data Members for Class Attributes
int m_index;
bool m_isRead;
long m_width;
size_t m_repeat;
bool m_varLength;
double m_scale;
double m_zero;
String m_display;
String m_dimen;
ValueType m_type;
static const short LLIMITSHORT;
static const long LLIMITLONG;
static const unsigned short LLIMITUSHORT;
static const unsigned long LLIMITULONG;
static const unsigned char LLIMITUCHAR;
static const float LLIMITFLOAT;
static const double LLIMITDOUBLE;
static const short ULIMITSHORT;
static const long ULIMITLONG;
static const unsigned short ULIMITUSHORT;
static const unsigned long ULIMITULONG;
static const unsigned char ULIMITUCHAR;
static const float ULIMITFLOAT;
static const double ULIMITDOUBLE;
static const int LLIMITINT;
static const int ULIMITINT;
static const unsigned int LLIMITUINT;
static const unsigned int ULIMITUINT;
static const LONGLONG LLIMITLONGLONG;
static const LONGLONG ULIMITLONGLONG;
// Data Members for Associations
Table* m_parent;
static std::vector<String> s_columnKeys;
String m_comment;
String m_format;
String m_unit;
String m_name;
// Additional Implementation Declarations
};
// Class CCfits::Column::RangeError
// Class CCfits::Column::InvalidDataType
// Class CCfits::Column::InvalidRowParameter
// Class CCfits::Column::WrongColumnType
// Class CCfits::Column::UnspecifiedLengths
// Class CCfits::Column::InvalidRowNumber
// Class CCfits::Column::InsufficientElements
// Class CCfits::Column::NoNullValue
// Class CCfits::Column::InvalidNumberOfRows
// Class CCfits::Column
inline void Column::setDimen ()
{
// default implementation: do nothing. Overridden by ColumnVectorData.
}
inline std::ostream& operator << (std::ostream& s, const Column& right)
{
return right.put(s);
}
inline bool operator < (const Column& left, const Column& right)
{
return left.m_index < right.m_index;
}
inline bool operator > (const Column& left, const Column& right)
{
return left.m_index > right.m_index;
}
inline void Column::resetRead ()
{
m_isRead = false;
}
inline int Column::index () const
{
return m_index;
}
inline void Column::index (int value)
{
m_index = value;
}
inline bool Column::isRead () const
{
return m_isRead;
}
inline void Column::isRead (bool value)
{
m_isRead = value;
}
inline long Column::width () const
{
return m_width;
}
inline void Column::width (long value)
{
m_width = value;
}
inline size_t Column::repeat () const
{
return m_repeat;
}
inline bool Column::varLength () const
{
return m_varLength;
}
inline double Column::scale () const
{
return m_scale;
}
inline void Column::scale (double value)
{
m_scale = value;
int status(0);
if (fits_set_tscale(fitsPointer(),m_index,value,m_zero,&status)) throw FitsError(status);
}
inline double Column::zero () const
{
return m_zero;
}
inline void Column::zero (double value)
{
m_zero = value;
}
inline const String& Column::display () const
{
return m_display;
}
inline const String& Column::dimen () const
{
return m_dimen;
}
inline void Column::dimen (const String& value)
{
m_dimen = value;
}
inline ValueType Column::type () const
{
return m_type;
}
inline void Column::type (ValueType value)
{
m_type = value;
}
inline const String& Column::TBCOL ()
{
return s_TBCOL;
}
inline const String& Column::TTYPE ()
{
return s_TTYPE;
}
inline const String& Column::TFORM ()
{
return s_TFORM;
}
inline const String& Column::TDISP ()
{
return s_TDISP;
}
inline const String& Column::TUNIT ()
{
return s_TUNIT;
}
inline const String& Column::TSCAL ()
{
return s_TSCAL;
}
inline const String& Column::TZERO ()
{
return s_TZERO;
}
inline const String& Column::TDIM ()
{
return s_TDIM;
}
inline const String& Column::TNULL ()
{
return s_TNULL;
}
inline const String& Column::TLMIN ()
{
return s_TLMIN;
}
inline const String& Column::TLMAX ()
{
return s_TLMAX;
}
inline const String& Column::TDMAX ()
{
return s_TDMAX;
}
inline const String& Column::TDMIN ()
{
return s_TDMIN;
}
inline const std::vector<String>& Column::columnKeys ()
{
return s_columnKeys;
}
inline const String& Column::comment () const
{
return m_comment;
}
inline const String& Column::format () const
{
return m_format;
}
inline const String& Column::unit () const
{
return m_unit;
}
inline const String& Column::name () const
{
return m_name;
}
} // namespace CCfits
#endif
CCfits::Column::~Column
virtual ~Column()
destructor.
Definition: Column.cxx:234
CCfits::Column::NoNullValue
Exception thrown if a null value is specified without support from existing column header...
Definition: Column.h:932
CCfits::Column::name
const String & name() const
return name of Column (TTYPEn keyword)
Definition: Column.h:1532
CCfits::Column::InvalidRowNumber::InvalidRowNumber
InvalidRowNumber(const String &diag, bool silent=true)
Exception ctor, prefixes the string &quot;FitsError: Invalid Row Number - Column: &quot; before the specific me...
Definition: Column.cxx:94
CCfits::Column::InvalidDataType
Exception thrown for invalid data type inputs.
Definition: Column.h:860
CCfits::Column::repeat
size_t repeat() const
get the repeat count for the rows
Definition: Column.h:1390
CCfits::Column::fitsPointer
fitsfile * fitsPointer()
fits pointer corresponding to fits file containing column data.
Definition: Column.cxx:264
CCfits::Column::rows
int rows() const
return the number of rows in the table.
Definition: Column.cxx:275
CCfits::Column::width
long width() const
return column data width
Definition: Column.h:1380
CCfits::Column::resetRead
void resetRead()
reset the Column&#39;s isRead flag to false
Definition: Column.h:1355
CCfits::Table::updateRows
void updateRows()
update the number of rows in the table
Definition: Table.cxx:340
CCfits::Column::makeHDUCurrent
void makeHDUCurrent()
make HDU containing this the current HDU of the fits file.
Definition: Column.cxx:270
CCfits::Column::getNullValue
bool getNullValue(T *nullVal) const
Get the value of the TNULLn keyword for the column.
Definition: ColumnT.h:1520
CCfits::FitsError
FitsError is the exception thrown by non-zero cfitsio status codes.
Definition: FitsError.h:112
CCfits::Column::display
const String & display() const
return TDISPn keyword
Definition: Column.h:1422
CCfits::Column::write
void write(const std::vector< S > &indata, long firstRow)
write a vector of values into a scalar column starting with firstRow
Definition: ColumnT.h:869
CCfits::Column::InvalidNumberOfRows
Exception thrown if user enters a non-positive number for the number of rows to write.
Definition: Column.h:944
CCfits::Column::RangeError::RangeError
RangeError(const String &msg, bool silent=true)
Exception ctor, prefixes the string &quot;FitsError: Range error in operation &quot; before the specific messag...
Definition: Column.cxx:43
CCfits::Column::InsufficientElements
Exception thrown if the data supplied for a write operation is less than declared.
Definition: Column.h:920
CCfits::Column::dimen
const String & dimen() const
return TDIMn keyword
Definition: Column.h:1427
CCfits::Column::scale
double scale() const
get TSCALn value
Definition: Column.h:1400
CCfits::Column::read
void read(std::vector< S > &vals, long first, long last)
Retrieve data from a scalar column into a std::vector.
Definition: ColumnT.h:42
CCfits::Column::isRead
bool isRead() const
flag set to true if the entire column data has been read from disk
Definition: Column.h:1370
CCfits::Column::RangeError
exception to be thrown for inputs that cause range errors in column read operations.
Definition: Column.h:848
CCfits::Column::put
virtual std::ostream & put(std::ostream &s) const
internal implementation of &lt;&lt; operator.
Definition: Column.cxx:302
CCfits::Column::zero
double zero() const
get TZEROn value
Definition: Column.h:1412
CCfits::Column::readArrays
void readArrays(std::vector< std::valarray< S > > &vals, long first, long last)
return a set of rows of a vector column into a vector of valarrays
Definition: ColumnT.h:680
CCfits::Column::InsufficientElements::InsufficientElements
InsufficientElements(const String &msg, bool silent=true)
Exception ctor, prefixes the string &quot;FitsError: not enough elements supplied for write operation: &quot; ...
Definition: Column.cxx:104
CCfits::FitsException
FitsException is the base class for all exceptions thrown by this library.
Definition: FitsError.h:93
CCfits::Column::writeArrays
void writeArrays(const std::vector< std::valarray< S > > &indata, long firstRow)
write a vector of valarray objects to the column, starting at row firstRow &gt;= 1
Definition: ColumnT.h:1257
CCfits::Column::InvalidRowParameter::InvalidRowParameter
InvalidRowParameter(const String &diag, bool silent=true)
Exception ctor, prefixes the string &quot;FitsError: row offset or length incompatible with column declara...
Definition: Column.cxx:63
CCfits::Column::setDimen
virtual void setDimen()
set the TDIMn keyword.
Definition: Column.h:1332
CCfits::Column::unit
const String & unit() const
get units of data in Column (TUNITn keyword)
Definition: Column.h:1527
CCfits::ValueType
ValueType
CCfits value types and their CFITSIO equivalents (in caps)
Definition: CCfits.h:81
CCfits::Column::NoNullValue::NoNullValue
NoNullValue(const String &diag, bool silent=true)
Exception ctor, prefixes the string &quot;Fits Error: No null value specified for column: &quot; before the spe...
Definition: Column.cxx:114
CCfits::Column::WrongColumnType
Exception thrown on attempting to access a scalar column as vector data.
Definition: Column.h:884
CCfits::operator<<
std::ostream & operator<<(std::ostream &s, const Column &right)
output operator for Column objects.
Definition: Column.h:1337
CCfits::Column::setDisplay
void setDisplay()
set the TDISPn keyword
Definition: Column.cxx:280
CCfits::Column::addNullValue
void addNullValue(T nullVal)
Set the TNULLn keyword for the column.
Definition: ColumnT.h:1485
CCfits::Column::Column
Column(const Column &right)
copy constructor, used in copying Columns to standard library containers.
Definition: Column.cxx:171
CCfits::Table
Definition: Table.h:282
CCfits::Column::index
int index() const
get the Column index (the n in TTYPEn etc).
Definition: Column.h:1360
CCfits::Column::InvalidDataType::InvalidDataType
InvalidDataType(const String &str=string(), bool silent=true)
Exception ctor, prefixes the string &quot;FitsError: Incorrect data type: &quot; before the specific message...
Definition: Column.cxx:53
CCfits::Column::WrongColumnType::WrongColumnType
WrongColumnType(const String &diag, bool silent=true)
Exception ctor, prefixes the string &quot;FitsError: Attempt to return scalar data from vector column...
Definition: Column.cxx:73
CCfits::Column::comment
const String & comment() const
retrieve comment for Column
Definition: Column.h:1517
CCfits::Column::InvalidNumberOfRows::InvalidNumberOfRows
InvalidNumberOfRows(int number, bool silent=true)
Exception ctor, prefixes the string &quot;Fits Error: number of rows to write must be positive &quot; before th...
Definition: Column.cxx:124
CCfits::Column::InvalidRowNumber
Exception thrown on attempting to read a row number beyond the end of a table.
Definition: Column.h:908
CCfits::Column::type
ValueType type() const
returns the data type of the column
Definition: Column.h:1437
CCfits::Column::varLength
bool varLength() const
boolean, set to true if Column has variable length vector rows.
Definition: Column.h:1395
CCfits::Column::format
const String & format() const
return TFORMn keyword
Definition: Column.h:1522
CCfits::Column
Abstract base class for Column objects.
Definition: Column.h:841
CCfits::Column::InvalidRowParameter
Exception thrown on incorrect row writing request.
Definition: Column.h:872
CCfits::Column::readData
virtual void readData(long firstRow, long nelements, long firstElem=1)=0
Read (or reread) data from the disk into the Column object&#39;s internal arrays.
CCfits::Table::insertRows
void insertRows(long first, long number=1)
insert empty rows into the table
Definition: Table.cxx:400
CCfits::Column::parent
Table * parent() const
return a pointer to the Table which owns this Column
Definition: Column.cxx:312
CCfits::Table::deleteRows
void deleteRows(long first, long number=1)
delete a range of rows in a table.
Definition: Table.cxx:419