casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FITSHistoryUtil.h
Go to the documentation of this file.
00001 //# FITSHistoryUtil.h: Class of static functions to help with FITS History cards.
00002 //# Copyright (C) 2002
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: FITSHistoryUtil.h 20299 2008-04-03 05:56:44Z gervandiepen $
00028 
00029 
00030 #ifndef FITS_FITSHISTORYUTIL_H
00031 #define FITS_FITSHISTORYUTIL_H
00032 
00033 #include <vector>
00034 #include <casa/aips.h>
00035 
00036 
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 class ConstFitsKeywordList;
00041 class FitsKeywordList;
00042 class String;
00043 template<class T> class Vector;
00044 class LoggerHolder;
00045 
00046 // <summary>
00047 // A class with static functions to help deal with FITS History cards.
00048 // </summary>
00049 
00050 // <use visibility=export>
00051 
00052 // <reviewed reviewer="Eric Sessoms" date="2002/08/19" tests="tFITSHistoryUtil.cc">
00053 // </reviewed>
00054 
00055 // <prerequisite>
00056 //   <li> General knowledge of FITS, and particularly FITS keywords, is
00057 //        assumed.
00058 //   <li> Presumably you are using this class in conjunction
00059 //        with the "native" 
00060 //        <linkto class=FitsKeywordList>FitsKeywordList</linkto>
00061 // </prerequisite>
00062 //
00063 // <etymology>
00064 // This is a collection of static utility functions for use with FITS
00065 // HISTORY keywords.
00066 // </etymology>
00067 //
00068 // <synopsis>
00069 // Manipulate HISTORY information. FITS HISTORY cards are interconverted with
00070 // String as follows:
00071 // <ul>
00072 // <li> 'HISTORY ' and trailing blanks are removed from each card.
00073 // <li> Continuation cards are CARDS that have '>' in the first line.
00074 // <li> A string is made by concatenating the leading card and all continuation
00075 //    cards.
00076 // </ul>
00077 // For example:
00078 // <srcblock>
00079 // HISTORY Every good
00080 // HISTORY > boy deserves
00081 // HISTORY >fudge.
00082 // </srcblock>
00083 // Becomes the C++ String: "Every good boy deservesfudge." Note the lack of
00084 // a space between deserves and fudge.
00085 //
00086 // History cards are broken into groups. A group is delimited by
00087 // <srcblock>
00088 // HISTORY AIPS++ START TYPE
00089 // HISTORY AIPS++ END [TYPE]
00090 // </srcblock>
00091 // Where type might be, e.g., LOGTABLE. HISTORY cards not enclosed between
00092 // START/END pairs are implicitly of type "" (i.e. the empty string).
00093 // The TYPE is optional on the END statement. It is essentially a comment.
00094 //
00095 // At present, START/END pairs cannot be nested, although this would be an
00096 // obvious extension.
00097 // </synopsis>
00098 //
00099 // <motivation>
00100 // The FitsKeywordList class can be somewhat tedious to use, as it deals with,
00101 // e.g., char* pointers rather than Strings. This class makes it easy to
00102 // interconvert between the HISTORY keywords and a Vector of related history
00103 // information.
00104 // </motivation>
00105 //
00106 
00107 class FITSHistoryUtil
00108 {
00109 public:
00110     // Get the strings in the next keyword group. Returns the number of
00111     // strings found (0 when no history remains).  If necessary, strings will be
00112     // resized larger. in must be set to the first card before the first call to
00113     // getHistoryGroup, and should not be reset until all history is extracted
00114     // (otherwise the same history will be extracted more than once). This method
00115     // can be used as follows:
00116     // <srcBlock>
00117     // uInt n;
00118     // Vector<String> group;
00119     // String type;
00120     // ConstFITSKeywordList keys(...);
00121     // ...
00122     // keys.first();
00123     // while ((n = FITSHistoryUtil::getHistoryGroup(group, type, keys)) != 0) {
00124     //     ... process this history group
00125     // }
00126     // </srcBlock>
00127     // strings will have no embedded newlines. strings is not resized if it is more 
00128     // than large enough to hold the number of history cards in the group (i.e. there
00129     // may be values at the end of strings which are not part of the requested group.
00130     static uInt getHistoryGroup(Vector<String> &strings, String &groupType,
00131                                 ConstFitsKeywordList &in);
00132 
00133     // Add history strings of the specified groupType to an existing FitsKeywordList.
00134     // This function will split long strings across HISTORY cards and set
00135     // up the group START/END keywords if necessary. nstrings must be specified
00136     // because strings might have come from something like getHistoryGroup, i.e.
00137     // it might have garbage entries at the end. The strings may have embedded
00138     // newlines, but they must have no other non-printable characters.
00139     static void addHistoryGroup(FitsKeywordList &out,
00140                                 const std::vector<String> &strings,
00141                                 uInt nstrings, const String &groupType);
00142 
00143     // Some functions to help convert between log tables and FITS HISTORY cards.
00144     // It is intended that these functions will only be used by the functions in
00145     // classes like ImageFITSConverter.
00146     // 
00147     // Table rows are in AIPS++ format if they have a valid time and priority,
00148     // otherwise they are in the standard FITS HISTORY format. The history lines
00149     // are processed by contiguous groups where all lines in that group are
00150     // either in AIPS++ or HISTORY format. Note that history.nelements() might
00151     // be greater than nstrings for efficiency (i.e.  the history vector will
00152     // not be shrunk unnecessarily).
00153     //
00154     // Note that these functions are in a separate .cc file so that if they
00155     // are not used the table function is not linked in if other functions in
00156     // this class are used.
00157     //
00158     // The strings are assumed to be from or going to the get/addHistoryGroup
00159     // functions, i.e. strings that span multiple lines are joined, 
00160     // AIPS++ START/END cards are stripped, etc.
00161     //
00162     // The AIPS++ format is: the first line DATE PRIORITY [SRCCODE='xxx']
00163     // [OBJID='xxx'] and the second lins is the message.  These entries are in
00164     // an AIPS++ START LOGTABLE history sequence.
00165     // <group>
00166     static void fromHISTORY(LoggerHolder& logSink, 
00167                             const Vector<String>& history, 
00168                             uInt nstrings, Bool aipsppFormat);
00169 
00170     // toHistory signals that it is done by setting nstrings to 0.
00171     // The returned value is firstLine + n_lines_read, i.e. use
00172     // it as firstLine in your next call.
00173     static uInt toHISTORY(std::vector<String>& history, Bool& aipsppFormat,
00174                           uInt& nstrings, uInt firstLine, 
00175                           const LoggerHolder& logSink);
00176     // </group>
00177 
00178 };
00179 
00180 
00181 } //# NAMESPACE CASA - END
00182 
00183 #endif