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