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