56 #define G_ACCESS1 "GFitsTable::operator[](int&)"
57 #define G_ACCESS2 "GFitsTable::operator[](std::string&)"
58 #define G_SET1 "GFitsTable::set(int&, GFitsTableCol&)"
59 #define G_SET2 "GFitsTable::set(std::string&, GFitsTableCol&)"
60 #define G_INSERT1 "GFitsTable::insert(int, GFitsTableCol&)"
61 #define G_INSERT2 "GFitsTable::insert(std::string&, GFitsTableCol&)"
62 #define G_REMOVE1 "GFitsTable::remove(int&)"
63 #define G_REMOVE2 "GFitsTable::remove(std::string&)"
64 #define G_INSERT_ROWS "GFitsTable::insert_rows(int&, int&)"
65 #define G_REMOVE_ROWS "GFitsTable::remove_rows(int&, int&)"
66 #define G_DATA_OPEN "GFitsTable::data_open(void*)"
67 #define G_DATA_SAVE "GFitsTable::data_save()"
68 #define G_GET_TFORM "GFitsTable::get_tform(int&)"
165 if (
this != &table) {
203 std::string msg =
"FITS table empty. Please use the column access "
204 "operator only on FITS tables that contain columns.";
209 #if defined(G_RANGE_CHECK)
210 if (colnum < 0 || colnum >=
m_cols) {
219 std::string msg =
"Empty FITS column pointer encountered.";
245 std::string msg =
"FITS table empty. Please use the column access "
246 "operator only on FITS tables that contain columns.";
251 #if defined(G_RANGE_CHECK)
252 if (colnum < 0 || colnum >=
m_cols) {
261 std::string msg =
"Empty FITS column pointer encountered.";
285 std::string msg =
"FITS table empty. Please use the column access "
286 "operator only on FITS tables that contain columns.";
295 std::string msg =
"FITS table column \""+colname+
"\" not found. "
296 "Please specify an existing column name";
320 std::string msg =
"FITS table empty. Please use the column access "
321 "operator only on FITS tables that contain columns.";
330 std::string msg =
"FITS table column \""+colname+
"\" not found. "
331 "Please specify an existing column name";
359 if (colnum < 0 || colnum >=
ncols()) {
402 std::string msg =
"FITS table column \""+colname+
"\" not found. "
403 "Please specify an existing column name";
408 return (
set(colnum, column));
436 if (colnum < 0 || colnum >
ncols()) {
450 std::string msg =
"Specified FITS table column has "+
453 "specify a FITS table column with the same number "
454 "of rows as the table.";
474 for (
int src = 0, dst = 0; dst <
m_cols+1; ++dst) {
531 std::string msg =
"FITS table column \""+colname+
"\" not found. "
532 "Please specify an existing column name";
537 return (
insert(colnum, column));
554 if (colnum < 0 || colnum >=
ncols()) {
576 for (
int src = 0, dst = 0; src <
m_cols; ++src) {
625 std::string msg =
"FITS table column \""+colname+
"\" not found. "
626 "Please specify an existing column name";
650 int rownum = this->
nrows();
678 if (row < 0 || row >
m_rows) {
687 for (
int icol = 0; icol <
m_cols; ++icol) {
721 if (row < 0 || row >=
m_rows) {
727 if (nrows < 0 || nrows >
m_rows-row) {
736 for (
int icol = 0; icol <
m_cols; ++icol) {
765 return (ptr != NULL);
784 result.append(
"=== GFitsTable ===");
793 result.append(
"ASCII table");
796 result.append(
"Binary table");
799 result.append(
"Unknown");
817 for (
int i = 0; i <
m_cols; ++i) {
828 result.append(
"\n Table columns undefined");
878 for (
int i = 0; i <
m_cols; ++i) {
917 for (
int i = 0; i <
m_cols; ++i) {
962 for (
int i = 0; i <
m_cols; ++i) {
971 if ((m_cols > 0) && (
m_rows > 0) && (naxis1 > 0)) {
982 card(
"TFIELDS", tfields,
"number of table fields");
983 card(
"NAXIS1", naxis1,
"width of table in bytes");
984 card(
"NAXIS2", naxis2,
"number of rows in table");
987 for (
int i = 0; i <
m_cols; ++i) {
1006 std::string val_ttype(ttype);
1007 std::string val_tform(tform);
1008 std::string val_tunit(tunit);
1017 if (ttype != NULL)
delete [] ttype;
1018 if (tform != NULL)
delete [] tform;
1019 if (tunit != NULL)
delete [] tunit;
1023 std::string val_tdim =
"";
1024 if (tdim.size() > 0) {
1026 for (
int k = 1; k < tdim.size(); ++k) {
1029 val_tdim.append(
")");
1033 std::string com_ttype =
"label for field " +
gammalib::str(i+1);
1034 std::string com_tform =
"data format of field " +
gammalib::str(i+1);
1035 std::string com_tunit =
"physical unit of field" +
gammalib::str(i+1);
1036 std::string com_tdim =
"dimensions of field " +
gammalib::str(i+1);
1039 card(key_ttype, val_ttype, com_ttype);
1040 card(key_tform, val_tform, com_tform);
1041 card(key_tunit, val_tunit, com_tunit);
1042 if (!val_tdim.empty()) {
1043 card(key_tdim, val_tdim, com_tdim);
1053 card(key_tzero, 0,
"offset for unsigned integers");
1054 card(key_tscal, 0,
"data are not scaled");
1055 hdr[key_tzero].value((
unsigned long)(32768));
1056 hdr[key_tscal].value(1);
1060 card(key_tzero, 0,
"offset for unsigned integers");
1061 card(key_tscal, 0,
"data are not scaled");
1062 hdr[key_tzero].value((
unsigned long)(2147483648));
1063 hdr[key_tscal].value(1);
1081 for (
int i = m_cols; i < 100; ++i) {
1152 for (
int i = 0; i <
m_cols; ++i) {
1160 for (
int i = 0; i <
m_cols; ++i) {
1165 sprintf(keyname,
"TTYPE%d", i+1);
1170 value[strlen(value)-1] =
'\0';
1180 unsigned long offset = 0;
1181 sprintf(keyname,
"TZERO%d", i+1);
1184 if (typecode ==
__TSHORT && offset == 32768u) {
1187 else if (typecode == -
__TSHORT && offset == 32768u) {
1190 else if (typecode ==
__TLONG && offset == 2147483648u) {
1193 else if (typecode == -
__TLONG && offset == 2147483648u) {
1196 else if (typecode ==
__TINT && offset == 2147483648u) {
1199 else if (typecode == -
__TINT && offset == 2147483648u) {
1203 std::string msg =
"But column '"+std::string(value)+
"' has"
1205 " unexpected associated TZERO="+
1215 double tscale = 1.0;
1216 sprintf(keyname,
"TSCAL%d", i+1);
1226 sprintf(keyname,
"TUNIT%d", i+1);
1234 unit[strlen(unit)-1] =
'\0';
1239 sprintf(keyname,
"TDIM%d", i+1);
1247 dim[strlen(dim)-1] =
'\0';
1251 std::vector<int> vdim;
1253 if (sdim.length() > 0) {
1255 for (
int k = 0; k < elements.size(); ++k) {
1263 std::ostringstream colname;
1265 std::string msg =
"FITS table column \""+colname.str()+
"\" has "
1266 "unsupported typecode "+
1299 if (!vdim.empty()) {
1303 for (
int k = 1; k < vdim.size(); ++k) {
1314 if (vdim.size() < 1) {
1315 msg =
"Empty TDIM keyword encountered while there are "+
1324 for (
int k = 1; k < vdim.size(); ++k) {
1332 " column elements while there are "+
1382 #if defined(G_DEBUG_SAVE)
1383 std::cout <<
"GFitsTable::save: entry" << std::endl;
1384 for (
int i = 0; i <
m_cols; ++i) {
1391 for (
int i = 0; i <
m_cols; ++i) {
1394 std::string msg =
"Number of rows in column \""+
1397 "does not correspond to the number of rows "
1398 "in the FITS table ("+
1412 bool replace = (status == 0 && type !=
m_type);
1416 if (status == 107 || replace) {
1425 char** ttype = NULL;
1426 char** tform = NULL;
1427 char** tunit = NULL;
1429 ttype =
new char*[
m_cols];
1430 tform =
new char*[
m_cols];
1431 tunit =
new char*[
m_cols];
1432 for (
int i = 0; i <
m_cols; ++i) {
1437 for (
int i = 0; i <
m_cols; ++i) {
1441 if (ttype[tfields] != NULL && tform[tfields] != NULL &&
1442 tunit[tfields] != NULL)
1458 status =
__ffgabc(tfields, tform, 1, &rowlen, &tbcol, &status);
1460 &tbcol, tform, tunit, NULL, &status);
1464 tunit, NULL, 0, &status);
1474 ttype, tform, tunit, NULL, &status);
1479 for (
int i = 0; i <
m_cols; ++i) {
1480 if (ttype[i] != NULL)
delete [] ttype[i];
1481 if (tform[i] != NULL)
delete [] tform[i];
1482 if (tunit[i] != NULL)
delete [] tunit[i];
1484 if (ttype != NULL)
delete [] ttype;
1485 if (ttype != NULL)
delete [] tform;
1486 if (ttype != NULL)
delete [] tunit;
1496 for (
int i = 0; i <
m_cols; ++i) {
1505 #if defined(G_DEBUG_SAVE)
1506 std::cout <<
"GFitsTable::save: created new table" << std::endl;
1512 else if (status != 0) {
1524 #if defined(G_DEBUG_SAVE)
1525 std::cout <<
"GFitsTable::save: FITS table contains ";
1526 std::cout << num_cols <<
" columns." << std::endl;
1531 if (
m_columns == NULL && num_cols > 0) {
1532 for (
int i = 0; i < num_cols; ++i) {
1551 #if defined(G_DEBUG_SAVE)
1552 std::cout <<
"GFitsTable::save: FITS table contains ";
1553 std::cout << num_rows <<
" rows." << std::endl;
1563 long long firstrow = num_rows;
1571 #if defined(G_DEBUG_SAVE)
1572 std::cout <<
"GFitsTable::save: Added " <<
nrows;
1573 std::cout <<
" rows to FITS table." << std::endl;
1577 else if (
m_rows < num_rows) {
1580 long long firstrow = num_rows;
1588 #if defined(G_DEBUG_SAVE)
1589 std::cout <<
"GFitsTable::save: Deleted " <<
nrows;
1590 std::cout <<
" rows from FITS table." << std::endl;
1596 #if defined(G_DEBUG_SAVE)
1597 std::cout <<
"GFitsTable::save: Now update all columns." << std::endl;
1604 for (
int i = 0; i <
m_cols; ++i) {
1633 #if defined(G_DEBUG_SAVE)
1634 std::cout <<
"GFitsTable::save: Write column " << i;
1635 std::cout <<
"." << std::endl;
1644 #if defined(G_DEBUG_SAVE)
1645 std::cout <<
"GFitsTable::save: Now delete all obsolete columns.";
1646 std::cout << std::endl;
1657 sprintf(keyname,
"TTYPE%d",
colnum);
1662 value[strlen(value)-1] =
'\0';
1667 for (
int i = 0; i <
m_cols; ++i) {
1686 #if defined(G_DEBUG_SAVE)
1687 std::cout <<
"GFitsTable::save: Deleted obsolete column ";
1688 std::cout << value <<
" from FITS table." << std::endl;
1698 #if defined(G_DEBUG_SAVE)
1699 std::cout <<
"GFitsTable::save: Now update the FITS header for all columns.";
1700 std::cout << std::endl;
1707 #if defined(G_DEBUG_SAVE)
1708 std::cout <<
"GFitsTable::save: exit" << std::endl;
1747 for (
int i = 0; i <
m_cols; ++i) {
1777 ptr =
new char[size+1];
1778 std::strncpy(ptr,
m_columns[colnum]->name().c_str(), size);
1813 ptr =
new char[size+1];
1814 std::strncpy(ptr,
m_columns[colnum]->ascii_format().c_str(), size);
1818 ptr =
new char[size+1];
1819 std::strncpy(ptr,
m_columns[colnum]->tform_binary().c_str(), size);
1852 ptr =
new char[size+1];
1853 std::strncpy(ptr,
m_columns[colnum]->unit().c_str(), size);
1949 for (
int i = 0; i <
m_cols; ++i) {
1978 for (
int i = 0; i <
m_cols; ++i) {
FITS table Boolean column class interface definition.
void unit(const std::string &unit)
Set column unit.
const int & ncols(void) const
Return number of columns in table.
FITS table double column class interface definition.
void number(const int &number)
Set number of elements in column.
virtual GFitsTableCol * clone(void) const =0
Clones object.
#define __ffdhdu(A, B, C)
std::string replace_segment(const std::string &arg, const std::string &segment, const std::string &replacement)
Replace string segment in string.
int m_rows
Number of rows in table.
std::string number(const std::string &noun, const int &number)
Convert singular noun into number noun.
void connect(void *vptr)
Connect table column to FITS file.
GFitsTable(void)
Void constructor.
FITS table unsigned long integer column class interface definition.
#define __ffgtcl(A, B, C, D, E, F)
char * get_ttype(const int &colnum) const
Returns pointer to column type.
GFitsTableCol * set(const int &colnum, const GFitsTableCol &column)
Set column.
std::string print_hdu(const GChatter &chatter=NORMAL) const
Print basic HDU information.
void insert_rows(const int &row, const int &nrows)
Insert rows into the table.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
Abstract FITS extension base class.
int m_type
Table type (1=ASCII, 2=Binary)
GFitsTableCol * alloc_column(int typecode) const
Allocates column.
FITS table double complex column.
bool contains(const std::string &colname) const
Checks the presence of a column in table.
FITS table long long integer column class interface definition.
virtual HDUType exttype(void) const =0
void nrows(const int &nrows)
Set number of rows in column.
void append_rows(const int &nrows)
Append rows to the table.
std::string strip_chars(const std::string &arg, const std::string &chars)
Strip leading and trailing character from string.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
void * m_fitsfile
FITS file pointer pointing on actual HDU.
GFitsTableCol ** m_columns
Array of table columns.
FITS table float column class interface definition.
char * get_tform(const int &colnum) const
Returns pointer to column format.
const GFitsHeader & header(void) const
Return extension header.
FITS file class interface definition.
#define __ffgkey(A, B, C, D, E)
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
virtual void insert(const int &row, const int &nrows)=0
GFitsHDU & operator=(const GFitsHDU &hdu)
Assignment operator.
virtual void remove(const int &row, const int &nrows)=0
FITS table string column.
GFitsTableCol * operator[](const int &colnum)
Returns pointer to table column.
#define __ffgncl(A, B, C)
std::string print(const GChatter &chatter=NORMAL) const
Print column information.
#define __ffmahd(A, B, C, D)
void data_save(void)
Save table into FITS file.
char * get_tunit(const int &colnum) const
Returns pointer to column unit.
void update_header(void)
Update header after row or column manipulations.
CFITSIO interface header.
Abstract interface for FITS table column.
#define __ffibin(A, B, C, D, E, F, G, H, I)
FITS table Boolean column.
void data_open(void *vptr)
Open Table.
void copy_members(const GFitsTable &table)
Copy class members.
void width(const int &width)
Set width in Bytes of one column element.
FITS table unsigned long integer column.
FITS table string column class interface definition.
FITS table unsigned short integer column class interface definition.
virtual ~GFitsTable(void)
Destructor.
#define __ffdrow(A, B, C, D)
Abstract interface for FITS table.
void type(const int &type)
Set type code.
FITS table bit column class interface definition.
#define __ffgky(A, B, C, D, E, F)
void dim(const std::vector< int > &dim)
Set column dimension.
#define __ffitab(A, B, C, D, E, F, G, H, I, J)
GFitsHeader m_header
HDU header.
void is_variable(const bool &variable)
Set variable-length flag.
void tscale(const double &tscale)
Set TSCALE value.
FITS table double complex column class interface definition.
#define __ffirow(A, B, C, D)
virtual void save(void)
Save table column into FITS file.
FITS table long long integer column.
FITS table long integer column.
void init_members(void)
Initialise class members.
const int & nrows(void) const
Return number of rows in table.
void colnum(const int &colnum)
Set column number.
int colnum(const std::string &colname) const
Returns column number of a given column name.
#define __ffgnrw(A, B, C)
std::string typecode(int type) const
Return typecode as string.
int m_cols
Number of columns in table.
void free_members(void)
Free class members.
#define __ffcrtb(A, B, C, D, E, F, G, H, I)
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.
FITS table unsigned short integer column.
void remove(const int &colnum)
Remove column from the table.
Exception handler interface definition.
FITS table long integer column class interface definition.
void data_close(void)
Close table.
FITS table short integer column class interface definition.
#define __ffgkyd(A, B, C, D, E)
void repeat(const int &repeat)
Set repeat value.
int toint(const std::string &arg)
Convert string into integer value.
FITS table short integer column.
#define __ffdcol(A, B, C)
void data_connect(void *vptr)
Connect table data to FITS file.
FITS table Byte column class interface definition.
int fits_move_to_hdu(const std::string &caller, void *vptr, const int &hdunum=0)
Move to FITS extension.
void free_columns(void)
Free column pointers.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
#define __fficol(A, B, C, D, E)
virtual std::string ascii_format(void) const =0
FITS table float complex column.
#define __ffgabc(A, B, C, D, E, F)
GFitsHeaderCard & card(const int &cardno)
Return header card.
GFitsTableCol * insert(int colnum, const GFitsTableCol &column)
Insert column into the table.
void name(const std::string &name)
Set column name.
GFitsTableCol * ptr_column(const std::string &colname) const
Returns pointer of column with given name.
GFitsTable & operator=(const GFitsTable &table)
Assignment operator.
void remove_rows(const int &row, const int &nrows)
Remove rows from the table.
FITS table double column.
int m_hdunum
HDU number (starting from 0)
FITS table float complex column class interface definition.
std::string print(const GChatter &chatter=NORMAL) const
Print table information.
std::string tform_binary(void) const
Returns TFORM code for binary table column.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
FITS table abstract base class interface definition.