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>
80 int err() const { return m_err_status; }
81 //</group>
82 //
83 // record size, in bytes, of a FITS block.
84 // Normally set at 2880, unless some form of blocking was used.
85 int fitsrecsize() const { return m_recsize; }
86 // is it a valid fits file (SIMPLE==T). If not, the only
87 // safest operation is to skip the data portion of the
88 // current HeaderDataUnit
89 Bool isafits() const { return m_valid_fits; }
90 // see if there may be FITS extensions present (EXTENT==T)
91 Bool isextend() const { return m_extend; }
92 // test if end of file has been reached
93 Bool eof() const { return Bool(m_rec_type == FITS::EndOfFile); }
94 // the FITS record type
96 // Header Data Unit type (e.g.
97 FITS::HDUType hdutype() const { return m_hdu_type; }
99 // return the datasize of the current HDU. This excludes
100 // the trailing end of the blocked data portion.
101 OFF_T datasize() const { return m_data_size; }
102 // data characteristics
103 Int itemsize() const { return m_item_size; }
104 // for input, size of remaining data
105 // for output, size of data written
106 OFF_T currsize() const { return m_curr_size; }
107 // get FitsKeyCardTranslator
109 // get the fitsfile pointer
110 fitsfile *getfptr() const { return m_fptr; }
111
112 // get the size of the last skipped HDU
113 OFF_T getskipsize() const {return m_skipHDU_size;}
114
115
116 protected:
118
119 fitsfile *m_fptr;
120 const int m_recsize;
121 Bool m_valid_fits; // True if SIMPLE == T
122 Bool m_extend; // True if EXTEND == T
123 Bool m_isaprimary; // True if there is a primary HDU
124 Bool m_header_done; // True if header has been processed
127
128 FITSErrorHandler m_errfn; // error handler function
132
133 char *m_curr; // pointer to current record
134 int m_bytepos; // current byte position within record
135 Int m_item_size; // data characteristics
137 //uInt m_data_size;
139 // for input, size of remaining data
140 // for output, size of data written
141 //uInt m_curr_size;
143
144 // for size of the last HDU skipped
146
147 // set error message that belongs to one of the enumerated types
148 virtual void errmsg(FitsErrs, const char *) = 0;
149
150};
151
152//<summary> fixed-length sequential blocked FITS input </summary>
153
154class FitsInput : public FitsIO {
156 friend OFF_T HeaderDataUnit::read_all_data(char *);
157 friend int HeaderDataUnit::read_data(char *, Int);
160
161 public:
162 //<group>
163 FitsInput(const char *, const FITS::FitsDevice &, int = 10,
167 //</group>
168
169 int skip_hdu();
170
171 // skip all remaining data
173
174 //int skip_hdu2();
175 // read special or unrecognizable records
176 char *read_sp();
177
178 // get hdu header image cards as strings. By default the strings will be of
179 // variable length. You can optionally ask for them to be length 80 (padded
180 // with spaces).
182
183 // number of physical blocks read/written
184 int blockno() const {return m_fin.blockno();}
185
186 // number of logical records read/written
187 int recno() const {return m_fin.recno();}
188 BlockInput & getfin(){ return m_fin; } // for test use only
189
190 // the number of hdu in this fits file
191 int getnumhdu() const {return m_thdunum;}
192
193 private:
195 BlockInput &make_input(const char *, const FITS::FitsDevice &, int,
197
198 // flag used for read control in errors
200 // total number of hdu in this fits file
202
203 virtual void errmsg(FitsErrs, const char *);
204 void init();
208
209 //# check if this comes out ok in cxx2html
210 // Special interface to class HeaderDataUnit
211 //<group>
212 // special way to process header
214 // read all data into a given address - all responsibility is given
215 // to the user
216 OFF_T read_all(FITS::HDUType, char *);
217 // read N bytes into address
218 int read(FITS::HDUType, char *, int );
219 // skip N bytes
220 int skip(FITS::HDUType, OFF_T);
221 //</group>
222};
223
224//<summary> fixed-length sequential blocked FITS output </summary>
225
226class FitsOutput : public FitsIO {
230
231 public:
232 //<group>
233 FitsOutput(const char *, const FITS::FitsDevice &, int = 10,
237 //</group>
238 // used by PrimaryArray, BinaryTabelExtention etc to work with the constructor without keyword list.
240 // write a special record. For this the record type must also
241 // be to set to FITS::SpecialRecord
242 int write_sp(char *rec);
243 // check if the current hdu is done. It was private.
245 return (m_rec_type == FITS::HDURecord && m_data_size == 0);
246 }
248 void setfptr( fitsfile* ffp );
250
251 private:
254 BlockOutput &make_output(const char *, const FITS::FitsDevice &, int,
256
257 virtual void errmsg(FitsErrs, const char *);
258
262
263 // Special interface to class HeaderDataUnit
264 //<group>
266 // write all data from address
267 int write_all(FITS::HDUType, char *, char);
268 // write N bytes from address
269 int write(FITS::HDUType, char *, Int, char);
270 //</group>
271};
272
273//<summary> FITS input from disk </summary>
274
275class FitsDiskInput : public BlockInput {
276 public:
277 FitsDiskInput(const char *, int, int = 1,
280 // implements skip in terms of lseek
281 char *skip(int);
282};
283
284//<summary> FITS output to disk </summary>
285
287 public:
288 FitsDiskOutput(const char *, int, int = 1,
291};
292
293//<summary> FITS input from standard input </summary>
294
295class FitsStdInput : public BlockInput {
296 public:
300};
301
302//<summary> FITS output to standard output </summary>
303
310
311//<summary> FITS input from 9-track tape </summary>
312
314 public:
315 FitsTape9Input(const char *, int, int = 10,
318};
319
320//<summary> FITS output to 9-track tape </summary>
321
323 public:
324 FitsTape9Output(const char *, int, int = 10,
327};
328
329
330} //# NAMESPACE CASACORE - END
331
332# endif
int blockno() const
number of physical blocks read/written
Definition blockio.h:67
int recno() const
number of logical records read/written
Definition blockio.h:82
fixed-length blocked sequential input base class
Definition blockio.h:137
fixed-length blocked sequential output base class
Definition blockio.h:173
static void defaultHandler(const char *errMessage, ErrorLevel severity)
The default error handler.
FitsRecType
Types of FITS Records.
Definition fits.h:250
ValueType
FITS I/O Error message types.
Definition fits.h:165
HDUType
Types of FITS Header-Data Units.
Definition fits.h:261
FitsDevice
Supported FITS Physical Devices.
Definition fits.h:256
FITS input from disk
Definition fitsio.h:275
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:286
FitsDiskOutput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
Bool eof() const
test if end of file has been reached
Definition fitsio.h:93
int err() const
Definition fitsio.h:80
Int itemsize() const
data characteristics
Definition fitsio.h:103
Bool isafits() const
is it a valid fits file (SIMPLE==T).
Definition fitsio.h:89
FITS::FitsRecType m_rec_type
Definition fitsio.h:125
const int m_recsize
Definition fitsio.h:120
OFF_T currsize() const
for input, size of remaining data for output, size of data written
Definition fitsio.h:106
FITS::FitsRecType rectype() const
the FITS record type
Definition fitsio.h:95
FitsKeyCardTranslator & getkc()
get FitsKeyCardTranslator
Definition fitsio.h:108
Bool isextend() const
see if there may be FITS extensions present (EXTENT==T)
Definition fitsio.h:91
int fitsrecsize() const
record size, in bytes, of a FITS block.
Definition fitsio.h:85
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:119
fitsfile * getfptr() const
get the fitsfile pointer
Definition fitsio.h:110
OFF_T m_skipHDU_size
for size of the last HDU skipped
Definition fitsio.h:145
virtual ~FitsIO()
FITS::ValueType m_data_type
Definition fitsio.h:136
OFF_T m_curr_size
for input, size of remaining data for output, size of data written uInt m_curr_size;
Definition fitsio.h:142
FitsErrs m_err_status
Definition fitsio.h:129
OFF_T getskipsize() const
get the size of the last skipped HDU
Definition fitsio.h:113
FITSErrorHandler m_errfn
Definition fitsio.h:128
FitsKeyCardTranslator m_kc
Definition fitsio.h:130
Bool m_isaprimary
Definition fitsio.h:123
FITS::HDUType hdutype() const
Header Data Unit type (e.g.
Definition fitsio.h:97
Bool m_valid_fits
Definition fitsio.h:121
FitsErrs
error return code.
Definition fitsio.h:76
Bool m_header_done
Definition fitsio.h:124
FitsKeywordList m_kw
Definition fitsio.h:131
char * m_curr
Definition fitsio.h:133
OFF_T m_data_size
uInt m_data_size;
Definition fitsio.h:138
OFF_T datasize() const
return the datasize of the current HDU.
Definition fitsio.h:101
FITS::ValueType datatype() const
Definition fitsio.h:98
FITS::HDUType m_hdu_type
Definition fitsio.h:126
fixed-length sequential blocked FITS input
Definition fitsio.h:154
int m_thdunum
total number of hdu in this fits file
Definition fitsio.h:201
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:199
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:191
FitsInput(FITSErrorHandler errhandler=FITSError::defaultHandler)
BlockInput & m_fin
Definition fitsio.h:194
int recno() const
number of logical records read/written
Definition fitsio.h:187
bool get_data_type(FITS::ValueType &)
bool current_hdu_type(FITS::HDUType &)
int blockno() const
number of physical blocks read/written
Definition fitsio.h:184
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:188
translator between Keyword lists and fixed FITS cars
Definition fits.h:983
linked list of FITS keywords
Definition fits.h:735
fixed-length sequential blocked FITS output
Definition fitsio.h:226
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:244
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:252
void setfptr(fitsfile *ffp)
Bool required_keys_only()
Definition fitsio.h:249
Bool m_required_keys_only
Definition fitsio.h:253
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:247
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:295
FitsStdInput(int, FITSErrorHandler errhandler=FITSError::defaultHandler)
FITS output to standard output
Definition fitsio.h:304
FitsStdOutput(int, FITSErrorHandler errhandler=FITSError::defaultHandler)
FITS input from 9-track tape
Definition fitsio.h:313
FitsTape9Input(const char *, int, int=10, FITSErrorHandler errhandler=FITSError::defaultHandler)
FITS output to 9-track tape
Definition fitsio.h:322
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:108
this file contains all the compiler specific defines
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