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: aips2-request@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//# $Id$
27
28#ifndef FITS_FITSIO_H
29#define FITS_FITSIO_H
30
31#include <casacore/casa/aips.h>
32# include <casacore/fits/FITS/fits.h>
33# include <casacore/fits/FITS/blockio.h>
34# include <casacore/fits/FITS/hdu.h>
35//# include <casacore/casa/stdvector.h>
36# include <casacore/casa/Arrays/Vector.h>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40//<summary> sequential FITS I/O </summary>
41// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
42// </reviewed>
43//<synopsis>
44// FitsIO is a base class that handles all the sequential blocked
45// FITS I/O. Special derived classes do the input and output.
46// No interpretation of the data is attempted here, there are
47// special FITS classes that handle syntax and interpretation.
48//</synopsis>
49//<example>
50//<srcblock>
51// FitsInput fin("myfile.fits",FITS::Disk); // open disk file for FITS input
52// if (fin.err() == FitsIO::IOERR) { // check if open succeeded
53// cout << "Could not open FITS input\n";
54// exit(0);
55// }
56// if (fin.rectype() == FITS::HDURecord && // test for primary array
57// fin.hdutype() == FITS::PrimaryArrayHDU) {
58// }
59//</srcblock>
60//</example>
61
62class FitsIO {
63 public:
64 virtual ~FitsIO();
65
66 // error return code. Should be one of an
67 // enumerated type:
68 //
69 //# until cxx2html can handle enum() we duplicate it here
70 //
71 //<srcblock>
72 // enum FitsErrs { OK, IOERR, MISSKEY, BADBEGIN, EMPTYFILE,
73 // NOPRIMARY, BADOPER, BADEOF, MEMERR, BADBITPIX, NOAXISN,
74 // NOPCOUNT, NOGCOUNT, BADPCOUNT, BADGCOUNT, NOGROUPS,
75 // BADNAXIS, BADPRIMARY, BADSIZE, HDUERR };
76 //</srcblock>
77 //<group>
82 int err() const { return m_err_status; }
83 //</group>
84 //
85 // record size, in bytes, of a FITS block.
86 // Normally set at 2880, unless some form of blocking was used.
87 int fitsrecsize() const { return m_recsize; }
88 // is it a valid fits file (SIMPLE==T). If not, the only
89 // safest operation is to skip the data portion of the
90 // current HeaderDataUnit
91 Bool isafits() const { return m_valid_fits; }
92 // see if there may be FITS extensions present (EXTENT==T)
93 Bool isextend() const { return m_extend; }
94 // test if end of file has been reached
95 Bool eof() const { return Bool(m_rec_type == FITS::EndOfFile); }
96 // the FITS record type
98 // Header Data Unit type (e.g.
99 FITS::HDUType hdutype() const { return m_hdu_type; }
101 // return the datasize of the current HDU. This excludes
102 // the trailing end of the blocked data portion.
103 OFF_T datasize() const { return m_data_size; }
104 // data characteristics
105 Int itemsize() const { return m_item_size; }
106 // for input, size of remaining data
107 // for output, size of data written
108 OFF_T currsize() const { return m_curr_size; }
109 // get FitsKeyCardTranslator
111 // get the fitsfile pointer
112 fitsfile *getfptr() const { return m_fptr; }
113
114 // get the size of the last skipped HDU
115 OFF_T getskipsize() const {return m_skipHDU_size;}
116
117
118 protected:
120
121 fitsfile *m_fptr;
122 const int m_recsize;
123 Bool m_valid_fits; // True if SIMPLE == T
124 Bool m_extend; // True if EXTEND == T
125 Bool m_isaprimary; // True if there is a primary HDU
126 Bool m_header_done; // True if header has been processed
129
130 FITSErrorHandler m_errfn; // error handler function
134
135 char *m_curr; // pointer to current record
136 int m_bytepos; // current byte position within record
137 Int m_item_size; // data characteristics
139 //uInt m_data_size;
141 // for input, size of remaining data
142 // for output, size of data written
143 //uInt m_curr_size;
145
146 // for size of the last HDU skipped
148
149 // set error message that belongs to one of the enumerated types
150 virtual void errmsg(FitsErrs, const char *) = 0;
151
152};
153
154//<summary> fixed-length sequential blocked FITS input </summary>
155
156class FitsInput : public FitsIO {
158 friend OFF_T HeaderDataUnit::read_all_data(char *);
159 friend int HeaderDataUnit::read_data(char *, Int);
162
163 public:
164 //<group>
165 FitsInput(const char *, const FITS::FitsDevice &, int = 10,
169 //</group>
170
171 int skip_hdu();
172
173 // skip all remaining data
175
176 //int skip_hdu2();
177 // read special or unrecognizable records
178 char *read_sp();
179
180 // get hdu header image cards as strings. By default the strings will be of
181 // variable length. You can optionally ask for them to be length 80 (padded
182 // with spaces).
184
185 // number of physical blocks read/written
186 int blockno() const {return m_fin.blockno();}
187
188 // number of logical records read/written
189 int recno() const {return m_fin.recno();}
190 BlockInput & getfin(){ return m_fin; } // for test use only
191
192 // the number of hdu in this fits file
193 int getnumhdu() const {return m_thdunum;}
194
195 private:
197 BlockInput &make_input(const char *, const FITS::FitsDevice &, int,
199
200 // flag used for read control in errors
202 // total number of hdu in this fits file
204
205 virtual void errmsg(FitsErrs, const char *);
206 void init();
210
211 //# check if this comes out ok in cxx2html
212 // Special interface to class HeaderDataUnit
213 //<group>
214 // special way to process header
216 // read all data into a given address - all responsibility is given
217 // to the user
218 OFF_T read_all(FITS::HDUType, char *);
219 // read N bytes into address
220 int read(FITS::HDUType, char *, int );
221 // skip N bytes
222 int skip(FITS::HDUType, OFF_T);
223 //</group>
224};
225
226//<summary> fixed-length sequential blocked FITS output </summary>
227
228class FitsOutput : public FitsIO {
232
233 public:
234 //<group>
235 FitsOutput(const char *, const FITS::FitsDevice &, int = 10,
239 //</group>
240 // used by PrimaryArray, BinaryTabelExtention etc to work with the constructor without keyword list.
242 // write a special record. For this the record type must also
243 // be to set to FITS::SpecialRecord
244 int write_sp(char *rec);
245 // check if the current hdu is done. It was private.
247 return (m_rec_type == FITS::HDURecord && m_data_size == 0);
248 }
250 void setfptr( fitsfile* ffp );
252
253 private:
256 BlockOutput &make_output(const char *, const FITS::FitsDevice &, int,
258
259 virtual void errmsg(FitsErrs, const char *);
260
264
265 // Special interface to class HeaderDataUnit
266 //<group>
268 // write all data from address
269 int write_all(FITS::HDUType, char *, char);
270 // write N bytes from address
271 int write(FITS::HDUType, char *, Int, char);
272 //</group>
273};
274
275//<summary> FITS input from disk </summary>
276
277class FitsDiskInput : public BlockInput {
278 public:
279 FitsDiskInput(const char *, int, int = 1,
282 // implements skip in terms of lseek
283 char *skip(int);
284};
285
286//<summary> FITS output to disk </summary>
287
289 public:
290 FitsDiskOutput(const char *, int, int = 1,
293};
294
295//<summary> FITS input from standard input </summary>
296
297class FitsStdInput : public BlockInput {
298 public:
302};
303
304//<summary> FITS output to standard output </summary>
305
312
313//<summary> FITS input from 9-track tape </summary>
314
316 public:
317 FitsTape9Input(const char *, int, int = 10,
320};
321
322//<summary> FITS output to 9-track tape </summary>
323
325 public:
326 FitsTape9Output(const char *, int, int = 10,
329};
330
331
332} //# NAMESPACE CASACORE - END
333
334# endif
int blockno() const
number of physical blocks read/written
Definition blockio.h:69
int recno() const
number of logical records read/written
Definition blockio.h:84
fixed-length blocked sequential input base class
Definition blockio.h:139
fixed-length blocked sequential output base class
Definition blockio.h:175
static void defaultHandler(const char *errMessage, ErrorLevel severity)
The default error handler.
FitsRecType
Types of FITS Records.
Definition fits.h:252
ValueType
FITS I/O Error message types.
Definition fits.h:167
HDUType
Types of FITS Header-Data Units.
Definition fits.h:263
FitsDevice
Supported FITS Physical Devices.
Definition fits.h:258
FITS input from disk
Definition fitsio.h:277
FitsDiskInput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
char * skip(int)
implements skip in terms of lseek
FITS output to disk
Definition fitsio.h:288
FitsDiskOutput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
Bool eof() const
test if end of file has been reached
Definition fitsio.h:95
int err() const
Definition fitsio.h:82
Int itemsize() const
data characteristics
Definition fitsio.h:105
Bool isafits() const
is it a valid fits file (SIMPLE==T).
Definition fitsio.h:91
FITS::FitsRecType m_rec_type
Definition fitsio.h:127
const int m_recsize
Definition fitsio.h:122
OFF_T currsize() const
for input, size of remaining data for output, size of data written
Definition fitsio.h:108
FITS::FitsRecType rectype() const
the FITS record type
Definition fitsio.h:97
FitsKeyCardTranslator & getkc()
get FitsKeyCardTranslator
Definition fitsio.h:110
Bool isextend() const
see if there may be FITS extensions present (EXTENT==T)
Definition fitsio.h:93
int fitsrecsize() const
record size, in bytes, of a FITS block.
Definition fitsio.h:87
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:121
fitsfile * getfptr() const
get the fitsfile pointer
Definition fitsio.h:112
OFF_T m_skipHDU_size
for size of the last HDU skipped
Definition fitsio.h:147
virtual ~FitsIO()
FITS::ValueType m_data_type
Definition fitsio.h:138
OFF_T m_curr_size
for input, size of remaining data for output, size of data written uInt m_curr_size;
Definition fitsio.h:144
FitsErrs m_err_status
Definition fitsio.h:131
OFF_T getskipsize() const
get the size of the last skipped HDU
Definition fitsio.h:115
FITSErrorHandler m_errfn
Definition fitsio.h:130
FitsKeyCardTranslator m_kc
Definition fitsio.h:132
Bool m_isaprimary
Definition fitsio.h:125
FITS::HDUType hdutype() const
Header Data Unit type (e.g.
Definition fitsio.h:99
Bool m_valid_fits
Definition fitsio.h:123
FitsErrs
error return code.
Definition fitsio.h:78
Bool m_header_done
Definition fitsio.h:126
FitsKeywordList m_kw
Definition fitsio.h:133
char * m_curr
Definition fitsio.h:135
OFF_T m_data_size
uInt m_data_size;
Definition fitsio.h:140
OFF_T datasize() const
return the datasize of the current HDU.
Definition fitsio.h:103
FITS::ValueType datatype() const
Definition fitsio.h:100
FITS::HDUType m_hdu_type
Definition fitsio.h:128
fixed-length sequential blocked FITS input
Definition fitsio.h:156
int m_thdunum
total number of hdu in this fits file
Definition fitsio.h:203
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:201
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:193
FitsInput(FITSErrorHandler errhandler=FITSError::defaultHandler)
BlockInput & m_fin
Definition fitsio.h:196
int recno() const
number of logical records read/written
Definition fitsio.h:189
bool get_data_type(FITS::ValueType &)
bool current_hdu_type(FITS::HDUType &)
int blockno() const
number of physical blocks read/written
Definition fitsio.h:186
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:190
translator between Keyword lists and fixed FITS cars
Definition fits.h:985
linked list of FITS keywords
Definition fits.h:737
fixed-length sequential blocked FITS output
Definition fitsio.h:228
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:246
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:254
void setfptr(fitsfile *ffp)
Bool required_keys_only()
Definition fitsio.h:251
Bool m_required_keys_only
Definition fitsio.h:255
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:249
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.
FITS input from standard input
Definition fitsio.h:297
FitsStdInput(int, FITSErrorHandler errhandler=FITSError::defaultHandler)
FITS output to standard output
Definition fitsio.h:306
FitsStdOutput(int, FITSErrorHandler errhandler=FITSError::defaultHandler)
FITS input from 9-track tape
Definition fitsio.h:315
FitsTape9Input(const char *, int, int=10, FITSErrorHandler errhandler=FITSError::defaultHandler)
FITS output to 9-track tape
Definition fitsio.h:324
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:111
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:44
unsigned int uInt
Definition aipstype.h:51
int Int
Definition aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:42