Commit e21b42cd45fdba0ae5407ca16db2cb4824434fb3

Authored by knodlseder
1 parent b6aee015

correct HDU selection (using fitsfile pointer)

include/GFitsAsciiTable.hpp
@@ -40,7 +40,7 @@ public: @@ -40,7 +40,7 @@ public:
40 GFitsAsciiTable& operator= (const GFitsAsciiTable& table); 40 GFitsAsciiTable& operator= (const GFitsAsciiTable& table);
41 41
42 // Methods 42 // Methods
43 - void open(__fitsfile* fptr); 43 + void open(__fitsfile* fptr);
44 void close(void); 44 void close(void);
45 GFitsAsciiTable* clone(void) const; 45 GFitsAsciiTable* clone(void) const;
46 GFitsTableCol* column(const std::string colname); 46 GFitsTableCol* column(const std::string colname);
include/GFitsBinTable.hpp
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 #define GFITSBINTABLE_HPP 15 #define GFITSBINTABLE_HPP
16 16
17 /* __ Includes ___________________________________________________________ */ 17 /* __ Includes ___________________________________________________________ */
18 -#include <vector> 18 +//#include <vector>
19 #include "GFitsCfitsio.hpp" 19 #include "GFitsCfitsio.hpp"
20 #include "GFitsData.hpp" 20 #include "GFitsData.hpp"
21 #include "GFitsTableCol.hpp" 21 #include "GFitsTableCol.hpp"
@@ -44,7 +44,7 @@ public: @@ -44,7 +44,7 @@ public:
44 GFitsBinTable& operator= (const GFitsBinTable& table); 44 GFitsBinTable& operator= (const GFitsBinTable& table);
45 45
46 // Methods 46 // Methods
47 - void open(__fitsfile* fptr); 47 + void open(__fitsfile* fptr);
48 void close(void); 48 void close(void);
49 GFitsBinTable* clone(void) const; 49 GFitsBinTable* clone(void) const;
50 GFitsTableCol* column(const std::string colname); 50 GFitsTableCol* column(const std::string colname);
include/GFitsCfitsio.hpp
@@ -88,7 +88,10 @@ typedef fitsfile __fitsfile; @@ -88,7 +88,10 @@ typedef fitsfile __fitsfile;
88 #define __TDBLCOMPLEX 163 88 #define __TDBLCOMPLEX 163
89 89
90 /* __ Type definition ____________________________________________________ */ 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 /* __ Dummy function _____________________________________________________ */ 96 /* __ Dummy function _____________________________________________________ */
94 inline 97 inline
include/GFitsData.hpp
@@ -35,7 +35,7 @@ public: @@ -35,7 +35,7 @@ public:
35 virtual GFitsData& operator= (const GFitsData& data); 35 virtual GFitsData& operator= (const GFitsData& data);
36 36
37 // Methods 37 // Methods
38 - virtual void open(__fitsfile* fptr) = 0; 38 + virtual void open(__fitsfile* fptr) = 0;
39 virtual void close(void) = 0; 39 virtual void close(void) = 0;
40 virtual GFitsData* clone(void) const = 0; 40 virtual GFitsData* clone(void) const = 0;
41 41
include/GFitsHDU.hpp
@@ -42,26 +42,24 @@ public: @@ -42,26 +42,24 @@ public:
42 GFitsHDU& operator= (const GFitsHDU& hdu); 42 GFitsHDU& operator= (const GFitsHDU& hdu);
43 43
44 // Methods 44 // Methods
45 - void open(__fitsfile* fptr, int hdunum); 45 + void open(__fitsfile* fptr, int hdunum);
46 void save(void); 46 void save(void);
47 std::string extname(void) const; 47 std::string extname(void) const;
48 int extno(void) const; 48 int extno(void) const;
49 int exttype(void) const; 49 int exttype(void) const;
50 GFitsHeader* header(void) const; 50 GFitsHeader* header(void) const;
51 GFitsData* data(void) const; 51 GFitsData* data(void) const;
52 - GFitsTableCol* column(const std::string colname) const; 52 + GFitsTableCol* column(const std::string& colname) const;
53 53
54 private: 54 private:
55 // Private methods 55 // Private methods
56 void init_members(void); 56 void init_members(void);
57 void copy_members(const GFitsHDU& hdu); 57 void copy_members(const GFitsHDU& hdu);
58 void free_members(void); 58 void free_members(void);
59 - void move2hdu(void);  
60 59
61 // Private data area 60 // Private data area
62 - __fitsfile* m_fitsfile; // FITS file pointer 61 + __fitsfile m_fitsfile; // FITS file pointer
63 std::string m_name; // HDU name 62 std::string m_name; // HDU name
64 - int m_num; // HDU number (starting from 1)  
65 int m_type; // HDU type 63 int m_type; // HDU type
66 GFitsHeader* m_header; // HDU header 64 GFitsHeader* m_header; // HDU header
67 GFitsData* m_data; // HDU data 65 GFitsData* m_data; // HDU data
@@ -72,7 +70,7 @@ private: @@ -72,7 +70,7 @@ private:
72 * Inline methods * 70 * Inline methods *
73 ***************************************************************************/ 71 ***************************************************************************/
74 inline std::string GFitsHDU::extname(void) const { return m_name; } 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 inline int GFitsHDU::exttype(void) const { return m_type; } 74 inline int GFitsHDU::exttype(void) const { return m_type; }
77 inline GFitsHeader* GFitsHDU::header(void) const { return m_header; } 75 inline GFitsHeader* GFitsHDU::header(void) const { return m_header; }
78 inline GFitsData* GFitsHDU::data(void) const { return m_data; } 76 inline GFitsData* GFitsHDU::data(void) const { return m_data; }
include/GFitsHeader.hpp
@@ -39,7 +39,7 @@ public: @@ -39,7 +39,7 @@ public:
39 GFitsHeader& operator= (const GFitsHeader& header); 39 GFitsHeader& operator= (const GFitsHeader& header);
40 40
41 // Methods 41 // Methods
42 - void open(__fitsfile* fptr); 42 + void open(__fitsfile* fptr);
43 void close(void); 43 void close(void);
44 GFitsHeaderCard* card(const std::string keyname); 44 GFitsHeaderCard* card(const std::string keyname);
45 GFitsHeaderCard* card(const int cardno); 45 GFitsHeaderCard* card(const int cardno);
include/GFitsImage.hpp
@@ -26,6 +26,9 @@ @@ -26,6 +26,9 @@
26 ***************************************************************************/ 26 ***************************************************************************/
27 class GFitsImage : public GFitsData { 27 class GFitsImage : public GFitsData {
28 28
  29 + // I/O friends
  30 + friend ostream& operator<< (ostream& os, const GFitsImage& image);
  31 +
29 public: 32 public:
30 // Constructors and destructors 33 // Constructors and destructors
31 GFitsImage(); 34 GFitsImage();
@@ -36,7 +39,7 @@ public: @@ -36,7 +39,7 @@ public:
36 GFitsImage& operator= (const GFitsImage& image); 39 GFitsImage& operator= (const GFitsImage& image);
37 40
38 // Methods 41 // Methods
39 - void open(__fitsfile* fptr); 42 + void open(__fitsfile* fptr);
40 void close(void); 43 void close(void);
41 GFitsImage* clone(void) const; 44 GFitsImage* clone(void) const;
42 45
include/GFitsTableCol.hpp
@@ -71,7 +71,7 @@ protected: @@ -71,7 +71,7 @@ protected:
71 int m_repeat; 71 int m_repeat;
72 int m_width; 72 int m_width;
73 int m_length; 73 int m_length;
74 - __fitsfile* m_fitsfile; 74 + __fitsfile m_fitsfile;
75 75
76 private: 76 private:
77 // Private methods 77 // Private methods
@@ -90,7 +90,7 @@ inline void GFitsTableCol::set_type(const int type) { m_type = type; } @@ -90,7 +90,7 @@ inline void GFitsTableCol::set_type(const int type) { m_type = type; }
90 inline void GFitsTableCol::set_repeat(const int repeat) { m_repeat = repeat; } 90 inline void GFitsTableCol::set_repeat(const int repeat) { m_repeat = repeat; }
91 inline void GFitsTableCol::set_width(const int width) { m_width = width; } 91 inline void GFitsTableCol::set_width(const int width) { m_width = width; }
92 inline void GFitsTableCol::set_length(const int length) { m_length = length; } 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 inline std::string GFitsTableCol::name(void) { return m_name; } 94 inline std::string GFitsTableCol::name(void) { return m_name; }
95 inline int GFitsTableCol::colnum(void) { return m_colnum; } 95 inline int GFitsTableCol::colnum(void) { return m_colnum; }
96 inline int GFitsTableCol::type(void) { return m_type; } 96 inline int GFitsTableCol::type(void) { return m_type; }
src/fits/GFitsAsciiTable.cpp
@@ -13,9 +13,14 @@ @@ -13,9 +13,14 @@
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15 /* __ Includes ___________________________________________________________ */ 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 #include "GException.hpp" 17 #include "GException.hpp"
17 #include "GFitsAsciiTable.hpp" 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 /* __ Namespaces _________________________________________________________ */ 25 /* __ Namespaces _________________________________________________________ */
21 26
@@ -124,6 +129,7 @@ GFitsAsciiTable&amp; GFitsAsciiTable::operator= (const GFitsAsciiTable&amp; table) @@ -124,6 +129,7 @@ GFitsAsciiTable&amp; GFitsAsciiTable::operator= (const GFitsAsciiTable&amp; table)
124 * Open Table * 129 * Open Table *
125 * ----------------------------------------------------------------------- * 130 * ----------------------------------------------------------------------- *
126 ***************************************************************************/ 131 ***************************************************************************/
  132 +/// NOT YET IMPLEMENTED
127 void GFitsAsciiTable::open(__fitsfile* fptr) 133 void GFitsAsciiTable::open(__fitsfile* fptr)
128 { 134 {
129 cout << "open ASCII table" << endl; 135 cout << "open ASCII table" << endl;
@@ -192,8 +198,6 @@ GFitsTableCol* GFitsAsciiTable::column(const int colnum) @@ -192,8 +198,6 @@ GFitsTableCol* GFitsAsciiTable::column(const int colnum)
192 } 198 }
193 199
194 200
195 -  
196 -  
197 /*========================================================================== 201 /*==========================================================================
198 = = 202 = =
199 = GFitsAsciiTable private methods = 203 = GFitsAsciiTable private methods =
@@ -275,7 +279,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsAsciiTable&amp; table) @@ -275,7 +279,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsAsciiTable&amp; table)
275 os << " Number of rows ............: " << table.m_rows << endl; 279 os << " Number of rows ............: " << table.m_rows << endl;
276 os << " Number of columns .........: " << table.m_cols << endl; 280 os << " Number of columns .........: " << table.m_cols << endl;
277 for (int i = 0; i < table.m_cols; ++i) 281 for (int i = 0; i < table.m_cols; ++i)
278 - os << i; 282 + os << " " << *(table.m_columns[i]);
279 283
280 // Return output stream 284 // Return output stream
281 return os; 285 return os;
src/fits/GFitsBinTable.cpp
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15 /* __ Includes ___________________________________________________________ */ 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 #include "GException.hpp" 17 #include "GException.hpp"
17 #include "GTools.hpp" 18 #include "GTools.hpp"
18 #include "GFitsBinTable.hpp" 19 #include "GFitsBinTable.hpp"
@@ -21,7 +22,6 @@ @@ -21,7 +22,6 @@
21 #include "GFitsTableLngCol.hpp" 22 #include "GFitsTableLngCol.hpp"
22 #include "GFitsTableFltCol.hpp" 23 #include "GFitsTableFltCol.hpp"
23 #include "GFitsTableDblCol.hpp" 24 #include "GFitsTableDblCol.hpp"
24 -#include <iostream> // cout, cerr  
25 25
26 /* __ Namespaces _________________________________________________________ */ 26 /* __ Namespaces _________________________________________________________ */
27 27
@@ -132,8 +132,13 @@ GFitsBinTable&amp; GFitsBinTable::operator= (const GFitsBinTable&amp; table) @@ -132,8 +132,13 @@ GFitsBinTable&amp; GFitsBinTable::operator= (const GFitsBinTable&amp; table)
132 ***************************************************************************/ 132 ***************************************************************************/
133 void GFitsBinTable::open(__fitsfile* fptr) 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 // Determine number of rows in table 141 // Determine number of rows in table
136 - int status = 0;  
137 long nrows = 0; 142 long nrows = 0;
138 status = __ffgnrw(fptr, &nrows, &status); 143 status = __ffgnrw(fptr, &nrows, &status);
139 if (status != 0) 144 if (status != 0)
src/fits/GFitsData.cpp
@@ -116,37 +116,10 @@ GFitsData&amp; GFitsData::operator= (const GFitsData&amp; data) @@ -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,17 +13,17 @@
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15 /* __ Includes ___________________________________________________________ */ 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 #include "GException.hpp" 17 #include "GException.hpp"
17 #include "GTools.hpp" 18 #include "GTools.hpp"
18 #include "GFitsHDU.hpp" 19 #include "GFitsHDU.hpp"
19 -#include <iostream> // cout, cerr  
20 20
21 /* __ Namespaces _________________________________________________________ */ 21 /* __ Namespaces _________________________________________________________ */
22 22
23 /* __ Method name definitions ____________________________________________ */ 23 /* __ Method name definitions ____________________________________________ */
24 #define G_OPEN "GFitsHDU::open(int)" 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 /* __ Macros _____________________________________________________________ */ 28 /* __ Macros _____________________________________________________________ */
29 29
@@ -127,23 +127,25 @@ GFitsHDU&amp; GFitsHDU::operator= (const GFitsHDU&amp; hdu) @@ -127,23 +127,25 @@ GFitsHDU&amp; GFitsHDU::operator= (const GFitsHDU&amp; hdu)
127 ***************************************************************************/ 127 ***************************************************************************/
128 void GFitsHDU::open(__fitsfile* fptr, int hdunum) 128 void GFitsHDU::open(__fitsfile* fptr, int hdunum)
129 { 129 {
130 - // Store information  
131 - m_fitsfile = fptr;  
132 - m_num = hdunum;  
133 -  
134 // Move to HDU 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 // Get HDU type 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 if (status != 0) 142 if (status != 0)
141 throw GException::fits_error(G_OPEN, status); 143 throw GException::fits_error(G_OPEN, status);
142 144
143 // Allocate and open HDU header 145 // Allocate and open HDU header
144 if (m_header != NULL) delete m_header; 146 if (m_header != NULL) delete m_header;
145 m_header = new GFitsHeader(); 147 m_header = new GFitsHeader();
146 - m_header->open(m_fitsfile); 148 + m_header->open(&m_fitsfile);
147 149
148 // Open HDU data area 150 // Open HDU data area
149 if (m_data != NULL) delete m_data; 151 if (m_data != NULL) delete m_data;
@@ -161,7 +163,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) @@ -161,7 +163,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
161 throw GException::fits_unknown_HDU_type(G_OPEN, m_type); 163 throw GException::fits_unknown_HDU_type(G_OPEN, m_type);
162 break; 164 break;
163 } 165 }
164 - m_data->open(m_fitsfile); 166 + m_data->open(&m_fitsfile);
165 167
166 // Get HDU name from header 168 // Get HDU name from header
167 m_name = strip_whitespace(m_header->string("EXTNAME")); 169 m_name = strip_whitespace(m_header->string("EXTNAME"));
@@ -172,8 +174,6 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) @@ -172,8 +174,6 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
172 m_name = "NoName"; 174 m_name = "NoName";
173 } 175 }
174 176
175 - //cout << "HDU #" << hdunum << ": " << m_type << " : " << m_name << endl;  
176 -  
177 // Return 177 // Return
178 return; 178 return;
179 } 179 }
@@ -183,10 +183,14 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) @@ -183,10 +183,14 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
183 * Save HDU to FITS file * 183 * Save HDU to FITS file *
184 * ----------------------------------------------------------------------- * 184 * ----------------------------------------------------------------------- *
185 ***************************************************************************/ 185 ***************************************************************************/
  186 +/// NOT YET IMPLEMENTED !!!
