CCfits  2.6
ExtHDU.h
1 // Astrophysics Science Division,
2 // NASA/ Goddard Space Flight Center
3 // HEASARC
4 // http://heasarc.gsfc.nasa.gov
5 // e-mail: ccfits@legacy.gsfc.nasa.gov
6 //
7 // Original author: Ben Dorman
8 
9 #ifndef EXTHDU_H
10 #define EXTHDU_H 1
11 
12 // CCfitsHeader
13 #include "CCfits.h"
14 // HDU
15 #include "HDU.h"
16 // FitsError
17 #include "FitsError.h"
18 
19 namespace CCfits {
20  class Column;
21 
22 } // namespace CCfits
23 
24 
25 namespace CCfits {
26 
438  class ExtHDU : public HDU //## Inherits: <unnamed>%38048213E7A8
439  {
440 
441  public:
442 
443 
444 
445  class WrongExtensionType : public FitsException //## Inherits: <unnamed>%39E61E630349
446  {
447  public:
448  WrongExtensionType (const String& msg, bool silent = true);
449 
450  protected:
451  private:
452  private: //## implementation
453  };
454  ExtHDU(const ExtHDU &right);
455  virtual ~ExtHDU();
456  friend bool operator<(const ExtHDU &left,const ExtHDU &right);
457 
458  friend bool operator>(const ExtHDU &left,const ExtHDU &right);
459 
460  friend bool operator<=(const ExtHDU &left,const ExtHDU &right);
461 
462  friend bool operator>=(const ExtHDU &left,const ExtHDU &right);
463 
464  static void readHduName (const fitsfile* fptr, int hduIndex, String& hduName, int& hduVersion);
465  virtual void readData (bool readFlag = false, const std::vector<String>& keys = std::vector<String>()) = 0;
466  const String& name () const;
467  virtual HDU * clone (FITS* p) const = 0;
468  // By all means necessary, set the fitsfile pointer so that
469  // this HDU is the current HDU.
470  //
471  // This would appear to be a good candidate for the public
472  // interface.
473  virtual void makeThisCurrent () const;
474  virtual Column& column (const String& colName, bool caseSensitive = true) const;
475  virtual Column& column (int colIndex) const;
476  virtual long rows () const;
477  virtual void addColumn (ValueType type, const String& columnName, long repeatWidth, const String& colUnit = String(""), long decimals = -1, size_t columnNumber = 0);
478  virtual void copyColumn(const Column& inColumn, int colIndx, bool insertNewCol=true);
479  virtual void deleteColumn (const String& columnName);
480  virtual long getRowsize () const;
481  virtual int numCols () const;
482  virtual const ColMap& column () const;
483 
484  bool isCompressed () const;
485  int version () const;
486  void version (int value);
487  static const String& missHDU ();
488  static void setMissHDU (const String& value);
489 
490  public:
491  // Additional Public Declarations
492 
493  // interface is virtually identical to PHDU. The implementation is
494  // similar apart from a check for wrong extension type.
495 
496 
497 
498 
499  template <typename S>
500  void write(const std::vector<long>& first,
501  long nElements,
502  const std::valarray<S>& data,
503  S* nullValue);
504 
505 
506  template <typename S>
507  void write(long first,
508  long nElements,
509  const std::valarray<S>& data,
510  S* nullValue);
511 
512  template <typename S>
513  void write(const std::vector<long>& first,
514  long nElements,
515  const std::valarray<S>& data);
516 
517 
518  template <typename S>
519  void write(long first,
520  long nElements,
521  const std::valarray<S>& data);
522 
523  template <typename S>
524  void write(const std::vector<long>& firstVertex,
525  const std::vector<long>& lastVertex,
526  const std::valarray<S>& data);
527 
528  // read image data & return the array. Can't return a reference because type
529  // conversion in general requires allocating a new object.
530  // note semantics of reading column data are easily distinguished: they require
531  // the user to perform the operation EXT.column({name,index}).read(...)
532 
533  template <typename S>
534  void read (std::valarray<S>& image) ;
535 
536  template<typename S>
537  void read (std::valarray<S>& image,
538  long first,
539  long nElements,
540  S* nullValue) ;
541 
542  template<typename S>
543  void read (std::valarray<S>& image,
544  const std::vector<long>& first,
545  long nElements,
546  S* nullValue) ;
547 
548  template<typename S>
549  void read (std::valarray<S>& image,
550  const std::vector<long>& firstVertex,
551  const std::vector<long>& lastVertex,
552  const std::vector<long>& stride) ;
553 
554  template<typename S>
555  void read (std::valarray<S>& image,
556  long first,
557  long nElements) ;
558 
559  template<typename S>
560  void read (std::valarray<S>& image,
561  const std::vector<long>& first,
562  long nElements) ;
563 
564  template<typename S>
565  void read (std::valarray<S>& image,
566  const std::vector<long>& firstVertex,
567  const std::vector<long>& lastVertex,
568  const std::vector<long>& stride,
569  S* nullValue) ;
570 
571  protected:
572  // ExtHDU needs a default constructor. This is it.
573  ExtHDU (FITS* p, HduType xtype, const String &hduName, int version);
574  // The writing constructor. Forces the user to supply a name
575  // for the HDU
576  ExtHDU (FITS* p, HduType xtype, const String &hduName, int bitpix, int naxis, const std::vector<long>& axes, int version);
577  // ExtHDU constructor for getting ExtHDUs by number.
578  // Necessary since EXTNAME is a reserved not required
579  // keyword.
580  ExtHDU (FITS* p, HduType xtype, int number);
581 
582  virtual std::ostream & put (std::ostream &s) const = 0;
583  virtual void setColumn (const String& colname, Column* value);
584  virtual void checkExtensionType () const;
585  int getVersion ();
586  long pcount () const;
587  void pcount (long value);
588  long gcount () const;
589  void gcount (long value);
590  HduType xtension () const;
591  void xtension (HduType value);
592 
593  // Additional Protected Declarations
594 
595  private:
596  virtual void initRead () = 0;
597  void checkXtension ();
598 
599  // Additional Private Declarations
600 
601  private: //## implementation
602  // Data Members for Class Attributes
603  long m_pcount;
604  long m_gcount;
605  int m_version;
606  HduType m_xtension;
607  static String s_missHDU;
608 
609  // Data Members for Associations
610  String m_name;
611 
612  // Additional Implementation Declarations
613 
614  };
615 
616  // Class CCfits::ExtHDU::WrongExtensionType
617 
618  // Class CCfits::ExtHDU
619 
620  inline bool operator<(const ExtHDU &left,const ExtHDU &right)
621  {
622  if (left.m_name < right.m_name) return true;
623  if (left.m_name > right.m_name) return false;
624  if (left.m_name == right.m_name)
625  {
626  if (left.m_version < right.m_version) return true;
627  }
628  return false;
629  }
630 
631  inline bool operator>(const ExtHDU &left,const ExtHDU &right)
632  {
633  return !operator<=(left,right);
634  }
635 
636  inline bool operator<=(const ExtHDU &left,const ExtHDU &right)
637  {
638  if (left.m_name <= right.m_name)
639  {
640  if (left.m_version <= right.m_version) return true;
641  }
642  return false;
643  }
644 
645  inline bool operator>=(const ExtHDU &left,const ExtHDU &right)
646  {
647  return !operator<(left,right);
648  }
649 
650 
651  inline const String& ExtHDU::name () const
652  {
653 
654  return m_name;
655  }
656 
657  inline long ExtHDU::pcount () const
658  {
659  return m_pcount;
660  }
661 
662  inline void ExtHDU::pcount (long value)
663  {
664  m_pcount = value;
665  }
666 
667  inline long ExtHDU::gcount () const
668  {
669  return m_gcount;
670  }
671 
672  inline void ExtHDU::gcount (long value)
673  {
674  m_gcount = value;
675  }
676 
677  inline int ExtHDU::version () const
678  {
679  return m_version;
680  }
681 
682  inline void ExtHDU::version (int value)
683  {
684  m_version = value;
685  }
686 
687  inline HduType ExtHDU::xtension () const
688  {
689  return m_xtension;
690  }
691 
692  inline void ExtHDU::xtension (HduType value)
693  {
694  m_xtension = value;
695  }
696 
697  inline const String& ExtHDU::missHDU ()
698  {
699  return s_missHDU;
700  }
701 
702  inline void ExtHDU::setMissHDU (const String& value)
703  {
704  s_missHDU = value;
705  }
706 
707 } // namespace CCfits
708 
709 
710 #endif
virtual const ColMap & column() const
return a reference to the multimap containing the columns.
Definition: ExtHDU.cxx:306
void write(const std::vector< long > &first, long nElements, const std::valarray< S > &data, S *nullValue)
Write a set of pixels to an image extension with the first pixel specified by an n-tuple, processing undefined data.
Definition: ExtHDUT.h:426
virtual ~ExtHDU()
destructor
Definition: ExtHDU.cxx:131
void read(std::valarray< S > &image)
Read image data into container.
Definition: ExtHDUT.h:18
virtual void readData(bool readFlag=false, const std::vector< String > &keys=std::vector< String >())=0
read data from HDU depending on readFlag and keys.
HduType xtension() const
return the extension type
Definition: ExtHDU.h:687
virtual long getRowsize() const
return the optimal number of rows to read or write at a time
Definition: ExtHDU.cxx:290
Exception to be thrown on unmatched extension types.
Definition: ExtHDU.h:445
int version() const
return the extension version number.
Definition: ExtHDU.h:677
virtual HDU * clone(FITS *p) const =0
virtual copy constructor
WrongExtensionType(const String &msg, bool silent=true)
Exception ctor, prefixes the string &quot;Fits Error: wrong extension type&quot; before the specific message...
Definition: ExtHDU.cxx:42
virtual long rows() const
return the number of rows in the extension.
Definition: ExtHDU.cxx:235
long bitpix() const
return the data type keyword.
Definition: HDU.h:998
virtual void addColumn(ValueType type, const String &columnName, long repeatWidth, const String &colUnit=String(""), long decimals=-1, size_t columnNumber=0)
add a new column to an existing table HDU.
Definition: ExtHDU.cxx:248
virtual void makeThisCurrent() const
move the fitsfile pointer to this current HDU.
Definition: ExtHDU.cxx:208
Base class for all HDU [Header-Data Unit] objects.
Definition: HDU.h:673
long pcount() const
return required pcount keyword value
Definition: ExtHDU.h:657
Memory object representation of a disk FITS file.
Definition: FITS.h:628
FitsException is the base class for all exceptions thrown by this library.
Definition: FitsError.h:93
base class for all FITS extension HDUs, i.e. Image Extensions and Tables.
Definition: ExtHDU.h:438
ValueType
CCfits value types and their CFITSIO equivalents (in caps)
Definition: CCfits.h:81
std::multimap< std::string, CCfits::Column * > ColMap
Type definition for a table&#39;s column container.
Definition: CCfits.h:142
const String & name() const
return the name of the extension.
Definition: ExtHDU.h:651
bool isCompressed() const
return true if image is stored using compression.
Definition: ExtHDU.cxx:312
long gcount() const
return required gcount keyword value
Definition: ExtHDU.h:667
ExtHDU(const ExtHDU &right)
copy constructor
Definition: ExtHDU.cxx:53
long axes() const
return the number of axes in the HDU data section (always 2 for tables).
Definition: HDU.h:978
virtual void copyColumn(const Column &inColumn, int colIndx, bool insertNewCol=true)
copy a column (from different or same HDU and file) into an existing table HDU.
Definition: ExtHDU.cxx:255
static void readHduName(const fitsfile *fptr, int hduIndex, String &hduName, int &hduVersion)
read extension name.
Definition: ExtHDU.cxx:148
Abstract base class for Column objects.
Definition: Column.h:841
virtual int numCols() const
return the number of Columns in the Table (the TFIELDS keyword).
Definition: ExtHDU.cxx:298
virtual void deleteColumn(const String &columnName)
delete a column in a Table extension by name.
Definition: ExtHDU.cxx:260