00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef IOFITS_H
00032 #define IOFITS_H
00033
00034 #include <iostream>
00035 #include <string>
00036 #include <vector>
00037 #include "AO_cpp.h"
00038 #include "fitsio.h"
00039
00040 namespace Arroyo {
00041
00042 using std::string;
00043 using std::vector;
00044 using std::ostream;
00045 using std::cerr;
00046 using std::endl;
00047
00051
00052 class iofits {
00053
00054 protected:
00055
00057 fitsfile * fp;
00058
00060 string filename;
00061
00063 mutable int status;
00064
00065 private:
00066
00068 char charcomm[256];
00069
00071 char val[256];
00072
00073 public:
00074
00075 enum imagetype { FLOATIMG=-32, USHORTIMG=20, DOUBLEIMG=-64, BYTEIMG=8,
00076 SHORTIMG=16, LONGIMG=32 };
00077
00080 iofits(){fp = NULL; status = 0;};
00081
00084 iofits(const char * infile, int iomode = READONLY);
00085
00088 iofits(const iofits & iof){iofits::operator=(iof);};
00089
00092 virtual ~iofits();
00093
00096 iofits & operator = (const iofits & iof);
00097
00100 void open(const char * infile, int iomode = READONLY);
00101
00104 void close();
00105
00108 void create(const char * infile);
00109
00112 string name() const {return(filename);}
00113
00116 bool key_exists(const char * keyname) const;
00117
00120 void read_record(int record,
00121 string & value) const;
00122
00125 template<class T>
00126 void read_key(const char * keyname,
00127 T & value,
00128 string & comment) const;
00129
00132 template<class T>
00133 void write_key(const char * keyname,
00134 const T & value,
00135 const string & comment);
00136
00139 template<class T>
00140 void update_key(const char * keyname,
00141 const T & value,
00142 const string & comment);
00143
00146 void delete_key(const char * keyname);
00147
00150 void delete_record(int record);
00151
00154 string read_record(int record) const {
00155 char card[FLEN_CARD];
00156 fits_read_record(fp, record, card, &status);
00157 return(string(card));
00158 };
00159
00162 string record_head(int record) const;
00163
00166 string record_val(int record) const;
00167
00170 int get_img_dim() const;
00171
00174 int get_status() const {return(status);};
00175
00178 vector<long> get_img_size() const;
00179
00182 int movabs_hdu(const int & hdunum) const;
00183
00186 int movrel_hdu(const int & hdunum) const;
00187
00190 int get_num_hdus() const;
00191
00194 int get_hdu_num() const;
00195
00198 void create_hdu();
00199
00202 void create_image(const vector<long> & axes, imagetype imgtp);
00203
00206 template<class T>
00207 void create_image(const vector<long> & axes, const T * t);
00208
00211 template<class T>
00212 void read_image(int first, int last, T * pixframe) const;
00213
00216 template<class T>
00217 void write_image(int first, int last, const T * pixframe);
00218
00221 void read_image_header(int & bitpix, vector<long> & axes) const;
00222
00225 void write_image_header(int bitpix, const vector<long> & axes);
00226
00229 void print_header(ostream & os, const char * prefix = "") const;
00230
00232 static int verbose_level;
00233
00234 };
00235
00236 template<> void iofits::read_key(const char * keyname,
00237 bool & value, string & comment) const;
00238 template<> void iofits::read_key(const char * keyname,
00239 string & value, string & comment) const;
00240 template<> void iofits::read_key(const char * keyname,
00241 long & value, string & comment) const;
00242 template<> void iofits::read_key(const char * keyname,
00243 float & value, string & comment) const;
00244 template<> void iofits::read_key(const char * keyname,
00245 double & value, string & comment) const;
00246
00247 template<> void iofits::write_key(const char * keyname,
00248 const bool & value, const string & comment);
00249 template<> void iofits::write_key(const char * keyname,
00250 const string & value, const string & comment);
00251 template<> void iofits::write_key(const char * keyname,
00252 const long & value, const string & comment);
00253 template<> void iofits::write_key(const char * keyname,
00254 const float & value, const string & comment);
00255 template<> void iofits::write_key(const char * keyname,
00256 const double & value, const string & comment);
00257
00258 template<> void iofits::create_image(const vector<long> & axes,
00259 const char * pixframe);
00260 template<> void iofits::create_image(const vector<long> & axes,
00261 const unsigned short * pixframe);
00262 template<> void iofits::create_image(const vector<long> & axes,
00263 const short * pixframe);
00264 template<> void iofits::create_image(const vector<long> & axes,
00265 const long * pixframe);
00266 template<> void iofits::create_image(const vector<long> & axes,
00267 const float * pixframe);
00268 template<> void iofits::create_image(const vector<long> & axes,
00269 const double * pixframe);
00270
00271 template<> void iofits::read_image(int first, int last, char * pixframe) const;
00272 template<> void iofits::read_image(int first, int last, unsigned short * pixframe) const;
00273 template<> void iofits::read_image(int first, int last, short * pixframe) const;
00274 template<> void iofits::read_image(int first, int last, long * pixframe) const;
00275 template<> void iofits::read_image(int first, int last, float * pixframe) const;
00276 template<> void iofits::read_image(int first, int last, double * pixframe) const;
00277
00278 template<> void iofits::write_image(int first, int last, const char * pixframe);
00279 template<> void iofits::write_image(int first, int last, const unsigned short * pixframe);
00280 template<> void iofits::write_image(int first, int last, const short * pixframe);
00281 template<> void iofits::write_image(int first, int last, const long * pixframe);
00282 template<> void iofits::write_image(int first, int last, const float * pixframe);
00283 template<> void iofits::write_image(int first, int last, const double * pixframe);
00284
00285 }
00286
00287 #endif