casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FITSKeywordUtil.h
Go to the documentation of this file.
00001 //# FITSKeywordUtil.h: Class of static functions to help with FITS Keywords.
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: FITSKeywordUtil.h 20299 2008-04-03 05:56:44Z gervandiepen $
00028 
00029 
00030 #ifndef FITS_FITSKEYWORDUTIL_H
00031 #define FITS_FITSKEYWORDUTIL_H
00032 
00033 #include <casa/aips.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 class ConstFitsKeywordList;
00038 class FitsKeywordList;
00039 class RecordInterface;
00040 class IPosition;
00041 class String;
00042 template<class T> class Vector;
00043 
00044 // <summary>
00045 // A class with static functions to help deal with FITS Keywords.
00046 // </summary>
00047 
00048 // <use visibility=export>
00049 
00050 // <reviewed reviewer="Eric Sessoms" date="2002/08/19" tests="tFITSKeywordUtil.cc">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 //   <li> General knowledge of FITS, and particularly FITS keywords, is
00055 //        assumed.
00056 //   <li> Presumably you are using this class in conjunction
00057 //        with the "native" 
00058 //        <linkto class=FitsKeywordList>FitsKeywordList</linkto>
00059 //   <li> You also need to understand the
00060 //        <linkto class=RecordInterface>RecordInterface</linkto>
00061 //        class.
00062 // </prerequisite>
00063 //
00064 // <etymology>
00065 // This is a collection of static utility functions for use with FITS
00066 // keywords.
00067 // </etymology>
00068 //
00069 // <synopsis>
00070 // This class provides functions to conveniently interconvert between AIPS++
00071 // types and a FitsKeywordList which is needed by the native FITS classes.
00072 // It is more convenient to maintain the list within AIPS++
00073 // as a Record, so we only need methods to turn a FitsKeywordList into a 
00074 // Record, and vice versa.
00075 //
00076 // Note that it is not necessary to construct a FITSKeywordUtil object
00077 // since you can use its static functions directly.
00078 // </synopsis>
00079 //
00080 // <example>
00081 // This example shows how you put values from a Record into a
00082 // FItsKeywordList.
00083 // <srcblock>
00084 // Record rec;
00085 // rec.define("hello", 6.5);
00086 // rec.define("world", True);
00087 // Vector<Int> naxis(5); 
00088 // naxis(0) = 128; 
00089 // naxis(1) = 64; 
00090 // naxis(2) = 32;
00091 // naxis(3) = 16;
00092 // naxis(4) = 8;
00093 // rec.define("naxis", naxis);
00094 // // fields can have comments
00095 // rec.setComment("hello","A comment for HELLO");
00096 // // Add a comment to the rec
00097 // FITSKeywordUtil::addComment(rec,"My comment goes here");
00098 // // Create an empty FitsKeywordList, containing only "SIMPLE=T"
00099 // FitsKeywordList kwl = FITSKeywordUtil::makeKeywordList();
00100 // // and add the fields in rec to this list
00101 // FITSKeywordUtil::addKeywords(kwl, rec);
00102 // </srcblock>
00103 // </example>
00104 //
00105 // <example>
00106 // This example shows how you extract fits keywords into a Record.
00107 // <srcblock>
00108 // Record rec;
00109 // FitsKeywordList kwl;
00110 // ConstFitsKeywordList kwlRO;
00111 // Vector<String> ignore(1);
00112 // ignore(1)= "simple"; // ignore the SIMPLE keyword
00113 // FITSKeywordUtil::getKeywords(rec, kwlRO, ignore);
00114 // </srcblock>
00115 // </example>
00116 //
00117 // <motivation>
00118 // The FitsKeywordList class can be somewhat tedious to use, as it deals with,
00119 // e.g., char* pointers rather than Strings. This class makes it easy to
00120 // interconvert between FITS keywords and AIPS++ types.
00121 // </motivation>
00122 //
00123 // <todo asof="2000/06/21">
00124 //   <li> Get/set history as a vector of strings as well.
00125 //   <li> This could be a namespace rather than a class.
00126 // </todo>
00127 
00128 class FITSKeywordUtil
00129 {
00130 public:
00131     // Make an initial FitsKeywordList for either a FITS primary header
00132          // or a FITS extension header (image or table). A primary header
00133          // requires "SIMPLE = T", an extension header "XTENSION = IMAGE "
00134          // or "XTENSION = BINTABLE " for image or table, respectively.
00135     // This is required of any FITS keyword list. This is provided as
00136          // a convenience so that you do not have to know anything about the class
00137     // <linkto class=FitsKeywordList>FitsKeywordList</linkto>.
00138     static FitsKeywordList makeKeywordList(Bool primHead=True, Bool binImage=True);
00139 
00140     // Add the fields from in to the out FitsKeywordList as keywords.
00141     // Upcases field names, turns arrays into indexed keywords, tries to interleave
00142     // e.g. crval, crpix, etc. 
00143     // COMMENT* are standalone comments, and HISTORY* are history cards.
00144     // (COMMENT and HISTORY may be of any capitalization). Note however that
00145     // you will generally add History keywords with the class
00146     // <linkto class=FITSHistoryUtil>FITSHistoryUtil</linkto>.
00147     // Returns False in the following instances:
00148     // <ul>
00149     // <li> The value of a string field is longer than 68 characters.  The value is truncated.
00150     // <li> An illegal type for a FITS keyword (e.g. Complex).  The field is ignored.
00151     // <li> An array field has more than 2 dimensions. The field is stored as a vector.
00152     // <li> An array field name is too long to hold the name and the index characters.  The name is truncated.
00153     // <li> Too many rows or columns for a 2D array (first 999 in each are used).
00154     // <li> Too many elements in a 1D array (first 999 are used).
00155     // <li> A field is neither a scalar or an array (e.g. a record).  The field is ignored.
00156     // </ul>
00157     static Bool addKeywords(FitsKeywordList &out, const RecordInterface &in);
00158 
00159     // Extract keywords from in and define them in out.  
00160     // Output field names are downcased.  Keywords matching
00161     // the names in ignore (which are treated as regular expressions) are
00162     // not created in out.  This test happens after the field names
00163     // have been downcased.
00164     // All indexed keywords will be ignored if the root name is in the ignore
00165     // vector (e.g. NAXIS implies NAXIS4 and other indexed NAXIS keywords
00166     // are ignored).
00167     // By default history keywords are ignored, since they
00168     // should be handled in class 
00169     // <linkto class=FITSHistoryUtil>FITSHistoryUtil</linkto>.
00170     // This always returns True.
00171     static Bool getKeywords(RecordInterface &out, ConstFitsKeywordList &in, 
00172                             const Vector<String> &ignore, 
00173                             Bool ignoreHistory=True);
00174 
00175     
00176     // Remove some keywords from a record. This can be useful
00177     // if, e.g., you first need to construct a coordinate system from the
00178     // header, but you later want to remove CROTA etc.
00179     // The strings in the ignore vector are treated as regular expressions.
00180     static void removeKeywords(RecordInterface &out, 
00181                                const Vector<String> &ignore);
00182 
00183     // Convert a TDIMnnn keyword value into an IPosition.  This returns
00184     // False if the tdim string has an invalid format.
00185     static Bool fromTDIM(IPosition& shape, const String& tdim);
00186 
00187     // Convert an IPosition to a String appropriate for use as the
00188     // value of a TDIMnnn keyword.  This returns False if the
00189     // converted string has more than 71 characters
00190     // (making it impossible to be used as a string keyword value).
00191     static Bool toTDIM(String& tdim, const IPosition& shape);
00192 
00193     // Add a comment/history to the supplied record. It will automatically
00194     // figure out a unique name and add it to the end. If the comment contains
00195     // embedded newlines this function will break the string across multiple
00196     // FITS comment entries. At present it will not however make sure that the
00197     // strings are short enough (i.e. <= 72 characters per line).
00198     // 
00199     // Note that while you can add history anywhere into header, in the actual
00200     // keyword list they will always appear after the END keyword.
00201 
00202     // Note however that you will generally manipulate History keywords with
00203     // the class <linkto class=FITSHistoryUtil>FITSHistoryUtil</linkto>.
00204     // <group>
00205     static void addComment(RecordInterface &header, const String &comment);
00206     static void addHistory(RecordInterface &header, const String &history);
00207     // </group>
00208 };
00209 
00210 
00211 } //# NAMESPACE CASA - END
00212 
00213 #endif