test_GFits.cpp
10.2 KB
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
/***************************************************************************
* test_GFits.cpp - test FITS classes *
* ----------------------------------------------------------------------- *
* copyright : (C) 2008 by Jurgen Knodlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* __ Includes ___________________________________________________________ */
#include "test_GFits.hpp"
/* __ Namespaces _________________________________________________________ */
/* __ Globals ____________________________________________________________ */
/***************************************************************************
* Verification routines *
***************************************************************************/
int fequal(double val, double ref)
{
return (fabs(val-ref) < 1.0e-5) ? 1 : 0;
}
int dequal(double val, double ref)
{
return (fabs(val-ref) < 1.0e-10) ? 1 : 0;
}
/***************************************************************************
* Test: Open *
***************************************************************************/
void test_open(void)
{
std::cout << "Test GFits: Open FITS file: ";
try {
GFits fits;
fits.open("test_GFits.fits");
}
catch (exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to open FITS file." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ". ok." << std::endl;
}
/***************************************************************************
* Test: Columns *
***************************************************************************/
void test_columns(void)
{
GFits fits;
try {
// Open FITS file
fits.open("test_GFits.fits");
}
catch (exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to open test file." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
//
// Test single string column
//
std::cout << "Test GFits: String column handling: ";
try {
GFitsTableStrCol str = *((GFitsTableStrCol*)fits.hdu("BinTable")->column("TSTRING"));
if (str.string(0) != "1" || str.string(1) != "2" || str.string(2) != "") {
cout << endl << "TEST ERROR: Bad single TSTRING values read ("
<< str.string(0) << ", " << str.string(1) << ", " << str.string(2) << ")." << endl;
throw;
}
else
std::cout << ".";
std::string nullstr = "empty";
str.set_nullstr(nullstr);
if (str.string(2) != "empty") {
cout << endl << "TEST ERROR: Bad single TSTRING NULL value read ("
<< str.string(2) << ")." << endl;
throw;
}
else
std::cout << ".";
}
catch (exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to handle single TSTRING column." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ". ok." << std::endl;
//
// Test single short column
//
std::cout << "Test GFits: Short column handling: ";
try {
GFitsTableShtCol sht = *((GFitsTableShtCol*)fits.hdu("BinTable")->column("TSHORT"));
if (sht.integer(0) != 1 || sht.real(0) != 1.0 || sht.string(0) != "1" ||
sht.integer(1) != 2 || sht.real(1) != 2.0 || sht.string(1) != "2" ||
sht.integer(2) != -3 || sht.real(2) != -3.0 || sht.string(2) != "-3") {
cout << endl << "TEST ERROR: Bad single TSHORT values read." << endl;
throw;
}
else
std::cout << ".";
}
catch (exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to handle single TSHORT column." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ". ok." << std::endl;
//
// Test single long column
//
std::cout << "Test GFits: Long column handling: ";
try {
GFitsTableLngCol lng = *((GFitsTableLngCol*)fits.hdu("BinTable")->column("TLONG"));
if (lng.integer(0) != 10 || lng.real(0) != 10.0 || lng.string(0) != "10" ||
lng.integer(1) != -20 || lng.real(1) != -20.0 || lng.string(1) != "-20" ||
lng.integer(2) != 30 || lng.real(2) != 30.0 || lng.string(2) != "30") {
cout << endl << "TEST ERROR: Bad single TLONG values read." << endl;
throw;
}
else
std::cout << ".";
}
catch (exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to handle single TLONG column." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ". ok." << std::endl;
//
// Test single floating point column
//
std::cout << "Test GFits: Floating point column handling: ";
try {
GFitsTableFltCol flt = *((GFitsTableFltCol*)fits.hdu("BinTable")->column("TFLOAT"));
if (!fequal(flt.real(0),1.0)) {
cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
<< flt.real(0) << " != 1.0)." << endl;
throw;
}
else
std::cout << ".";
if (!fequal(flt.real(1),-2.1)) {
cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
<< flt.real(1) << " != -2.1)." << endl;
throw;
}
else
std::cout << ".";
if (flt.integer(0) != 1) {
cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
<< flt.integer(0) << " != 1)." << endl;
throw;
}
else
std::cout << ".";
if (flt.integer(1) != -2) {
cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
<< flt.integer(1) << " != -2)." << endl;
throw;
}
else
std::cout << ".";
if (flt.string(0) != "1.000000e+00") {
cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
<< flt.string(0) << " != 1.000000e+00)." << endl;
throw;
}
else
std::cout << ".";
if (flt.string(1) != "-2.100000e+00") {
cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
<< flt.string(1) << " != -2.100000e+00)." << endl;
throw;
}
else
std::cout << ".";
float nullval = -99.9;
flt.set_nullval(&nullval);
if (!fequal(flt.real(2),-99.9)) {
cout << endl << "TEST ERROR: Bad single TFLOAT NULL value read ("
<< flt.real(2) << ")." << endl;
throw;
}
else
std::cout << ".";
}
catch (exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to handle single TFLOAT column." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ". ok." << std::endl;
//
// Test single double column
//
std::cout << "Test GFits: Double precision column handling: ";
try {
GFitsTableDblCol dbl = *((GFitsTableDblCol*)fits.hdu("BinTable")->column("TDOUBLE"));
if (!dequal(dbl.real(0),11.1)) {
cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
<< dbl.real(0) << " != 11.1)." << endl;
throw;
}
else
std::cout << ".";
if (!dequal(dbl.real(2),22.2)) {
cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
<< dbl.real(2) << " != 22.2)." << endl;
throw;
}
else
std::cout << ".";
if (dbl.integer(0) != 11) {
cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
<< dbl.integer(0) << " != 11)." << endl;
throw;
}
else
std::cout << ".";
if (dbl.integer(2) != 22) {
cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
<< dbl.integer(2) << " != 22)." << endl;
throw;
}
else
std::cout << ".";
if (dbl.string(0) != "1.110000e+01") {
cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
<< dbl.string(0) << " != 1.110000e+01)." << endl;
throw;
}
else
std::cout << ".";
if (dbl.string(2) != "2.220000e+01") {
cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
<< dbl.string(2) << " != 2.220000e+01)." << endl;
throw;
}
else
std::cout << ".";
double nullval = -9999.9;
dbl.set_nullval(&nullval);
if (!dequal(dbl.real(1),-9999.9)) {
cout << endl << "TEST ERROR: Bad single TDOUBLE NULL value read ("
<< dbl.real(1) << ")." << endl;
throw;
}
else
std::cout << ".";
}
catch (exception &e) {
std::cout << std::endl << "TEST ERROR: Unable to handle single TDOUBLE column." << std::endl;
std::cout << e.what() << std::endl;
throw;
}
std::cout << ". ok." << std::endl;
}
/***************************************************************************
* Main test function *
***************************************************************************/
int main(void)
{
// Dump header
std::cout << std::endl;
std::cout << "***********************" << std::endl;
std::cout << "* GFits class testing *" << std::endl;
std::cout << "***********************" << std::endl;
// Execute the tests
test_open();
test_columns();
// Return
return 0;
}