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