15 #include "HDUCreator.h"
56 class ImageExt :
public ExtHDU
63 virtual void readData (
bool readFlag =
false,
const std::vector<String>& keys = std::vector<String>());
64 const std::valarray<T>& image ()
const;
65 virtual void zero (
double value);
66 virtual void scale (
double value);
67 virtual double zero ()
const;
68 virtual double scale ()
const;
73 ImageExt (FITSBase* p,
const String &hduName,
bool readDataFlag =
false,
const std::vector<String>& keys = std::vector<String>(),
int version = 1);
74 ImageExt (FITSBase* p,
const String &hduName,
int bpix,
int naxis,
const std::vector<long>& naxes,
int version = 1);
77 virtual void checkExtensionType()
const;
82 virtual void initRead ();
83 virtual std::ostream & put (std::ostream &s)
const;
87 virtual const std::valarray<T>& readImage (
long first,
long nElements, T* nullValue);
91 virtual const std::valarray<T>& readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride, T* nullValue);
95 virtual void writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue = 0);
99 virtual void writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::valarray<T>& inData);
100 const Image<T>& data ()
const;
110 friend class HDUCreator;
115 template <
typename T>
116 inline std::ostream & ImageExt<T>::put (std::ostream &s)
const
118 s <<
"Image Extension:: " <<
" Name: " << name() <<
" Extension: " << xtension()
119 <<
" BITPIX "<< bitpix() <<
'\n';
121 s <<
" Axis Lengths: \n";
122 for (
size_t j =1; j < static_cast<size_t>( axes() ) ; j++)
124 s <<
" Axis: " << j <<
" " << axis(j-1) <<
'\n';
129 s <<
"Image Extension:: Version: " << version() <<
" HDU number: " << index() <<
'\n';
131 s <<
" HISTORY: " << history() <<
'\n';
132 s <<
" COMMENTS: " <<comment() <<
'\n';
134 s <<
"BinTable:: nKeywords: " << keyWord().size() <<
'\n';
139 template <
typename T>
140 inline const Image<T>& ImageExt<T>::data ()
const
147 template <
typename T>
149 : ExtHDU(right), m_data(right.m_data)
153 template <
typename T>
154 ImageExt<T>::ImageExt (FITSBase* p,
const String &hduName,
bool readDataFlag,
const std::vector<String>& keys,
int version)
155 : ExtHDU(p,ImageHdu,hduName,version), m_data()
158 if (readDataFlag || keys.size() ) readData(readDataFlag,keys);
161 template <
typename T>
162 ImageExt<T>::ImageExt (FITSBase* p,
const String &hduName,
int bpix,
int naxis,
const std::vector<long>& naxes,
int version)
163 : ExtHDU(p,ImageHdu,hduName,bpix,naxis,naxes,version), m_data()
169 FITSUtil::CVarray<long> convert;
170 FITSUtil::auto_array_ptr<long>
axis(convert(naxes));
171 static char EXTNAME[] =
"EXTNAME";
172 static char HDUVERS[] =
"HDUVERS";
174 if ( fits_create_img(
fitsPointer(), bpix, naxis,
axis.get(), &status) )
177 throw FitsError(status);
183 const_cast<char*>(hduName.c_str()), comment,&status))
185 throw FitsError(status);
187 if (version != 0 && fits_write_key(
fitsPointer(),Tint,HDUVERS,&version,
188 comment,&status))
throw FitsError(status);
193 template <
typename T>
194 ImageExt<T>::~ImageExt()
199 template <
typename T>
200 void ImageExt<T>::initRead ()
204 template <
typename T>
205 ImageExt<T> * ImageExt<T>::clone (FITSBase* p)
const
208 cloned->parent() = p;
212 template <
typename T>
213 void ImageExt<T>::readData (
bool readFlag,
const std::vector<String>& keys)
220 if ( keys.size() > 0)
222 std::list<string> keyList;
226 for (std::vector<string>::const_iterator j = keys.begin(); j != keys.end(); ++j)
228 keyList.push_back(*j);
230 readKeywords(keyList);
236 FITSUtil::FitsNullValue<T> null;
240 for (
size_t i = 0; i < naxes().size(); i++) nelements *= naxes(i);
241 m_data.readImage(fitsPointer(),first,nelements,&nulval,naxes(),anynul());
246 template <
typename T>
247 const std::valarray<T>& ImageExt<T>::image ()
const
250 return m_data.image();
253 template <
typename T>
254 const std::valarray<T>& ImageExt<T>::readImage (
long first,
long nElements, T* nullValue)
256 checkExtensionType();
257 return m_data.readImage(fitsPointer(),first,nElements,nullValue,naxes(),anynul());
260 template <
typename T>
261 const std::valarray<T>& ImageExt<T>::readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride, T* nullValue)
263 checkExtensionType();
264 return m_data.readImage(fitsPointer(),firstVertex,lastVertex,stride,nullValue,naxes(),anynul());
267 template <
typename T>
268 void ImageExt<T>::writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue)
270 checkExtensionType();
271 m_data.writeImage(fitsPointer(),first,nElements,inData,naxes(),nullValue);
274 template <
typename T>
275 void ImageExt<T>::writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::valarray<T>& inData)
277 checkExtensionType();
278 m_data.writeImage(fitsPointer(),firstVertex,lastVertex,inData,naxes());
281 template <
typename T>
282 void ImageExt<T>::zero (
double value)
285 if (checkImgDataTypeChange(value, scale()))
290 if (fits_update_key(fitsPointer(), Tdouble, BZERO, &value, 0, &status))
291 throw FitsError(status);
292 fits_flush_file(fitsPointer(), &status);
299 string msg(
"CCfits Error: Cannot set BZERO to a value which will change image data\n");
300 msg +=
" from integer type to floating point type.";
301 throw FitsException(msg,silent);
305 template <
typename T>
306 void ImageExt<T>::scale (
double value)
309 if (checkImgDataTypeChange(zero(), value))
314 if (fits_update_key(fitsPointer(), Tdouble, BSCALE, &value, 0, &status))
315 throw FitsError(status);
316 fits_flush_file(fitsPointer(), &status);
323 string msg(
"CCfits Error: Cannot set BSCALE to a value which will change image data\n");
324 msg +=
" from integer type to floating point type.";
325 throw FitsException(msg,silent);
329 template <
typename T>
330 double ImageExt<T>::zero ()
const
336 template <
typename T>
337 double ImageExt<T>::scale ()
const
344 template <
typename T>
345 inline void ImageExt<T>::checkExtensionType()
const
long axis(size_t index) const
return the size of axis numbered index [zero based].
Definition: HDU.h:841
fitsfile * fitsPointer() const
return the fitsfile pointer for the FITS object containing the HDU
Definition: HDU.cxx:309
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
ExtHDU(const ExtHDU &right)
copy constructor
Definition: ExtHDU.cxx:55
virtual double scale() const
return the BSCALE keyword value
Definition: HDU.h:868
virtual double zero() const
return the BZERO keyword value
Definition: HDU.h:878
const string & comment() const
return the comment string previously read by getComment()
Definition: HDU.h:820