186 void GFitsHDU::save(void) 187 void GFitsHDU::save(void)
187 { 188 {
188 // Move to HDU 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 // Save header 195 // Save header
192 //... 196 //...
@@ -198,11 +202,12 @@ void GFitsHDU::save(void) @@ -198,11 +202,12 @@ void GFitsHDU::save(void)
198 return; 202 return;
199 } 203 }
200 204
  205 +
201 /*************************************************************************** 206 /***************************************************************************
202 * Return pointer to column of table * 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 // Initialise pointer 212 // Initialise pointer
208 GFitsTableCol* ptr = NULL; 213 GFitsTableCol* ptr = NULL;
@@ -241,10 +246,12 @@ GFitsTableCol* GFitsHDU::column(const std::string colname) const @@ -241,10 +246,12 @@ GFitsTableCol* GFitsHDU::column(const std::string colname) const
241 void GFitsHDU::init_members(void) 246 void GFitsHDU::init_members(void)
242 { 247 {
243 // Initialise members 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 // Return 256 // Return
250 return; 257 return;
@@ -254,21 +261,15 @@ void GFitsHDU::init_members(void) @@ -254,21 +261,15 @@ void GFitsHDU::init_members(void)
254 /*************************************************************************** 261 /***************************************************************************
255 * Copy class members * 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 void GFitsHDU::copy_members(const GFitsHDU& hdu) 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 // Return 274 // Return
274 return; 275 return;
@@ -294,23 +295,6 @@ void GFitsHDU::free_members(void) @@ -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 = GFitsHDU friends = 300 = GFitsHDU friends =
@@ -325,7 +309,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu) @@ -325,7 +309,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu)
325 { 309 {
326 // Put header in stream 310 // Put header in stream
327 os << "=== GFitsHDU ===" << endl; 311 os << "=== GFitsHDU ===" << endl;
328 - os << " HDU number ................: " << hdu.m_num << endl; 312 + os << " HDU number ................: " << hdu.m_fitsfile.HDUposition << endl;
329 os << " HDU name ..................: " << hdu.m_name << endl; 313 os << " HDU name ..................: " << hdu.m_name << endl;
330 os << " HDU type ..................: "; 314 os << " HDU type ..................: ";
331 switch (hdu.m_type) { 315 switch (hdu.m_type) {
@@ -345,7 +329,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu) @@ -345,7 +329,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu)
345 os << *hdu.m_header; 329 os << *hdu.m_header;
346 switch (hdu.m_type) { 330 switch (hdu.m_type) {
347 case 0: // Image HDU 331 case 0: // Image HDU
348 - os << "Image"; 332 + os << *(GFitsImage*)hdu.m_data;
349 break; 333 break;
350 case 1: // ASCII Table HDU 334 case 1: // ASCII Table HDU
351 os << *(GFitsAsciiTable*)hdu.m_data; 335 os << *(GFitsAsciiTable*)hdu.m_data;
src/fits/GFitsHeader.cpp
@@ -13,9 +13,9 @@ @@ -13,9 +13,9 @@
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15 /* __ Includes ___________________________________________________________ */ 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 #include "GException.hpp" 17 #include "GException.hpp"
17 #include "GFitsHeader.hpp" 18 #include "GFitsHeader.hpp"
18 -#include <iostream> // cout, cerr  
19 19
20 /* __ Namespaces _________________________________________________________ */ 20 /* __ Namespaces _________________________________________________________ */
21 21
@@ -124,9 +124,14 @@ GFitsHeader&amp; GFitsHeader::operator= (const GFitsHeader&amp; header) @@ -124,9 +124,14 @@ GFitsHeader&amp; GFitsHeader::operator= (const GFitsHeader&amp; header)
124 ***************************************************************************/ 124 ***************************************************************************/
125 void GFitsHeader::open(__fitsfile* fptr) 125 void GFitsHeader::open(__fitsfile* fptr)
126 { 126 {
127 - // Determine number of cards in header 127 + // Move to HDU
128 int status = 0; 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 if (status != 0) 135 if (status != 0)
131 throw GException::fits_error(G_OPEN, status); 136 throw GException::fits_error(G_OPEN, status);
132 137
src/fits/GFitsHeaderCard.cpp
@@ -229,12 +229,17 @@ int GFitsHeaderCard::integer(void) @@ -229,12 +229,17 @@ int GFitsHeaderCard::integer(void)
229 ***************************************************************************/ 229 ***************************************************************************/
230 void GFitsHeaderCard::read(__fitsfile* fptr, int keynum) 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 // Read keyword 238 // Read keyword
233 char keyname[80]; 239 char keyname[80];
234 char value[80]; 240 char value[80];
235 char comment[80]; 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 if (status != 0) 243 if (status != 0)
239 throw GException::fits_error(G_READ_NUM, status); 244 throw GException::fits_error(G_READ_NUM, status);
240 245
@@ -257,11 +262,16 @@ void GFitsHeaderCard::read(__fitsfile* fptr, int keynum) @@ -257,11 +262,16 @@ void GFitsHeaderCard::read(__fitsfile* fptr, int keynum)
257 ***************************************************************************/ 262 ***************************************************************************/
258 void GFitsHeaderCard::read(__fitsfile* fptr, std::string keyname) 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 // Read keyword 271 // Read keyword
261 char value[80]; 272 char value[80];
262 char comment[80]; 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 // Catch error 276 // Catch error
267 if (status == 202) // Keyword not found 277 if (status == 202) // Keyword not found
@@ -288,10 +298,15 @@ void GFitsHeaderCard::read(__fitsfile* fptr, std::string keyname) @@ -288,10 +298,15 @@ void GFitsHeaderCard::read(__fitsfile* fptr, std::string keyname)
288 ***************************************************************************/ 298 ***************************************************************************/
289 void GFitsHeaderCard::write(__fitsfile* fptr) 299 void GFitsHeaderCard::write(__fitsfile* fptr)
290 { 300 {
291 - // Write keyword 301 + // Move to HDU
292 int status = 0; 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 if (status != 0) 310 if (status != 0)
296 throw GException::fits_error(G_WRITE, status); 311 throw GException::fits_error(G_WRITE, status);
297 312
src/fits/GFitsImage.cpp
@@ -13,9 +13,9 @@ @@ -13,9 +13,9 @@
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15 /* __ Includes ___________________________________________________________ */ 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 #include "GException.hpp" 17 #include "GException.hpp"
17 #include "GFitsImage.hpp" 18 #include "GFitsImage.hpp"
18 -#include <iostream> // cout, cerr  
19 19
20 /* __ Namespaces _________________________________________________________ */ 20 /* __ Namespaces _________________________________________________________ */
21 21
@@ -124,6 +124,7 @@ GFitsImage&amp; GFitsImage::operator= (const GFitsImage&amp; image) @@ -124,6 +124,7 @@ GFitsImage&amp; GFitsImage::operator= (const GFitsImage&amp; image)
124 * Open Image * 124 * Open Image *
125 * ----------------------------------------------------------------------- * 125 * ----------------------------------------------------------------------- *
126 ***************************************************************************/ 126 ***************************************************************************/
  127 +/// NOT YET IMPLEMENTED
127 void GFitsImage::open(__fitsfile* fptr) 128 void GFitsImage::open(__fitsfile* fptr)
128 { 129 {
129 // Return 130 // Return
@@ -201,6 +202,26 @@ void GFitsImage::free_members(void) @@ -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,9 +13,9 @@
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15 /* __ Includes ___________________________________________________________ */ 15 /* __ Includes ___________________________________________________________ */
  16 +#include <iostream>
16 #include "GException.hpp" 17 #include "GException.hpp"
17 #include "GFitsTableCol.hpp" 18 #include "GFitsTableCol.hpp"
18 -#include <iostream> // cout, cerr  
19 19
20 /* __ Namespaces _________________________________________________________ */ 20 /* __ Namespaces _________________________________________________________ */
21 21
@@ -131,12 +131,13 @@ void GFitsTableCol::init_members(void) @@ -131,12 +131,13 @@ void GFitsTableCol::init_members(void)
131 { 131 {
132 // Initialise members 132 // Initialise members
133 m_name.clear(); 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 // Return 142 // Return
142 return; 143 return;
@@ -191,8 +192,8 @@ void GFitsTableCol::free_members(void) @@ -191,8 +192,8 @@ void GFitsTableCol::free_members(void)
191 ostream& operator<< (ostream& os, const GFitsTableCol& column) 192 ostream& operator<< (ostream& os, const GFitsTableCol& column)
192 { 193 {
193 // Put header in stream 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 os << column.m_type << " repeat="; 197 os << column.m_type << " repeat=";
197 os << column.m_repeat << " width="; 198 os << column.m_repeat << " width=";
198 os << column.m_width << " length="; 199 os << column.m_width << " length=";
src/fits/GFitsTableDblCol.cpp
@@ -356,8 +356,9 @@ void GFitsTableDblCol::load(void) @@ -356,8 +356,9 @@ void GFitsTableDblCol::load(void)
356 356
357 // Load column data 357 // Load column data
358 int status = 0; 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 if (status != 0) 362 if (status != 0)
362 throw GException::fits_error(G_LOAD, status); 363 throw GException::fits_error(G_LOAD, status);
363 364
src/fits/GFitsTableFltCol.cpp
@@ -356,13 +356,12 @@ void GFitsTableFltCol::load(void) @@ -356,13 +356,12 @@ void GFitsTableFltCol::load(void)
356 // Allocate memory 356 // Allocate memory
357 if (m_data != NULL) delete [] m_data; 357 if (m_data != NULL) delete [] m_data;
358 m_data = new float[m_size]; 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 // Load column data 360 // Load column data
363 int status = 0; 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 if (status != 0) 365 if (status != 0)
367 throw GException::fits_error(G_LOAD, status); 366 throw GException::fits_error(G_LOAD, status);
368 367
src/fits/GFitsTableLngCol.cpp
@@ -359,8 +359,9 @@ void GFitsTableLngCol::load(void) @@ -359,8 +359,9 @@ void GFitsTableLngCol::load(void)
359 359
360 // Load column data 360 // Load column data
361 int status = 0; 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 if (status != 0) 365 if (status != 0)
365 throw GException::fits_error(G_LOAD, status); 366 throw GException::fits_error(G_LOAD, status);
366 367
src/fits/GFitsTableShtCol.cpp
@@ -359,8 +359,9 @@ void GFitsTableShtCol::load(void) @@ -359,8 +359,9 @@ void GFitsTableShtCol::load(void)
359 359
360 // Load column data 360 // Load column data
361 int status = 0; 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 if (status != 0) 365 if (status != 0)
365 throw GException::fits_error(G_LOAD, status); 366 throw GException::fits_error(G_LOAD, status);
366 367
src/fits/GFitsTableStrCol.cpp
@@ -392,8 +392,9 @@ void GFitsTableStrCol::load(void) @@ -392,8 +392,9 @@ void GFitsTableStrCol::load(void)
392 392
393 // Load column data 393 // Load column data
394 int status = 0; 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 if (status != 0) 398 if (status != 0)
398 throw GException::fits_error(G_LOAD, status); 399 throw GException::fits_error(G_LOAD, status);
399 400
test/test_GFits.cpp
@@ -41,6 +41,7 @@ void test_open(void) @@ -41,6 +41,7 @@ void test_open(void)
41 try { 41 try {
42 GFits fits; 42 GFits fits;
43 fits.open("test_GFits.fits"); 43 fits.open("test_GFits.fits");
  44 + cout << endl << fits;
44 } 45 }
45 catch (exception &e) { 46 catch (exception &e) {
46 std::cout << std::endl << "TEST ERROR: Unable to open FITS file." << std::endl; 47 std::cout << std::endl << "TEST ERROR: Unable to open FITS file." << std::endl;
@@ -67,7 +68,6 @@ void test_columns(void) @@ -67,7 +68,6 @@ void test_columns(void)
67 throw; 68 throw;
68 } 69 }
69 70
70 -  
71 // 71 //
72 // Test single string column 72 // Test single string column
73 // 73 //