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 "FitsError.h"
00018
00019 #include "CCfits.h"
00020
00021 #include "FITSUtil.h"
00022
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
00766 {
00767 public:
00768 RangeError (const String& msg, bool silent = true);
00769
00770 protected:
00771 private:
00772 private:
00773 };
00774
00775
00776
00777 class InvalidDataType : public FitsException
00778 {
00779 public:
00780 InvalidDataType (const String& str = string(), bool silent = true);
00781
00782 protected:
00783 private:
00784 private:
00785 };
00786
00787
00788
00789 class InvalidRowParameter : public FitsException
00790 {
00791 public:
00792 InvalidRowParameter (const String& diag, bool silent = true);
00793
00794 protected:
00795 private:
00796 private:
00797 };
00798
00799
00800
00801 class WrongColumnType : public FitsException
00802 {
00803 public:
00804 WrongColumnType (const String& diag, bool silent = true);
00805
00806 protected:
00807 private:
00808 private:
00809 };
00810
00811
00812
00813 class UnspecifiedLengths : public FitsException
00814 {
00815 public:
00816 UnspecifiedLengths (const String& diag, bool silent = true);
00817
00818 protected:
00819 private:
00820 private:
00821 };
00822
00823
00824
00825 class InvalidRowNumber : public FitsException
00826 {
00827 public:
00828 InvalidRowNumber (const String& diag, bool silent = true);
00829
00830 protected:
00831 private:
00832 private:
00833 };
00834
00835
00836
00837 class InsufficientElements : public FitsException
00838 {
00839 public:
00840 InsufficientElements (const String& msg, bool silent = true);
00841
00842 protected:
00843 private:
00844 private:
00845 };
00846
00847
00848
00849 class NoNullValue : public FitsException
00850 {
00851 public:
00852 NoNullValue (const String& diag, bool silent = true);
00853
00854 protected:
00855 private:
00856 private:
00857 };
00858
00859
00860
00861 class InvalidNumberOfRows : public FitsException
00862 {
00863 public:
00864 InvalidNumberOfRows (size_t number, bool silent = true);
00865
00866 protected:
00867 private:
00868 private:
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
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
00884 friend bool operator < (const Column& left, const Column& right);
00885
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
00917
00918
00919
00920
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
00949
00950
00951
00952
00953
00954
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
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
01034
01035
01036
01037 template <typename S>
01038 void read(std::vector<S>& vals, long first, long last) ;
01039
01040
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
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
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
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
01072
01073
01074
01075 template <typename S>
01076 void read(std::vector<S>& vals, long first, long last, S* nullValue) ;
01077
01078
01079 template <typename S>
01080 void read(std::valarray<S>& vals, long first, long last, S* nullValue);
01081
01082
01083 template <typename S>
01084 void read(std::valarray<S>& vals, long rows, S* nullValue) ;
01085
01086
01087 template <typename S>
01088 void readArrays(std::vector<std::valarray<S> >& vals, long first, long last, S* nullValue);
01089
01090
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,
01107 const String &columnName,
01108 ValueType type, const String &format,
01109 const String &unit,
01110 Table* p,
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
01117
01118
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
01136
01137 private:
01138 Column & operator=(const Column &right);
01139
01140
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
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
01164
01165 private:
01166
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
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
01207
01208 };
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230 inline void Column::setDimen ()
01231 {
01232
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 }
01436
01437
01438 #endif