casacore
Loading...
Searching...
No Matches
FITSKeywordUtil.h
Go to the documentation of this file.
1// # FITSKeywordUtil.h: Class of static functions to help with FITS Keywords.
2// # Copyright (C) 2002
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_FITSKEYWORDUTIL_H
27#define FITS_FITSKEYWORDUTIL_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31
32namespace casacore { // # NAMESPACE CASACORE - BEGIN
33
35class FitsKeywordList;
36class RecordInterface;
37class IPosition;
38class String;
39
40// <summary>
41// A class with static functions to help deal with FITS Keywords.
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="Eric Sessoms" date="2002/08/19" tests="tFITSKeywordUtil.cc">
47// </reviewed>
48
49// <prerequisite>
50// <li> General knowledge of FITS, and particularly FITS keywords, is
51// assumed.
52// <li> Presumably you are using this class in conjunction
53// with the "native"
54// <linkto class=FitsKeywordList>FitsKeywordList</linkto>
55// <li> You also need to understand the
56// <linkto class=RecordInterface>RecordInterface</linkto>
57// class.
58// </prerequisite>
59//
60// <etymology>
61// This is a collection of static utility functions for use with FITS
62// keywords.
63// </etymology>
64//
65// <synopsis>
66// This class provides functions to conveniently interconvert between Casacore
67// types and a FitsKeywordList which is needed by the native FITS classes.
68// It is more convenient to maintain the list within Casacore
69// as a Record, so we only need methods to turn a FitsKeywordList into a
70// Record, and vice versa.
71//
72// Note that it is not necessary to construct a FITSKeywordUtil object
73// since you can use its static functions directly.
74// </synopsis>
75//
76// <example>
77// This example shows how you put values from a Record into a
78// FItsKeywordList.
79// <srcblock>
80// Record rec;
81// rec.define("hello", 6.5);
82// rec.define("world", True);
83// Vector<Int> naxis(5);
84// naxis(0) = 128;
85// naxis(1) = 64;
86// naxis(2) = 32;
87// naxis(3) = 16;
88// naxis(4) = 8;
89// rec.define("naxis", naxis);
90// // fields can have comments
91// rec.setComment("hello","A comment for HELLO");
92// // Add a comment to the rec
93// FITSKeywordUtil::addComment(rec,"My comment goes here");
94// // Create an empty FitsKeywordList, containing only "SIMPLE=T"
95// FitsKeywordList kwl = FITSKeywordUtil::makeKeywordList();
96// // and add the fields in rec to this list
97// FITSKeywordUtil::addKeywords(kwl, rec);
98// </srcblock>
99// </example>
100//
101// <example>
102// This example shows how you extract fits keywords into a Record.
103// <srcblock>
104// Record rec;
105// FitsKeywordList kwl;
106// ConstFitsKeywordList kwlRO;
107// Vector<String> ignore(1);
108// ignore(1)= "simple"; // ignore the SIMPLE keyword
109// FITSKeywordUtil::getKeywords(rec, kwlRO, ignore);
110// </srcblock>
111// </example>
112//
113// <motivation>
114// The FitsKeywordList class can be somewhat tedious to use, as it deals with,
115// e.g., char* pointers rather than Strings. This class makes it easy to
116// interconvert between FITS keywords and Casacore types.
117// </motivation>
118//
119// <todo asof="2000/06/21">
120// <li> Get/set history as a vector of strings as well.
121// <li> This could be a namespace rather than a class.
122// </todo>
123
125 public:
126 // Make an initial FitsKeywordList for either a FITS primary header
127 // or a FITS extension header (image or table). A primary header
128 // requires "SIMPLE = T", an extension header "XTENSION = IMAGE "
129 // or "XTENSION = BINTABLE " for image or table, respectively.
130 // This is required of any FITS keyword list. This is provided as
131 // a convenience so that you do not have to know anything about the class
132 // <linkto class=FitsKeywordList>FitsKeywordList</linkto>.
133 static FitsKeywordList makeKeywordList(Bool primHead = True, Bool binImage = True);
134
135 // Add the fields from in to the out FitsKeywordList as keywords.
136 // Upcases field names, turns arrays into indexed keywords, tries to interleave
137 // e.g. crval, crpix, etc.
138 // COMMENT* are standalone comments, and HISTORY* are history cards.
139 // (COMMENT and HISTORY may be of any capitalization). Note however that
140 // you will generally add History keywords with the class
141 // <linkto class=FITSHistoryUtil>FITSHistoryUtil</linkto>.
142 // Returns False in the following instances:
143 // <ul>
144 // <li> The value of a string field is longer than 68 characters. The value is truncated.
145 // <li> An illegal type for a FITS keyword (e.g. Complex). The field is ignored.
146 // <li> An array field has more than 2 dimensions. The field is stored as a vector.
147 // <li> An array field name is too long to hold the name and the index characters. The name is
148 // truncated. <li> Too many rows or columns for a 2D array (first 999 in each are used). <li> Too
149 // many elements in a 1D array (first 999 are used). <li> A field is neither a scalar or an array
150 // (e.g. a record). The field is ignored.
151 // </ul>
153
154 // Extract keywords from in and define them in out.
155 // Output field names are downcased. Keywords matching
156 // the names in ignore (which are treated as regular expressions) are
157 // not created in out. This test happens after the field names
158 // have been downcased.
159 // All indexed keywords will be ignored if the root name is in the ignore
160 // vector (e.g. NAXIS implies NAXIS4 and other indexed NAXIS keywords
161 // are ignored).
162 // By default history keywords are ignored, since they
163 // should be handled in class
164 // <linkto class=FITSHistoryUtil>FITSHistoryUtil</linkto>.
165 // This always returns True.
167 const Vector<String> &ignore, Bool ignoreHistory = True);
168
169 // Remove some keywords from a record. This can be useful
170 // if, e.g., you first need to construct a coordinate system from the
171 // header, but you later want to remove CROTA etc.
172 // The strings in the ignore vector are treated as regular expressions.
173 static void removeKeywords(RecordInterface &out, const Vector<String> &ignore);
174
175 // Convert a TDIMnnn keyword value into an IPosition. This returns
176 // False if the tdim string has an invalid format.
177 static Bool fromTDIM(IPosition &shape, const String &tdim);
178
179 // Convert an IPosition to a String appropriate for use as the
180 // value of a TDIMnnn keyword. This returns False if the
181 // converted string has more than 71 characters
182 // (making it impossible to be used as a string keyword value).
183 static Bool toTDIM(String &tdim, const IPosition &shape);
184
185 // Add a comment/history to the supplied record. It will automatically
186 // figure out a unique name and add it to the end. If the comment contains
187 // embedded newlines this function will break the string across multiple
188 // FITS comment entries. At present it will not however make sure that the
189 // strings are short enough (i.e. <= 72 characters per line).
190 //
191 // Note that while you can add history anywhere into header, in the actual
192 // keyword list they will always appear after the END keyword.
193
194 // Note however that you will generally manipulate History keywords with
195 // the class <linkto class=FITSHistoryUtil>FITSHistoryUtil</linkto>.
196 // <group>
197 static void addComment(RecordInterface &header, const String &comment);
198 static void addHistory(RecordInterface &header, const String &history);
199 // </group>
200};
201
202} // namespace casacore
203
204#endif
list of read-only FITS keywords
Definition fits.h:1229
static FitsKeywordList makeKeywordList(Bool primHead=True, Bool binImage=True)
Make an initial FitsKeywordList for either a FITS primary header or a FITS extension header (image or...
static Bool toTDIM(String &tdim, const IPosition &shape)
Convert an IPosition to a String appropriate for use as the value of a TDIMnnn keyword.
static Bool fromTDIM(IPosition &shape, const String &tdim)
Convert a TDIMnnn keyword value into an IPosition.
static void addHistory(RecordInterface &header, const String &history)
static void addComment(RecordInterface &header, const String &comment)
Add a comment/history to the supplied record.
static Bool getKeywords(RecordInterface &out, ConstFitsKeywordList &in, const Vector< String > &ignore, Bool ignoreHistory=True)
Extract keywords from in and define them in out.
static void removeKeywords(RecordInterface &out, const Vector< String > &ignore)
Remove some keywords from a record.
static Bool addKeywords(FitsKeywordList &out, const RecordInterface &in)
Add the fields from in to the out FitsKeywordList as keywords.
linked list of FITS keywords
Definition fits.h:983
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
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
const String & comment(const RecordFieldId &) const override
Get the comment for this field.
RecordInterface()
The default constructor creates an empty record with a variable structure.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41