CCfits  2.4
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 
421  class ExtHDU : public HDU //## Inherits: <unnamed>%38048213E7A8
422  {
423 
424  public:
425 
426 
427 
428  class WrongExtensionType : public FitsException //## Inherits: <unnamed>%39E61E630349
429  {
430  public:
431  WrongExtensionType (const String& msg, bool silent = true);
432 
433  protected:
434  private:
435  private: //## implementation
436  };
437  ExtHDU(const ExtHDU &right);
438  virtual ~ExtHDU();
439  friend bool operator<(const ExtHDU &left,const ExtHDU &right);
440 
441  friend bool operator>(const ExtHDU &left,const ExtHDU &right);
442 
443  friend bool operator<=(const ExtHDU &left,const ExtHDU &right);
444 
445  friend bool operator>=(const ExtHDU &left,const ExtHDU &right);
446 
447  static void readHduName (const fitsfile* fptr, int hduIndex, String& hduName, int& hduVersion);
448  virtual void readData (bool readFlag = false, const std::vector<String>& keys = std::vector<String>()) = 0;
449  const String& name () const;
450  virtual HDU * clone (FITSBase* p) const = 0;
451  // By all means necessary, set the fitsfile pointer so that
452  // this HDU is the current HDU.
453  //
454  // This would appear to be a good candidate for the public
455  // interface.
456  virtual void makeThisCurrent () const;
457  virtual Column& column (const String& colName, bool caseSensitive = true) const;
458  virtual Column& column (int colIndex) const;
459  virtual long rows () const;
460  virtual void addColumn (ValueType type, const String& columnName, long repeatWidth, const String& colUnit = String(""), long decimals = -1, size_t columnNumber = 0);
461  virtual void deleteColumn (const String& columnName);
462  virtual long getRowsize () const;
463  virtual int numCols () const;
464  virtual const std::map<string, Column*>& column () const;
465 
466  bool isCompressed () const;
467  int version () const;
468  void version (int value);
469  static const String& missHDU ();
470  static void setMissHDU (const String& value);
471 
472  public:
473  // Additional Public Declarations
474 
475  // interface is virtually identical to PHDU. The implementation is
476  // similar apart from a check for wrong extension type.
477 
478 
479 
480 
481  template <typename S>
482  void write(const std::vector<long>& first,
483  long nElements,
484  const std::valarray<S>& data,
485  S* nullValue);
486 
487 
488  template <typename S>
489  void write(long first,
490  long nElements,
491  const std::valarray<S>& data,
492  S* nullValue);
493 
494  template <typename S>
495  void write(const std::vector<long>& first,
496  long nElements,
497  const std::valarray<S>& data);
498 
499 
500  template <typename S>
501  void write(long first,
502  long nElements,
503  const std::valarray<S>& data);
504 
505  template <typename S>
506  void write(const std::vector<long>& firstVertex,
507  const std::vector<long>& lastVertex,
508  const std::valarray<S>& data);
509 
510  // read image data & return the array. Can't return a reference because type
511  // conversion in general requires allocating a new object.
512  // note semantics of reading column data are easily distinguished: they require
513  // the user to perform the operation EXT.column({name,index}).read(...)
514 
515  template <typename S>
516  void read (std::valarray<S>& image) ;
517 
518  template<typename S>
519  void read (std::valarray<S>& image,
520  long first,
521  long nElements,
522  S* nullValue) ;
523 
524  template<typename S>
525  void read (std::valarray<S>& image,
526  const std::vector<long>& first,
527  long nElements,
528  S* nullValue) ;
529 
530  template<typename S>
531  void read (std::valarray<S>& image,
532  const std::vector<long>& firstVertex,
533  const std::vector<long>& lastVertex,
534  const std::vector<long>& stride) ;
535 
536  template<typename S>
537  void read (std::valarray<S>& image,
538  long first,
539  long nElements) ;
540 
541  template<typename S>
542  void read (std::valarray<S>& image,
543  const std::vector<long>& first,
544  long nElements) ;
545 
546  template<typename S>
547  void read (std::valarray<S>& image,
548  const std::vector<long>& firstVertex,
549  const std::vector<long>& lastVertex,
550  const std::vector<long>& stride,
551  S* nullValue) ;
552 
553  protected:
554  // ExtHDU needs a default constructor. This is it.
555  ExtHDU (FITSBase* p, HduType xtype, const String &hduName, int version);
556  // The writing constructor. Forces the user to supply a name
557  // for the HDU
558  ExtHDU (FITSBase* p, HduType xtype, const String &hduName, int bitpix, int naxis, const std::vector<long>& axes, int version);
559  // ExtHDU constructor for getting ExtHDUs by number.
560  // Necessary since EXTNAME is a reserved not required
561  // keyword.
562  ExtHDU (FITSBase* p, HduType xtype, int number);
563 
564  virtual std::ostream & put (std::ostream &s) const = 0;
565  virtual void setColumn (const String& colname, Column* value);
566  virtual void checkExtensionType () const;
567  int getVersion ();
568  long pcount () const;
569  void pcount (long value);
570  long gcount () const;
571  void gcount (long value);
572  HduType xtension () const;
573  void xtension (HduType value);
574 
575  // Additional Protected Declarations
576 
577  private:
578  virtual void initRead () = 0;
579  void checkXtension ();
580 
581  // Additional Private Declarations
582 
583  private: //## implementation
584  // Data Members for Class Attributes
585  long m_pcount;
586  long m_gcount;
587  int m_version;
588  HduType m_xtension;
589  static String s_missHDU;
590 
591  // Data Members for Associations
592  String m_name;
593 
594  // Additional Implementation Declarations
595 
596  };
597 
598  // Class CCfits::ExtHDU::WrongExtensionType
599 
600  // Class CCfits::ExtHDU
601 
602  inline bool operator<(const ExtHDU &left,const ExtHDU &right)
603  {
604  if (left.m_name < right.m_name) return true;
605  if (left.m_name > right.m_name) return false;
606  if (left.m_name == right.m_name)
607  {
608  if (left.m_version < right.m_version) return true;
609  }
610  return false;
611  }
612 
613  inline bool operator>(const ExtHDU &left,const ExtHDU &right)
614  {
615  return !operator<=(left,right);
616  }
617 
618  inline bool operator<=(const ExtHDU &left,const ExtHDU &right)
619  {
620  if (left.m_name <= right.m_name)
621  {
622  if (left.m_version <= right.m_version) return true;
623  }
624  return false;
625  }
626 
627  inline bool operator>=(const ExtHDU &left,const ExtHDU &right)
628  {
629  return !operator<(left,right);
630  }
631 
632 
633  inline const String& ExtHDU::name () const
634  {
635 
636  return m_name;
637  }
638 
639  inline long ExtHDU::pcount () const
640  {
641  return m_pcount;
642  }
643 
644  inline void ExtHDU::pcount (long value)
645  {
646  m_pcount = value;
647  }
648 
649  inline long ExtHDU::gcount () const
650  {
651  return m_gcount;
652  }
653 
654  inline void ExtHDU::gcount (long value)
655  {
656  m_gcount = value;
657  }
658 
659  inline int ExtHDU::version () const
660  {
661  return m_version;
662  }
663 
664  inline void ExtHDU::version (int value)
665  {
666  m_version = value;
667  }
668 
669  inline HduType ExtHDU::xtension () const
670  {
671  return m_xtension;
672  }
673 
674  inline void ExtHDU::xtension (HduType value)
675  {
676  m_xtension = value;
677  }
678 
679  inline const String& ExtHDU::missHDU ()
680  {
681  return s_missHDU;
682  }
683 
684  inline void ExtHDU::setMissHDU (const String& value)
685  {
686  s_missHDU = value;
687  }
688 
689 } // namespace CCfits
690 
691 
692 #endif
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:408
virtual ~ExtHDU()
destructor
Definition: ExtHDU.cxx:135
virtual const std::map< string, Column * > & column() const
return a reference to the array containing the columns.
Definition: ExtHDU.cxx:305
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:669
virtual long getRowsize() const
return the optimal number of rows to read or write at a time
Definition: ExtHDU.cxx:289
Exception to be thrown on unmatched extension types.
Definition: ExtHDU.h:428
int version() const
return the extension version number.
Definition: ExtHDU.h:659
WrongExtensionType(const String &msg, bool silent=true)
Exception ctor, prefixes the string "Fits Error: wrong extension type" before the specific message...
Definition: ExtHDU.cxx:44
virtual long rows() const
return the number of rows in the extension.
Definition: ExtHDU.cxx:239
long bitpix() const
return the data type keyword.
Definition: HDU.h:858
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:252
virtual HDU * clone(FITSBase *p) const =0
virtual copy constructor
virtual void makeThisCurrent() const
move the fitsfile pointer to this current HDU.
Definition: ExtHDU.cxx:212
Base class for all HDU [Header-Data Unit] objects.
Definition: HDU.h:543
long pcount() const
return required pcount keyword value
Definition: ExtHDU.h:639
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:421
ValueType
CCfits value types and their CFITSIO equivalents (in caps)
Definition: CCfits.h:79
const String & name() const
return the name of the extension.
Definition: ExtHDU.h:633
bool isCompressed() const
return true if image is stored using compression.
Definition: ExtHDU.cxx:311
long gcount() const
return required gcount keyword value
Definition: ExtHDU.h:649
ExtHDU(const ExtHDU &right)
copy constructor
Definition: ExtHDU.cxx:55
long axes() const
return the number of axes in the HDU data section (always 2 for tables).
Definition: HDU.h:835
static void readHduName(const fitsfile *fptr, int hduIndex, String &hduName, int &hduVersion)
read extension name.
Definition: ExtHDU.cxx:152
Abstract base class for Column objects.
Definition: Column.h:827
virtual int numCols() const
return the number of Columns in the Table (the TFIELDS keyword).
Definition: ExtHDU.cxx:297
virtual void deleteColumn(const String &columnName)
delete a column in a Table extension by name.
Definition: ExtHDU.cxx:259