casacore
Loading...
Searching...
No Matches
FITSTable.h
Go to the documentation of this file.
1// # FITSTable.h: Simplified interface to FITS tables with Casacore Look and Feel.
2// # Copyright (C) 1995,1996,1997,1999,2000,2001
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_FITSTABLE_H
27#define FITS_FITSTABLE_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/casa/Containers/Record.h>
32#include <casacore/tables/Tables/TableRecord.h>
33#include <casacore/casa/Containers/Block.h>
34#include <casacore/fits/FITS/hdu.h>
35#include <casacore/fits/FITS/fitsio.h>
36#include <casacore/casa/iosfwd.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40class String;
41class FITSFieldCopier;
42class TableDesc;
43
44// <summary>
45// Simplified interface to FITS tables with Casacore Look and Feel.
46// </summary>
47//
48// <use visibility=export>
49//
50// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
51// </reviewed>
52//
53// <prerequisite>
54// <li> General knowledge of FITS binary and ASCII tables.
55// </prerequisite>
56//
57// <etymology>
58// </etymology>
59//
60// <synopsis>
61// FITSTablular is an obstract base class which is used for read-only access to
62// tabular FITS-like data structures.
63// </synopsis>
64//
65// <example>
66// </example>
67//
68// <motivation>
69// </motivation>
70//
71// <todo asof="1995/06/01">
72// <li> Eventually we'd like to be able to write the tables as well as read
73// them.
74// </todo>
75
77 public:
78 virtual ~FITSTabular();
79 // isValid() returns False if this object isn't a valid Tabular data
80 // structure.
81 virtual Bool isValid() const = 0;
82 // Returns keywords which are associated with the underlying FITS files.
83 virtual const TableRecord &keywords() const = 0;
84 // Returns the description of the underlying FITS table.
85 virtual const RecordDesc &description() const = 0;
86 // Returns any TUNITnnn associated with a column (the field names
87 // are the column names, each field value is the TUNITnnn value for
88 // that field). Note that only those columns with a non-empty
89 // TUNITnnn have an entry in the units() Record.
90 virtual const Record &units() const = 0;
91 // Returns any TDISPnnn associated with a column (the field names
92 // are the column names, each field value is the TDISPnnn value for
93 // that field). Note that only those columns with a non-empty
94 // TDISPnnn have an entry in the displayFormats() Record.
95 virtual const Record &displayFormats() const = 0;
96 // Returns any TNULLnnn associated with a column (the field names
97 // are the column names, each field value is the TNULLnnn value for
98 // that field). Note that only those columns with a specific entry for
99 // TNULLnnn and which have not been promoted to doubles due TSCAL
100 // and TZERO values will have an entry in the nulls() Record.
101 // The meaning of TNULL is only defined for integer and byte columns.
102 // When a column is promoted to a double because of scaling,
103 // any TNULL values will be assigned a value of NaN.
104 virtual const Record &nulls() const = 0;
105
106 // Returns True if we have advanced past the end of data.
107 virtual Bool pastEnd() const = 0;
108
109 // Advance the row if possible (guaranteed harmless if pastEnd() is True.
110 virtual void next() = 0;
111
112 // Reopen the table, default behavior is to do nothing, return False
113 virtual Bool reopen(const String &) { return False; }
114
115 // return the name
116 virtual const String &name() const = 0;
117
118 // Has the description changed since construction, default is False
119 virtual Bool hasChanged() const { return False; }
120 // reset the changed flag, default do nothing
121 virtual void resetChangedFlag() { ; }
122
123 // Return the currentRow. This is guaranteed to be valid so long as only
124 // member functions of this base class are called (so you can safely attach
125 // RecordFieldPtr objects to it. The result is undefined if pastEnd() is True.
126 virtual const Record &currentRow() const = 0;
127
128 // Helper function for retrieving keywords from a native-FITS hdu.
129 // If allKeywords is not True, some keywords will be excluded
130 // from the list. Currently the list of excluded keywords
131 // includes TTYPEnnn, TFORMnnn, and TUNITnnn
133
134 // Helper function for retrieving a description from a native-FITS hdu.
136
137 // Help function for retrieving any shape information from String columns
138 // using the SubString convention.
139 // Information is returned in a Record having named fields = all String
140 // columns following those convention. Each of these fields is, in turn,
141 // a sub-record having these three fields: NCHAR, NELEM, DELIM.
142 // If NELEM == -1 then there must have been a DELIM specified and
143 // this field is a variable shaped string array where each element has
144 // at most NCHAR and they are separated by DELIM (which is a String field here).
145 // Otherwise, DELIM is not used and there are NCHAR per element for each
146 // of NELEM in each cell for this column.
148
149 // Helper function for retrieving the TUNITnnn from a native-FITS hdu.
151
152 // Helper function for retrieving the TDISPnnn from a native-FITS hdu.
154
155 // Helper function for retrieving the TNULLnnn from a native-FITS hdu.
157
158 // Get a TableDesc appropriate to hold a FITSTabular
159 // the keywords, description, units, displayFormats, and nulls are all used
160 static TableDesc tableDesc(const FITSTabular &fitstabular);
161};
162
163// <summary>
164// Attach a FITSTabular to a binary or ASCII table
165// </summary>
166//
167// <use visibility=export>
168//
169// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
170// </reviewed>
171//
172// <prerequisite>
173// <li> General knowledge of FITS binary and ASCII tables.
174// </prerequisite>
175//
176// <etymology>
177// </etymology>
178//
179// <synopsis>
180// FITSTable is a FITSTabular which is attached to a FITS table (on disk only
181// presently), either Binary or ASCII.
182// </synopsis>
183//
184// <example>
185// </example>
186//
187// <motivation>
188// </motivation>
189//
190// <todo asof="1995/06/01">
191// <li>
192// </todo>
193
194class FITSTable : public FITSTabular {
195 public:
196 // this creates an invalid (isValid() return False) FITSTable
197 // Its primary purpose is so that FITSTables can be created before
198 // the file name is known. reopen() is then used to open the file.
199 FITSTable(uInt whichHDU = 1, Bool allKeywords = False);
200
201 // 0-relative HDU. It can never be zero by the FITS rules.
202 // allKeywords is passed to FITSTabular::keywordsFromHDU
203 // See the documentation for that function for a list of
204 // excluded keywords when allKeywords is False.
205 FITSTable(const String &fileName, uInt whichHDU = 1, Bool allKeywords = False);
207
208 // Has the end of file been reached yet
209 virtual Bool eof() const { return io_p->eof(); }
210
211 // Attach this FITSTable to a new file name, same HDU# as at open time
212 virtual Bool reopen(const String &fileName);
213 virtual const String &name() const { return name_p; }
214
215 virtual Bool isValid() const { return isValid_p; }
216
217 virtual const TableRecord &keywords() const { return keywords_p; }
218 virtual const RecordDesc &description() const { return description_p; }
219 virtual const Record &units() const { return units_p; }
220 virtual const Record &displayFormats() const { return disps_p; }
221 virtual const Record &nulls() const { return nulls_p; }
222
223 virtual Bool pastEnd() const;
224 virtual void next();
225 virtual const Record &currentRow() const;
226
227 // single FITS tables know how many rows there are
228 // unlike general FITSTabulars, which may not know
229 // (e.g. if it is a FITSMultiTable)
230 virtual uInt nrow() const { return raw_table_p->nrows(); }
231
232 // these tables should also know where they are
233 virtual Int rownr() const { return row_nr_p; }
234
235 // and it should be possible to move to a desired row
236 // the rownr() member can be used to verify that a move
237 // was successful - this will happen if the requested row
238 // was < rownr() or >= nrow() - i.e. movements backwards or
239 // beyond the end of the file are not possible.
240 virtual void move(Int torow);
241
242 // the keywords from the Primary HDU
243 virtual const TableRecord &primaryKeywords() const { return primaryKeys_p; }
244
245 protected:
246 // SDFITSTable needs to make some keywords appear as
247 // columns, this requires access to description_p, keywords_p, and
248 // row_p. However, its not something that typical FITSTable
249 // users will want. Therefore, I've provided this protected
250 // function for SDFITSTable to use so as to not have to provide
251 // direct access to those data members at the public level.
252 // The named keywords and values are appended to the end of
253 // row_p and removed from keywords_p, description_p is modified
254 // appropriately. The returned value is False if any named
255 // keyword did not appear in keywords_p (however, all named
256 // keywords that DO appear in keywords_p will have been correctly
257 // moved).
259
260 private:
261 // Undefined and inaccessible. An alternative would be to use reference
262 // semantics like Table.
265
266 void fill_row();
268
270
272
274
287 // One per field in row_p, of the right type. i.e. casting required.
293 // these are used by VADESC columns
296 // I had trouble making a Block<VADescFitsField>
299
300 // It is necessary to read the PDA to get the primary keywords.
301 // If there is any data there, the FITS classes do not provide any way to
302 // just skip over them to get to the next HDU. The only way to do that is
303 // to actually read all of the data. If there is no data, this step is
304 // unnecessary and so this subroutine need only be called after the primary
305 // keywords have been read AND the PDA has some data in it. Closing the
306 // FitsInput and reopening it is faster in most cases than reading in each
307 // data value.
309};
310
311// <summary>
312// Simplified interface to create and write to a FITS Binary Table
313// </summary>
314//
315// <use visibility=export>
316//
317// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
318// </reviewed>
319//
320// <prerequisite>
321// <li> General knowledge of FITS binary and ASCII tables.
322// </prerequisite>
323//
324// <etymology>
325// </etymology>
326//
327// <synopsis>
328// </synopsis>
329//
330// <example>
331// </example>
332//
333// <motivation>
334// </motivation>
335//
336// <todo asof="1995/06/01">
337// <li> probably much
338// </todo>
339
341 public:
342 enum { DefaultMaxStringSize = 16 };
343
344 // You MUST have already written a first HDU to FitsOutput.
345 // description contains the names and types of the table columns to be written.
346 // The row is not rearranged (i.e. they are used in order) for alignment purposes.
347 // Array columns must have fixed shape unless tdimColumns is used. Use the
348 // maxLengths record to indicate any string columns which should have a length other
349 // than the default value by providing an int field of the same name as the string
350 // field in this record.
351 // The size of the table (nrows) must be given at creation. Use extraKeywords to
352 // indicate any keywords not automatically created. The units record is used to
353 // indicate the units for any column. Provide a string field with the same name as
354 // the column field in description. If freeOutput is True, file must come from new
355 // since it will be deleted upon destruction. You might not want this to happen if
356 // you are going to write many tables to the same fits file. Use variableShapes to
357 // signal which array columns have variable shape and use maxLengths to indicate
358 // the maximum size of those variable shaped columns. The variableShapes record
359 // should contain a String corresponding to the longest TDIM value appropriate for
360 // each variable shaped column. The maxLengths record should contain an int field
361 // for each variable shaped column which indicates the maximum number of elements
362 // to be found in that column. Unused values in any cell in the variable shaped
363 // columns will be filled with zero. These columns will use the SDFITS TDIM convention
364 // where for column nnn there is a corresponding TDIMnnn column where
365 // the values in each row are the true shape of the data in column nnn.
366 // variableShapes appears as the last argument for backwards compatibility with
367 // existing code.
368 FITSTableWriter(FitsOutput *file, const RecordDesc &description, const Record &maxLengths,
369 uInt nrows, const Record &extraKeywords, const Record &units,
370 Bool freeOutput = True, const Record &variableShapes = Record());
371
373
374 // use this to set the value of the current row to be written
375 RecordInterface &row() { return row_p; }
376
377 // Write the current row()
378 void write();
379
380 // Don't delete this out from under us!
382
383 // Returns a writer, with the first HDU filled in (set to null). The caller
384 // is responsible for deleting the pointer returned from makeWriter.
385 static FitsOutput *makeWriter(const String &fileName);
386
387 private:
388 // Undefined and inaccessible
392
399};
400
401// <summary>
402// Simplified interface to create and write to FITS random groups
403// </summary>
404//
405// <use visibility=export>
406//
407// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
408// </reviewed>
409//
410// <prerequisite>
411// <li> General knowledge of FITS binary and ASCII tables.
412// </prerequisite>
413//
414// <etymology>
415// </etymology>
416//
417// <synopsis>
418// Like FITSTableWriter except that this must be the first HDU and
419// all "columns" in the description must have the same type, i.e. float.
420// </synopsis>
421//
422// <example>
423// </example>
424//
425// <motivation>
426// </motivation>
427//
428// <todo asof="1995/06/01">
429// <li> probably much
430// </todo>
431
433 public:
434 // Since this must always be the first HDU, there is no point in constructing it
435 // with a FitsOutput. description indicates the names of the random groups parameters.
436 // nrows is a synonym for ngroups. Use extraKeywords to
437 // indicate any keywords not automatically created (SIMPLE, BITPIX, NAXIS*, EXTEND,
438 // BLOCKED, GROUPS, PCOUNT, GOUNT, ORIGIN, END). If freeOutput is True, file will be
439 // deleted by the destructor. You might not want this to happen if
440 // you are going to write any extensions to the same fits file. You can get the
441 // FitsOutput used here from write()
442 FITSGroupWriter(const String &fileName, const RecordDesc &description, uInt nrows,
443 const Record &extraKeywords, Bool freeOutput = True);
444
446
447 // Set the values for the current group
448 RecordInterface &row() { return row_p; }
449
450 // Write the current group (row()).
451 void write();
452
453 // Don't delete this out from under us!
455
456 private:
457 // Undefined and inaccessible
461
468
469 // Checks error status of writer_p and group_p. Cleans up and throws an exception if bad.
470 void check_error(const char *extra_info = 0);
471};
472
473} // namespace casacore
474
475#endif
BINTABLE extension.
Definition hdu.h:1076
RecordInterface & row()
Set the values for the current group.
Definition FITSTable.h:448
void write()
Write the current group (row()).
FITSGroupWriter(const FITSGroupWriter &)
PrimaryGroup< Float > * group_p
Definition FITSTable.h:465
FitsOutput * writer()
Don't delete this out from under us!
Definition FITSTable.h:454
FITSGroupWriter(const String &fileName, const RecordDesc &description, uInt nrows, const Record &extraKeywords, Bool freeOutput=True)
Since this must always be the first HDU, there is no point in constructing it with a FitsOutput.
FITSGroupWriter & operator=(const FITSGroupWriter &)
void check_error(const char *extra_info=0)
Checks error status of writer_p and group_p.
FITSGroupWriter()
Undefined and inaccessible.
RecordInterface & row()
use this to set the value of the current row to be written
Definition FITSTable.h:375
void write()
Write the current row().
FITSTableWriter & operator=(const FITSTableWriter &)
Block< FITSFieldCopier * > copiers_p
Definition FITSTable.h:398
static FitsOutput * makeWriter(const String &fileName)
Returns a writer, with the first HDU filled in (set to null).
FITSTableWriter(FitsOutput *file, const RecordDesc &description, const Record &maxLengths, uInt nrows, const Record &extraKeywords, const Record &units, Bool freeOutput=True, const Record &variableShapes=Record())
You MUST have already written a first HDU to FitsOutput.
FitsOutput * writer()
Don't delete this out from under us!
Definition FITSTable.h:381
FITSTableWriter()
Undefined and inaccessible.
FITSTableWriter(const FITSTableWriter &)
BinaryTableExtension * bintable_p
Definition FITSTable.h:396
TableRecord primaryKeys_p
Definition FITSTable.h:279
Block< void * > row_fields_p
Definition FITSTable.h:289
virtual void move(Int torow)
and it should be possible to move to a desired row the rownr() member can be used to verify that a mo...
virtual Bool pastEnd() const
Returns True if we have advanced past the end of data.
VADescFitsField * va_p
I had trouble making a Block<VADescFitsField>.
Definition FITSTable.h:297
void reopenAtFirstHDU(const String &name)
It is necessary to read the PDA to get the primary keywords.
BinaryTableExtension * raw_table_p
Definition FITSTable.h:276
virtual const Record & currentRow() const
Return the currentRow.
virtual Bool reopen(const String &fileName)
Attach this FITSTable to a new file name, same HDU# as at open time.
virtual const RecordDesc & description() const
Returns the description of the underlying FITS table.
Definition FITSTable.h:218
virtual void next()
Advance the row if possible (guaranteed harmless if pastEnd() is True.
virtual Bool eof() const
Has the end of file been reached yet.
Definition FITSTable.h:209
virtual Int rownr() const
these tables should also know where they are
Definition FITSTable.h:233
FITSTable(uInt whichHDU=1, Bool allKeywords=False)
this creates an invalid (isValid() return False) FITSTable Its primary purpose is so that FITSTables ...
RecordDesc description_p
Definition FITSTable.h:280
FITSTable(const FITSTable &)
Undefined and inaccessible.
Bool virtualColumns(const Vector< String > &keyNames)
SDFITSTable needs to make some keywords appear as columns, this requires access to description_p,...
virtual const TableRecord & keywords() const
Returns keywords which are associated with the underlying FITS files.
Definition FITSTable.h:217
Block< Int > field_types_p
Definition FITSTable.h:290
virtual const TableRecord & primaryKeywords() const
the keywords from the Primary HDU
Definition FITSTable.h:243
virtual const String & name() const
return the name
Definition FITSTable.h:213
Block< Int > tdims_p
Definition FITSTable.h:292
virtual Bool isValid() const
isValid() returns False if this object isn't a valid Tabular data structure.
Definition FITSTable.h:215
FitsInput * io_p
Definition FITSTable.h:277
Block< void * > vaptr_p
Definition FITSTable.h:295
Block< Bool > promoted_p
Definition FITSTable.h:291
FITSTable(const String &fileName, uInt whichHDU=1, Bool allKeywords=False)
0-relative HDU.
TableRecord keywords_p
Definition FITSTable.h:278
virtual const Record & nulls() const
Returns any TNULLnnn associated with a column (the field names are the column names,...
Definition FITSTable.h:221
FITSTable & operator=(const FITSTable &)
virtual const Record & units() const
Returns any TUNITnnn associated with a column (the field names are the column names,...
Definition FITSTable.h:219
uInt nfields_p
One per field in row_p, of the right type.
Definition FITSTable.h:288
virtual const Record & displayFormats() const
Returns any TDISPnnn associated with a column (the field names are the column names,...
Definition FITSTable.h:220
virtual uInt nrow() const
single FITS tables know how many rows there are unlike general FITSTabulars, which may not know (e....
Definition FITSTable.h:230
Block< Int > vatypes_p
these are used by VADESC columns
Definition FITSTable.h:294
virtual Bool hasChanged() const
Has the description changed since construction, default is False.
Definition FITSTable.h:119
virtual const Record & currentRow() const =0
Return the currentRow.
virtual Bool pastEnd() const =0
Returns True if we have advanced past the end of data.
virtual const TableRecord & keywords() const =0
Returns keywords which are associated with the underlying FITS files.
static Record displayFormatsFromHDU(BinaryTableExtension &hdu)
Helper function for retrieving the TDISPnnn from a native-FITS hdu.
virtual Bool isValid() const =0
isValid() returns False if this object isn't a valid Tabular data structure.
virtual const Record & nulls() const =0
Returns any TNULLnnn associated with a column (the field names are the column names,...
static Record nullsFromHDU(BinaryTableExtension &hdu)
Helper function for retrieving the TNULLnnn from a native-FITS hdu.
static RecordDesc descriptionFromHDU(BinaryTableExtension &hdu)
Helper function for retrieving a description from a native-FITS hdu.
virtual const RecordDesc & description() const =0
Returns the description of the underlying FITS table.
virtual const String & name() const =0
return the name
virtual const Record & units() const =0
Returns any TUNITnnn associated with a column (the field names are the column names,...
virtual void next()=0
Advance the row if possible (guaranteed harmless if pastEnd() is True.
virtual Bool reopen(const String &)
Reopen the table, default behavior is to do nothing, return False.
Definition FITSTable.h:113
static TableRecord keywordsFromHDU(HeaderDataUnit &hdu, Bool allKeywords=False)
Helper function for retrieving keywords from a native-FITS hdu.
virtual void resetChangedFlag()
reset the changed flag, default do nothing
Definition FITSTable.h:121
static Record unitsFromHDU(BinaryTableExtension &hdu)
Helper function for retrieving the TUNITnnn from a native-FITS hdu.
static TableDesc tableDesc(const FITSTabular &fitstabular)
Get a TableDesc appropriate to hold a FITSTabular the keywords, description, units,...
static Record subStringShapeFromHDU(BinaryTableExtension &hdu)
Help function for retrieving any shape information from String columns using the SubString convention...
virtual const Record & displayFormats() const =0
Returns any TDISPnnn associated with a column (the field names are the column names,...
fixed-length sequential blocked FITS input
Definition fitsio.h:170
fixed-length sequential blocked FITS output
Definition fitsio.h:242
Random Group datastructure.
Definition hdu.h:632
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
const RecordDesc & description() const
Describes the current structure of this Record.
FitsField< FitsVADesc > VADescFitsField
Definition hdu.h:1006
unsigned int uInt
Definition aipstype.h:49
RecordInterface()
The default constructor creates an empty record with a variable structure.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41