10 #define PRIMARYHDU_H 1 17 #include "HDUCreator.h" 33 class PrimaryHDU :
public PHDU
37 virtual PrimaryHDU<T> * clone (FITSBase* 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 std::valarray<T>& image ();
44 void setImage (
const std::valarray<T>& inData);
48 virtual const std::valarray<T>& readImage (
long first,
long nElements, T* nullValue);
52 virtual const std::valarray<T>& readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride, T* nullValue);
56 virtual void writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue = 0);
60 virtual void writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,
const std::valarray<T>& inData);
67 PrimaryHDU (FITSBase* p,
const int bitpix,
const int naxis,
const std::vector<long>& naxes,
const std::valarray<T>& data = std::valarray<T>());
71 PrimaryHDU (FITSBase* p,
bool readFlag =
false,
const std::vector<String>& keys = std::vector<String>());
76 PrimaryHDU(
const PrimaryHDU< T > &right);
77 PrimaryHDU< T > & operator=(
const PrimaryHDU< T > &right);
79 virtual std::ostream & put (std::ostream &s)
const;
80 const Image<T>& data ()
const;
89 friend class HDUCreator;
96 inline std::ostream & PrimaryHDU<T>::put (std::ostream &s)
const 98 s <<
"PrimaryHDU:: Simple? " <<
simple() <<
" Extend?: " <<
extend() <<
99 " Bitpix: " << bitpix() <<
" naxis = " <<
axes() <<
"\n";
100 s <<
"Axis Lengths: \n";
104 for (
int i=0; i <
axes(); i++)
105 s <<
" axis[" << i <<
"] " <<
axis(i) <<
"\n";
107 s <<
"\nNumber of keywords read: " <<
keyWord().size() <<
"\n";
109 for (std::map<String,Keyword*>::const_iterator ki =
keyWord().begin();
112 s << *((*ki).second) << std::endl;
116 s <<
" HISTORY: " <<
history() <<
'\n';
117 s <<
" COMMENTS: " <<
comment() <<
'\n';
121 template <
typename T>
122 inline const Image<T>& PrimaryHDU<T>::data ()
const 129 template <
typename T>
130 PrimaryHDU<T>::PrimaryHDU(
const PrimaryHDU<T> &right)
131 :
PHDU(right), m_data(right.m_data)
135 template <
typename T>
136 PrimaryHDU<T>::PrimaryHDU (FITSBase* p,
const int bitpix,
const int naxis,
const std::vector<long>& naxes,
const std::valarray<T>& data)
137 :
PHDU(p,bitpix,naxis,naxes),m_data(data)
141 template <
typename T>
142 PrimaryHDU<T>::PrimaryHDU (FITSBase* p,
bool readFlag,
const std::vector<String>& keys)
147 if (readFlag || keys.size())
readData(readFlag,keys);
152 template <
typename T>
153 PrimaryHDU<T> * PrimaryHDU<T>::clone (FITSBase* p)
const 155 PrimaryHDU<T>* cloned =
new PrimaryHDU<T>(*this);
156 cloned->parent() = p;
160 template <
typename T>
161 void PrimaryHDU<T>::readData (
bool readFlag,
const std::vector<String>& keys)
167 if ( keys.size() > 0)
169 std::list<String> keyList(keys.size());
173 std::copy(keys.begin(),keys.end(),keyList.begin());
174 readKeywords(keyList);
179 if ( readFlag && (naxis() > 0) )
181 FITSUtil::FitsNullValue<T> null;
184 long nelements(std::accumulate(
naxes().begin(),
naxes().end(),init,std::multiplies<long>() ));
185 readImage(1,nelements,&nulValue);
190 template <
typename T>
191 const std::valarray<T>& PrimaryHDU<T>::image ()
const 194 return m_data.image();
197 template <
typename T>
198 std::valarray<T>& PrimaryHDU<T>::image ()
201 return m_data.image();
204 template <
typename T>
205 void PrimaryHDU<T>::setImage (
const std::valarray<T>& inData)
207 m_data.image().resize(inData.size());
208 m_data.setImage(inData);
211 template <
typename T>
212 const std::valarray<T>& PrimaryHDU<T>::readImage (
long first,
long nElements, T* nullValue)
215 return m_data.readImage(
fitsPointer(),first,nElements,nullValue,
naxes(),anynul());
218 template <
typename T>
219 const std::valarray<T>& PrimaryHDU<T>::readImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride, T* nullValue)
222 return m_data.readImage(
fitsPointer(),firstVertex,lastVertex,stride,nullValue,
naxes(),anynul());
225 template <
typename T>
226 void PrimaryHDU<T>::writeImage (
long first,
long nElements,
const std::valarray<T>& inData, T* nullValue)
231 template <
typename T>
232 void PrimaryHDU<T>::writeImage (
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,
const std::valarray<T>& inData)
234 m_data.writeImage(
fitsPointer(),firstVertex,lastVertex,stride,inData,
naxes());
virtual void initRead()
Definition: PHDU.cxx:77
bool simple() const
Returns the value of the Primary's SIMPLE keyword.
Definition: PHDU.h:393
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
bool extend() const
Returns the value of the Primary's EXTEND keyword.
Definition: PHDU.h:403
std::map< String, Keyword * > & keyWord()
return the associative array containing the HDU keywords so far read.
Definition: HDU.h:893
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
virtual void makeThisCurrent() const
move the fitsfile pointer to this current HDU.
Definition: HDU.cxx:321
PHDU(const PHDU &right)
copy constructor
Definition: PHDU.cxx:22
long axes() const
return the number of axes in the HDU data section (always 2 for tables).
Definition: HDU.h:835
std::vector< long > & naxes()
return the HDU data axis array.
Definition: HDU.h:943
virtual void readData(bool readFlag=false, const std::vector< String > &keys=std::vector< String >())=0
read primary HDU data
const string & history() const
return the history string previously read by getHistory()
Definition: HDU.h:825
const string & comment() const
return the comment string previously read by getComment()
Definition: HDU.h:820