Commit e21b42cd45fdba0ae5407ca16db2cb4824434fb3

Authored by knodlseder
1 parent b6aee015

correct HDU selection (using fitsfile pointer)

include/GFitsAsciiTable.hpp
... ... @@ -40,7 +40,7 @@ public:
40 40 GFitsAsciiTable& operator= (const GFitsAsciiTable& table);
41 41  
42 42 // Methods
43   - void open(__fitsfile* fptr);
  43 + void open(__fitsfile* fptr);
44 44 void close(void);
45 45 GFitsAsciiTable* clone(void) const;
46 46 GFitsTableCol* column(const std::string colname);
... ...
include/GFitsBinTable.hpp
... ... @@ -15,7 +15,7 @@
15 15 #define GFITSBINTABLE_HPP
16 16  
17 17 /* __ Includes ___________________________________________________________ */
18   -#include <vector>
  18 +//#include <vector>
19 19 #include "GFitsCfitsio.hpp"
20 20 #include "GFitsData.hpp"
21 21 #include "GFitsTableCol.hpp"
... ... @@ -44,7 +44,7 @@ public:
44 44 GFitsBinTable& operator= (const GFitsBinTable& table);
45 45  
46 46 // Methods
47   - void open(__fitsfile* fptr);
  47 + void open(__fitsfile* fptr);
48 48 void close(void);
49 49 GFitsBinTable* clone(void) const;
50 50 GFitsTableCol* column(const std::string colname);
... ...
include/GFitsCfitsio.hpp
... ... @@ -88,7 +88,10 @@ typedef fitsfile __fitsfile;
88 88 #define __TDBLCOMPLEX 163
89 89  
90 90 /* __ Type definition ____________________________________________________ */
91   -typedef int __fitsfile;
  91 +typedef struct {
  92 + int HDUposition; // HDU position in file; 0 = first HDU
  93 + int* Fptr; // Pointer to FITS file structure
  94 +} __fitsfile;
92 95  
93 96 /* __ Dummy function _____________________________________________________ */
94 97 inline
... ...
include/GFitsData.hpp
... ... @@ -35,7 +35,7 @@ public:
35 35 virtual GFitsData& operator= (const GFitsData& data);
36 36  
37 37 // Methods
38   - virtual void open(__fitsfile* fptr) = 0;
  38 + virtual void open(__fitsfile* fptr) = 0;
39 39 virtual void close(void) = 0;
40 40 virtual GFitsData* clone(void) const = 0;
41 41  
... ...
include/GFitsHDU.hpp
... ... @@ -42,26 +42,24 @@ public:
42 42 GFitsHDU& operator= (const GFitsHDU& hdu);
43 43  
44 44 // Methods
45   - void open(__fitsfile* fptr, int hdunum);
  45 + void open(__fitsfile* fptr, int hdunum);
46 46 void save(void);
47 47 std::string extname(void) const;
48 48 int extno(void) const;
49 49 int exttype(void) const;
50 50 GFitsHeader* header(void) const;
51 51 GFitsData* data(void) const;
52   - GFitsTableCol* column(const std::string colname) const;
  52 + GFitsTableCol* column(const std::string& colname) const;
53 53  
54 54 private:
55 55 // Private methods
56 56 void init_members(void);
57 57 void copy_members(const GFitsHDU& hdu);
58 58 void free_members(void);
59   - void move2hdu(void);
60 59  
61 60 // Private data area
62   - __fitsfile* m_fitsfile; // FITS file pointer
  61 + __fitsfile m_fitsfile; // FITS file pointer
63 62 std::string m_name; // HDU name
64   - int m_num; // HDU number (starting from 1)
65 63 int m_type; // HDU type
66 64 GFitsHeader* m_header; // HDU header
67 65 GFitsData* m_data; // HDU data
... ... @@ -72,7 +70,7 @@ private:
72 70 * Inline methods *
73 71 ***************************************************************************/
74 72 inline std::string GFitsHDU::extname(void) const { return m_name; }
75   -inline int GFitsHDU::extno(void) const { return m_num; }
  73 +inline int GFitsHDU::extno(void) const { return m_fitsfile.HDUposition; }
