CCfits  2.5
ExtHDU.h
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 EXTHDU_H
00010 #define EXTHDU_H 1
00011 
00012 // CCfitsHeader
00013 #include "CCfits.h"
00014 // HDU
00015 #include "HDU.h"
00016 // FitsError
00017 #include "FitsError.h"
00018 
00019 namespace CCfits {
00020   class Column;
00021 
00022 } // namespace CCfits
00023 
00024 
00025 namespace CCfits {
00026 
00438   class ExtHDU : public HDU  //## Inherits: <unnamed>%38048213E7A8
00439   {
00440 
00441     public:
00442 
00443 
00444 
00445       class WrongExtensionType : public FitsException  //## Inherits: <unnamed>%39E61E630349
00446       {
00447         public:
00448             WrongExtensionType (const String& msg, bool silent = true);
00449 
00450         protected:
00451         private:
00452         private: //## implementation
00453       };
00454         ExtHDU(const ExtHDU &right);
00455         virtual ~ExtHDU();
00456         friend bool operator<(const ExtHDU &left,const ExtHDU &right);
00457 
00458         friend bool operator>(const ExtHDU &left,const ExtHDU &right);
00459 
00460         friend bool operator<=(const ExtHDU &left,const ExtHDU &right);
00461 
00462         friend bool operator>=(const ExtHDU &left,const ExtHDU &right);
00463 
00464         static void readHduName (const fitsfile* fptr, int hduIndex, String& hduName, int& hduVersion);
00465         virtual void readData (bool readFlag = false, const std::vector<String>& keys = std::vector<String>()) = 0;
00466         const String& name () const;
00467         virtual HDU * clone (FITSBase* p) const = 0;
00468         //      By all means necessary, set the fitsfile pointer so that
00469         //      this HDU is the current HDU.
00470         //
00471         //      This would appear to be a good candidate for the public
00472         //      interface.
00473         virtual void makeThisCurrent () const;
00474         virtual Column& column (const String& colName, bool caseSensitive = true) const;
00475         virtual Column& column (int colIndex) const;
00476         virtual long rows () const;
00477         virtual void addColumn (ValueType type, const String& columnName, long repeatWidth, const String& colUnit = String(""), long decimals = -1, size_t columnNumber = 0);
00478         virtual void copyColumn(const Column& inColumn, int colIndx, bool insertNewCol=true);
00479         virtual void deleteColumn (const String& columnName);
00480         virtual long getRowsize () const;
00481         virtual int numCols () const;
00482         virtual const ColMap& column () const;
00483 
00484         bool isCompressed () const;
00485         int version () const;
00486         void version (int value);
00487         static const String& missHDU ();
00488         static void setMissHDU (const String& value);
00489 
00490     public:
00491       // Additional Public Declarations
00492 
00493       // interface is virtually identical to PHDU. The implementation is
00494       // similar apart from a check for wrong extension type.
00495 
00496 
00497 
00498 
00499       template <typename S>
00500       void write(const std::vector<long>& first,
00501                     long nElements,
00502                     const std::valarray<S>& data,
00503                     S* nullValue);
00504 
00505 
00506       template <typename S>
00507       void write(long first,
00508                     long nElements,
00509                     const std::valarray<S>& data,
00510                     S* nullValue);                
00511 
00512       template <typename S>
00513       void write(const std::vector<long>& first,
00514                     long nElements,
00515                     const std::valarray<S>& data);
00516 
00517 
00518       template <typename S>
00519       void write(long first,
00520                     long nElements,
00521                     const std::valarray<S>& data);
00522 
00523       template <typename S>
00524       void write(const std::vector<long>& firstVertex,
00525                     const std::vector<long>& lastVertex,
00526                     const std::valarray<S>& data);     
00527 
00528       // read image data & return the array. Can't return a reference because type
00529       // conversion in general requires allocating a new object.
00530       // note semantics of reading column data are easily distinguished: they require
00531       // the user to perform the operation EXT.column({name,index}).read(...)
00532 
00533       template <typename S>
00534       void read (std::valarray<S>& image) ; 
00535 
00536       template<typename S> 
00537       void read (std::valarray<S>& image, 
00538                       long first,
00539                       long nElements, 
00540                       S* nullValue) ; 
00541 
00542       template<typename S>
00543       void read (std::valarray<S>& image, 
00544                       const std::vector<long>& first, 
00545                       long nElements, 
00546                       S* nullValue) ; 
00547 
00548       template<typename S>
00549       void read (std::valarray<S>& image, 
00550                       const std::vector<long>& firstVertex, 
00551                       const std::vector<long>& lastVertex, 
00552                       const std::vector<long>& stride) ; 
00553 
00554       template<typename S>
00555       void read (std::valarray<S>& image, 
00556                       long first,
00557                       long nElements) ; 
00558 
00559       template<typename S>
00560       void read (std::valarray<S>& image, 
00561                       const std::vector<long>& first,
00562                       long nElements) ; 
00563 
00564       template<typename S>
00565       void read (std::valarray<S>& image, 
00566                       const std::vector<long>& firstVertex, 
00567                       const std::vector<long>& lastVertex, 
00568                       const std::vector<long>& stride, 
00569                       S* nullValue) ; 
00570 
00571     protected:
00572         //      ExtHDU needs a default constructor. This is it.
00573         ExtHDU (FITSBase* p, HduType xtype, const String &hduName, int version);
00574         //      The writing constructor. Forces the user to supply a name
00575         //      for the HDU
00576         ExtHDU (FITSBase* p, HduType xtype, const String &hduName, int bitpix, int naxis, const std::vector<long>& axes, int version);
00577         //      ExtHDU constructor for getting ExtHDUs by number.
00578         //      Necessary since EXTNAME is a reserved not required
00579         //      keyword.
00580         ExtHDU (FITSBase* p, HduType xtype, int number);
00581 
00582         virtual std::ostream & put (std::ostream &s) const = 0;
00583         virtual void setColumn (const String& colname, Column* value);
00584         virtual void checkExtensionType () const;
00585         int getVersion ();
00586         long pcount () const;
00587         void pcount (long value);
00588         long gcount () const;
00589         void gcount (long value);
00590         HduType xtension () const;
00591         void xtension (HduType value);
00592 
00593       // Additional Protected Declarations
00594 
00595     private:
00596         virtual void initRead () = 0;
00597         void checkXtension ();
00598 
00599       // Additional Private Declarations
00600 
00601     private: //## implementation
00602       // Data Members for Class Attributes
00603         long m_pcount;
00604         long m_gcount;
00605         int m_version;
00606         HduType m_xtension;
00607         static String s_missHDU;
00608 
00609       // Data Members for Associations
00610         String m_name;
00611 
00612       // Additional Implementation Declarations
00613 
00614   };
00615 
00616   // Class CCfits::ExtHDU::WrongExtensionType 
00617 
00618   // Class CCfits::ExtHDU 
00619 
00620   inline bool operator<(const ExtHDU &left,const ExtHDU &right)
00621   {
00622         if (left.m_name < right.m_name) return true; 
00623         if (left.m_name > right.m_name) return false;
00624         if (left.m_name == right.m_name)
00625         {
00626                 if (left.m_version < right.m_version) return true;
00627         }      
00628         return false;       
00629   }
00630 
00631   inline bool operator>(const ExtHDU &left,const ExtHDU &right)
00632   {
00633      return !operator<=(left,right);
00634   }
00635 
00636   inline bool operator<=(const ExtHDU &left,const ExtHDU &right)
00637   {
00638         if (left.m_name <= right.m_name) 
00639         {
00640                 if (left.m_version <= right.m_version) return true;
00641         }
00642         return false;     
00643   }
00644 
00645   inline bool operator>=(const ExtHDU &left,const ExtHDU &right)
00646   {
00647     return !operator<(left,right);    
00648   }
00649 
00650 
00651   inline const String& ExtHDU::name () const
00652   {
00653 
00654     return m_name;
00655   }
00656 
00657   inline long ExtHDU::pcount () const
00658   {
00659     return m_pcount;
00660   }
00661 
00662   inline void ExtHDU::pcount (long value)
00663   {
00664     m_pcount = value;
00665   }
00666 
00667   inline long ExtHDU::gcount () const
00668   {
00669     return m_gcount;
00670   }
00671 
00672   inline void ExtHDU::gcount (long value)
00673   {
00674     m_gcount = value;
00675   }
00676 
00677   inline int ExtHDU::version () const
00678   {
00679     return m_version;
00680   }
00681 
00682   inline void ExtHDU::version (int value)
00683   {
00684     m_version = value;
00685   }
00686 
00687   inline HduType ExtHDU::xtension () const
00688   {
00689     return m_xtension;
00690   }
00691 
00692   inline void ExtHDU::xtension (HduType value)
00693   {
00694     m_xtension = value;
00695   }
00696 
00697   inline const String& ExtHDU::missHDU ()
00698   {
00699     return s_missHDU;
00700   }
00701 
00702   inline void ExtHDU::setMissHDU (const String& value)
00703   {
00704     s_missHDU = value;
00705   }
00706 
00707 } // namespace CCfits
00708 
00709 
00710 #endif