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