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
115 open(filename, create);
215 return new GFits(*
this);
236 #if defined(G_RANGE_CHECK)
237 if (extno < 0 || extno >=
size()) {
248 std::string msg =
"FITS HDU with extension number "+
275 #if defined(G_RANGE_CHECK)
276 if (extno < 0 || extno >=
size()) {
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.";
375 std::string msg =
"FITS extension number "+
gammalib::str(extno)+
" is "
376 "not an image. Please specify the extension number "
404 std::string msg =
"FITS extension number "+
gammalib::str(extno)+
" is "
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.";
489 std::string msg =
"FITS extension number "+
gammalib::str(extno)+
" is "
490 "not a table. Please specify the extension number "
518 std::string msg =
"FITS extension number "+
gammalib::str(extno)+
" is "
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)
601 if (extno < 0 || extno >=
size()) {
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"
620 if ((
m_hdu[extno] != NULL) && (
m_hdu[extno] != &hdu)) {
638 return (
m_hdu[extno]);
657 std::string msg =
"No extension with name \""+extname+
"\" found in "
658 "FITS file. Please specify a valid extension name.";
663 return (
set(extno, hdu));
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)
782 if (extno < 0 || extno >=
size()) {
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.";
848 return (
insert(extno, hdu));
865 #if defined(G_RANGE_CHECK)
866 if (extno < 0 || extno >=
size()) {
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.";
890 for (
int i = extno; i <
size(); ++i) {
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;
1306 else if (filename.
exists()) {
1307 std::string msg =
"Attempted to overwrite FITS file \""+filename.
url()+
1308 "\". Please set clobber flag to true.";
1313 GFits fits(filename,
true);
1316 for (
int i = 0; i <
size(); ++i) {
1327 #if defined(G_DEBUG)
1328 std::cout <<
"GFits::saveto: exit" << std::endl;
1372 std::string extname = image->
extname();
1375 if (!name.empty()) {
1397 std::string extname = table->
extname();
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);
1736 image->
open(fptr,0);
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 "
Long long integer FITS image class definition.
std::vector< GFitsHDU * > m_hdu
Pointers to HDUs.
GFitsImage * new_image(void)
Allocate new FITS image and return memory pointer.
GFitsHDU * at(const int &extno)
Get pointer to HDU.
Double precision FITS image class definition.
Abstract FITS image base class.
#define __ffdhdu(A, B, C)
GFitsTable * table(const int &extno)
Get pointer to table HDU.
GFits(void)
Void constructor.
void clear(void)
Clear FITS file.
Signed Byte FITS image class definition.
void publish(const GFitsHDU &hdu)
Publish FITS HDU.
void open(void *vptr, int hdunum)
Open HDU.
Single precision FITS image class definition.
Abstract FITS extension base class.
Signed Byte FITS image class.
void connect(void *fptr)
Connect HDU to FITS file.
const GFilename & filename(void) const
Return FITS filename.
Unsigned long image FITS class.
virtual HDUType exttype(void) const =0
GFilename m_filename
FITS file name.
#define __ffinit(A, B, C)
void * m_fitsfile
FITS file pointer pointing on actual HDU.
Unsigned short FITS image class definition.
#define __ffcrim(A, B, C, D, E)
#define __ffthdu(A, B, C)
FITS file class interface definition.
Long integer FITS image class definition.
const int & extno(void) const
Return extension number.
GFits & operator=(const GFits &fits)
Assignment operator.
Long long integer FITS image class.
VO client class interface definition.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
Unsigned long image FITS class definition.
GFitsImage * new_primary(void)
Return minimal primary HDU.
void save(const bool &clobber=false)
Saves FITS file.
#define __ffmahd(A, B, C, D)
void remove(const int &extno)
Remove HDU from FITS file.
Double precision FITS image class.
GFits * clone(void) const
Clone FITS file.
CFITSIO interface header.
void open(const GFilename &filename, const bool &create=false)
Open or (optionally) create 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.
#define __ffopen(A, B, C, D)
bool exists(void) const
Checks whether file exists.
Abstract interface for FITS table.
virtual GFitsHDU * clone(void) const =0
Clones object.
#define __ffgky(A, B, C, D, E, F)
Short integer FITS image class.
Single precision FITS image class.
Unsigned short FITS image class.
void remove(void) const
Remove file from disk.
const std::string & extname(void) const
Return extension name.
Short integer FITS image class definition.
FITS Byte image class definition.
Long integer FITS image class.
GFitsImage * image(const int &extno)
Get pointer to image HDU.
void reserve(const int &num)
Reserves space for HDUs in FITS file.
std::string url(void) const
Return Uniform Resource Locator (URL)
void init_members(void)
Initialise class members.
void clear(void)
Clear file name.
bool is_empty(void) const
Signals if there are no HDUs in FITS file.
int size(void) const
Return number of HDUs in FITS file.
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.
GFitsHDU * insert(const int &extno, const GFitsHDU &hdu)
Set HDU for the specified extension number.
virtual ~GFits(void)
Destructor.
bool m_created
FITS file has been created (true/false)
Exception handler interface definition.
bool m_readwrite
FITS file is readwrite (true/false)
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
std::string toupper(const std::string &s)
Convert string to upper case.
VO table class definition.
FITS binary table class definition.
void copy_members(const GFits &fits)
Copy class members.
int fits_move_to_hdu(const std::string &caller, void *vptr, const int &hdunum=0)
Move to FITS extension.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
GFitsHDU * set(const int &extno, const GFitsHDU &hdu)
Set HDU for the specified extension number.
FITS ASCII table class definition.
std::string print(const GChatter &chatter=NORMAL) const
Print FITS information.
void close(void)
Close FITS file.
int extno(const std::string &extname) const
Return extension number for specified extension name.
void * m_fitsfile
FITS file pointer.
#define __ffgiet(A, B, C)
void extend(const GFits &fits)
Append FITS file.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.