/usr/include/CCfits/ImageExt.h is in libccfits-dev 2.4+dfsg-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | // Astrophysics Science Division,
// NASA/ Goddard Space Flight Center
// HEASARC
// http://heasarc.gsfc.nasa.gov
// e-mail: ccfits@legacy.gsfc.nasa.gov
//
// Original author: Ben Dorman
#ifndef IMAGEEXT_H
#define IMAGEEXT_H 1
// ExtHDU
#include "ExtHDU.h"
// HDUCreator
#include "HDUCreator.h"
// Image
#include "Image.h"
// FITSUtil
#include "FITSUtil.h"
#ifdef _MSC_VER
#include "MSconfig.h" // for truncation warning
#endif
namespace CCfits {
/*! \class ImageExt<T>
ImageExt<T> is a subclass of ExtHDU that contains image data
of type T.
*/
/*! \fn virtual ImageExt<T>::~ImageExt();
\brief destructor
*/
/*! \fn virtual void ImageExt<T>::readData (bool readFlag = false, const std::vector<String>& keys = std::vector<String>());
\brief read Image extension HDU data
Called by FITS ctor, not intended for general use.
parameters control how much gets read on initialization.
\param readFlag read the image data if true
\param key a vector of strings of keyword names to be read from the HDU
*/
/*! \fn const std::valarray<T>& ImageExt<T>::image() const;
\brief return the image data
*/
template <typename T>
class ImageExt : public ExtHDU //## Inherits: <unnamed>%3804A11121D8
{
public:
virtual ~ImageExt();
virtual ImageExt<T> * clone (FITSBase* p) const;
virtual void readData (bool readFlag = false, const std::vector<String>& keys = std::vector<String>());
const std::valarray<T>& image () const;
virtual void zero (double value);
virtual void scale (double value);
virtual double zero () const;
virtual double scale () const;
// Additional Public Declarations
protected:
ImageExt (FITSBase* p, const String &hduName, bool readDataFlag = false, const std::vector<String>& keys = std::vector<String>(), int version = 1);
ImageExt (FITSBase* p, const String &hduName, int bpix, int naxis, const std::vector<long>& naxes, int version = 1);
// Additional Protected Declarations
virtual void checkExtensionType() const;
private:
ImageExt(const ImageExt< T > &right);
ImageExt< T > & operator=(const ImageExt< T > &right);
virtual void initRead ();
virtual std::ostream & put (std::ostream &s) const;
// Read data reads the image if readFlag is true and
// optional keywords if supplied. Thus, with no arguments,
// readData() does nothing.
virtual const std::valarray<T>& readImage (long first, long nElements, T* nullValue);
// Read data reads the image if readFlag is true and
// optional keywords if supplied. Thus, with no arguments,
// readData() does nothing.
virtual const std::valarray<T>& readImage (const std::vector<long>& firstVertex, const std::vector<long>& lastVertex, const std::vector<long>& stride, T* nullValue);
// Read data reads the image if readFlag is true and
// optional keywords if supplied. Thus, with no arguments,
// readData() does nothing.
virtual void writeImage (long first, long nElements, const std::valarray<T>& inData, T* nullValue = 0);
// Read data reads the image if readFlag is true and
// optional keywords if supplied. Thus, with no arguments,
// readData() does nothing.
virtual void writeImage (const std::vector<long>& firstVertex, const std::vector<long>& lastVertex, const std::valarray<T>& inData);
const Image<T>& data () const;
// Additional Private Declarations
private: //## implementation
// Data Members for Associations
Image<T> m_data;
// Additional Implementation Declarations
friend class ExtHDU;
friend class HDUCreator;
};
// Parameterized Class CCfits::ImageExt
template <typename T>
inline std::ostream & ImageExt<T>::put (std::ostream &s) const
{
s << "Image Extension:: " << " Name: " << name() << " Extension: " << xtension()
<< " BITPIX "<< bitpix() << '\n';
s << " Axis Lengths: \n";
for (size_t j =1; j < static_cast<size_t>( axes() ) ; j++)
{
s << " Axis: " << j << " " << axis(j-1) << '\n';
}
s << "Image Extension:: Version: " << version() << " HDU number: " << index() << '\n';
s << " HISTORY: " << history() << '\n';
s << " COMMENTS: " <<comment() << '\n';
s << "BinTable:: nKeywords: " << keyWord().size() << '\n';
return s;
}
template <typename T>
inline const Image<T>& ImageExt<T>::data () const
{
return m_data;
}
// Parameterized Class CCfits::ImageExt
template <typename T>
ImageExt<T>::ImageExt(const ImageExt<T> &right)
: ExtHDU(right), m_data(right.m_data)
{
}
template <typename T>
ImageExt<T>::ImageExt (FITSBase* p, const String &hduName, bool readDataFlag, const std::vector<String>& keys, int version)
: ExtHDU(p,ImageHdu,hduName,version), m_data()
{
initRead();
if (readDataFlag || keys.size() ) readData(readDataFlag,keys);
}
template <typename T>
ImageExt<T>::ImageExt (FITSBase* p, const String &hduName, int bpix, int naxis, const std::vector<long>& naxes, int version)
: ExtHDU(p,ImageHdu,hduName,bpix,naxis,naxes,version), m_data()
{
// resize m_image according to naxes, and data according to m_image,
// and equate them. Valarray = must be performed on items of the same
// size according to the standard.
int status (0);
FITSUtil::CVarray<long> convert;
FITSUtil::auto_array_ptr<long> axis(convert(naxes));
static char EXTNAME[] = "EXTNAME";
static char HDUVERS[] = "HDUVERS";
if ( fits_create_img(fitsPointer(), bpix, naxis, axis.get(), &status) )
{
throw FitsError(status);
}
else
{
char * comment = 0;
if (fits_write_key(fitsPointer(),Tstring,EXTNAME,
const_cast<char*>(hduName.c_str()), comment,&status))
{
throw FitsError(status);
}
if (version != 0 && fits_write_key(fitsPointer(),Tint,HDUVERS,&version,
comment,&status)) throw FitsError(status);
}
}
template <typename T>
ImageExt<T>::~ImageExt()
{
}
template <typename T>
void ImageExt<T>::initRead ()
{
}
template <typename T>
ImageExt<T> * ImageExt<T>::clone (FITSBase* p) const
{
ImageExt<T>* cloned = new ImageExt<T>(*this);
cloned->parent() = p;
return cloned;
}
template <typename T>
void ImageExt<T>::readData (bool readFlag, const std::vector<String>& keys)
{
// Default reading mode. Read everything if readFlag is true.
// this is identical to the equivalent method for PrimaryHDU<T>,
// so will one day turn this into a simple call that shares the code.
makeThisCurrent();
if ( keys.size() > 0)
{
std::list<string> keyList;
// keys is converted to a list so that any keys not in the header
// can be easily erased. internally an exception will be thrown,
// on a missing key, and its catch clause will print a message.
for (std::vector<string>::const_iterator j = keys.begin(); j != keys.end(); ++j)
{
keyList.push_back(*j);
}
readKeywords(keyList);
}
if ( readFlag) // read the entire image, setting null values to FLT_MIN.
{
FITSUtil::FitsNullValue<T> null;
T nulval = null();
long first(1);
long nelements(1);
for (size_t i = 0; i < naxes().size(); i++) nelements *= naxes(i);
m_data.readImage(fitsPointer(),first,nelements,&nulval,naxes(),anynul());
}
}
template <typename T>
const std::valarray<T>& ImageExt<T>::image () const
{
return m_data.image();
}
template <typename T>
const std::valarray<T>& ImageExt<T>::readImage (long first, long nElements, T* nullValue)
{
checkExtensionType();
return m_data.readImage(fitsPointer(),first,nElements,nullValue,naxes(),anynul());
}
template <typename T>
const std::valarray<T>& ImageExt<T>::readImage (const std::vector<long>& firstVertex, const std::vector<long>& lastVertex, const std::vector<long>& stride, T* nullValue)
{
checkExtensionType();
return m_data.readImage(fitsPointer(),firstVertex,lastVertex,stride,nullValue,naxes(),anynul());
}
template <typename T>
void ImageExt<T>::writeImage (long first, long nElements, const std::valarray<T>& inData, T* nullValue)
{
checkExtensionType();
m_data.writeImage(fitsPointer(),first,nElements,inData,naxes(),nullValue);
}
template <typename T>
void ImageExt<T>::writeImage (const std::vector<long>& firstVertex, const std::vector<long>& lastVertex, const std::valarray<T>& inData)
{
checkExtensionType();
m_data.writeImage(fitsPointer(),firstVertex,lastVertex,inData,naxes());
}
template <typename T>
void ImageExt<T>::zero (double value)
{
makeThisCurrent();
if (checkImgDataTypeChange(value, scale()))
{
if (naxis())
{
int status(0);
if (fits_update_key(fitsPointer(), Tdouble, BZERO, &value, 0, &status))
throw FitsError(status);
fits_flush_file(fitsPointer(), &status);
HDU::zero(value);
}
}
else
{
bool silent=false;
string msg("CCfits Error: Cannot set BZERO to a value which will change image data\n");
msg += " from integer type to floating point type.";
throw FitsException(msg,silent);
}
}
template <typename T>
void ImageExt<T>::scale (double value)
{
makeThisCurrent();
if (checkImgDataTypeChange(zero(), value))
{
if (naxis())
{
int status(0);
if (fits_update_key(fitsPointer(), Tdouble, BSCALE, &value, 0, &status))
throw FitsError(status);
fits_flush_file(fitsPointer(), &status);
HDU::scale(value);
}
}
else
{
bool silent=false;
string msg("CCfits Error: Cannot set BSCALE to a value which will change image data\n");
msg += " from integer type to floating point type.";
throw FitsException(msg,silent);
}
}
template <typename T>
double ImageExt<T>::zero () const
{
return HDU::zero();
}
template <typename T>
double ImageExt<T>::scale () const
{
return HDU::scale();
}
// Additional Declarations
template <typename T>
inline void ImageExt<T>::checkExtensionType() const
{
}
} // namespace CCfits
#endif
|