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