FITSImgParser.h

Go to the documentation of this file.
00001 //# FITSImgParser.h: Class for parsing multi-extension FITS images
00002 //# Copyright (C) 2001,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 //# $Id$
00027 
00028 #ifndef IMAGES_FITSImgParser_H
00029 #define IMAGES_FITSImgParser_H
00030 
00031 #include <casacore/casa/aips.h>
00032 #include <casacore/fits/FITS/fits.h>
00033 #include <casacore/casa/Arrays/Vector.h>
00034 #include <casacore/casa/BasicSL/String.h>
00035 
00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00037 
00038 //# Forward Declarations
00039 class FITSExtInfo;
00040 class HeaderDataUnit;
00041 
00042 // <summary>
00043 // Class for handling FITS Image extensions
00044 // </summary>
00045 
00046 // <use visibility=export>
00047 
00048 // <reviewed reviewer="" date="" tests="tFITSImgParser.cc">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //   <li> <linkto class=FITSExtInfo>FITSExtInfo</linkto>
00053 //   <li> <linkto class=HeaderDataUnit>HeaderDataUnit</linkto>
00054 // </prerequisite>
00055 
00056 // <etymology>
00057 //  This class parses through a FITS image and stores essential information
00058 //  for each extension.
00059 // </etymology>
00060 
00061 // <synopsis>
00062 // The class parses through a FITS image and extracts information
00063 // on its extensions, e.g. the extension name and the extension version.
00064 // It is possible to identify a certain extension and to get the its
00065 // extension index.
00066 //
00067 // It is also explored whether some of the FITS extensions can be
00068 // loaded as a quality image (data + error + mask).
00069 // </synopsis>
00070 
00071 // <example>
00072 // <srcblock>
00073 //    FITSImgParser fitsImg("in.fits");
00074 //    uInt numHDU    = fitsImg.get_numhdu();                // get the total number of HDU's
00075 //    uInt firstdata = fitsImg.get_firstdata_index();       // get the first HDU with data
00076 //    String allExts = fitsImg.get_extlist_string(String("\n"));  // get a string representation of all extensions
00077 //    String hasQual = fitsImg.has_qualityimg();            // check whether some of the extensions form quality image
00078 // </srcblock>
00079 // </example>
00080 
00081 // <motivation>
00082 // Investigate and select FITS extensions
00083 // </motivation>
00084 
00085 //# <todo asof="2011/08/16">
00086 //# </todo>
00087 
00088 class FITSImgParser
00089 {
00090 public: 
00091   // Construct a parser from the FITS file.
00092   FITSImgParser(const String& name);
00093 
00094   // Copy constructor (reference semantics).
00095   FITSImgParser(const FITSImgParser& other);
00096 
00097   // Destructor, does not much.
00098   ~FITSImgParser();
00099 
00100   // Assignment (reference semantics).
00101   FITSImgParser& operator=(const FITSImgParser& other);
00102 
00103   // Returns the name of the disk file.
00104   String fitsname (Bool stripPath=False) const;
00105 
00106   // Identify the index of an extension.
00107   Int get_index(const FITSExtInfo &extinfo);
00108 
00109   // Find an extension; return -1 if not found.
00110   Int find_extension(const String &extname, const Int &extversion=-1);
00111 
00112   // Get the index of the first extension with data.
00113   uInt get_firstdata_index(void);
00114 
00115   // Get the number of extensions.
00116   uInt get_numhdu(void) { return numhdu_p;};
00117 
00118   // Get a string representation of the extension list.
00119   String get_extlist_string(const String &delimiter, const String &qualmarker="",
00120                   const String &fitsmarker="", const Bool &listall=True);
00121 
00122   // Get the flag indicating at least one quality image.
00123   Bool has_qualityimg(void) {return qualimglist_p.size() > 0 ? True : False;};
00124 
00125   // Check whether the extensions named in the extension expression
00126   // can be loaded as a quality image.
00127   Bool is_qualityimg(const String &extexpr);
00128 
00129   // Find all necessary access information for the extensions to be loaded
00130   // as a quality image.
00131   Bool get_quality_data(const String &extexpr, Int &data_HDU, Int &error_HDU,
00132         String &error_type, Int &mask_HDU, String &mask_type, Int &mask_value);
00133 
00134 private:  
00135   String         name_p;
00136   uInt           numhdu_p;
00137 
00138   FITSExtInfo   *extensions_p;
00139   Vector<String>  qualimglist_p;
00140 
00141   Bool           hasmeasurement_p;
00142 
00143   static const char *storeKwords_p[];
00144   static const int   nKwords_p;
00145 
00146   // Setup the object (used by constructors).
00147   void setup(void);
00148 
00149   // Get the information on an extension.
00150   void process_extension(HeaderDataUnit *h, const uInt &extindex);
00151 
00152   // Extract the list of extensions from the extension expression.
00153   Bool get_extlist(const String &extexpr, Vector<String> &extlist);
00154 
00155   // Get the first extension with HDU type "data" from the
00156   // list of indices. Returns "-1" if there is none.
00157   Int get_dataindex(const Vector<Int> &extindex);
00158 
00159   // Get the error extension name for the given data extension.
00160   String get_errorext(const Int &ext_index);
00161 
00162   // Get the mask extension name for the given data extension.
00163   String get_maskext(const Int &ext_index);
00164 
00165   // Check the keywords with fixed values
00166   Bool confirm_fix_keywords(const Int &ext_index);
00167 
00168   // Check whether the extension has a certain HDU type.
00169   Bool index_is_HDUtype(const Int &ext_index, const String &hdutype);
00170 
00171   // Find and store all set of extensions
00172   // that can be loaded as a quality image.
00173   Bool find_qualimgs(void);
00174 };
00175 
00176 
00177 //class FitsKeywordList;
00178 
00179 // <summary>
00180 // Class for storing FITS Image extension information
00181 // </summary>
00182 
00183 // <use visibility=export>
00184 
00185 // <reviewed reviewer="" date="" tests="tFITSImgParser.cc">
00186 // </reviewed>
00187 
00188 // <prerequisite>
00189 // </prerequisite>
00190 
00191 // <etymology>
00192 // The class stores the essential information on a FITS
00193 // image extension.
00194 // </etymology>
00195 
00196 // <synopsis>
00197 // The class stores the essential information on a FITS image extension,
00198 // which is the FITS file name, the extension name, the extension version,
00199 // the index within the FITS file.
00200 // </synopsis>
00201 //
00202 // <example>
00203 // <srcblock>
00204 //    FITSImgParser fitsImg("in.fits");
00205 //    FITSExtInfo extinfo("in.fits", 0, "SCI", 1, True);
00206 //    Int index = fitsImg.get_index(extinfo);              // get the index of extension "[SCI, 1]"
00207 // </srcblock>
00208 // </example>
00209 //
00210 // <motivation>
00211 // Helper class for accessing multi-extension FITS files.
00212 // </motivation>
00213 //
00214 //# <todo asof="2011/02/17">
00215 //# </todo>
00216 class FITSExtInfo
00217 {
00218 public:
00219         // Construct the object
00220         FITSExtInfo(const String &name, const uInt &extindex, const String &extname,
00221                         const Int &extversion, const Bool &hasdata);
00222 
00223         // Construct the object
00224         FITSExtInfo()
00225         {
00226                 FITSExtInfo("", 0, "", 0, False);
00227         };
00228 
00229         // Copy constructor (reference semantics)
00230         FITSExtInfo(const FITSExtInfo& other);
00231 
00232         // Destructor does nothing.
00233         ~FITSExtInfo();
00234 
00235         // Assignment (reference semantics).
00236         FITSExtInfo& operator=(const FITSExtInfo& other);
00237 
00238         // Relational operator.
00239         Bool operator==(const FITSExtInfo &extinfo);
00240 
00241         // All extension information as a string.
00242         String get_extexpr(void);
00243 
00244         // Return the extension name.
00245         String get_extname(void){return extname_p;};
00246 
00247         // Return the extension version.
00248         Int get_extversion(void){return extversion_p;};
00249 
00250         // Return whether there is data.
00251         Bool has_data(void){return hasdata_p;};
00252 
00253         // Add a list of keywords.
00254         void add_kwlist(FitsKeywordList &kwlist);
00255 
00256         // Return a keyword.
00257         FitsKeyword *get_keyword(const String kname){return kwlist_p(kname.c_str());};
00258 
00259 private:
00260         String name_p;
00261         uInt   extindex_p;
00262         String extname_p;
00263         Int    extversion_p;
00264         Bool   hasdata_p;
00265         FitsKeywordList kwlist_p;
00266 };
00267 
00268 } //# NAMESPACE CASACORE - END
00269 
00270 #endif
00271 
00272 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1