-
Notifications
You must be signed in to change notification settings - Fork 1
/
PHDU.cxx
174 lines (145 loc) · 4.2 KB
/
PHDU.cxx
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
// Astrophysics Science Division,
// NASA/ Goddard Space Flight Center
// HEASARC
// http://heasarc.gsfc.nasa.gov
// e-mail: [email protected]
//
// Original author: Ben Dorman
// FITS
#include "FITS.h"
// PHDU
#include "PHDU.h"
namespace CCfits {
// Class CCfits::PHDU
PHDU::PHDU(const PHDU &right)
: HDU(right), m_simple(true),
m_extend(true)
{
}
PHDU::PHDU (FITS* p, int bpix, int naxis, const std::vector<long>& axes)
: HDU(p,bpix,naxis, axes), m_simple(true), m_extend(true)
{
int status (0);
// If file name explicitly asks for compression, don't create an
// image here. Primaries can't hold compressed images. The FITS
// image ctor will have to create an image extension instead.
string::size_type compressSpecifier =
FITSUtil::checkForCompressString(p->name());
if (compressSpecifier == string::npos)
{
long *naxesArray = 0;
FITSUtil::CVarray<long> convert;
naxesArray = convert(axes);
if (fits_create_img(fitsPointer(), bpix, naxis, naxesArray, &status) != 0)
{
delete [] naxesArray;
throw FitsError(status);
}
if (fits_flush_file(fitsPointer(),&status))
{
delete [] naxesArray;
throw FitsError(status);
}
delete [] naxesArray;
}
index(0);
}
PHDU::PHDU (FITS* p)
//! Reading Primary HDU constructor.
/*! Constructor used when reading the primary HDU from an existing file.
* Does nothing except initialize, with the real work done by the subclass
* PrimaryHDU<T>.
*/
: HDU(p), m_simple(true),
m_extend(true)
{
}
PHDU::~PHDU()
{
//! Destructor
}
void PHDU::initRead ()
{
//! Read image header and update fits pointer accordingly.
/*! Private: called by ctor.
*/
long pcount=0, gcount=0;
int status=0;
int simp = 0;
int xtend = 0;
int numAxes = 0;
if (fits_get_img_dim(fitsPointer(), &numAxes, &status) != 0)
{
throw FitsError(status);
}
naxis() = numAxes;
FITSUtil::auto_array_ptr<long> pAxes(0);
if (numAxes > 0) pAxes.reset(new long[numAxes]);
long* axes = pAxes.get();
int bpix = 0;
if (fits_read_imghdr(fitsPointer(), MAXDIM, &simp, &bpix, &numAxes,
axes, &pcount, &gcount, &xtend, &status) != 0)
throw FitsError(status);
bitpix(bpix);
simple(simp != 0);
extend(xtend != 0);
if (numAxes > 0)
{
naxes().resize(naxis());
std::copy(&axes[0],&axes[numAxes],naxes().begin());
}
}
void PHDU::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);
}
}
void PHDU::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);
}
}
double PHDU::zero () const
{
return HDU::zero();
}
double PHDU::scale () const
{
return HDU::scale();
}
// Additional Declarations
} // namespace CCfits