casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FITSImgParser.h
Go to the documentation of this file.
1 //# FITSImgParser.h: Class for parsing multi-extension FITS images
2 //# Copyright (C) 2001,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 //# $Id$
27 
28 #ifndef IMAGES_FITSImgParser_H
29 #define IMAGES_FITSImgParser_H
30 
31 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 class FITSExtInfo;
40 class HeaderDataUnit;
41 
42 // <summary>
43 // Class for handling FITS Image extensions
44 // </summary>
45 
46 // <use visibility=export>
47 
48 // <reviewed reviewer="" date="" tests="tFITSImgParser.cc">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class=FITSExtInfo>FITSExtInfo</linkto>
53 // <li> <linkto class=HeaderDataUnit>HeaderDataUnit</linkto>
54 // </prerequisite>
55 
56 // <etymology>
57 // This class parses through a FITS image and stores essential information
58 // for each extension.
59 // </etymology>
60 
61 // <synopsis>
62 // The class parses through a FITS image and extracts information
63 // on its extensions, e.g. the extension name and the extension version.
64 // It is possible to identify a certain extension and to get the its
65 // extension index.
66 //
67 // It is also explored whether some of the FITS extensions can be
68 // loaded as a quality image (data + error + mask).
69 // </synopsis>
70 
71 // <example>
72 // <srcblock>
73 // FITSImgParser fitsImg("in.fits");
74 // uInt numHDU = fitsImg.get_numhdu(); // get the total number of HDU's
75 // uInt firstdata = fitsImg.get_firstdata_index(); // get the first HDU with data
76 // String allExts = fitsImg.get_extlist_string(String("\n")); // get a string representation of all extensions
77 // String hasQual = fitsImg.has_qualityimg(); // check whether some of the extensions form quality image
78 // </srcblock>
79 // </example>
80 
81 // <motivation>
82 // Investigate and select FITS extensions
83 // </motivation>
84 
85 //# <todo asof="2011/08/16">
86 //# </todo>
87 
89 {
90 public:
91  // Construct a parser from the FITS file.
92  FITSImgParser(const String& name);
93 
94  // Copy constructor (reference semantics).
95  FITSImgParser(const FITSImgParser& other);
96 
97  // Destructor, does not much.
99 
100  // Assignment (reference semantics).
101  FITSImgParser& operator=(const FITSImgParser& other);
102 
103  // Returns the name of the disk file.
104  String fitsname (Bool stripPath=False) const;
105 
106  // Identify the index of an extension.
107  Int get_index(const FITSExtInfo &extinfo);
108 
109  // Find an extension; return -1 if not found.
110  Int find_extension(const String &extname, const Int &extversion=-1);
111 
112  // Get the index of the first extension with data.
114 
115  // Get the number of extensions.
116  uInt get_numhdu(void) { return numhdu_p;};
117 
118  // Get a string representation of the extension list.
119  String get_extlist_string(const String &delimiter, const String &qualmarker="",
120  const String &fitsmarker="", const Bool &listall=True);
121 
122  // Get the flag indicating at least one quality image.
123  Bool has_qualityimg(void) {return qualimglist_p.size() > 0 ? True : False;};
124 
125  // Check whether the extensions named in the extension expression
126  // can be loaded as a quality image.
127  Bool is_qualityimg(const String &extexpr);
128 
129  // Find all necessary access information for the extensions to be loaded
130  // as a quality image.
131  Bool get_quality_data(const String &extexpr, Int &data_HDU, Int &error_HDU,
132  String &error_type, Int &mask_HDU, String &mask_type, Int &mask_value);
133 
134 private:
137 
140 
142 
143  static const char *storeKwords_p[];
144  static const int nKwords_p;
145 
146  // Setup the object (used by constructors).
147  void setup(void);
148 
149  // Get the information on an extension.
150  void process_extension(HeaderDataUnit *h, const uInt &extindex);
151 
152  // Extract the list of extensions from the extension expression.
153  Bool get_extlist(const String &extexpr, Vector<String> &extlist);
154 
155  // Get the first extension with HDU type "data" from the
156  // list of indices. Returns "-1" if there is none.
157  Int get_dataindex(const Vector<Int> &extindex);
158 
159  // Get the error extension name for the given data extension.
160  String get_errorext(const Int &ext_index);
161 
162  // Get the mask extension name for the given data extension.
163  String get_maskext(const Int &ext_index);
164 
165  // Check the keywords with fixed values
166  Bool confirm_fix_keywords(const Int &ext_index);
167 
168  // Check whether the extension has a certain HDU type.
169  Bool index_is_HDUtype(const Int &ext_index, const String &hdutype);
170 
171  // Find and store all set of extensions
172  // that can be loaded as a quality image.
173  Bool find_qualimgs(void);
174 };
175 
176 
177 //class FitsKeywordList;
178 
179 // <summary>
180 // Class for storing FITS Image extension information
181 // </summary>
182 
183 // <use visibility=export>
184 
185 // <reviewed reviewer="" date="" tests="tFITSImgParser.cc">
186 // </reviewed>
187 
188 // <prerequisite>
189 // </prerequisite>
190 
191 // <etymology>
192 // The class stores the essential information on a FITS
193 // image extension.
194 // </etymology>
195 
196 // <synopsis>
197 // The class stores the essential information on a FITS image extension,
198 // which is the FITS file name, the extension name, the extension version,
199 // the index within the FITS file.
200 // </synopsis>
201 //
202 // <example>
203 // <srcblock>
204 // FITSImgParser fitsImg("in.fits");
205 // FITSExtInfo extinfo("in.fits", 0, "SCI", 1, True);
206 // Int index = fitsImg.get_index(extinfo); // get the index of extension "[SCI, 1]"
207 // </srcblock>
208 // </example>
209 //
210 // <motivation>
211 // Helper class for accessing multi-extension FITS files.
212 // </motivation>
213 //
214 //# <todo asof="2011/02/17">
215 //# </todo>
217 {
218 public:
219  // Construct the object
220  FITSExtInfo(const String &name, const uInt &extindex, const String &extname,
221  const Int &extversion, const Bool &hasdata);
222 
223  // Construct the object
225  {
226  FITSExtInfo("", 0, "", 0, False);
227  };
228 
229  // Copy constructor (reference semantics)
230  FITSExtInfo(const FITSExtInfo& other);
231 
232  // Destructor does nothing.
233  ~FITSExtInfo();
234 
235  // Assignment (reference semantics).
236  FITSExtInfo& operator=(const FITSExtInfo& other);
237 
238  // Relational operator.
239  Bool operator==(const FITSExtInfo &extinfo);
240 
241  // All extension information as a string.
242  String get_extexpr(void);
243 
244  // Return the extension name.
245  String get_extname(void){return extname_p;};
246 
247  // Return the extension version.
249 
250  // Return whether there is data.
251  Bool has_data(void){return hasdata_p;};
252 
253  // Add a list of keywords.
254  void add_kwlist(FitsKeywordList &kwlist);
255 
256  // Return a keyword.
257  FitsKeyword *get_keyword(const String kname){return kwlist_p(kname.c_str());};
258 
259 private:
260  String name_p;
266 };
267 
268 } //# NAMESPACE CASACORE - END
269 
270 #endif
271 
272 
Bool find_qualimgs(void)
Find and store all set of extensions that can be loaded as a quality image.
A 1-D Specialization of the Array class.
Definition: ArrayFwd.h:9
String get_maskext(const Int &ext_index)
Get the mask extension name for the given data extension.
int Int
Definition: aipstype.h:50
class FitsKeywordList;
Bool get_quality_data(const String &extexpr, Int &data_HDU, Int &error_HDU, String &error_type, Int &mask_HDU, String &mask_type, Int &mask_value)
Find all necessary access information for the extensions to be loaded as a quality image...
FITSExtInfo * extensions_p
void setup(void)
Setup the object (used by constructors).
Int find_extension(const String &extname, const Int &extversion=-1)
Find an extension; return -1 if not found.
uInt get_firstdata_index(void)
Get the index of the first extension with data.
String get_extlist_string(const String &delimiter, const String &qualmarker="", const String &fitsmarker="", const Bool &listall=True)
Get a string representation of the extension list.
FITSImgParser(const String &name)
Construct a parser from the FITS file.
base class that defines a HDU
Definition: hdu.h:71
Bool index_is_HDUtype(const Int &ext_index, const String &hdutype)
Check whether the extension has a certain HDU type.
String get_extname(void)
Return the extension name.
Bool get_extlist(const String &extexpr, Vector< String > &extlist)
Extract the list of extensions from the extension expression.
static const char * storeKwords_p[]
Bool operator==(const FITSExtInfo &extinfo)
Relational operator.
static const int nKwords_p
~FITSImgParser()
Destructor, does not much.
void process_extension(HeaderDataUnit *h, const uInt &extindex)
Get the information on an extension.
const Char * c_str() const
Get char array.
Definition: String.h:557
uInt get_numhdu(void)
Get the number of extensions.
Vector< String > qualimglist_p
Bool is_qualityimg(const String &extexpr)
Check whether the extensions named in the extension expression can be loaded as a quality image...
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
~FITSExtInfo()
Destructor does nothing.
const Bool False
Definition: aipstype.h:44
Bool has_qualityimg(void)
Get the flag indicating at least one quality image.
Class for handling FITS Image extensions.
Definition: FITSImgParser.h:88
FitsKeywordList kwlist_p
FITSExtInfo & operator=(const FITSExtInfo &other)
Assignment (reference semantics).
Int get_dataindex(const Vector< Int > &extindex)
Get the first extension with HDU type &quot;data&quot; from the list of indices.
Bool has_data(void)
Return whether there is data.
Bool confirm_fix_keywords(const Int &ext_index)
Check the keywords with fixed values.
linked list of FITS keywords
Definition: fits.h:737
FITS keyword.
Definition: fits.h:515
String get_extexpr(void)
All extension information as a string.
String get_errorext(const Int &ext_index)
Get the error extension name for the given data extension.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
Int get_extversion(void)
Return the extension version.
Int get_index(const FITSExtInfo &extinfo)
Identify the index of an extension.
String fitsname(Bool stripPath=False) const
Returns the name of the disk file.
FITSExtInfo()
Construct the object.
FITSImgParser & operator=(const FITSImgParser &other)
Assignment (reference semantics).
const Bool True
Definition: aipstype.h:43
void add_kwlist(FitsKeywordList &kwlist)
Add a list of keywords.
unsigned int uInt
Definition: aipstype.h:51
FitsKeyword * get_keyword(const String kname)
Return a keyword.