10 #define PRIMARYHDU_H 1
17 #include "HDUCreator.h"
33 class PrimaryHDU :
public PHDU
37 virtual PrimaryHDU<T> * clone (FITS* p)
const;
41 virtual void readData (
bool readFlag =
false,
const std::vector<String>& keys = std::vector<String>());
42 const std::valarray<T>& image ()
const;
43 const std::valarray<T>& readImage (
long first,
long nElements, T* nullValue);
44 const std::valarray<T>& readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,T* nullValue);
45 void writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue = 0);
46 void writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,
const std::valarray<T>& inData);
47 virtual void zero (
double value);
48 virtual void scale (
double value);
49 virtual void suppressScaling(
bool toggle =
true);
50 virtual void resetImageRead ();
57 PrimaryHDU (FITS* p,
const int bitpix,
const int naxis,
const std::vector<long>& naxes,
const std::valarray<T>& data = std::valarray<T>());
61 PrimaryHDU (FITS* p,
bool readFlag =
false,
const std::vector<String>& keys = std::vector<String>());
66 PrimaryHDU(
const PrimaryHDU< T > &right);
67 PrimaryHDU< T > & operator=(
const PrimaryHDU< T > &right);
69 virtual std::ostream & put (std::ostream &s)
const;
70 const Image<T>& data ()
const;
79 friend class HDUCreator;
86 inline std::ostream & PrimaryHDU<T>::put (std::ostream &s)
const
88 s <<
"PrimaryHDU:: Simple? " << simple() <<
" Extend?: " << extend() <<
89 " Bitpix: " << bitpix() <<
" naxis = " << axes() <<
"\n";
90 s <<
"Axis Lengths: \n";
94 for (
int i=0; i < axes(); i++)
95 s <<
" axis[" << i <<
"] " << axis(i) <<
"\n";
97 s <<
"\nNumber of keywords read: " << keyWord().size() <<
"\n";
99 for (std::map<String,Keyword*>::const_iterator ki = keyWord().begin();
100 ki != keyWord().end(); ki++)
102 s << *((*ki).second) << std::endl;
106 s <<
" HISTORY: " << history() <<
'\n';
107 s <<
" COMMENTS: " <<comment() <<
'\n';
111 template <
typename T>
112 inline const Image<T>& PrimaryHDU<T>::data ()
const
119 template <
typename T>
120 PrimaryHDU<T>::PrimaryHDU(
const PrimaryHDU<T> &right)
121 : PHDU(right), m_data(right.m_data)
125 template <
typename T>
126 PrimaryHDU<T>::PrimaryHDU (FITS* p,
const int bitpix,
const int naxis,
const std::vector<long>& naxes,
const std::valarray<T>& data)
127 : PHDU(p,bitpix,naxis,naxes),m_data(data)
131 template <
typename T>
132 PrimaryHDU<T>::PrimaryHDU (FITS* p,
bool readFlag,
const std::vector<String>& keys)
137 if (readFlag || keys.size()) readData(readFlag,keys);
142 template <
typename T>
143 PrimaryHDU<T> * PrimaryHDU<T>::clone (FITS* p)
const
145 PrimaryHDU<T>* cloned =
new PrimaryHDU<T>(*
this);
146 cloned->parent() = p;
150 template <
typename T>
151 void PrimaryHDU<T>::readData (
bool readFlag,
const std::vector<String>& keys)
157 if ( keys.size() > 0)
159 std::list<String> keyList(keys.size());
163 std::copy(keys.begin(),keys.end(),keyList.begin());
164 readKeywords(keyList);
169 if ( readFlag && (naxis() > 0) )
171 FITSUtil::FitsNullValue<T>
null;
174 long nelements(std::accumulate(naxes().begin(),naxes().end(),init,std::multiplies<long>() ));
175 readImage(1,nelements,&nulValue);
180 template <
typename T>
181 const std::valarray<T>& PrimaryHDU<T>::image ()
const
184 return m_data.image();
188 template <
typename T>
189 const std::valarray<T>& PrimaryHDU<T>::readImage (
long first,
long nElements, T* nullValue)
192 return m_data.readImage(fitsPointer(),first,nElements,nullValue,naxes(),anynul());
195 template <
typename T>
196 const std::valarray<T>& PrimaryHDU<T>::readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,T* nullValue)
199 return m_data.readImage(fitsPointer(),firstVertex,lastVertex,stride,nullValue,naxes(),anynul());
202 template <
typename T>
203 void PrimaryHDU<T>::writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue)
206 m_data.writeImage(fitsPointer(),first,nElements,inData,naxes(),newNaxisN,nullValue);
208 naxes(naxes().size()-1,newNaxisN);
211 template <
typename T>
212 void PrimaryHDU<T>::writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,
const std::valarray<T>& inData)
215 m_data.writeImage(fitsPointer(),firstVertex,lastVertex,stride,inData,naxes(),newNaxisN);
217 naxes(naxes().size()-1,newNaxisN);
220 template <
typename T>
221 void PrimaryHDU<T>::scale (
double value)
224 m_data.scalingHasChanged();
227 template <
typename T>
228 void PrimaryHDU<T>::zero (
double value)
231 m_data.scalingHasChanged();
234 template <
typename T>
235 void PrimaryHDU<T>::suppressScaling (
bool toggle)
237 HDU::suppressScaling(toggle);
238 m_data.scalingHasChanged();
241 template <
typename T>
242 void PrimaryHDU<T>::resetImageRead()
virtual double zero() const
return the BZERO keyword value
Definition: PHDU.cxx:160
virtual double scale() const
return the BSCALE keyword value
Definition: PHDU.cxx:166
PHDU(const PHDU &right)
copy constructor
Definition: PHDU.cxx:20
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26