casacore
Loading...
Searching...
No Matches
fitsio.h
Go to the documentation of this file.
1// # fitsio.h:
2// # Copyright (C) 1993,1994,1995,1996,1999,2001,2003
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef FITS_FITSIO_H
27#define FITS_FITSIO_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/fits/FITS/fits.h>
31#include <casacore/fits/FITS/blockio.h>
32#include <casacore/fits/FITS/hdu.h>
33// # include <casacore/casa/stdvector.h>
34#include <casacore/casa/Arrays/Vector.h>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38//<summary> sequential FITS I/O </summary>
39// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
40// </reviewed>
41//<synopsis>
42// FitsIO is a base class that handles all the sequential blocked
43// FITS I/O. Special derived classes do the input and output.
44// No interpretation of the data is attempted here, there are
45// special FITS classes that handle syntax and interpretation.
46//</synopsis>
47//<example>
48//<srcblock>
49// FitsInput fin("myfile.fits",FITS::Disk); // open disk file for FITS input
50// if (fin.err() == FitsIO::IOERR) { // check if open succeeded
51// cout << "Could not open FITS input\n";
52// exit(0);
53// }
54// if (fin.rectype() == FITS::HDURecord && // test for primary array
55// fin.hdutype() == FITS::PrimaryArrayHDU) {
56// }
57//</srcblock>
58//</example>
59
60class FitsIO {
61 public:
62 virtual ~FitsIO();
63
64 // error return code. Should be one of an
65 // enumerated type:
66 //
67 // # until cxx2html can handle enum() we duplicate it here
68 //
69 //<srcblock>
70 // enum FitsErrs { OK, IOERR, MISSKEY, BADBEGIN, EMPTYFILE,
71 // NOPRIMARY, BADOPER, BADEOF, MEMERR, BADBITPIX, NOAXISN,
72 // NOPCOUNT, NOGCOUNT, BADPCOUNT, BADGCOUNT, NOGROUPS,
73 // BADNAXIS, BADPRIMARY, BADSIZE, HDUERR };
74 //</srcblock>
75 //<group>
98 int err() const { return m_err_status; }
99 //</group>
100 //
101 // record size, in bytes, of a FITS block.
102 // Normally set at 2880, unless some form of blocking was used.
103 int fitsrecsize() const { return m_recsize; }
104 // is it a valid fits file (SIMPLE==T). If not, the only
105 // safest operation is to skip the data portion of the
106 // current HeaderDataUnit
107 Bool isafits() const { return m_valid_fits; }
108 // see if there may be FITS extensions present (EXTENT==T)
109 Bool isextend() const { return m_extend; }
110 // test if end of file has been reached
111 Bool eof() const { return Bool(m_rec_type == FITS::EndOfFile); }
112 // the FITS record type
114 // Header Data Unit type (e.g.
115 FITS::HDUType hdutype() const { return m_hdu_type; }
117 // return the datasize of the current HDU. This excludes
118 // the trailing end of the blocked data portion.
119 OFF_T datasize() const { return m_data_size; }
120 // data characteristics
121 Int itemsize() const { return m_item_size; }
122 // for input, size of remaining data
123 // for output, size of data written
124 OFF_T currsize() const { return m_curr_size; }
125 // get FitsKeyCardTranslator
127 // get the fitsfile pointer
128 fitsfile *getfptr() const { return m_fptr; }
129
130 // get the size of the last skipped HDU
131 OFF_T getskipsize() const { return m_skipHDU_size; }
132
133 protected:
135
136 fitsfile *m_fptr;
137 const int m_recsize;
138 Bool m_valid_fits; // True if SIMPLE == T
139 Bool m_extend; // True if EXTEND == T
140 Bool m_isaprimary; // True if there is a primary HDU
141 Bool m_header_done; // True if header has been processed
144
145 FITSErrorHandler m_errfn; // error handler function
149
150 char *m_curr; // pointer to current record
151 int m_bytepos; // current byte position within record
152 Int m_item_size; // data characteristics
154 // uInt m_data_size;
156 // for input, size of remaining data
157 // for output, size of data written
158 // uInt m_curr_size;
160
161 // for size of the last HDU skipped
163
164 // set error message that belongs to one of the enumerated types
165 virtual void errmsg(FitsErrs, const char *) = 0;
166};
167
168//<summary> fixed-length sequential blocked FITS input </summary>
169
170class FitsInput : public FitsIO {
172 friend OFF_T HeaderDataUnit::read_all_data(char *);
173 friend int HeaderDataUnit::read_data(char *, Int);
176
177 public:
178 //<group>
179 FitsInput(const char *, const FITS::FitsDevice &, int = 10,
183 //</group>
184
185 int skip_hdu();
186
187 // skip all remaining data
189
190 // int skip_hdu2();
191 // read special or unrecognizable records
192 char *read_sp();
193
194 // get hdu header image cards as strings. By default the strings will be of
195 // variable length. You can optionally ask for them to be length 80 (padded
196 // with spaces).
198
199 // number of physical blocks read/written
200 int blockno() const { return m_fin.blockno(); }
201
202 // number of logical records read/written
203 int recno() const { return m_fin.recno(); }
204 BlockInput &getfin() { return m_fin; } // for test use only
205
206 // the number of hdu in this fits file
207 int getnumhdu() const { return m_thdunum; }
208
209 private:
211 BlockInput &make_input(const char *, const FITS::FitsDevice &, int,
213
214 // flag used for read control in errors
216 // total number of hdu in this fits file
218
219 virtual void errmsg(FitsErrs, const char *);
220 void init();
224
225 // # check if this comes out ok in cxx2html
226 // Special interface to class HeaderDataUnit
227 //<group>
228 // special way to process header
230 // read all data into a given address - all responsibility is given
231 // to the user
232 OFF_T read_all(FITS::HDUType, char *);
233 // read N bytes into address
234 int read(FITS::HDUType, char *, int);
235 // skip N bytes
236 int skip(FITS::HDUType, OFF_T);
237 //</group>
238};
239
240//<summary> fixed-length sequential blocked FITS output </summary>
241
242class FitsOutput : public FitsIO {
246
247 public:
248 //<group>
249 FitsOutput(const char *, const FITS::FitsDevice &, int = 10,
253 //</group>
254 // used by PrimaryArray, BinaryTabelExtention etc to work with the constructor without keyword
255 // list.
257 // write a special record. For this the record type must also
258 // be to set to FITS::SpecialRecord
259 int write_sp(char *rec);
260 // check if the current hdu is done. It was private.
261 int hdu_complete() { return (m_rec_type == FITS::HDURecord && m_data_size == 0); }
263 void setfptr(fitsfile *ffp);
265
266 private:
269 BlockOutput &make_output(const char *, const FITS::FitsDevice &, int,
271
272 virtual void errmsg(FitsErrs, const char *);
273
277
278 // Special interface to class HeaderDataUnit
279 //<group>
281 // write all data from address
282 int write_all(FITS::HDUType, char *, char);
283 // write N bytes from address
284 int write(FITS::HDUType, char *, Int, char);
285 //</group>
286};
287
288//<summary> FITS input from disk </summary>
289
290class FitsDiskInput : public BlockInput {
291 public:
292 FitsDiskInput(const char *, int, int = 1,
295 // implements skip in terms of lseek
296 char *skip(int);
297};
298
299//<summary> FITS output to disk </summary>
300
302 public:
303 FitsDiskOutput(const char *, int, int = 1,
306};
307
308//<summary> FITS input from standard input </summary>
309
315
316//<summary> FITS output to standard output </summary>
317
323
324//<summary> FITS input from 9-track tape </summary>
325
327 public:
328 FitsTape9Input(const char *, int, int = 10,
331};
332
333//<summary> FITS output to 9-track tape </summary>
334
336 public:
337 FitsTape9Output(const char *, int, int = 10,
340};
341
342} // namespace casacore
343
344#endif
fixed-length blocked sequential input base class
Definition blockio.h:135
BlockInput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
Construction can be done either from a filename or from a file descriptor.
fixed-length blocked sequential output base class
Definition blockio.h:169
BlockOutput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
Construction can be done either from a filename or from a file descriptor.
static void defaultHandler(const char *errMessage, ErrorLevel severity)
The default error handler.
FitsRecType
Types of FITS Records.
Definition fits.h:349
ValueType
FITS I/O Error message types.
Definition fits.h:180
HDUType
Types of FITS Header-Data Units.
Definition fits.h:362
FitsDevice
Supported FITS Physical Devices.
Definition fits.h:359
FitsDiskInput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
char * skip(int)
implements skip in terms of lseek
FitsDiskOutput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
Bool eof() const
test if end of file has been reached
Definition fitsio.h:111
int err() const
Definition fitsio.h:98
Int itemsize() const
data characteristics
Definition fitsio.h:121
Bool isafits() const
is it a valid fits file (SIMPLE==T).
Definition fitsio.h:107
FITS::FitsRecType m_rec_type
Definition fitsio.h:142
const int m_recsize
Definition fitsio.h:137
OFF_T currsize() const
for input, size of remaining data for output, size of data written
Definition fitsio.h:124
FITS::FitsRecType rectype() const
the FITS record type
Definition fitsio.h:113
FitsKeyCardTranslator & getkc()
get FitsKeyCardTranslator
Definition fitsio.h:126
Bool isextend() const
see if there may be FITS extensions present (EXTENT==T)
Definition fitsio.h:109
int fitsrecsize() const
record size, in bytes, of a FITS block.
Definition fitsio.h:103
virtual void errmsg(FitsErrs, const char *)=0
set error message that belongs to one of the enumerated types
FitsIO(FITSErrorHandler)
fitsfile * m_fptr
Definition fitsio.h:136
fitsfile * getfptr() const
get the fitsfile pointer
Definition fitsio.h:128
OFF_T m_skipHDU_size
for size of the last HDU skipped
Definition fitsio.h:162
virtual ~FitsIO()
FITS::ValueType m_data_type
Definition fitsio.h:153
OFF_T m_curr_size
for input, size of remaining data for output, size of data written uInt m_curr_size;
Definition fitsio.h:159
FitsErrs m_err_status
Definition fitsio.h:146
OFF_T getskipsize() const
get the size of the last skipped HDU
Definition fitsio.h:131
FITSErrorHandler m_errfn
Definition fitsio.h:145
FitsKeyCardTranslator m_kc
Definition fitsio.h:147
Bool m_isaprimary
Definition fitsio.h:140
FITS::HDUType hdutype() const
Header Data Unit type (e.g.
Definition fitsio.h:115
Bool m_valid_fits
Definition fitsio.h:138
FitsErrs
error return code.
Definition fitsio.h:76
Bool m_header_done
Definition fitsio.h:141
FitsKeywordList m_kw
Definition fitsio.h:148
char * m_curr
Definition fitsio.h:150
OFF_T m_data_size
uInt m_data_size;
Definition fitsio.h:155
OFF_T datasize() const
return the datasize of the current HDU.
Definition fitsio.h:119
FITS::ValueType datatype() const
Definition fitsio.h:116
FITS::HDUType m_hdu_type
Definition fitsio.h:143
int m_thdunum
total number of hdu in this fits file
Definition fitsio.h:217
Vector< String > kwlist_str(Bool length80=False)
get hdu header image cards as strings.
Bool m_got_rec
flag used for read control in errors
Definition fitsio.h:215
FitsInput(const char *, const FITS::FitsDevice &, int=10, FITSErrorHandler errhandler=FITSError::defaultHandler)
BlockInput & make_input(const char *, const FITS::FitsDevice &, int, FITSErrorHandler errhandler=FITSError::defaultHandler)
OFF_T read_all(FITS::HDUType, char *)
read all data into a given address - all responsibility is given to the user
int process_header(FITS::HDUType, FitsKeywordList &)
Special interface to class HeaderDataUnit.
int getnumhdu() const
the number of hdu in this fits file
Definition fitsio.h:207
FitsInput(FITSErrorHandler errhandler=FITSError::defaultHandler)
BlockInput & m_fin
Definition fitsio.h:210
int recno() const
number of logical records read/written
Definition fitsio.h:203
bool get_data_type(FITS::ValueType &)
bool current_hdu_type(FITS::HDUType &)
int blockno() const
number of physical blocks read/written
Definition fitsio.h:200
virtual void errmsg(FitsErrs, const char *)
set error message that belongs to one of the enumerated types
int skip(FITS::HDUType, OFF_T)
skip N bytes
int read(FITS::HDUType, char *, int)
read N bytes into address
char * read_sp()
int skip_hdu2(); read special or unrecognizable records
void skip_all(FITS::HDUType)
skip all remaining data
BlockInput & getfin()
Definition fitsio.h:204
translator between Keyword lists and fixed FITS cars
Definition fits.h:1259
linked list of FITS keywords
Definition fits.h:983
BlockOutput & make_output(const char *, const FITS::FitsDevice &, int, FITSErrorHandler errhandler=FITSError::defaultHandler)
int hdu_complete()
check if the current hdu is done.
Definition fitsio.h:261
int write(FITS::HDUType, char *, Int, char)
write N bytes from address
int write_sp(char *rec)
write a special record.
BlockOutput & m_fout
Definition fitsio.h:267
void setfptr(fitsfile *ffp)
Bool required_keys_only()
Definition fitsio.h:264
Bool m_required_keys_only
Definition fitsio.h:268
FitsOutput(FITSErrorHandler errhandler=FITSError::defaultHandler)
void set_data_info(FitsKeywordList &kwl, FITS::HDUType t, FITS::ValueType dt, OFF_T ds, Int is)
used by PrimaryArray, BinaryTabelExtention etc to work with the constructor without keyword list.
BlockOutput & getfout()
Definition fitsio.h:262
FitsOutput(const char *, const FITS::FitsDevice &, int=10, FITSErrorHandler errhandler=FITSError::defaultHandler)
int write_all(FITS::HDUType, char *, char)
write all data from address
virtual void errmsg(FitsErrs, const char *)
set error message that belongs to one of the enumerated types
int write_hdr(FitsKeywordList &, FITS::HDUType, FITS::ValueType, OFF_T, Int)
Special interface to class HeaderDataUnit.
FitsStdInput(int, FITSErrorHandler errhandler=FITSError::defaultHandler)
FitsStdOutput(int, FITSErrorHandler errhandler=FITSError::defaultHandler)
FitsTape9Input(const char *, int, int=10, FITSErrorHandler errhandler=FITSError::defaultHandler)
FitsTape9Output(const char *, int, int=10, FITSErrorHandler errhandler=FITSError::defaultHandler)
OFF_T read_all_data(char *)
int read_data(char *, Int)
int write_data(FitsOutput &, char *, Int)
int write_all_data(FitsOutput &, char *)
int get_hdr(FITS::HDUType, FitsKeywordList &)
int write_hdr(FitsOutput &)
write the current header
void(* FITSErrorHandler)(const char *errMessage, FITSError::ErrorLevel severity)
Define a typedef for the handler function signature for convenience.
Definition FITSError.h:106
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40