76 74 inline int GFitsHDU::exttype(void) const { return m_type; }
77 75 inline GFitsHeader* GFitsHDU::header(void) const { return m_header; }
78 76 inline GFitsData* GFitsHDU::data(void) const { return m_data; }
... ...
include/GFitsHeader.hpp
... ... @@ -39,7 +39,7 @@ public:
39 39 GFitsHeader& operator= (const GFitsHeader& header);
40 40  
41 41 // Methods
42   - void open(__fitsfile* fptr);
  42 + void open(__fitsfile* fptr);
43 43 void close(void);
44 44 GFitsHeaderCard* card(const std::string keyname);
45 45 GFitsHeaderCard* card(const int cardno);
... ...
include/GFitsImage.hpp
... ... @@ -26,6 +26,9 @@
26 26 ***************************************************************************/
27 27 class GFitsImage : public GFitsData {
28 28  
  29 + // I/O friends
  30 + friend ostream& operator<< (ostream& os, const GFitsImage& image);
  31 +
29 32 public:
30 33 // Constructors and destructors
31 34 GFitsImage();
... ... @@ -36,7 +39,7 @@ public:
36 39 GFitsImage& operator= (const GFitsImage& image);
37 40  
38 41 // Methods
39   - void open(__fitsfile* fptr);
  42 + void open(__fitsfile* fptr);
40 43 void close(void);
41 44 GFitsImage* clone(void) const;
42 45  
... ...
include/GFitsTableCol.hpp
... ... @@ -71,7 +71,7 @@ protected:
71 71 int m_repeat;
72 72 int m_width;
73 73 int m_length;
74   - __fitsfile* m_fitsfile;
  74 + __fitsfile m_fitsfile;
75 75  
76 76 private:
77 77 // Private methods
... ... @@ -90,7 +90,7 @@ inline void GFitsTableCol::set_type(const int type) { m_type = type; }
90 90 inline void GFitsTableCol::set_repeat(const int repeat) { m_repeat = repeat; }
91 91 inline void GFitsTableCol::set_width(const int width) { m_width = width; }
92 92 inline void GFitsTableCol::set_length(const int length) { m_length = length; }
93   -inline void GFitsTableCol::set_fitsfile(const __fitsfile* fptr) { m_fitsfile = (__fitsfile*)fptr; }
  93 +inline void GFitsTableCol::set_fitsfile(const __fitsfile* fptr) { m_fitsfile = *fptr; }
94 94 inline std::string GFitsTableCol::name(void) { return m_name; }
95 95 inline int GFitsTableCol::colnum(void) { return m_colnum; }
96 96 inline int GFitsTableCol::type(void) { return m_type; }
... ...
src/fits/GFitsAsciiTable.cpp
... ... @@ -13,9 +13,14 @@
13 13 ***************************************************************************/
14 14  
15 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 17 #include "GException.hpp"
17 18 #include "GFitsAsciiTable.hpp"
18   -#include <iostream> // cout, cerr
  19 +#include "GFitsTableStrCol.hpp"
  20 +#include "GFitsTableShtCol.hpp"
  21 +#include "GFitsTableLngCol.hpp"
  22 +#include "GFitsTableFltCol.hpp"
  23 +#include "GFitsTableDblCol.hpp"
19 24  
20 25 /* __ Namespaces _________________________________________________________ */
21 26  
... ... @@ -124,6 +129,7 @@ GFitsAsciiTable&amp; GFitsAsciiTable::operator= (const GFitsAsciiTable&amp; table)
124 129 * Open Table *
125 130 * ----------------------------------------------------------------------- *
126 131 ***************************************************************************/
  132 +/// NOT YET IMPLEMENTED
127 133 void GFitsAsciiTable::open(__fitsfile* fptr)
128 134 {
129 135 cout << "open ASCII table" << endl;
... ... @@ -192,8 +198,6 @@ GFitsTableCol* GFitsAsciiTable::column(const int colnum)
192 198 }
193 199  
194 200  
195   -
196   -
197 201 /*==========================================================================
198 202 = =
199 203 = GFitsAsciiTable private methods =
... ... @@ -275,7 +279,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsAsciiTable&amp; table)
275 279 os << " Number of rows ............: " << table.m_rows << endl;
276 280 os << " Number of columns .........: " << table.m_cols << endl;
277 281 for (int i = 0; i < table.m_cols; ++i)
278   - os << i;
  282 + os << " " << *(table.m_columns[i]);
279 283  
280 284 // Return output stream
281 285 return os;
... ...
src/fits/GFitsBinTable.cpp
... ... @@ -13,6 +13,7 @@
13 13 ***************************************************************************/
14 14  
15 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 17 #include "GException.hpp"
17 18 #include "GTools.hpp"
18 19 #include "GFitsBinTable.hpp"
... ... @@ -21,7 +22,6 @@
21 22 #include "GFitsTableLngCol.hpp"
22 23 #include "GFitsTableFltCol.hpp"
23 24 #include "GFitsTableDblCol.hpp"
24   -#include <iostream> // cout, cerr
25 25  
26 26 /* __ Namespaces _________________________________________________________ */
27 27  
... ... @@ -132,8 +132,13 @@ GFitsBinTable&amp; GFitsBinTable::operator= (const GFitsBinTable&amp; table)
132 132 ***************************************************************************/
133 133 void GFitsBinTable::open(__fitsfile* fptr)
134 134 {
  135 + // Move to HDU
  136 + int status = 0;
  137 + status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
  138 + if (status != 0)
  139 + throw GException::fits_error(G_OPEN, status);
  140 +
135 141 // Determine number of rows in table
136   - int status = 0;
137 142 long nrows = 0;
138 143 status = __ffgnrw(fptr, &nrows, &status);
139 144 if (status != 0)
... ...
src/fits/GFitsData.cpp
... ... @@ -116,37 +116,10 @@ GFitsData&amp; GFitsData::operator= (const GFitsData&amp; data)
116 116 = =
117 117 ==========================================================================*/
118 118  
119   -/***************************************************************************
120   - * Open Data *
121   - * ----------------------------------------------------------------------- *
122   - ***************************************************************************/
123   -void GFitsData::open(__fitsfile* fptr)
124   -{
125   - // Return
126   - return;
127   -}
128   -
129   -
130   -/***************************************************************************
131   - * Close Data *
132   - * ----------------------------------------------------------------------- *
133   - ***************************************************************************/
134   -void GFitsData::close(void)
135   -{
136   - // Free members
137   - free_members();
138   -
139   - // Initialise members
140   - init_members();
141   -
142   - // Return
143   - return;
144   -}
145   -
146 119  
147 120 /*==========================================================================
148 121 = =
149   - = GFitsData private methods =
  122 + = GFitsData private methods =
150 123 = =
151 124 ==========================================================================*/
152 125  
... ...
src/fits/GFitsHDU.cpp
... ... @@ -13,17 +13,17 @@
13 13 ***************************************************************************/
14 14  
15 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 17 #include "GException.hpp"
17 18 #include "GTools.hpp"
18 19 #include "GFitsHDU.hpp"
19   -#include <iostream> // cout, cerr
20 20  
21 21 /* __ Namespaces _________________________________________________________ */
22 22  
23 23 /* __ Method name definitions ____________________________________________ */
24 24 #define G_OPEN "GFitsHDU::open(int)"
25   -#define G_COLUMN "GFitsHDU::column(std::string)"
26   -#define G_MOVE2HDU "GFitsHDU::move2hdu(void)"
  25 +#define G_SAVE "GFitsHDU::save()"
  26 +#define G_COLUMN "GFitsHDU::column(const std::string&)"
27 27  
28 28 /* __ Macros _____________________________________________________________ */
29 29  
... ... @@ -127,23 +127,25 @@ GFitsHDU&amp; GFitsHDU::operator= (const GFitsHDU&amp; hdu)
127 127 ***************************************************************************/
128 128 void GFitsHDU::open(__fitsfile* fptr, int hdunum)
129 129 {
130   - // Store information
131   - m_fitsfile = fptr;
132   - m_num = hdunum;
133   -
134 130 // Move to HDU
135   - move2hdu();
  131 + int status = 0;
  132 + status = __ffmahd(fptr, hdunum, NULL, &status);
  133 + if (status != 0)
  134 + throw GException::fits_error(G_OPEN, status);
  135 +
  136 + // Store information.
  137 + // Note that the HDU number - 1 is stored in m_fitsfile->HDUposition !!!
  138 + m_fitsfile = *fptr;
136 139  
137 140 // Get HDU type
138   - int status = 0;
139   - status = __ffghdt(m_fitsfile, &m_type, &status);
  141 + status = __ffghdt(&m_fitsfile, &m_type, &status);
140 142 if (status != 0)
141 143 throw GException::fits_error(G_OPEN, status);
142 144  
143 145 // Allocate and open HDU header
144 146 if (m_header != NULL) delete m_header;
145 147 m_header = new GFitsHeader();
146   - m_header->open(m_fitsfile);
  148 + m_header->open(&m_fitsfile);
147 149  
148 150 // Open HDU data area
149 151 if (m_data != NULL) delete m_data;
... ... @@ -161,7 +163,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
161 163 throw GException::fits_unknown_HDU_type(G_OPEN, m_type);
162 164 break;
163 165 }
164   - m_data->open(m_fitsfile);
  166 + m_data->open(&m_fitsfile);
165 167  
166 168 // Get HDU name from header
167 169 m_name = strip_whitespace(m_header->string("EXTNAME"));
... ... @@ -172,8 +174,6 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
172 174 m_name = "NoName";
173 175 }
174 176  
175   - //cout << "HDU #" << hdunum << ": " << m_type << " : " << m_name << endl;
176   -
177 177 // Return
178 178 return;
179 179 }
... ... @@ -183,10 +183,14 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
183 183 * Save HDU to FITS file *
184 184 * ----------------------------------------------------------------------- *
185 185 ***************************************************************************/
  186 +/// NOT YET IMPLEMENTED !!!
