Column.h

00001 //   Read the documentation to learn more about C++ code generator
00002 //   versioning.
00003 //      This is version 1.7 release dated June 2007
00004 //      Astrophysics Science Division,
00005 //      NASA/ Goddard Space Flight Center
00006 //      HEASARC
00007 //      http://heasarc.gsfc.nasa.gov
00008 //      e-mail: ccfits@legacy.gsfc.nasa.gov
00009 //
00010 //      Original author: Ben Dorman, L3-Communications EER Systems Inc.
00011 
00012 #ifndef COLUMN_H
00013 #define COLUMN_H 1
00014 #include <iostream>
00015 
00016 // FitsError
00017 #include "FitsError.h"
00018 // CCfitsHeader
00019 #include "CCfits.h"
00020 // FITSUtil
00021 #include "FITSUtil.h"
00022 // Table
00023 #include "Table.h"
00024 
00025 #include <complex>
00026 
00027 
00028 namespace CCfits {
00029 
00030 
00031 
00758   class Column 
00759   {
00760 
00761     public:
00762 
00763 
00764 
00765       class RangeError : public FitsException  //## Inherits: <unnamed>%3946526D031A
00766       {
00767         public:
00768             RangeError (const String& msg, bool silent = true);
00769 
00770         protected:
00771         private:
00772         private: //## implementation
00773       };
00774 
00775 
00776 
00777       class InvalidDataType : public FitsException  //## Inherits: <unnamed>%3947CF30033E
00778       {
00779         public:
00780             InvalidDataType (const String& str = string(), bool silent = true);
00781 
00782         protected:
00783         private:
00784         private: //## implementation
00785       };
00786 
00787 
00788 
00789       class InvalidRowParameter : public FitsException  //## Inherits: <unnamed>%39B5310F01A0
00790       {
00791         public:
00792             InvalidRowParameter (const String& diag, bool silent = true);
00793 
00794         protected:
00795         private:
00796         private: //## implementation
00797       };
00798 
00799 
00800 
00801       class WrongColumnType : public FitsException  //## Inherits: <unnamed>%39B545780082
00802       {
00803         public:
00804             WrongColumnType (const String& diag, bool silent = true);
00805 
00806         protected:
00807         private:
00808         private: //## implementation
00809       };
00810 
00811 
00812 
00813       class UnspecifiedLengths : public FitsException  //## Inherits: <unnamed>%3A018C9D007D
00814       {
00815         public:
00816             UnspecifiedLengths (const String& diag, bool silent = true);
00817 
00818         protected:
00819         private:
00820         private: //## implementation
00821       };
00822 
00823 
00824 
00825       class InvalidRowNumber : public FitsException  //## Inherits: <unnamed>%3B0A850F0307
00826       {
00827         public:
00828             InvalidRowNumber (const String& diag, bool silent = true);
00829 
00830         protected:
00831         private:
00832         private: //## implementation
00833       };
00834 
00835 
00836 
00837       class InsufficientElements : public FitsException  //## Inherits: <unnamed>%3B0BE611010A
00838       {
00839         public:
00840             InsufficientElements (const String& msg, bool silent = true);
00841 
00842         protected:
00843         private:
00844         private: //## implementation
00845       };
00846 
00847 
00848 
00849       class NoNullValue : public FitsException  //## Inherits: <unnamed>%3B0D589A0092
00850       {
00851         public:
00852             NoNullValue (const String& diag, bool silent = true);
00853 
00854         protected:
00855         private:
00856         private: //## implementation
00857       };
00858 
00859 
00860 
00861       class InvalidNumberOfRows : public FitsException  //## Inherits: <unnamed>%3B20EB8B0205
00862       {
00863         public:
00864             InvalidNumberOfRows (size_t number, bool silent = true);
00865 
00866         protected:
00867         private:
00868         private: //## implementation
00869       };
00870         Column(const Column &right);
00871         virtual ~Column();
00872         bool operator==(const Column &right) const;
00873 
00874         bool operator!=(const Column &right) const;
00875 
00876         virtual void readData (long firstRow, long nelements, long firstElem = 1) = 0;
00877         //      Virtual copy constructor.
00878         virtual Column * clone () const = 0;
00879         int rows () const;
00880         void setDisplay ();
00881         virtual void setDimen ();
00882         friend std::ostream& operator << (std::ostream& s, const Column& right);
00883         //      Inequality operators for imposing sort order on columns.
00884         friend bool operator < (const Column& left, const Column& right);
00885         //      Inequality operators for imposing sort order on columns.
00886         friend bool operator > (const Column& left, const Column& right);
00887         void setLimits (ValueType type);
00888         void unit (const String& value);
00889         int index () const;
00890         void index (int value);
00891         bool isRead () const;
00892         void isRead (bool value);
00893         long width () const;
00894         void width (long value);
00895         size_t repeat () const;
00896         bool varLength () const;
00897         double scale () const;
00898         void scale (double value);
00899         double zero () const;
00900         void zero (double value);
00901         const String& display () const;
00902         const String& dimen () const;
00903         void dimen (const String& value);
00904         ValueType type () const;
00905         void type (ValueType value);
00906         static const String& TFORM ();
00907         static const String& TDISP ();
00908         static const String& TSCAL ();
00909         static const String& TZERO ();
00910         static const String& TDIM ();
00911         const String& format () const;
00912         const String& unit () const;
00913         const String& name () const;
00914 
00915     public:
00916       // Additional Public Declarations
00917 
00918         // scalar column interface. Column's Data Member is a std::vector<T>,
00919         // input data is std::vector<S>, std::valarray<S> or S* where S is not
00920         // in general the same as T.
00921 
00922         template <typename S>                   
00923         void write (const std::vector<S>& indata, long firstRow);
00924 
00925         void write (const std::vector<std::complex<float> >& indata, long firstRow);
00926 
00927         void write (const std::vector<std::complex<double> >& indata, long firstRow);
00928 
00929         template <typename S>                   
00930         void write (const std::valarray<S>& indata, long firstRow);
00931 
00932         void write (const std::valarray<std::complex<float> >& indata, long firstRow);
00933 
00934         void write (const std::valarray<std::complex<double> >& indata, long firstRow);
00935 
00936         template <typename S>                   
00937         void write (S* indata, long nRows, long firstRow);
00938 
00939 
00940         template <typename S>                   
00941         void write (const std::vector<S>& indata, long firstRow, S* nullValue);
00942 
00943         template <typename S>                   
00944         void write (const std::valarray<S>& indata, long firstRow, S* nullValue);
00945 
00946         template <typename S>                   
00947         void write (S* indata, long nRows, long firstRow, S* nullValue);        
00948         // vector column interface. We provide an interface that allows input of a vector, valarray and C-array.
00949         // there are versions that write variable numbers of elements per row as specified
00950         // in the vectorLengths argument. The user also can directly write a vector<valarray<T> >
00951         // object which is how the data are stored in the ColumnVectorData object. 
00952         // this last one is also used internally to implement the variable lengths versions.
00953 
00954         // fixed length write to binary table from valarray.
00955 
00956 
00957         template <typename S>
00958         void write (const std::valarray<S>& indata, long nRows, long firstRow);
00959 
00960         void write (const std::valarray<std::complex<float> >& indata, long nRows, long firstRow);
00961 
00962         void write (const std::valarray<std::complex<double> >& indata, long nRows, long firstRow);
00963 
00964 
00965         template <typename S>
00966         void write (const std::vector<S>& indata, long nRows, long firstRow);
00967 
00968         void write (const std::vector<std::complex<float> >& indata, long nRows, long firstRow);
00969 
00970         void write (const std::vector<std::complex<double> >& indata, long nRows, long firstRow);
00971 
00972 
00973 
00974         template <typename S>
00975         void write (S* indata, long nElements, long nRows, long firstRow);
00976 
00977 
00978         template <typename S>
00979         void write (const std::valarray<S>& indata, long nRows, long firstRow, S* nullValue);
00980 
00981 
00982         template <typename S>
00983         void write (const std::vector<S>& indata, long nRows, long firstRow, S* nullValue);
00984 
00985         template <typename S>
00986         void write (S* indata, long nElements, long nRows, long firstRow, S* nullValue);
00987 
00988         // variable-length write to vector column from valarray or vector.
00989 
00990         template <typename S>
00991         void write (const std::valarray<S>& indata,  
00992                         const std::vector<long>& vectorLengths, 
00993                         long firstRow);        
00994 
00995         void write (const std::valarray<std::complex<float> >& indata,  
00996                         const std::vector<long>& vectorLengths, 
00997                         long firstRow);        
00998 
00999         void write (const std::valarray<std::complex<double> >& indata,  
01000                         const std::vector<long>& vectorLengths, 
01001                         long firstRow);      
01002 
01003         template <typename S>
01004         void write (const std::vector<S>& indata, 
01005                         const std::vector<long>& vectorLengths, 
01006                         long firstRow);
01007 
01008 
01009 
01010         void write (const std::vector<std::complex<float> >& indata, 
01011                         const std::vector<long>& vectorLengths, 
01012                         long firstRow);
01013 
01014         void write (const std::vector<std::complex<double> >& indata, 
01015                         const std::vector<long>& vectorLengths, 
01016                         long firstRow);
01017 
01018         template <typename S>
01019         void write (S* indata, long nElements,  
01020                         const std::vector<long>& vectorLengths, 
01021                         long firstRow);
01022 
01023         template <typename S>
01024         void writeArrays (const std::vector<std::valarray<S> >& indata, long firstRow); 
01025 
01026         void writeArrays (const std::vector<std::valarray<std::complex<float> > >& indata, long firstRow); 
01027 
01028         void writeArrays (const std::vector<std::valarray<std::complex<double> > >& indata, long firstRow); 
01029 
01030         template <typename S>
01031         void writeArrays (const std::vector<std::valarray<S> >& indata, long firstRow, S* nullValue);  
01032 
01033         // get specified elements of a scalar column, returned as a std::vector
01034         // S is NOT the type of the column data itself, it is the type of the returned
01035         // data.
01036 
01037         template <typename S>
01038         void read(std::vector<S>& vals, long first, long last) ;
01039 
01040         // VC++, at least, won't compile these as template covering std::complex instances.
01041         void read(std::vector< std::complex<float> >& , long first, long last);
01042 
01043         void read(std::vector< std::complex<double> >& , long first, long last);
01044 
01045         void read(std::vector<String>& vals, long first, long last);
01046 
01047         // return a set of rows from a scalar column as a valarray.
01048         template <typename S>
01049         void read(std::valarray<S>& vals, long first, long last) ;
01050 
01051         void read(std::valarray<std::complex<float> >& vals, long first, long last) ;
01052 
01053         void read(std::valarray<std::complex<double> >& vals, long first, long last) ;
01054 
01055         // return a single  row of a vector column.
01056         template <typename S>
01057         void read(std::valarray<S>& vals, long rows) ;
01058 
01059         void read(std::valarray<std::complex<float> >& vals, long rows) ;
01060 
01061         void read(std::valarray<std::complex<double> >& vals, long rows) ;
01062 
01063         // get a set of rows from a vector column.
01064         template <typename S>
01065         void readArrays(std::vector<std::valarray<S> >& vals, long first, long last) ;
01066 
01067         void readArrays(std::vector<std::valarray<std::complex<float> > >& vals, long first, long last) ;
01068 
01069         void readArrays(std::vector<std::valarray<std::complex<double> > >& vals, long first, long last) ;
01070 
01071         // nullValue has no meaning when the target column has floating point/std::complex
01072         // type. Also, implict conversion of std::complex to pure real is not supported
01073         // by cfitsio.
01074 
01075         template <typename S>
01076         void read(std::vector<S>& vals, long first, long last, S* nullValue) ;
01077 
01078         // return a set of rows from a scalar column as a valarray.
01079         template <typename S>
01080         void read(std::valarray<S>& vals, long first, long last, S* nullValue);
01081 
01082         // return a single  row of a vector column.
01083         template <typename S>
01084         void read(std::valarray<S>& vals, long rows, S* nullValue) ;
01085 
01086         // get a set of rows from a vector column.
01087         template <typename S>
01088         void readArrays(std::vector<std::valarray<S> >& vals, long first, long last, S* nullValue);
01089 
01090         // add a null value to the column 
01091         template <typename T>
01092         void addNullValue(T nullVal);
01093 
01094         void write (const std::vector<String>& indata, long firstRow);
01095 
01096         friend void Table::insertRows(long first, long number);
01097 
01098         friend void Table::deleteRows(long first, long number);
01099 
01100         friend void Table::deleteRows(const std::vector<long>& rowList);
01101 
01102         friend void Table::initRead();
01103 
01104         friend void Table::reindex();
01105     protected:
01106         Column (int columnIndex,        // The column index, i.e. the integer n in the keyword TCOLn
01107         const String &columnName,       // The column name, curiously TTYPEn
01108         ValueType type, const String &format,   // The TFORMn keyword.
01109         const String &unit,     // The TUNITn keyword
01110         Table* p,       // ! The Table containing the Column object
01111         int rpt = 1, long w = 1, const String &comment = "");
01112         Column (Table* p = 0);
01113 
01114         virtual bool compare (const Column &right) const;
01115         fitsfile* fitsPointer ();
01116         //      Protected method to set the current HDU to be the one containing this Column object. For use in
01117         //      public read/write methods to ensure that data regarding numbers of rows and width relate to the
01118         //      right HDU
01119         void makeHDUCurrent ();
01120         virtual std::ostream& put (std::ostream& s) const;
01121         Table* parent () const;
01122         void varLength (bool value);
01123         static const String& TBCOL ();
01124         static const String& TTYPE ();
01125         static const String& TUNIT ();
01126         static const String& TNULL ();
01127         static const String& TLMIN ();
01128         static const String& TLMAX ();
01129         static const String& TDMAX ();
01130         static const String& TDMIN ();
01131         Table* parent ();
01132         static const std::vector<String>& columnKeys ();
01133         const String& comment () const;
01134 
01135       // Additional Protected Declarations
01136 
01137     private:
01138         Column & operator=(const Column &right);
01139 
01140         //      Insert one or more blank rows into a FITS column.
01141         virtual void insertRows (long first, long number = 1) = 0;
01142         virtual void deleteRows (long first, long number = 1) = 0;
01143         static void loadColumnKeys ();
01144         void name (const String& value);
01145         void format (const String& value);
01146         long numberOfElements (long& first, long& last);
01147 
01148       // Data Members for Class Attributes
01149         static const String s_TBCOL;
01150         static const String s_TTYPE;
01151         static const String s_TFORM;
01152         static const String s_TDISP;
01153         static const String s_TUNIT;
01154         static const String s_TSCAL;
01155         static const String s_TZERO;
01156         static const String s_TDIM;
01157         static const String s_TNULL;
01158         static const String s_TLMIN;
01159         static const String s_TLMAX;
01160         static const String s_TDMAX;
01161         static const String s_TDMIN;
01162 
01163       // Additional Private Declarations
01164 
01165     private: //## implementation
01166       // Data Members for Class Attributes
01167         int m_index;
01168         bool m_isRead;
01169         long m_width;
01170         size_t m_repeat;
01171         bool m_varLength;
01172         double m_scale;
01173         double m_zero;
01174         String m_display;
01175         String m_dimen;
01176         ValueType m_type;
01177         static const short LLIMITSHORT;
01178         static const long LLIMITLONG;
01179         static const unsigned short LLIMITUSHORT;
01180         static const unsigned long LLIMITULONG;
01181         static const unsigned char LLIMITUCHAR;
01182         static const float LLIMITFLOAT;
01183         static const double LLIMITDOUBLE;
01184         static const short ULIMITSHORT;
01185         static const long ULIMITLONG;
01186         static const unsigned short ULIMITUSHORT;
01187         static const unsigned long ULIMITULONG;
01188         static const unsigned char ULIMITUCHAR;
01189         static const float ULIMITFLOAT;
01190         static const double ULIMITDOUBLE;
01191         static const int LLIMITINT;
01192         static const int ULIMITINT;
01193         static const unsigned int LLIMITUINT;
01194         static const unsigned int ULIMITUINT;
01195         static const LONGLONG LLIMITLONGLONG;
01196         static const LONGLONG ULIMITLONGLONG;
01197 
01198       // Data Members for Associations
01199         Table* m_parent;
01200         static std::vector<String> s_columnKeys;
01201         String m_comment;
01202         String m_format;
01203         String m_unit;
01204         String m_name;
01205 
01206       // Additional Implementation Declarations
01207 
01208   };
01209 
01210   // Class CCfits::Column::RangeError 
01211 
01212   // Class CCfits::Column::InvalidDataType 
01213 
01214   // Class CCfits::Column::InvalidRowParameter 
01215 
01216   // Class CCfits::Column::WrongColumnType 
01217 
01218   // Class CCfits::Column::UnspecifiedLengths 
01219 
01220   // Class CCfits::Column::InvalidRowNumber 
01221 
01222   // Class CCfits::Column::InsufficientElements 
01223 
01224   // Class CCfits::Column::NoNullValue 
01225 
01226   // Class CCfits::Column::InvalidNumberOfRows 
01227 
01228   // Class CCfits::Column 
01229 
01230   inline void Column::setDimen ()
01231   {
01232   // default implementation: do nothing. Overridden by ColumnVectorData.
01233   }
01234 
01235   inline std::ostream& operator << (std::ostream& s, const Column& right)
01236   {
01237 
01238     return right.put(s);
01239   }
01240 
01241   inline bool operator < (const Column& left, const Column& right)
01242   {
01243 
01244     return left.m_index < right.m_index;
01245   }
01246 
01247   inline bool operator > (const Column& left, const Column& right)
01248   {
01249 
01250     return left.m_index > right.m_index;
01251   }
01252 
01253   inline int Column::index () const
01254   {
01255     return m_index;
01256   }
01257 
01258   inline void Column::index (int value)
01259   {
01260     m_index = value;
01261   }
01262 
01263   inline bool Column::isRead () const
01264   {
01265     return m_isRead;
01266   }
01267 
01268   inline void Column::isRead (bool value)
01269   {
01270     m_isRead = value;
01271   }
01272 
01273   inline long Column::width () const
01274   {
01275     return m_width;
01276   }
01277 
01278   inline void Column::width (long value)
01279   {
01280     m_width = value;
01281   }
01282 
01283   inline size_t Column::repeat () const
01284   {
01285     return m_repeat;
01286   }
01287 
01288   inline bool Column::varLength () const
01289   {
01290     return m_varLength;
01291   }
01292 
01293   inline double Column::scale () const
01294   {
01295     return m_scale;
01296   }
01297 
01298   inline void Column::scale (double value)
01299   {
01300     m_scale = value;
01301     int status(0);
01302     if (fits_set_tscale(fitsPointer(),m_index,value,m_zero,&status)) throw FitsError(status);
01303   }
01304 
01305   inline double Column::zero () const
01306   {
01307     return m_zero;
01308   }
01309 
01310   inline void Column::zero (double value)
01311   {
01312     m_zero = value;
01313   }
01314 
01315   inline const String& Column::display () const
01316   {
01317     return m_display;
01318   }
01319 
01320   inline const String& Column::dimen () const
01321   {
01322     return m_dimen;
01323   }
01324 
01325   inline void Column::dimen (const String& value)
01326   {
01327     m_dimen = value;
01328   }
01329 
01330   inline ValueType Column::type () const
01331   {
01332     return m_type;
01333   }
01334 
01335   inline void Column::type (ValueType value)
01336   {
01337     m_type = value;
01338   }
01339 
01340   inline const String& Column::TBCOL ()
01341   {
01342     return s_TBCOL;
01343   }
01344 
01345   inline const String& Column::TTYPE ()
01346   {
01347     return s_TTYPE;
01348   }
01349 
01350   inline const String& Column::TFORM ()
01351   {
01352     return s_TFORM;
01353   }
01354 
01355   inline const String& Column::TDISP ()
01356   {
01357     return s_TDISP;
01358   }
01359 
01360   inline const String& Column::TUNIT ()
01361   {
01362     return s_TUNIT;
01363   }
01364 
01365   inline const String& Column::TSCAL ()
01366   {
01367     return s_TSCAL;
01368   }
01369 
01370   inline const String& Column::TZERO ()
01371   {
01372     return s_TZERO;
01373   }
01374 
01375   inline const String& Column::TDIM ()
01376   {
01377     return s_TDIM;
01378   }
01379 
01380   inline const String& Column::TNULL ()
01381   {
01382     return s_TNULL;
01383   }
01384 
01385   inline const String& Column::TLMIN ()
01386   {
01387     return s_TLMIN;
01388   }
01389 
01390   inline const String& Column::TLMAX ()
01391   {
01392     return s_TLMAX;
01393   }
01394 
01395   inline const String& Column::TDMAX ()
01396   {
01397     return s_TDMAX;
01398   }
01399 
01400   inline const String& Column::TDMIN ()
01401   {
01402     return s_TDMIN;
01403   }
01404 
01405   inline Table* Column::parent ()
01406   {
01407     return m_parent;
01408   }
01409 
01410   inline const std::vector<String>& Column::columnKeys ()
01411   {
01412     return s_columnKeys;
01413   }
01414 
01415   inline const String& Column::comment () const
01416   {
01417     return m_comment;
01418   }
01419 
01420   inline const String& Column::format () const
01421   {
01422     return m_format;
01423   }
01424 
01425   inline const String& Column::unit () const
01426   {
01427     return m_unit;
01428   }
01429 
01430   inline const String& Column::name () const
01431   {
01432     return m_name;
01433   }
01434 
01435 } // namespace CCfits
01436 
01437 
01438 #endif

Generated on Thu Jun 28 11:49:08 2007 for CCfits by  doxygen 1.4.7