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