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