casacore
Loading...
Searching...
No Matches
blockio.h
Go to the documentation of this file.
1//# blockio.h:
2//# Copyright (C) 1993,1994,1995,1996,1999
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#ifndef FITS_BLOCKIO_H
26#define FITS_BLOCKIO_H
27
28//# Include this file first, because it may set LFS variables used by cfitsio.
29#include <casacore/casa/aips.h>
30
31//# Make sure that cfitsio does not declare the wcs headers.
32extern "C"{
33#include <fitsio.h> //# header file from cfitsio
34#include <fitsio2.h> //# using core functions of cfitsio
35}
36
37#include <stdlib.h>
38#include <unistd.h>
39#include <fcntl.h>
40
41#include <casacore/fits/FITS/FITSError.h>
42
43namespace casacore { //# NAMESPACE CASACORE - BEGIN
44
45//----------------------------------------------------------------------------
46//<category lib=aips module=FITS sect="Blocked I/O">
47//<summary> fixed-length blocked sequentual I/O base class </summary>
48//<synopsis>
49// BlockIO is a low level base class that implements fixed-length
50// blocked sequential I/O. Its derived classes, BlockInput and BlockOutput
51// are used by the FitsInput and FitsOutput classes. Users will hardly ever
52// need to use this class directly.
53//</synopsis>
54//<todo>
55// <li> ifdef kludges until OS dependent flags are developed
56// for the compilation system.
57//</todo>
58
59class BlockIO {
60 public:
61 // error return code
64 int err() const { return (int)m_err_status; }
65
66 // number of physical blocks read/written
67 int blockno() const { return m_block_no; }
68
69 // reset the m_iosize data member
70 void reset_iosize() { m_iosize = 0; }
71
72 // get the total bytes of data in m_buffer
73 int iosize() const { return m_iosize; }
74
75 // get the current read position within m_buffer
76 int current() const { return m_current; }
77
78 // get m_buffer
79 char* buffer() const { return m_buffer; }
80
81 // number of logical records read/written
82 int recno() const { return m_rec_no; }
83
84 // name of file associated with I/O stream, if applicable
85 const char *fname() const { return m_filename; }
86
87 // fits_close_file() does not work for reasons that the file pointer does not have the
88 // knowledge of chdu which were written with write_hdr() not write_***_hdr(). So create
89 // our own close_file() method.
90 int close_file( fitsfile *fptr, int *status);
91 // file descriptor associated with I/O stream, if applicable
92 int fdes() const { return m_fd; }
93 // get the fitsfile pointer
94 fitsfile *getfptr() const { return m_fptr; }
95 void setfptr( fitsfile* ffp );
96 protected:
97 // Construction can be done either from a filename with open options
98 // or from a file descriptor.
99 //
100 // The remaining arguments are the the logical record size and number
101 // of records that make up a physical record followed by the
102 // output stream that is used to write error messages to.
103 //<group>
104 BlockIO(const char *, int, int, int = 1,
106 BlockIO(int, int, int = 1,
108 virtual ~BlockIO();
109 //</group>
110
111 char *m_filename; // name of file
112 int m_options; // options on open statement
113 const int m_recsize; // size in bytes of a logical record
114 const int m_nrec; // maximum number of logical records
115 const int m_blocksize; // size in bytes of physical records
116 FITSErrorHandler m_errfn; // FITS error handler function
117 IOErrs m_err_status; // error number
118 int m_fd; // file descriptor
119 char *m_buffer; // the actual data buffer itself
120 int m_block_no; // number of physical blocks read/written
121 int m_rec_no; // number of logical records read/written
122 int m_current; // offset to current logical record
123 // size of record in buffer
125 // using fitsfile structure from cfitsio of NASA
126 fitsfile *m_fptr;
127
128 // set the error message and error number for later recovery
129 void errmsg(IOErrs, const char *);
130};
131
132//<summary> fixed-length blocked sequential input base class</summary>
133//<prerequisite>
134// <li> BlockIO
135//</prerequisite>
136
137class BlockInput : public BlockIO {
138 public:
139 // Construction can be done either from a filename or from
140 // a file descriptor.
141 //
142 // The remaining arguments are the the logical record size and number
143 // of records that make up a physical record followed by the
144 // output stream that is used to write error messages to.
145 //<group>
146 BlockInput(const char *, int, int = 1,
148 BlockInput(int, int, int = 1,
150 virtual ~BlockInput();
151 //</group>
152
153 // read the next logical record or first
154 // skip N logical records and then read the next one.
155 // (note it is not possible to skip a record without
156 // reading a record).
157 //<note role=caution> these functions return a pointer to an
158 // internal record. The user must make sure that
159 // after destruction of this class no dangling pointers
160 // are left.
161 //</note>
162 //<group>
163 virtual char *read(); // read a physical block.
164 virtual char *skip(int);
165 //</group>
166};
167
168//<summary> fixed-length blocked sequential output base class</summary>
169//<prerequisite>
170// <li> BlockIO
171//</prerequisite>
172
173class BlockOutput : public BlockIO {
174 public:
175 // Construction can be done either from a filename or from
176 // a file descriptor.
177 //
178 // The remaining arguments are the the logical record size and number
179 // of records that make up a physical record followed by the
180 // output stream that is used to write error messages to.
181 //<group>
182 BlockOutput(const char *, int, int = 1,
184 BlockOutput(int, int, int = 1,
186 virtual ~BlockOutput();
188 //</group>
189
190 // write the next logical record. The input must point
191 // to a logical record
192 virtual int write(char *);
193};
194
195} //# NAMESPACE CASACORE - END
196
197# endif
198
fixed-length blocked sequentual I/O base class
Definition blockio.h:59
IOErrs m_err_status
Definition blockio.h:117
fitsfile * getfptr() const
get the fitsfile pointer
Definition blockio.h:94
int close_file(fitsfile *fptr, int *status)
fits_close_file() does not work for reasons that the file pointer does not have the knowledge of chdu...
const char * fname() const
name of file associated with I/O stream, if applicable
Definition blockio.h:85
char * m_filename
Definition blockio.h:111
IOErrs
error return code
Definition blockio.h:62
int err() const
Definition blockio.h:64
void reset_iosize()
reset the m_iosize data member
Definition blockio.h:70
int iosize() const
get the total bytes of data in m_buffer
Definition blockio.h:73
virtual ~BlockIO()
const int m_recsize
Definition blockio.h:113
int current() const
get the current read position within m_buffer
Definition blockio.h:76
BlockIO(int, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
BlockIO(const char *, int, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
Construction can be done either from a filename with open options or from a file descriptor.
const int m_nrec
Definition blockio.h:114
int m_iosize
size of record in buffer
Definition blockio.h:124
const int m_blocksize
Definition blockio.h:115
int fdes() const
file descriptor associated with I/O stream, if applicable
Definition blockio.h:92
fitsfile * m_fptr
using fitsfile structure from cfitsio of NASA
Definition blockio.h:126
FITSErrorHandler m_errfn
Definition blockio.h:116
void setfptr(fitsfile *ffp)
int blockno() const
number of physical blocks read/written
Definition blockio.h:67
char * buffer() const
get m_buffer
Definition blockio.h:79
void errmsg(IOErrs, const char *)
set the error message and error number for later recovery
int recno() const
number of logical records read/written
Definition blockio.h:82
fixed-length blocked sequential input base class
Definition blockio.h:137
virtual char * read()
read the next logical record or first skip N logical records and then read the next one.
BlockInput(int, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
virtual char * skip(int)
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:173
virtual int write(char *)
write the next logical record.
BlockOutput(const char *, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
Construction can be done either from a filename or from a file descriptor.
BlockOutput(int, int, int=1, FITSErrorHandler errhandler=FITSError::defaultHandler)
static void defaultHandler(const char *errMessage, ErrorLevel severity)
The default error handler.
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