casacore
Loading...
Searching...
No Matches
FITSHistoryUtil.h
Go to the documentation of this file.
1// # FITSHistoryUtil.h: Class of static functions to help with FITS History cards.
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_FITSHISTORYUTIL_H
27#define FITS_FITSHISTORYUTIL_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <vector>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
36class FitsKeywordList;
37class String;
38class LoggerHolder;
39
40// <summary>
41// A class with static functions to help deal with FITS History cards.
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="Eric Sessoms" date="2002/08/19" tests="tFITSHistoryUtil.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// </prerequisite>
56//
57// <etymology>
58// This is a collection of static utility functions for use with FITS
59// HISTORY keywords.
60// </etymology>
61//
62// <synopsis>
63// Manipulate HISTORY information. FITS HISTORY cards are interconverted with
64// String as follows:
65// <ul>
66// <li> 'HISTORY ' and trailing blanks are removed from each card.
67// <li> Continuation cards are CARDS that have '>' in the first line.
68// <li> A string is made by concatenating the leading card and all continuation
69// cards.
70// </ul>
71// For example:
72// <srcblock>
73// HISTORY Every good
74// HISTORY > boy deserves
75// HISTORY >fudge.
76// </srcblock>
77// Becomes the C++ String: "Every good boy deservesfudge." Note the lack of
78// a space between deserves and fudge.
79//
80// History cards are broken into groups. A group is delimited by
81// <srcblock>
82// HISTORY AIPS++ START TYPE
83// HISTORY AIPS++ END [TYPE]
84// </srcblock>
85// Where type might be, e.g., LOGTABLE. HISTORY cards not enclosed between
86// START/END pairs are implicitly of type "" (i.e. the empty string).
87// The TYPE is optional on the END statement. It is essentially a comment.
88//
89// At present, START/END pairs cannot be nested, although this would be an
90// obvious extension.
91// </synopsis>
92//
93// <motivation>
94// The FitsKeywordList class can be somewhat tedious to use, as it deals with,
95// e.g., char* pointers rather than Strings. This class makes it easy to
96// interconvert between the HISTORY keywords and a Vector of related history
97// information.
98// </motivation>
99//
100
102 public:
103 // Get the strings in the next keyword group. Returns the number of
104 // strings found (0 when no history remains). If necessary, strings will be
105 // resized larger. in must be set to the first card before the first call to
106 // getHistoryGroup, and should not be reset until all history is extracted
107 // (otherwise the same history will be extracted more than once). This method
108 // can be used as follows:
109 // <srcBlock>
110 // uInt n;
111 // Vector<String> group;
112 // String type;
113 // ConstFITSKeywordList keys(...);
114 // ...
115 // keys.first();
116 // while ((n = FITSHistoryUtil::getHistoryGroup(group, type, keys)) != 0) {
117 // ... process this history group
118 // }
119 // </srcBlock>
120 // strings will have no embedded newlines. strings is not resized if it is more
121 // than large enough to hold the number of history cards in the group (i.e. there
122 // may be values at the end of strings which are not part of the requested group.
124
125 // Add history strings of the specified groupType to an existing FitsKeywordList.
126 // This function will split long strings across HISTORY cards and set
127 // up the group START/END keywords if necessary. nstrings must be specified
128 // because strings might have come from something like getHistoryGroup, i.e.
129 // it might have garbage entries at the end. The strings may have embedded
130 // newlines, but they must have no other non-printable characters.
131 static void addHistoryGroup(FitsKeywordList& out, const std::vector<String>& strings,
132 uInt nstrings, const String& groupType);
133
134 // Some functions to help convert between log tables and FITS HISTORY cards.
135 // It is intended that these functions will only be used by the functions in
136 // classes like ImageFITSConverter.
137 //
138 // Table rows are in Casacore format if they have a valid time and priority,
139 // otherwise they are in the standard FITS HISTORY format. The history lines
140 // are processed by contiguous groups where all lines in that group are
141 // either in Casacore or HISTORY format. Note that history.nelements() might
142 // be greater than nstrings for efficiency (i.e. the history vector will
143 // not be shrunk unnecessarily).
144 //
145 // Note that these functions are in a separate .cc file so that if they
146 // are not used the table function is not linked in if other functions in
147 // this class are used.
148 //
149 // The strings are assumed to be from or going to the get/addHistoryGroup
150 // functions, i.e. strings that span multiple lines are joined,
151 // AIPS++ START/END cards are stripped, etc.
152 //
153 // The Casacore format is: the first line DATE PRIORITY [SRCCODE='xxx']
154 // [OBJID='xxx'] and the second lins is the message. These entries are in
155 // an AIPS++ START LOGTABLE history sequence.
156 // <group>
157 static void fromHISTORY(LoggerHolder& logSink, const Vector<String>& history, uInt nstrings,
158 Bool aipsppFormat);
159
160 // toHistory signals that it is done by setting nstrings to 0.
161 // The returned value is firstLine + n_lines_read, i.e. use
162 // it as firstLine in your next call.
163 static uInt toHISTORY(std::vector<String>& history, Bool& aipsppFormat, uInt& nstrings,
164 uInt firstLine, const LoggerHolder& logSink);
165 // </group>
166};
167
168} // namespace casacore
169
170#endif
list of read-only FITS keywords
Definition fits.h:1229
static void fromHISTORY(LoggerHolder &logSink, const Vector< String > &history, uInt nstrings, Bool aipsppFormat)
Some functions to help convert between log tables and FITS HISTORY cards.
static void addHistoryGroup(FitsKeywordList &out, const std::vector< String > &strings, uInt nstrings, const String &groupType)
Add history strings of the specified groupType to an existing FitsKeywordList.
static uInt toHISTORY(std::vector< String > &history, Bool &aipsppFormat, uInt &nstrings, uInt firstLine, const LoggerHolder &logSink)
toHistory signals that it is done by setting nstrings to 0.
static uInt getHistoryGroup(Vector< String > &strings, String &groupType, ConstFitsKeywordList &in)
Get the strings in the next keyword group.
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
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40