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