186 187 void GFitsHDU::save(void)
187 188 {
188 189 // Move to HDU
189   - move2hdu();
  190 + int status = 0;
  191 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  192 + if (status != 0)
  193 + throw GException::fits_error(G_SAVE, status);
190 194  
191 195 // Save header
192 196 //...
... ... @@ -198,11 +202,12 @@ void GFitsHDU::save(void)
198 202 return;
199 203 }
200 204  
  205 +
201 206 /***************************************************************************
202 207 * Return pointer to column of table *
203 208 * ----------------------------------------------------------------------- *
204 209 ***************************************************************************/
205   -GFitsTableCol* GFitsHDU::column(const std::string colname) const
  210 +GFitsTableCol* GFitsHDU::column(const std::string& colname) const
206 211 {
207 212 // Initialise pointer
208 213 GFitsTableCol* ptr = NULL;
... ... @@ -241,10 +246,12 @@ GFitsTableCol* GFitsHDU::column(const std::string colname) const
241 246 void GFitsHDU::init_members(void)
242 247 {
243 248 // Initialise members
244   - m_fitsfile = NULL;
245   - m_type = 0;
246   - m_header = NULL;
247   - m_data = NULL;
  249 + m_fitsfile.HDUposition = 0;
  250 + m_fitsfile.Fptr = NULL;
  251 + m_name.clear();
  252 + m_type = 0;
  253 + m_header = NULL;
  254 + m_data = NULL;
248 255  
249 256 // Return
250 257 return;
... ... @@ -254,21 +261,15 @@ void GFitsHDU::init_members(void)
254 261 /***************************************************************************
255 262 * Copy class members *
256 263 * ----------------------------------------------------------------------- *
257   - * The function does not copy the FITS file pointer. This prevents that *
258   - * several copies of the FITS file pointer exist in different instances of *
259   - * GFitsHDU, which would lead to confusion since one instance could close *
260   - * the file while for another it still would be opened. *
261   - * The rule ONE INSTANCE - ONE FILE applies. *
262 264 ***************************************************************************/
263 265 void GFitsHDU::copy_members(const GFitsHDU& hdu)
264 266 {
265   - // Reset FITS file attributes
266   - m_fitsfile = NULL;
267   -
268   - // Copy other membres
269   - m_type = hdu.m_type;
270   - m_header = hdu.m_header->clone();
271   - m_data = hdu.m_data->clone();
  267 + // Copy members
  268 + m_fitsfile = hdu.m_fitsfile;
  269 + m_name = hdu.m_name;
  270 + m_type = hdu.m_type;
  271 + m_header = hdu.m_header->clone();
  272 + m_data = hdu.m_data->clone();
272 273  
273 274 // Return
274 275 return;
... ... @@ -294,23 +295,6 @@ void GFitsHDU::free_members(void)
294 295 }
295 296  
296 297  
297   -/***************************************************************************
298   - * Move FITS file pointer to HDU *
299   - * ----------------------------------------------------------------------- *
300   - ***************************************************************************/
301   -void GFitsHDU::move2hdu(void)
302   -{
303   - // Move FITS file pointer to HDU
304   - int status = 0;
305   - status = __ffmahd(m_fitsfile, m_num, NULL, &status);
306   - if (status != 0)
307   - throw GException::fits_error(G_MOVE2HDU, status);
308   -
309   - // Return
310   - return;
311   -}
312   -
313   -
314 298 /*==========================================================================
315 299 = =
316 300 = GFitsHDU friends =
... ... @@ -325,7 +309,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu)
325 309 {
326 310 // Put header in stream
327 311 os << "=== GFitsHDU ===" << endl;
328   - os << " HDU number ................: " << hdu.m_num << endl;
  312 + os << " HDU number ................: " << hdu.m_fitsfile.HDUposition << endl;
329 313 os << " HDU name ..................: " << hdu.m_name << endl;
330 314 os << " HDU type ..................: ";
331 315 switch (hdu.m_type) {
... ... @@ -345,7 +329,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu)
345 329 os << *hdu.m_header;
346 330 switch (hdu.m_type) {
347 331 case 0: // Image HDU
348   - os << "Image";
  332 + os << *(GFitsImage*)hdu.m_data;
349 333 break;
350 334 case 1: // ASCII Table HDU
351 335 os << *(GFitsAsciiTable*)hdu.m_data;
... ...
src/fits/GFitsHeader.cpp
... ... @@ -13,9 +13,9 @@
13 13 ***************************************************************************/
14 14  
15 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 17 #include "GException.hpp"
17 18 #include "GFitsHeader.hpp"
18   -#include <iostream> // cout, cerr
19 19  
20 20 /* __ Namespaces _________________________________________________________ */
21 21  
... ... @@ -124,9 +124,14 @@ GFitsHeader&amp; GFitsHeader::operator= (const GFitsHeader&amp; header)
124 124 ***************************************************************************/
125 125 void GFitsHeader::open(__fitsfile* fptr)
126 126 {
127   - // Determine number of cards in header
  127 + // Move to HDU
128 128 int status = 0;
129   - status = __ffghsp(fptr, &m_num_cards, NULL, &status);
  129 + status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
  130 + if (status != 0)
  131 + throw GException::fits_error(G_OPEN, status);
  132 +
  133 + // Determine number of cards in header
  134 + status = __ffghsp(fptr, &m_num_cards, NULL, &status);
130 135 if (status != 0)
131 136 throw GException::fits_error(G_OPEN, status);
132 137  
... ...
src/fits/GFitsHeaderCard.cpp
... ... @@ -229,12 +229,17 @@ int GFitsHeaderCard::integer(void)
229 229 ***************************************************************************/
230 230 void GFitsHeaderCard::read(__fitsfile* fptr, int keynum)
231 231 {
  232 + // Move to HDU
  233 + int status = 0;
  234 + status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
  235 + if (status != 0)
  236 + throw GException::fits_error(G_READ_NUM, status);
  237 +
232 238 // Read keyword
233 239 char keyname[80];
234 240 char value[80];
235 241 char comment[80];
236   - int status = 0;
237   - status = __ffgkyn(fptr, keynum, keyname, value, comment, &status);
  242 + status = __ffgkyn(fptr, keynum, keyname, value, comment, &status);
238 243 if (status != 0)
239 244 throw GException::fits_error(G_READ_NUM, status);
240 245  
... ... @@ -257,11 +262,16 @@ void GFitsHeaderCard::read(__fitsfile* fptr, int keynum)
257 262 ***************************************************************************/
258 263 void GFitsHeaderCard::read(__fitsfile* fptr, std::string keyname)
259 264 {
  265 + // Move to HDU
  266 + int status = 0;
  267 + status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
  268 + if (status != 0)
  269 + throw GException::fits_error(G_READ_NUM, status);
  270 +
260 271 // Read keyword
261 272 char value[80];
262 273 char comment[80];
263   - int status = 0;
264   - status = __ffgkey(fptr, (char*)keyname.c_str(), value, comment, &status);
  274 + status = __ffgkey(fptr, (char*)keyname.c_str(), value, comment, &status);
265 275  
266 276 // Catch error
267 277 if (status == 202) // Keyword not found
... ... @@ -288,10 +298,15 @@ void GFitsHeaderCard::read(__fitsfile* fptr, std::string keyname)
288 298 ***************************************************************************/
289 299 void GFitsHeaderCard::write(__fitsfile* fptr)
290 300 {
291   - // Write keyword
  301 + // Move to HDU
292 302 int status = 0;
293   - status = __ffuky(fptr, __TSTRING, (char*)m_keyname.c_str(),
294   - (char*)m_value.c_str(), (char*)m_comment.c_str(), &status);
  303 + status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
  304 + if (status != 0)
  305 + throw GException::fits_error(G_READ_NUM, status);
  306 +
  307 + // Write keyword
  308 + status = __ffuky(fptr, __TSTRING, (char*)m_keyname.c_str(),
  309 + (char*)m_value.c_str(), (char*)m_comment.c_str(), &status);
295 310 if (status != 0)
296 311 throw GException::fits_error(G_WRITE, status);
297 312  
... ...
src/fits/GFitsImage.cpp
... ... @@ -13,9 +13,9 @@
13 13 ***************************************************************************/
14 14  
15 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 17 #include "GException.hpp"
17 18 #include "GFitsImage.hpp"
18   -#include <iostream> // cout, cerr
19 19  
20 20 /* __ Namespaces _________________________________________________________ */
21 21  
... ... @@ -124,6 +124,7 @@ GFitsImage&amp; GFitsImage::operator= (const GFitsImage&amp; image)
124 124 * Open Image *
125 125 * ----------------------------------------------------------------------- *
126 126 ***************************************************************************/
  127 +/// NOT YET IMPLEMENTED
127 128 void GFitsImage::open(__fitsfile* fptr)
128 129 {
129 130 // Return
... ... @@ -201,6 +202,26 @@ void GFitsImage::free_members(void)
201 202 = =
202 203 ==========================================================================*/
203 204  
  205 +/***************************************************************************
  206 + * Output operator *
  207 + * ----------------------------------------------------------------------- *
  208 + ***************************************************************************/
  209 +/// DUMMY VERSION
  210 +ostream& operator<< (ostream& os, const GFitsImage& image)
  211 +{
  212 + // Put header in stream
  213 + os << "=== GFitsImage ===" << endl;
  214 +/*
  215 + os << " Number of rows ............: " << table.m_rows << endl;
  216 + os << " Number of columns .........: " << table.m_cols << endl;
  217 + for (int i = 0; i < table.m_cols; ++i)
  218 + os << " " << *(table.m_columns[i]);
  219 +*/
  220 +
  221 + // Return output stream
  222 + return os;
  223 +}
  224 +
204 225  
205 226 /*==========================================================================
206 227 = =
... ...
src/fits/GFitsTableCol.cpp
... ... @@ -13,9 +13,9 @@
13 13 ***************************************************************************/
14 14  
15 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 17 #include "GException.hpp"
17 18 #include "GFitsTableCol.hpp"
18   -#include <iostream> // cout, cerr
19 19  
20 20 /* __ Namespaces _________________________________________________________ */
21 21  
... ... @@ -131,12 +131,13 @@ void GFitsTableCol::init_members(void)
131 131 {
132 132 // Initialise members
133 133 m_name.clear();
134   - m_colnum = 0;
135   - m_type = 0;
136   - m_repeat = 0;
137   - m_width = 0;
138   - m_length = 0;
139   - m_fitsfile = NULL;
  134 + m_colnum = 0;
  135 + m_type = 0;
  136 + m_repeat = 0;
  137 + m_width = 0;
  138 + m_length = 0;
  139 + m_fitsfile.HDUposition = 0;
  140 + m_fitsfile.Fptr = NULL;
140 141  
141 142 // Return
142 143 return;
... ... @@ -191,8 +192,8 @@ void GFitsTableCol::free_members(void)
191 192 ostream& operator<< (ostream& os, const GFitsTableCol& column)
192 193 {
193 194 // Put header in stream
194   - os << "'" << column.m_name << "' [colnum=";
195   - os << column.m_colnum << "] ";
  195 + os << "'" << column.m_name << "'";
  196 + os << " [" << column.m_colnum << "] ";
196 197 os << column.m_type << " repeat=";
197 198 os << column.m_repeat << " width=";
198 199 os << column.m_width << " length=";
... ...
src/fits/GFitsTableDblCol.cpp
... ... @@ -356,8 +356,9 @@ void GFitsTableDblCol::load(void)
356 356  
357 357 // Load column data
358 358 int status = 0;
359   - status = __ffgcv(m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size,
360   - m_nulval, m_data, &m_anynul, &status);
  359 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  360 + status = __ffgcv(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size,
  361 + m_nulval, m_data, &m_anynul, &status);
361 362 if (status != 0)
362 363 throw GException::fits_error(G_LOAD, status);
363 364  
... ...
src/fits/GFitsTableFltCol.cpp
... ... @@ -356,13 +356,12 @@ void GFitsTableFltCol::load(void)
356 356 // Allocate memory
357 357 if (m_data != NULL) delete [] m_data;
358 358 m_data = new float[m_size];
359   -cout << endl;
360   -cout << "m_size: " << m_size << endl;
361   -cout << "m_colnum: " << m_colnum << endl;
  359 +
362 360 // Load column data
363 361 int status = 0;
364   - status = __ffgcv(m_fitsfile, __TFLOAT, m_colnum, 1, 1, m_size,
365   - m_nulval, m_data, &m_anynul, &status);
  362 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  363 + status = __ffgcv(&m_fitsfile, __TFLOAT, m_colnum, 1, 1, m_size,
  364 + m_nulval, m_data, &m_anynul, &status);
366 365 if (status != 0)
367 366 throw GException::fits_error(G_LOAD, status);
368 367  
... ...
src/fits/GFitsTableLngCol.cpp
... ... @@ -359,8 +359,9 @@ void GFitsTableLngCol::load(void)
359 359  
360 360 // Load column data
361 361 int status = 0;
362   - status = __ffgcv(m_fitsfile, __TLONG, m_colnum, 1, 1, m_size,
363   - m_nulval, m_data, &m_anynul, &status);
  362 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  363 + status = __ffgcv(&m_fitsfile, __TLONG, m_colnum, 1, 1, m_size,
  364 + m_nulval, m_data, &m_anynul, &status);
364 365 if (status != 0)
365 366 throw GException::fits_error(G_LOAD, status);
366 367  
... ...
src/fits/GFitsTableShtCol.cpp
... ... @@ -359,8 +359,9 @@ void GFitsTableShtCol::load(void)
359 359  
360 360 // Load column data
361 361 int status = 0;
362   - status = __ffgcv(m_fitsfile, __TSHORT, m_colnum, 1, 1, m_size,
363   - m_nulval, m_data, &m_anynul, &status);
  362 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  363 + status = __ffgcv(&m_fitsfile, __TSHORT, m_colnum, 1, 1, m_size,
  364 + m_nulval, m_data, &m_anynul, &status);
364 365 if (status != 0)
365 366 throw GException::fits_error(G_LOAD, status);
366 367  
... ...
src/fits/GFitsTableStrCol.cpp
... ... @@ -392,8 +392,9 @@ void GFitsTableStrCol::load(void)
392 392  
393 393 // Load column data
394 394 int status = 0;
395   - status = __ffgcvs(m_fitsfile, m_colnum, 1, 1, m_size,
396   - m_nulstr, m_data, &m_anynul, &status);
  395 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  396 + status = __ffgcvs(&m_fitsfile, m_colnum, 1, 1, m_size, m_nulstr, m_data,
  397 + &m_anynul, &status);
397 398 if (status != 0)
398 399 throw GException::fits_error(G_LOAD, status);
399 400  
... ...
test/test_GFits.cpp
... ... @@ -41,6 +41,7 @@ void test_open(void)
41 41 try {
42 42 GFits fits;
43 43 fits.open("test_GFits.fits");
  44 + cout << endl << fits;
44 45 }
45 46 catch (exception &e) {
46 47 std::cout << std::endl << "TEST ERROR: Unable to open FITS file." << std::endl;
... ... @@ -67,7 +68,6 @@ void test_columns(void)
67 68 throw;
68 69 }
69 70  
70   -
71 71 //
72 72 // Test single string column
73 73 //
... ...