15 #include "HDUCreator.h"
53 class ImageExt :
public ExtHDU
60 virtual void readData (
bool readFlag =
false,
const std::vector<String>& keys = std::vector<String>());
61 virtual void zero (
double value);
62 virtual void scale (
double value);
63 virtual double zero ()
const;
64 virtual double scale ()
const;
65 virtual void suppressScaling(
bool toggle =
true);
66 virtual void resetImageRead ();
71 ImageExt (FITS* p,
const String &hduName,
bool readDataFlag =
false,
const std::vector<String>& keys = std::vector<String>(),
int version = 1);
72 ImageExt (FITS* p,
const String &hduName,
int bpix,
int naxis,
const std::vector<long>& naxes,
int version = 1);
75 virtual void checkExtensionType()
const;
80 virtual void initRead ();
81 virtual std::ostream & put (std::ostream &s)
const;
82 const std::valarray<T>& readImage (
long first,
long nElements, T* nullValue);
83 const std::valarray<T>& readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,T* nullValue);
84 void writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue = 0);
85 void writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::valarray<T>& inData);
86 const Image<T>& data ()
const;
96 friend class HDUCreator;
101 template <
typename T>
102 inline std::ostream & ImageExt<T>::put (std::ostream &s)
const
104 s <<
"Image Extension:: " <<
" Name: " << name() <<
" Extension: " << xtension()
105 <<
" BITPIX "<< bitpix() <<
'\n';
107 s <<
" Axis Lengths: \n";
108 for (
size_t j =1; j <= static_cast<size_t>( axes() ) ; j++)
110 s <<
" Axis: " << j <<
" " << axis(j-1) <<
'\n';
115 s <<
"Image Extension:: Version: " << version() <<
" HDU number: " << index() <<
'\n';
117 s <<
" HISTORY: " << history() <<
'\n';
118 s <<
" COMMENTS: " <<comment() <<
'\n';
120 s <<
"BinTable:: nKeywords: " << keyWord().size() <<
'\n';
125 template <
typename T>
126 inline const Image<T>& ImageExt<T>::data ()
const
133 template <
typename T>
135 : ExtHDU(right), m_data(right.m_data)
139 template <
typename T>
140 ImageExt<T>::ImageExt (FITS* p,
const String &hduName,
bool readDataFlag,
const std::vector<String>& keys,
int version)
141 : ExtHDU(p,ImageHdu,hduName,version), m_data()
144 if (readDataFlag || keys.size() ) readData(readDataFlag,keys);
147 template <
typename T>
148 ImageExt<T>::ImageExt (FITS* p,
const String &hduName,
int bpix,
int naxis,
const std::vector<long>& naxes,
int version)
149 : ExtHDU(p,ImageHdu,hduName,bpix,naxis,naxes,version), m_data()
155 FITSUtil::CVarray<long> convert;
156 FITSUtil::auto_array_ptr<long> axis(convert(naxes));
157 static char EXTNAME[] =
"EXTNAME";
158 static char HDUVERS[] =
"HDUVERS";
160 if ( fits_create_img(fitsPointer(), bpix, naxis, axis.get(), &status) )
163 throw FitsError(status);
168 if (fits_write_key(fitsPointer(),Tstring,EXTNAME,
169 const_cast<char*
>(hduName.c_str()), comment,&status))
171 throw FitsError(status);
173 if (version != 0 && fits_write_key(fitsPointer(),Tint,HDUVERS,&version,
174 comment,&status))
throw FitsError(status);
179 template <
typename T>
180 ImageExt<T>::~ImageExt()
185 template <
typename T>
186 void ImageExt<T>::initRead ()
190 template <
typename T>
194 cloned->parent() = p;
198 template <
typename T>
199 void ImageExt<T>::readData (
bool readFlag,
const std::vector<String>& keys)
206 if ( keys.size() > 0)
208 std::list<string> keyList;
212 for (std::vector<string>::const_iterator j = keys.begin(); j != keys.end(); ++j)
214 keyList.push_back(*j);
216 readKeywords(keyList);
222 FITSUtil::FitsNullValue<T>
null;
226 for (
size_t i = 0; i < naxes().size(); i++) nelements *= naxes(i);
227 m_data.readImage(fitsPointer(),first,nelements,&nulval,naxes(),anynul());
233 template <
typename T>
234 const std::valarray<T>& ImageExt<T>::readImage (
long first,
long nElements,T* nullValue)
236 checkExtensionType();
237 return m_data.readImage(fitsPointer(),first,nElements,nullValue,naxes(),anynul());
240 template <
typename T>
241 const std::valarray<T>& ImageExt<T>::readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride, T* nullValue)
243 checkExtensionType();
244 return m_data.readImage(fitsPointer(),firstVertex,lastVertex,stride,nullValue,naxes(),anynul());
247 template <
typename T>
248 void ImageExt<T>::writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue)
250 checkExtensionType();
252 m_data.writeImage(fitsPointer(),first,nElements,inData,naxes(),newNaxisN,nullValue);
254 naxes(naxes().size()-1,newNaxisN);
257 template <
typename T>
258 void ImageExt<T>::writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::valarray<T>& inData)
260 checkExtensionType();
262 m_data.writeImage(fitsPointer(),firstVertex,lastVertex,inData,naxes(),newNaxisN);
264 naxes(naxes().size()-1,newNaxisN);
267 template <
typename T>
268 void ImageExt<T>::zero (
double value)
271 if (checkImgDataTypeChange(value, scale()))
276 if (fits_update_key(fitsPointer(), Tdouble, BZERO, &value, 0, &status))
277 throw FitsError(status);
278 fits_flush_file(fitsPointer(), &status);
285 string msg(
"CCfits Error: Cannot set BZERO to a value which will change image data\n");
286 msg +=
" from integer type to floating point type.";
287 throw FitsException(msg,silent);
289 m_data.scalingHasChanged();
292 template <
typename T>
293 void ImageExt<T>::scale (
double value)
296 if (checkImgDataTypeChange(zero(), value))
301 if (fits_update_key(fitsPointer(), Tdouble, BSCALE, &value, 0, &status))
302 throw FitsError(status);
303 fits_flush_file(fitsPointer(), &status);
310 string msg(
"CCfits Error: Cannot set BSCALE to a value which will change image data\n");
311 msg +=
" from integer type to floating point type.";
312 throw FitsException(msg,silent);
314 m_data.scalingHasChanged();
317 template <
typename T>
318 double ImageExt<T>::zero ()
const
324 template <
typename T>
325 double ImageExt<T>::scale ()
const
331 template <
typename T>
332 void ImageExt<T>::suppressScaling (
bool toggle)
334 HDU::suppressScaling(toggle);
335 m_data.scalingHasChanged();
338 template <
typename T>
339 void ImageExt<T>::resetImageRead()
345 template <
typename T>
346 inline void ImageExt<T>::checkExtensionType()
const
ExtHDU(const ExtHDU &right)
copy constructor
Definition: ExtHDU.cxx:53
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26