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