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