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