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 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 (FITSBase* p,
const int bitpix,
const int naxis,
const std::vector<long>& naxes,
const std::valarray<T>& data = std::valarray<T>());
61 PrimaryHDU (FITSBase* 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();
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 (FITSBase* 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 (FITSBase* 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 (FITSBase* 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);
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);
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)
238 m_data.scalingHasChanged();
241 template <
typename T>
242 void PrimaryHDU<T>::resetImageRead()
virtual void initRead()
Definition: PHDU.cxx:77
fitsfile * fitsPointer() const
return the fitsfile pointer for the FITS object containing the HDU
Definition: HDU.cxx:310
const string & history() const
return the history string previously read by getHistory()
Definition: HDU.h:857
bool extend() const
Returns the value of the Primary's EXTEND keyword.
Definition: PHDU.h:403
const string & comment() const
return the comment string previously read by getComment()
Definition: HDU.h:852
long axes() const
return the number of axes in the HDU data section (always 2 for tables).
Definition: HDU.h:867
std::map< String, Keyword * > & keyWord()
return the associative array containing the HDU keywords so far read.
Definition: HDU.h:929
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
long axis(size_t index) const
return the size of axis numbered index [zero based].
Definition: HDU.h:873
PHDU(const PHDU &right)
copy constructor
Definition: PHDU.cxx:22
virtual double scale() const
return the BSCALE keyword value
Definition: PHDU.cxx:168
virtual void makeThisCurrent() const
move the fitsfile pointer to this current HDU.
Definition: HDU.cxx:322
std::vector< long > & naxes()
return the HDU data axis array.
Definition: HDU.h:979
bool simple() const
Returns the value of the Primary's SIMPLE keyword.
Definition: PHDU.h:393
virtual void readData(bool readFlag=false, const std::vector< String > &keys=std::vector< String >())=0
read primary HDU data
virtual double zero() const
return the BZERO keyword value
Definition: PHDU.cxx:162
virtual void suppressScaling(bool toggle=true)
turn off image scaling regardless of the BSCALE and BZERO keyword values
Definition: HDU.cxx:462