CCfits
2.5
|
00001 // Astrophysics Science Division, 00002 // NASA/ Goddard Space Flight Center 00003 // HEASARC 00004 // http://heasarc.gsfc.nasa.gov 00005 // e-mail: ccfits@legacy.gsfc.nasa.gov 00006 // 00007 // Original author: Ben Dorman 00008 00009 #ifndef FITS_H 00010 #define FITS_H 1 00011 00012 // exception 00013 #include <exception> 00014 // string 00015 #include <string> 00016 // map 00017 #include <map> 00018 // ExtHDU 00019 #include "ExtHDU.h" 00020 // HDUCreator 00021 #include "HDUCreator.h" 00022 // FitsError 00023 #include "FitsError.h" 00024 00025 namespace CCfits { 00026 class FITSBase; 00027 class PHDU; 00028 class Table; 00029 00030 } // namespace CCfits 00031 //class PHDU; 00032 extern "C" 00033 { 00034 # include <sys/stat.h> 00035 } 00036 #include <memory> 00037 00038 00039 namespace CCfits { 00664 // ! The FITS object class. Contains a primary HDU and Extensions indexed by name. 00665 00666 00667 00668 class FITS 00669 { 00670 00671 public: 00672 00673 00674 00675 class NoSuchHDU : public FitsException //## Inherits: <unnamed>%396C90CB0236 00676 { 00677 public: 00678 NoSuchHDU (const String& diag, bool silent = true); 00679 00680 protected: 00681 private: 00682 private: //## implementation 00683 }; 00684 00685 00686 00687 class OperationNotSupported : public FitsException //## Inherits: <unnamed>%39806C7600D5 00688 { 00689 public: 00690 OperationNotSupported (const String& msg, bool silent = true); 00691 00692 protected: 00693 private: 00694 private: //## implementation 00695 }; 00696 00697 00698 00699 class CantOpen : public FitsException //## Inherits: <unnamed>%39C8EB1D02C0 00700 { 00701 public: 00702 CantOpen (const String& diag, bool silent = true); 00703 00704 protected: 00705 private: 00706 private: //## implementation 00707 }; 00708 00709 00710 00711 struct CantCreate : public FitsException //## Inherits: <unnamed>%39C8EB10020B 00712 { 00713 CantCreate (const String& diag, bool silent = false); 00714 00715 public: 00716 protected: 00717 private: 00718 private: //## implementation 00719 }; 00720 FITS (const String &name, RWmode mode = Read, bool readDataFlag = false, const std::vector<String>& primaryKeys = std::vector<String>()); 00721 // Open a file and read a specified HDU. 00722 // 00723 // Optional parameter allows the reading of specified primary HDU keys. 00724 FITS (const String &name, RWmode mode, const string &hduName, bool readDataFlag = false, const std::vector<String>& hduKeys = std::vector<String>(), const std::vector<String>& primaryKey = std::vector<String>(), int version = 1); 00725 // Read data from a set of specified HDUs. keywords can only be specified for the primary here. 00726 // The code will call a different constructor for the case where keywords are required for 00727 // the extensions. 00728 FITS (const String &name, RWmode mode, const std::vector<String>& hduNames, bool readDataFlag = false, const std::vector<String>& primaryKey = std::vector<String>()); 00729 // Initialize a new FITS file object with the primary from a 00730 // different file. 00731 FITS (const String& fileName, const FITS& source); 00732 // Fully general FITS HDU reader. May read any part of fits file by 00733 // supplying HDU names and version numbers, and optionally 00734 // the data read flag. 00735 FITS (const String &name, RWmode mode, const std::vector<String>& hduNames, const std::vector<std::vector<String> >& hduKeys, bool readDataFlag = false, const std::vector<String>& primaryKeys = std::vector<String>(), const std::vector<int>& hduVersions = std::vector<int>()); 00736 // Writing constructor. Takes a name and information to create an empty 00737 // Primary HDU which can then be filled with calls to HDU methods. 00738 FITS (const String& name, int bitpix, int naxis, long *naxes); 00739 // Open a file and read a specified HDU. 00740 // 00741 // Optional parameter allows the reading of specified primary HDU keys. 00742 FITS (const string &name, RWmode mode, int hduIndex, bool readDataFlag = false, const std::vector<String>& hduKeys = std::vector<String>(), const std::vector<String>& primaryKey = std::vector<String>()); 00743 // Open a file and read a HDU that contains specified 00744 // search keywords with [optional] specified values 00745 // (sometimes one just wants to know that the keyword is present). 00746 // 00747 // Optional parameters allows the reading of specified primary HDU keys and specified keywords in 00748 // the HDU of interest. 00749 FITS (const String &name, RWmode mode, const std::vector<String>& searchKeys, const std::vector<String> &searchValues, bool readDataFlag = false, const std::vector<String>& hduKeys = std::vector<String>(), const std::vector<String>& primaryKey = std::vector<string>(), int version = 1); 00750 ~FITS(); 00751 00752 static void clearErrors (); 00753 void deleteExtension (const String& doomed, int version = 1); 00754 // Read keys and data from a single ExtHDU in the file. 00755 void read (const String &hduName, bool readDataFlag = false, const std::vector<String> &keys = std::vector<String>(), int version = 1); 00756 // Read multiple ExtHDUs. If the version number needs to be specified then one must call a 00757 // different method. 00758 void read (const std::vector<String> &hduNames, bool readDataFlag = false); 00759 // Read selected data from multiple ExtHDUs 00760 void read (const std::vector<String> &hduNames, const std::vector<std::vector<String> > &keys, bool readDataFlag = false, const std::vector<int>& hduVersions = std::vector<int>()); 00761 // Read keys and data from a single ExtHDU in the file. 00762 void read (int hduIndex, // Construct and Read HDU specified by number. One can add further HDUs by number using 00763 // the HDUCreator factory. 00764 bool readDataFlag = false, const std::vector<String> &keys = std::vector<String>()); 00765 // Open a file and read a HDU that contains specified 00766 // search keywords with [optional] specified values 00767 // (sometimes one just wants to know that the keyword is present). 00768 // 00769 // Optional parameters allows the reading of specified primary HDU keys and specified keywords in 00770 // the HDU of interest. 00771 void read (const std::vector<String>& searchKeys, const std::vector<String> &searchValues, bool readDataFlag = false, const std::vector<String>& hduKeys = std::vector<String>(), int version = 1); 00772 const ExtHDU& extension (int i) const; 00773 fitsfile* fitsPointer () const; 00774 ExtHDU& extension (int i); 00775 const ExtHDU& extension (const String& hduName, int version = 1) const; 00776 const PHDU& pHDU () const; 00777 PHDU& pHDU (); 00778 ExtHDU& extension (const String& hduName, int version = 1); 00779 friend std::ostream& operator << (std::ostream& s, const FITS& right); 00780 // ! add a new Table extension to a FITS object 00781 Table* addTable (const String& hduName, int rows, // ! Number of rows in new table. Mandatory 00782 const std::vector<String>& columnName = std::vector<String>(), // ! Optional set of column names for new table 00783 const std::vector<String>& columnFmt = std::vector<String>(), // ! Column formats for column units. Mandatory if columnName is specified 00784 const std::vector<String>& columnUnit = std::vector<String>(), // ! Column formats for column units. Optional 00785 HduType type = BinaryTbl, int version = 1); 00786 // ! add a new ImageExt (image extension) to the FITS object. A "writing" method. 00787 ExtHDU* addImage (const String& hduName, int bpix, std::vector<long>& naxes, int version = 1); 00788 // Force destruction of the FITS object. Essentially 00789 // is a manual destructor call. 00790 void destroy () throw (); 00791 void flush (); 00792 const String& currentExtensionName () const; 00793 const ExtMap& extension () const; 00794 void resetPosition (); 00795 void currentExtensionName (const String& extName); 00796 const String& name () const; 00797 void copy (const HDU& source); 00798 Table& filter (const String& expression, ExtHDU& inputTable, bool overwrite = true, bool readData = false); 00799 ExtHDU& currentExtension (); 00800 void deleteExtension (int doomed); 00801 void setCompressionType (int compType); 00802 void setTileDimensions (const std::vector<long>& tileSizes); 00803 void setNoiseBits (int noiseBits); 00804 int getCompressionType () const; 00805 void getTileDimensions (std::vector<long>& tileSizes) const; 00806 int getNoiseBits () const; 00807 static bool verboseMode (); 00808 static void setVerboseMode (bool value); 00809 00810 public: 00811 // Additional Public Declarations 00812 00813 protected: 00814 // Additional Protected Declarations 00815 00816 private: 00817 FITS(const FITS &right); 00818 FITS & operator=(const FITS &right); 00819 00820 void unmapExtension (ExtHDU& doomed); 00821 int nextVersionNumber (const String& inputName) const; 00822 // read the primary HDU. Read the image if 00823 // readDataFlag is true. 00824 void read (bool readDataFlag = false, const std::vector<String>& keys = std::vector<String>()); 00825 // Returns index of current HDU where primary = 0. (Extended file syntax may cause a shift to an 00826 // extension.) 00827 int open (RWmode mode = Read); 00828 // Create returns true if a new file was created or an 00829 // existing file overwritten, false if appending. 00830 // 00831 // 00832 // It throws exception CantCreate or CantOpen if either fails. 00833 bool create (); 00834 // Close the fits file. 00835 // 00836 // Called in destructors so must not throw. 00837 int close () throw (); 00838 std::ostream & put (std::ostream &s) const; 00839 ExtHDU& extbyVersion (const String& hduName, int version) const; 00840 void pHDU (PHDU* value); 00841 void readExtensions (bool readDataFlag = false); 00842 ExtHDU* addExtension (ExtHDU* ext); 00843 void swap (FITS& right); 00844 ExtMap& extensionMap (); 00845 String nameOfUnmapped (int hduNum) const; 00846 void cloneHeader (const ExtHDU& source); 00847 00848 // Check if caller is requesting an already read ExtHDU (ie. one 00849 // that's already been added to ExtMap). If hduIdx=0, check by 00850 // matching name and optional version. Otherwise check by matching 00851 // hduIdx. If found, returns pointer to the ExtHDU. Otherwise 00852 // returns 0. This will not throw. 00853 ExtHDU* checkAlreadyRead(const int hduIdx, 00854 const String& hduName = string(""), const int version=1) const throw(); 00855 00856 // Additional Private Declarations 00857 00858 private: //## implementation 00859 // Data Members for Class Attributes 00860 static bool s_verboseMode; 00861 00862 // Data Members for Associations 00863 FITSBase* m_FITSImpl; 00864 00865 // Additional Implementation Declarations 00866 friend void HDU::makeThisCurrent() const; 00867 }; 00868 00869 // Class CCfits::FITS::NoSuchHDU 00870 00871 // Class CCfits::FITS::OperationNotSupported 00872 00873 // Class CCfits::FITS::CantOpen 00874 00875 // Class CCfits::FITS::CantCreate 00876 00877 // Class CCfits::FITS 00878 00879 inline ExtHDU& FITS::extension (const String& hduName, int version) 00880 { 00881 00882 return extbyVersion(hduName,version); 00883 } 00884 00885 inline std::ostream& operator << (std::ostream& s, const FITS& right) 00886 { 00887 00888 return right.put(s); 00889 } 00890 00891 inline bool FITS::verboseMode () 00892 { 00893 return s_verboseMode; 00894 } 00895 00896 inline void FITS::setVerboseMode (bool value) 00897 { 00898 s_verboseMode = value; 00899 } 00900 00901 } // namespace CCfits 00902 00903 00904 #endif