51#define G_AT1 "GFits::at(int&)"
52#define G_AT2 "GFits::at(std::string&)"
53#define G_IMAGE1 "GFits::image(int&)"
54#define G_IMAGE2 "GFits::image(std::string&)"
55#define G_TABLE1 "GFits::table(int&)"
56#define G_TABLE2 "GFits::table(std::string&)"
57#define G_SET1 "GFits::set(int&, GFitsHDU&)"
58#define G_SET2 "GFits::set(std::string&, GFitsHDU&)"
59#define G_INSERT1 "GFits::insert(const int& extno, GFitsHDU& hdu)"
60#define G_INSERT2 "GFits::insert(std::string&, GFitsHDU& hdu)"
61#define G_REMOVE1 "GFits::remove(int&)"
62#define G_REMOVE2 "GFits::remove(std::string&)"
63#define G_OPEN "GFits::open(GFilename&, bool&)"
64#define G_SAVE "GFits::save(bool&)"
65#define G_SAVETO "GFits::saveto(GFilename&, bool&)"
66#define G_PUBLISH "GFits::publish(std::string&, std::string&)"
67#define G_FREE_MEM "GFits::free_members()"
68#define G_NEW_IMAGE "GFits::new_image()"
73#define G_DELETE_EMPTY_FITS_FILES
215 return new GFits(*
this);
236 #if defined(G_RANGE_CHECK)
248 std::string msg =
"FITS HDU with extension number "+
275 #if defined(G_RANGE_CHECK)
287 std::string msg =
"FITS HDU with extension number "+
314 std::string msg =
"FITS extension \""+extname+
"\" not found in FITS "
315 "file. Please specify a valid extension name.";
344 std::string msg =
"FITS extension \""+extname+
"\" not found in FITS "
345 "file. Please specify a valid extension name.";
376 "not an image. Please specify the extension number "
405 "not an image. Please specify the extension number "
433 std::string msg =
"FITS extension \""+extname+
"\" is not an image. "
434 "Please specify the name of an image extension.";
461 std::string msg =
"FITS extension \""+extname+
"\" is not an image. "
462 "Please specify the name of an image extension.";
490 "not a table. Please specify the extension number "
519 "not a table. Please specify the extension number "
547 std::string msg =
"FITS extension \""+extname+
"\" is not a table. "
548 "Please specify the name of a table extension.";
575 std::string msg =
"FITS extension \""+extname+
"\" is not a table. "
576 "Please specify the name of a table extension.";
600 #if defined(G_RANGE_CHECK)
610 std::string msg =
"Attempt to set a table extension as the first"
611 " extension of a FITS file.\n"
612 "The first extension of a FITS file must be an"
613 " image, hence use the next slot to set a"
657 std::string msg =
"No extension with name \""+extname+
"\" found in "
658 "FITS file. Please specify a valid extension name.";
682 std::cout <<
"GFits::append(";
685 std::cout <<
"GFitsImage";
688 std::cout <<
"GFitsAsciiTable";
691 std::cout <<
"GFitsBinTable";
694 std::cout <<
"<unknown header type>";
697 std::cout <<
") (size=" <<
size() <<
"): entry" << std::endl;
718 std::cout <<
"GFits::append: append primary image to HDU.";
719 std::cout << std::endl;
723 m_hdu.push_back(primary);
747 std::cout <<
"GFits::append: append HDU (extno=" << n_hdu <<
")";
748 std::cout << std::endl;
752 m_hdu.push_back(ptr);
756 std::cout <<
"GFits::append: exit" << std::endl;
781 #if defined(G_RANGE_CHECK)
791 std::string msg =
"Attempt to insert a table extension as the first "
792 "extension of a FITS file. The first extension of "
793 "a FITS file must be an image, hence use the next "
794 "slot to insert a table.";
815 for (
int i =
extno + 1; i <
size(); ++i) {
842 std::string msg =
"No extension with name \""+extname+
"\" found in "
843 "FITS file. Please specify a valid extension name.";
865 #if defined(G_RANGE_CHECK)
875 std::string msg =
"Attempt to remove primary image from a FITS file "
876 "with a table extension as second extension. The "
877 "removal of the primary image would result in "
878 "having a table as the first extension of the FITS "
879 "file, which is not a valid FITS file.";
912 std::string msg =
"No extension with name \""+extname+
"\" found in "
913 "FITS file. Please specify a valid extension name.";
942 int num = fits.
size();
948 for (
int i = 0; i < num; ++i) {
954 m_hdu.push_back(ptr);
999 if (uextname ==
"PRIMARY") {
1007 for (
int i = 0; i <
size(); ++i) {
1047 msg =
"FITS file \""+
m_filename+
"\" has already been "
1048 "opened, cannot open it again.";
1051 msg =
"A FITS file \""+
m_filename+
"\" has already "
1052 "been opened, cannot open another FITS file \""+
1053 filename+
"\" before closing the existing one.";
1075 if (status == 104 || status == 107 || status == 112) {
1089 if (create && (status == 104 || status == 107)) {
1099 if (status == 202) {
1100 std::string msg =
"Keyword not found when opening FITS file \""+
1101 filename+
"\". Please specify a valid keyword.";
1106 else if (status != 0) {
1107 std::string msg =
"Error occured when opening FITS file \""+
1124 for (
int i = 0; i < num_hdu; ++i) {
1142 std::string msg =
"Unknown HDU type \""+
gammalib::str(type)+
"\" "
1152 m_hdu.push_back(hdu);
1181 #if defined(G_DEBUG)
1182 std::cout <<
"GFits::save (size=" <<
size() <<
"): entry" << std::endl;
1191 std::string msg =
"Attempted to overwrite FITS file \""+
m_filename+
1192 "\". Please set clobber flag to true.";
1198 std::string msg =
"Cannot save FITS file that was not open. Please "
1199 "open FITS file before saving or use saveto() "
1207 for (
int i = 0; i <
size(); ++i) {
1221 #if defined(G_DEBUG)
1222 std::cout <<
"GFits::save: currently " << num_hdu <<
" in file";
1223 std::cout << std::endl;
1228 for (
int i = num_hdu-1; i >= 0; --i) {
1236 #if defined(G_DEBUG)
1237 std::cout <<
"GFits::save: deleted HDUs" << std::endl;
1251 for (
int i = 0; i <
size(); ++i) {
1258 #if defined(G_DEBUG)
1259 std::cout <<
"GFits::save: saved HDUs" << std::endl;
1272 #if defined(G_DEBUG)
1273 std::cout <<
"GFits::save: exit" << std::endl;
1296 #if defined(G_DEBUG)
1297 std::cout <<
"GFits::saveto(\"" <<
filename <<
"\", " << clobber <<
")"
1298 <<
" (size=" <<
size() <<
"): entry" << std::endl;
1307 std::string msg =
"Attempted to overwrite FITS file \""+
filename.
url()+
1308 "\". Please set clobber flag to true.";
1316 for (
int i = 0; i <
size(); ++i) {
1327 #if defined(G_DEBUG)
1328 std::cout <<
"GFits::saveto: exit" << std::endl;
1375 if (!name.empty()) {
1400 if (!name.empty()) {
1436 std::string msg =
"Extension \""+extname+
"\" not found in FITS file. "
1437 "Please specify a valid extension name.";
1464 result.append(
"=== GFits ===");
1471 result.append(
"new file");
1474 result.append(
"existing file");
1478 result.append(
"read/write");
1481 result.append(
"read only");
1488 for (
int i = 0; i <
size(); ++i) {
1489 result.append(
"\n");
1545 for (
int i = 0; i < fits.
m_hdu.size(); ++i) {
1579 #if defined(G_DELETE_EMPTY_FITS_FILES)
1580 else if (
size() == 0) {
1590 if (status == 252) {
1593 if (new_status != 0) {
1597 else if (status != 0) {
1609 for (
int i = 0; i <
m_hdu.size(); ++i) {
1610 if (
m_hdu[i] != NULL) {
1659 std::sprintf(keyname,
"BZERO");
1663 std::sprintf(keyname,
"BSCALE");
1667 if (bitpix == 8 && bzero == -128 && bscale == 1) {
1670 else if (bitpix == 16 && bzero == 32768u && bscale == 1) {
1673 else if (bitpix == 32 && bzero == 2147483648u && bscale == 1) {
1707 std::string msg =
"Invalid number of bits per pixel (bitpix="+
1732 status =
__ffinit(&fptr,
"mem://", &status);
1733 status =
__ffcrim(fptr, 8, 0, NULL, &status);
1740 if (status == 252) {
1782 int position = (hdunum > 0) ? hdunum : (
FPTR(vptr)->HDUposition)+1;
1785 status =
__ffmahd(
FPTR(vptr), position, &type, &status);
1789 std::string msg =
"Unable to move FITS file pointer to extension "
Exception handler interface definition.
FITS ASCII table class definition.
FITS binary table class definition.
CFITSIO interface header.
#define __ffthdu(A, B, C)
#define __ffmahd(A, B, C, D)
#define __ffgiet(A, B, C)
#define __ffdhdu(A, B, C)
#define __ffgky(A, B, C, D, E, F)
#define __ffinit(A, B, C)
#define __ffcrim(A, B, C, D, E)
#define __ffopen(A, B, C, D)
FITS Byte image class definition.
Double precision FITS image class definition.
Single precision FITS image class definition.
Long long integer FITS image class definition.
Long integer FITS image class definition.
Signed Byte FITS image class definition.
Short integer FITS image class definition.
Unsigned long image FITS class definition.
Unsigned short FITS image class definition.
FITS file class interface definition.
VO client class interface definition.
VO table class definition.
std::string url(void) const
Return Uniform Resource Locator (URL)
void remove(void) const
Remove file from disk.
bool exists(void) const
Checks whether file exists.
void clear(void)
Clear file name.
Abstract FITS extension base class.
virtual HDUType exttype(void) const =0
const std::string & extname(void) const
Return extension name.
void * m_fitsfile
FITS file pointer pointing on actual HDU.
void open(void *vptr, int hdunum)
Open HDU.
void connect(void *fptr)
Connect HDU to FITS file.
virtual GFitsHDU * clone(void) const =0
Clones object.
const int & extno(void) const
Return extension number.
Double precision FITS image class.
Single precision FITS image class.
Long long integer FITS image class.
Long integer FITS image class.
Signed Byte FITS image class.
Short integer FITS image class.
Unsigned long image FITS class.
Unsigned short FITS image class.
Abstract FITS image base class.
Abstract interface for FITS table.
void copy_members(const GFits &fits)
Copy class members.
void * m_fitsfile
FITS file pointer.
int extno(const std::string &extname) const
Return extension number for specified extension name.
GFitsImage * new_image(void)
Allocate new FITS image and return memory pointer.
void init_members(void)
Initialise class members.
void open(const GFilename &filename, const bool &create=false)
Open or (optionally) create FITS file.
GFits(void)
Void constructor.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
virtual ~GFits(void)
Destructor.
bool m_created
FITS file has been created (true/false)
void extend(const GFits &fits)
Append FITS file.
GFitsHDU * set(const int &extno, const GFitsHDU &hdu)
Set HDU for the specified extension number.
int size(void) const
Return number of HDUs in FITS file.
std::string print(const GChatter &chatter=NORMAL) const
Print FITS information.
GFilename m_filename
FITS file name.
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
GFitsImage * image(const int &extno)
Get pointer to image HDU.
bool m_readwrite
FITS file is readwrite (true/false)
void reserve(const int &num)
Reserves space for HDUs in FITS file.
void close(void)
Close FITS file.
GFits & operator=(const GFits &fits)
Assignment operator.
void remove(const int &extno)
Remove HDU from FITS file.
GFitsHDU * insert(const int &extno, const GFitsHDU &hdu)
Set HDU for the specified extension number.
GFitsHDU * at(const int &extno)
Get pointer to HDU.
void save(const bool &clobber=false)
Saves FITS file.
void publish(const int &extno, const std::string &name="") const
Publish FITS HDU on VO Hub.
void free_members(void)
Delete class members.
void clear(void)
Clear FITS file.
const GFilename & filename(void) const
Return FITS filename.
GFitsImage * new_primary(void)
Return minimal primary HDU.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
GFits * clone(void) const
Clone FITS file.
std::vector< GFitsHDU * > m_hdu
Pointers to HDUs.
bool is_empty(void) const
Signals if there are no HDUs in FITS file.
void publish(const GFitsHDU &hdu)
Publish FITS HDU.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
int fits_move_to_hdu(const std::string &caller, void *vptr, const int &hdunum=0)
Move to FITS extension.
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.
std::string toupper(const std::string &s)
Convert string to upper case.