casacore
Loading...
Searching...
No Matches
fits.h
Go to the documentation of this file.
1//# fits.h:
2//# Copyright (C) 1993,1994,1995,1996,1997,1999,2000,2001,2003,2004
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# if !defined(AIPS_FITS)
27# define AIPS_FITS
28
29//# Note that aips.h has to come first for the correct definition of off_t.
30# include <casacore/casa/aips.h>
31# include <cfloat>
32# include <climits>
33# include <cstdlib>
34# include <cctype>
35# include <casacore/casa/iostream.h>
36# include <casacore/casa/BasicSL/Complex.h>
37# include <casacore/casa/BasicSL/IComplex.h>
38# include <casacore/fits/FITS/FITSError.h>
39
40namespace casacore { //# NAMESPACE CASACORE - BEGIN
41
42//# All FITS code seems to assume longs are 4 bytes. Currently
43//# this corresponds to an "int" on all useful platforms.
44 typedef Int FitsLong;
45//# recovered by GYL
46
47//# Forward declarations
49class FitsNameResult;
50class FitsValueResult;
51class FitsKeyword;
52class FitsParse;
53
54//<summary> FITS templated helper class </summary>
55// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
56// </reviewed>
57//<synopsis>
58// NoConvert is a template class that is not intended for
59// general use, it is used internally.
60//</synopsis>
61
62template <class TYPE>
63class NoConvert {
64 public:
66 void operator = (int) {; }
67};
68
69//<summary> FITS helper class </summary>
70// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
71// </reviewed>
72//<synopsis>
73// FitsLogical is a helper class that is not intended for
74// general use.
75//</synopsis>
76//<example>
77// Here is an example of the FitsLogical class.
78//<srcblock>
79// FitsLogical x;
80// FitsLogical y(True);
81// FitsLogical z = x;
82// ...
83// x = y; y = False; x.undefine();
84// Bool b;
85// if (x.isdefined())
86// b = x;
87// b = y; If y is undefined, b will be false.
88//</srcblock>
89//</example>
91 friend ostream & operator << (ostream &o, const FitsLogical &);
92 public:
93 FitsLogical() : v('\0') { }
94 FitsLogical(Bool x) : v(x == True ? 'T' : 'F') { }
96 v = (x == True ? 'T' : 'F'); return *this; }
97
100 void undefine() { v = '\0'; }
101 operator Bool() const { return v == 'T'; }
102 protected:
103 char v;
104};
105
106//<summary> helper class for FITS Binary Tables </summary>
107// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
108// </reviewed>
109//<synopsis>
110// This class is not intended for general use. It only has meaning
111// in the context of FITS Binary tables. There its use is incorporated
112// into the concept of a FitsField, where FitsBit is given a specialized
113// interpretation.
114//</synopsis>
115
116class FitsBit {
117 public:
119 FitsBit(unsigned char x) : bit_array(x) { }
120 FitsBit & operator = (unsigned char x) { bit_array = x; return *this; }
121 operator unsigned char() const { return bit_array; }
122 protected:
123 unsigned char bit_array;
124};
125
126//<summary> Variable Length Array Descriptor </summary>
127// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
128// </reviewed>
129
131 friend ostream & operator << (ostream &o, const FitsVADesc &);
132 public:
138 rel_offset = x.rel_offset; return *this; }
139 FitsVADesc(int n, int o) : no_elements(n), rel_offset(o) { }
140 void set(int n, int o) { no_elements = n; rel_offset = o; }
141 int num() const { return no_elements; }
142 int offset() const { return rel_offset; }
143 protected:
146};
147
148//<summary> static functions and enumerations </summary>
149// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
150// </reviewed>
151//<synopsis>
152// Many of the static functions are utility functions used internally in the
153// implementation of the member functions of the FITS classes. They are placed
154// in a single class to encapsulate them and to avoid adding many names to the
155// global name space. More important, from the user's perspective, are the
156// enumerations. They form the basic vocabulary of a FITS application. For example,
157// instead of referring to the FITS <src>NAXIS</src> keyword,
158// <src>FITS::NAXIS</src> should be used
159//</synopsis>
160
161class FITS {
162 public:
163
164 // FITS I/O Error message types
165
166 // Basic FITS Data Types for keywords and data
168 NOVALUE = 0, LOGICAL = 1, BIT = 2, CHAR = 3, BYTE = 4,
169 SHORT = 5, LONG = 6, FLOAT = 7, DOUBLE = 8, COMPLEX = 9,
170 ICOMPLEX = 10, DCOMPLEX = 11, VADESC = 12,
172 }; // REAL means either FLOAT or DOUBLE
173 // STRING and FSTRING are used internally in parsing keywords
174
186 x=0; return FITS::LONG; }
201
204
205 // data conversion routines: FITS - local
206 static void f2l(FitsLogical *,void *,int);
207 static void l2f(void *,FitsLogical *,int);
208 static void f2l(FitsBit *,void *,int);
209 static void l2f(void *,FitsBit *,int);
210 static void f2l(char *,void *,int);
211 static void l2f(void *,char *,int);
212 static void f2l(unsigned char *,void *,int);
213 static void l2f(void *,unsigned char *,int);
214 static void f2l(short *,void *,int);
215 static void l2f(void *,short *,int);
216 static void f2l(Int *,void *,int);
217 static void l2f(void *,Int *,int);
218 static void f2l(long *,void *,int);
219 static void l2f(void *,long *,int);
220 static void f2l(float *,void *,int);
221 static void l2f(void *,float *,int);
222 static void f2l(double *,void *,int);
223 static void l2f(void *,double *,int);
224 static void f2l(Complex *,void *,int);
225 static void l2f(void *,Complex *,int);
226 static void f2l(IComplex *,void *,int);
227 static void l2f(void *,IComplex *,int);
228 static void f2l(DComplex *,void *,int);
229 static void l2f(void *,DComplex *,int);
230 static void f2l(FitsVADesc *,void *,int);
231 static void l2f(void *,FitsVADesc *,int);
232 static void swap2(void *, void *, int);
233 static void swap4(void *, void *, int);
234 static void swap8(void *, void *, int);
235
236 // FITS Reserved Names. PZERO is named strangely because it can conflict with
237 // a standard #define in sys/param.h.
250
251 // Types of FITS Records
256
257 // Supported FITS Physical Devices
260 };
261
262 // Types of FITS Header-Data Units
268
269 // Options on FITS array manipulations
270 enum FitsArrayOption { NoOpt = 0, CtoF = 1, FtoC = 2};
271
273 static void valstr(ostream &o, const ValueType &ty, const void *val);
274 static Bool isa_digit(char c);
275 static int digit2bin(char c);
276 static Bool isa_text(char c);
277 static Bool isa_letter(char);
278 static int letter2bin(char);
279 static void fstr2str(char *, const char *, int);
280 static int str2fstr(char *, const char *, int);
281 static void get_name(const char *s, int len, FitsNameResult &result);
282 static int get_value_id(const char *s, int l, int &pos);
283 static void get_value(const char *s, int len, FitsValueResult &result);
284 static int trim_comment(const char *s, int len);
285 static int chk_comment(const char *s, int len);
286 static int get_comment(const char *s, int len, int &begpos);
287 static void get_numeric(const char *s, int len, FitsValueResult &result);
288 // utility function to parse the binary table variable array
289 // column (i.e. uses the heap) of the form nPt(dddd) where n
290 // is either 0 or 1, t is one of the standard FITS binary table
291 // column types and dddd is the maximum number of elements used
292 // by this column. If there is a format error in the input
293 // string (*s), then valType will have the value NOVALUE and
294 // maxelem will be -1.
295 static void parse_vatform(const char *s, FITS::ValueType &valType,
296 int &maxelem);
297 static constexpr Int minInt = INT_MIN;
298 static constexpr Int maxInt = INT_MAX;
299 static constexpr float minfloat = FLT_MIN;
300 static constexpr float maxfloat = FLT_MAX;
301 static constexpr double mindouble = DBL_MIN;
302 static constexpr double maxdouble = DBL_MAX;
303
304 private:
305 FITS();
306 static constexpr double tenpowerD[309] = { 1.0,
307 1.0E1, 1.0E2, 1.0E3, 1.0E4, 1.0E5, 1.0E6, 1.0E7, 1.0E8,
308 1.0E9, 1.0E10, 1.0E11, 1.0E12, 1.0E13, 1.0E14, 1.0E15, 1.0E16,
309 1.0E17, 1.0E18, 1.0E19, 1.0E20, 1.0E21, 1.0E22, 1.0E23, 1.0E24,
310 1.0E25, 1.0E26, 1.0E27, 1.0E28, 1.0E29, 1.0E30, 1.0E31, 1.0E32,
311 1.0E33, 1.0E34, 1.0E35, 1.0E36, 1.0E37, 1.0E38, 1.0E39, 1.0E40,
312 1.0E41, 1.0E42, 1.0E43, 1.0E44, 1.0E45, 1.0E46, 1.0E47, 1.0E48,
313 1.0E49, 1.0E50, 1.0E51, 1.0E52, 1.0E53, 1.0E54, 1.0E55, 1.0E56,
314 1.0E57, 1.0E58, 1.0E59, 1.0E60, 1.0E61, 1.0E62, 1.0E63, 1.0E64,
315 1.0E65, 1.0E66, 1.0E67, 1.0E68, 1.0E69, 1.0E70, 1.0E71, 1.0E72,
316 1.0E73, 1.0E74, 1.0E75, 1.0E76, 1.0E77, 1.0E78, 1.0E79, 1.0E80,
317 1.0E81, 1.0E82, 1.0E83, 1.0E84, 1.0E85, 1.0E86, 1.0E87, 1.0E88,
318 1.0E89, 1.0E90, 1.0E91, 1.0E92, 1.0E93, 1.0E94, 1.0E95, 1.0E96,
319 1.0E97, 1.0E98, 1.0E99, 1.0E100, 1.0E101, 1.0E102, 1.0E103, 1.0E104,
320 1.0E105, 1.0E106, 1.0E107, 1.0E108, 1.0E109, 1.0E110, 1.0E111, 1.0E112,
321 1.0E113, 1.0E114, 1.0E115, 1.0E116, 1.0E117, 1.0E118, 1.0E119, 1.0E120,
322 1.0E121, 1.0E122, 1.0E123, 1.0E124, 1.0E125, 1.0E126, 1.0E127, 1.0E128,
323 1.0E129, 1.0E130, 1.0E131, 1.0E132, 1.0E133, 1.0E134, 1.0E135, 1.0E136,
324 1.0E137, 1.0E138, 1.0E139, 1.0E140, 1.0E141, 1.0E142, 1.0E143, 1.0E144,
325 1.0E145, 1.0E146, 1.0E147, 1.0E148, 1.0E149, 1.0E150, 1.0E151, 1.0E152,
326 1.0E153, 1.0E154, 1.0E155, 1.0E156, 1.0E157, 1.0E158, 1.0E159, 1.0E160,
327 1.0E161, 1.0E162, 1.0E163, 1.0E164, 1.0E165, 1.0E166, 1.0E167, 1.0E168,
328 1.0E169, 1.0E170, 1.0E171, 1.0E172, 1.0E173, 1.0E174, 1.0E175, 1.0E176,
329 1.0E177, 1.0E178, 1.0E179, 1.0E180, 1.0E181, 1.0E182, 1.0E183, 1.0E184,
330 1.0E185, 1.0E186, 1.0E187, 1.0E188, 1.0E189, 1.0E190, 1.0E191, 1.0E192,
331 1.0E193, 1.0E194, 1.0E195, 1.0E196, 1.0E197, 1.0E198, 1.0E199, 1.0E200,
332 1.0E201, 1.0E202, 1.0E203, 1.0E204, 1.0E205, 1.0E206, 1.0E207, 1.0E208,
333 1.0E209, 1.0E210, 1.0E211, 1.0E212, 1.0E213, 1.0E214, 1.0E215, 1.0E216,
334 1.0E217, 1.0E218, 1.0E219, 1.0E220, 1.0E221, 1.0E222, 1.0E223, 1.0E224,
335 1.0E225, 1.0E226, 1.0E227, 1.0E228, 1.0E229, 1.0E230, 1.0E231, 1.0E232,
336 1.0E233, 1.0E234, 1.0E235, 1.0E236, 1.0E237, 1.0E238, 1.0E239, 1.0E240,
337 1.0E241, 1.0E242, 1.0E243, 1.0E244, 1.0E245, 1.0E246, 1.0E247, 1.0E248,
338 1.0E249, 1.0E250, 1.0E251, 1.0E252, 1.0E253, 1.0E254, 1.0E255, 1.0E256,
339 1.0E257, 1.0E258, 1.0E259, 1.0E260, 1.0E261, 1.0E262, 1.0E263, 1.0E264,
340 1.0E265, 1.0E266, 1.0E267, 1.0E268, 1.0E269, 1.0E270, 1.0E271, 1.0E272,
341 1.0E273, 1.0E274, 1.0E275, 1.0E276, 1.0E277, 1.0E278, 1.0E279, 1.0E280,
342 1.0E281, 1.0E282, 1.0E283, 1.0E284, 1.0E285, 1.0E286, 1.0E287, 1.0E288,
343 1.0E289, 1.0E290, 1.0E291, 1.0E292, 1.0E293, 1.0E294, 1.0E295, 1.0E296,
344 1.0E297, 1.0E298, 1.0E299, 1.0E300, 1.0E301, 1.0E302, 1.0E303, 1.0E304,
345 1.0E305, 1.0E306, 1.0E307, 1.0E308 };
346 static constexpr float tenpowerF[39] = { 1.0F,
347 1.0E1F, 1.0E2F, 1.0E3F, 1.0E4F, 1.0E5F, 1.0E6F, 1.0E7F, 1.0E8F,
348 1.0E9F, 1.0E10F, 1.0E11F, 1.0E12F, 1.0E13F, 1.0E14F, 1.0E15F, 1.0E16F,
349 1.0E17F, 1.0E18F, 1.0E19F, 1.0E20F, 1.0E21F, 1.0E22F, 1.0E23F, 1.0E24F,
350 1.0E25F, 1.0E26F, 1.0E27F, 1.0E28F, 1.0E29F, 1.0E30F, 1.0E31F, 1.0E32F,
351 1.0E33F, 1.0E34F, 1.0E35F, 1.0E36F, 1.0E37F, 1.0E38F };
352 static constexpr int minfltexp = -38;
353 static constexpr int maxfltexp = 38;
354 static constexpr int mindblexp = -308;
355 static constexpr int maxdblexp = 308;
356 static constexpr int maxsigdigits = 17;
357 static constexpr int maxdigl = 9; // max digits in a long
358 static constexpr int maxexpdig = 3; // max digits in an exponent
359 static double tenD(Int, int);
360 static float tenF(Int, int);
361 static int ckaccum(double &, Int, int);
362 static int ckaccum(float &, Int, int);
363};
364
365inline FITS::FITS() { } // just a dummy function to prevent instantiation
366inline Bool FITS::isa_digit(char c) { return isdigit(c) ? True : False; }
367inline int FITS::digit2bin(char c) { return c - '0'; }
368inline Bool FITS::isa_text(char c) { return isprint(c) ? True : False; }
369inline Bool FITS::isa_letter(char c) { return isupper(c) ? True : False; }
370inline int FITS::letter2bin(char c) { return c - 'A'; }
371
372ostream & operator << (ostream &, const FITS::ValueType &);
373
374inline double FITS::tenD(Int numb, int pow) {
375 return (pow > 0) ? (((double)numb) * tenpowerD[pow]) :
376 ((pow < 0) ? (((double)numb) / tenpowerD[-pow]) : ((double)numb));
377}
378inline float FITS::tenF(Int numb, int pow) {
379 return (pow > 0) ? (((float)numb) * tenpowerF[pow]) :
380 ((pow < 0) ? (((float)numb) / tenpowerF[-pow]) : ((float)numb));
381}
382
383//<summary> reserved FITS keyword </summary>
384// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
385// </reviewed>
386
388 public:
389 const char *aname() const;
391 int namesize() const;
392 FITS::ValueType type() const;
393 Bool isindexed() const;
394 Bool isessential() const;
395# if defined(TURBOCPP)
396 // It is best for the following to be private, but
397 // C-Front won't allow an initializer list if they are private.
398 // This issue isn't that crucial since functions in
399 // ReservedFitsKeywordCollection always return const items.
400 private:
401# endif
403 const char *aname_;
406 Bool isindexed_; // 0 = NOT INDEXED, 1 = INDEXED
407 Bool isessential_; // 0 = NO, 1 = YES
408};
409
410inline const char *ReservedFitsKeyword::aname() const { return aname_; }
411inline int ReservedFitsKeyword::namesize() const { return namesize_; }
416
417//<summary> collection of reserved FITS keywords </summary>
418// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
419// </reviewed>
420
422 public:
423 const ReservedFitsKeyword & operator [] (int i) const;
424 int no() const;
426 const void *, int, const char *&) const;
427 const ReservedFitsKeyword &get(const char *, int, Bool, FITS::ValueType,
428 const void *, int, const char *&) const;
429 const char *aname(FITS::ReservedName) const;
430 int essential_name(const char *, int) const;
432 const void *, int, const char *&) const;
433 int isreserved(const char *, int) const;
434 Bool isunique(int) const;
436 const ReservedFitsKeyword &userdef_item() const;
437 const ReservedFitsKeyword &err_item() const;
438 const ReservedFitsKeyword &end_item() const;
439 const ReservedFitsKeyword &spaces() const;
440 const ReservedFitsKeyword &comment() const;
441 const ReservedFitsKeyword &history() const;
442 int rules(const ReservedFitsKeyword &, const char *, int, Bool,
443 FITS::ValueType, const void *, int, const char *&) const;
444 private:
445 static constexpr int no_items = 56; // number of entries in the table
446 // Discussion of Reserved FitsKeyword Table
447 //
448 // 1. The reserved name itself (name_) is not unique; there may
449 // be more than one entry with the same reserved name.
450 // 2. The combination of reserved name, the data type, and whether
451 // it is indexed or not (name_, type_, isindexed_) is unique
452 // within the table.
453 // 3. The table is sorted by reserved name + type + isindexed.
454 static constexpr ReservedFitsKeyword resword[56] = {
455// key aname namesize isindexed Section
456// | | | type | isessential in|NOST
457// \|/ \|/ \|/\|/ \|/ \|/ \|/
458// ------ ------ - ------- ----- ----- ------------
459/* 0 */ { FITS::USER_DEF, "", 0, FITS::NOVALUE, False, False },
460/* 1 */ { FITS::AUTHOR, "AUTHOR", 6, FITS::STRING, False, False }, // 5.2.2.3
461/* 2 */ { FITS::BITPIX, "BITPIX", 6, FITS::LONG, False, True }, // 5.2.1.1
462/* 3 */ { FITS::BLANK, "BLANK", 5, FITS::LONG, False, False }, // 5.2.2.5
463/* 4 */ { FITS::BLOCKED, "BLOCKED", 7, FITS::LOGICAL, False, False }, // 5.2.2.1
464/* 5 */ { FITS::BSCALE, "BSCALE", 6, FITS::REAL, False, False }, // 5.2.2.5
465/* 6 */ { FITS::BUNIT, "BUNIT", 5, FITS::STRING, False, False }, // 5.2.2.5
466/* 7 */ { FITS::BZERO, "BZERO", 5, FITS::REAL, False, False }, // 5.2.2.5
467/* 8 */ { FITS::CDELT, "CDELT", 5, FITS::REAL, True, False }, // 5.2.2.5
468/* 9 */ { FITS::COMMENT, "COMMENT", 7, FITS::NOVALUE, False, False }, // 5.2.2.4
469/* 10 */ { FITS::CROTA, "CROTA", 5, FITS::REAL, True, False }, // 5.2.2.5
470/* 11 */ { FITS::CRPIX, "CRPIX", 5, FITS::REAL, True, False }, // 5.2.2.5
471/* 12 */ { FITS::CRVAL, "CRVAL", 5, FITS::REAL, True, False }, // 5.2.2.5
472/* 13 */ { FITS::CTYPE, "CTYPE", 5, FITS::STRING, True, False }, // 5.2.2.5
473/* 14 */ { FITS::DATAMAX, "DATAMAX", 7, FITS::REAL, False, False }, // 5.2.2.5
474/* 15 */ { FITS::DATAMIN, "DATAMIN", 7, FITS::REAL, False, False }, // 5.2.2.5
475/* 16 */ { FITS::DATE, "DATE", 4, FITS::STRING, False, False }, // 5.2.2.1
476/* 17 */ { FITS::DATE_OBS, "DATE-OBS", 8, FITS::STRING, False, False }, // 5.2.2.2
477/* 18 */ { FITS::END, "END", 3, FITS::NOVALUE, False, True }, // 5.2.1.1
478/* 19 */ { FITS::EPOCH, "EPOCH", 5, FITS::REAL, False, False }, // 5.2.2.2
479/* 20 */ { FITS::EQUINOX, "EQUINOX", 7, FITS::REAL, False, False }, // 5.2.2.2
480/* 21 */ { FITS::EXTEND, "EXTEND", 6, FITS::LOGICAL, False, True }, // 5.2.1.2
481/* 22 */ { FITS::EXTLEVEL, "EXTLEVEL", 8, FITS::LONG, False, False }, // 5.2.2.6
482/* 23 */ { FITS::EXTNAME, "EXTNAME", 7, FITS::STRING, False, False }, // 5.2.2.6
483/* 24 */ { FITS::EXTVER, "EXTVER", 6, FITS::LONG, False, False }, // 5.2.2.6
484/* 25 */ { FITS::GCOUNT, "GCOUNT", 6, FITS::LONG, False, True }, // 5.2.1.2
485/* 26 */ { FITS::GROUPS, "GROUPS", 6, FITS::LOGICAL, False, True }, // 7.1.1.6
486/* 27 */ { FITS::HISTORY, "HISTORY", 7, FITS::NOVALUE, False, False }, // 5.2.2.4
487/* 28 */ { FITS::INSTRUME, "INSTRUME", 8, FITS::STRING, False, False }, // 5.2.2.2
488/* 29 */ { FITS::NAXIS, "NAXIS", 5, FITS::LONG, False, True }, // 5.2.1.1
489/* 30 */ { FITS::NAXIS, "NAXIS", 5, FITS::LONG, True, True }, // 5.2.1.1
490/* 31 */ { FITS::OBJECT, "OBJECT", 6, FITS::STRING, False, False }, // 5.2.2.2
491/* 32 */ { FITS::OBSERVER, "OBSERVER", 8, FITS::STRING, False, False }, // 5.2.2.2
492/* 33 */ { FITS::ORIGIN, "ORIGIN", 6, FITS::STRING, False, False }, // 5.2.2.1
493/* 34 */ { FITS::PCOUNT, "PCOUNT", 6, FITS::LONG, False, True }, // 5.2.1.2
494/* 35 */ { FITS::PSCAL, "PSCAL", 5, FITS::REAL, True, False }, // 7.1.2.2
495/* 36 */ { FITS::PTYPE, "PTYPE", 5, FITS::STRING, True, False }, // 7.1.2.1
496/* 37 */ { FITS::PZERO_FITS, "PZERO", 5, FITS::REAL, True, False }, // 7.1.2.3
497/* 38 */ { FITS::REFERENC, "REFERENC", 8, FITS::STRING, False, False }, // 5.2.2.3
498/* 39 */ { FITS::SIMPLE, "SIMPLE", 6, FITS::LOGICAL, False, True }, // 5.2.1.1
499/* 40 */ { FITS::SPACES, " ", 8, FITS::NOVALUE, False, False }, // 5.2.2.4
500/* 41 */ { FITS::TBCOL, "TBCOL", 5, FITS::LONG, True, False }, // 8.1.1
501/* 42 */ { FITS::TDIM, "TDIM", 4, FITS::STRING, True, False }, // A.4, A.9.1
502/* 43 */ { FITS::TDISP, "TDISP", 5, FITS::STRING, True, False }, // A.4
503/* 44 */ { FITS::TELESCOP, "TELESCOP", 8, FITS::STRING, False, False }, // 5.2.2.2
504/* 45 */ { FITS::TFIELDS, "TFIELDS", 7, FITS::LONG, False, False }, // 8.1.1
505/* 46 */ { FITS::TFORM, "TFORM", 5, FITS::STRING, True, False }, // 8.1.1
506/* 47 */ { FITS::THEAP, "THEAP", 5, FITS::LONG, False, False }, // A.4, A.9.2
507/* 48 */ { FITS::TNULL, "TNULL", 5, FITS::STRING, True, False }, // 8.1.2
508/* 49 */ { FITS::TNULL, "TNULL", 5, FITS::LONG , True, False }, // A.4
509/* 50 */ { FITS::TSCAL, "TSCAL", 5, FITS::REAL, True, False }, // 8.1.2
510/* 51 */ { FITS::TTYPE, "TTYPE", 5, FITS::STRING, True, False }, // 8.1.2
511/* 52 */ { FITS::TUNIT, "TUNIT", 5, FITS::STRING, True, False }, // 8.1.2
512/* 53 */ { FITS::TZERO, "TZERO", 5, FITS::REAL, True, False }, // 8.1.2
513/* 54 */ { FITS::XTENSION, "XTENSION", 8, FITS::STRING, False, True }, // 5.2.1.2
514/* 55 */ { FITS::ERRWORD, "", 0, FITS::NOVALUE, False, False } // last
515};
516 static constexpr const ReservedFitsKeyword &user_def_item = resword[0]; // user-defined keyword
517 static constexpr const ReservedFitsKeyword &error_item = resword[55]; // error in keyword
518 static constexpr const ReservedFitsKeyword &end__item = resword[18];
519 static constexpr const ReservedFitsKeyword &spaces_item = resword[40];
520 static constexpr const ReservedFitsKeyword &comment_item = resword[9];
521 static constexpr const ReservedFitsKeyword &history_item = resword[27];
522 // alphabetic index to table
523 static constexpr int resalpha[26] = {
524 // A B C D E F G H I J K L M N O P Q R
525 1, 2, 8, 14, 18, 0, 25, 27, 28, 0, 0, 0, 0, 29, 31, 34, 0, 38,
526 // S T U V W X Y Z
527 39, 41, 0, 0, 0, 54, 0, 0
528};
529 const ReservedFitsKeyword &match(int, const char *, int, Bool,
530 FITS::ValueType, const void *, int, const char *&) const;
531
532};
533
535 operator [] (int i) const { return resword[i]; }
536inline int ReservedFitsKeywordCollection::no() const { return no_items; }
538 return (Bool)(resword[i + 1].name() != resword[i].name()); }
551
552//<summary> analyse the name of a header card </summary>
553// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
554// </reviewed>
555//<synopsis>
556// Analyse the name of a header card
557//</synopsis>
558
560 public:
561 Bool isaname; // 1 if there is a name present, otherwise 0
562 int begpos; // beginning position of name
563 int endpos; // ending position of name
564 Bool isaindex; // whether an index is present or not
565 int index; // index if present
566 int len; // length of name without index
567 enum ErrMsg { OK = 0, NO_0_NDX };
569};
570
571//<summary> analyse the value of a header card </summary>
572// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
573// </reviewed>
574//<synopsis>
575// Analyse the value of a header card
576//</synopsis>
577
579 public:
581 union {
583 int s[2]; // for strings, s[0] is offset, s[1] length
585 float f;
586 double d;
587 };
588 Complex c;
590 DComplex dc;
591 int begpos; // beginning position of value
592 int endpos; // ending position of value
593 Bool isa_point; // 1 if a point, otherwise 0
594 int pointpos; // position of point, if any
595 int no_sig; // number of significant digits
596 const char *errmsg; // error message, if any
597};
598
599//<summary> parse a header card </summary>
600// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
601// </reviewed>
602//<synopsis>
603// parse a header card
604//</synopsis>
605
607 friend class FitsKeywordList;
608 public:
609 FitsKeyword &parse(const char *, int); // Parsing one string
610 int no_errs() const;
611 const char *err(int) const;
612 private:
613 FitsParse(int = 10);
614 ~FitsParse();
616 const int max_errs;
617 const char **err_;
618 int seterr(const char *);
619 FitsKeyword &mkerr(const char *s, int len);
620};
621
622inline FitsParse::~FitsParse() { delete [] err_; }
623inline int FitsParse::no_errs() const { return no_errs_; }
624inline const char *FitsParse::err(int i) const { return err_[i]; }
625inline int FitsParse::seterr(const char *s) {
626 return no_errs_ < max_errs ? ( err_[no_errs_++] = s, 0) : -1; }
627
628//<summary> FITS keyword </summary>
629// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
630// </reviewed>
631//<synopsis>
632// A FITS keyword contains a name, a value and a comment.
633//</synopsis>
635 friend class FitsKeywordList;
636 friend class FitsParse;
637 // A word about friends: FitsKeywordList accesses the next and prev
638 // pointers and the FitsKeyword constructors.
639 // FitsParse only accesses the FitsKeyword constructors.
640
641 public:
642
643 FitsKeyword(const FitsKeyword &);
645 ~FitsKeyword();
646
647 //<group>
648 // get info about the name
649 const char *name() const;
650 int namelen() const;
651 Bool isreserved() const;
652 Bool isindexed() const;
653 const ReservedFitsKeyword &kw() const;
654 int index() const;
655 //</group>
656
657 //<group>
658 // access the keyword comment
659 const char *comm() const;
660 int commlen() const;
661 //</group>
662
663 // access the error status
664 int err() const;
665
666 // the datatype of the keyword
667 FITS::ValueType type() const;
668
669 // access the value of the keyword
670 //<group>
671 Bool asBool() const;
672 const char *asString() const;
673 int valStrlen() const;
674 Int asInt() const;
675 float asFloat() const;
676 double asDouble() const;
677 IComplex asIComplex() const;
678 Complex asComplex() const;
679 DComplex asDComplex() const;
680 const void *value() const;
681 //</group>
682
683 // change the value of the keyword
684 //<group>
686 FitsKeyword & operator = (const char *);
688 FitsKeyword & operator = (float);
689 FitsKeyword & operator = (double);
691 FitsKeyword & operator = (Complex);
692 FitsKeyword & operator = (DComplex);
693 //</group>
694
695 // change the comment of the keyword
696 void comm(const char *);
697
698 // change the name of the keyword
699 void name(const char *);
700
701 private:
704
705 //<group>
706 // the keyword name
707 // if name_ is 0, keyword is not a user defined name
708 // if ndx is 0, there is no index
709 char *name_;
711 int ndx;
712 short namelen_;
713 //</group>
714
715 //<group>
716 // the keyword comment
717 // if comm_ is 0, there is no comment
718 char *comm_;
719 short commlen_;
720 //</group>
721
722
723 //<group>
724 // the keyword value
726 union {
729 float fval;
730 double dval;
731 };
732 void *val; // pointer to allocated value, if any
733 short vallen; // only used for string data
734 void del_val(); // does an appropriate delete based on type
735 //</group>
736
737 void init(const FitsKeyword &);
738 void setval(const FITS::ValueType &, const void *, int);
739 void setcomm(const char *, int);
740 static void err(const char *, const FITS::ValueType &, const void *,
741 const char *);
742 static void memchk(void *);
743
744 //<group>
745 // private constructors for use by friends
746
747 // constructs user-defined keywords
748 // parms: name, namelen, type, val, vallen, comm, commlen
749 FitsKeyword(const char *, int ,
750 FITS::ValueType, const void *, int, const char *, int);
751 // constructs reserved keywords
752 // parms: resword, index, val, vallen, comm, commlen
754 FITS::ValueType, const void *, int, const char *, int);
755 //</group>
756
757
758};
759
760ostream & operator << (ostream &, const FitsKeyword &);
761
763 name_(0), kw_(0), comm_(0), val(0) { init(k); }
765 delete [] name_; delete [] comm_; del_val(); init(k); return *this; }
767 delete [] name_;
768 delete [] comm_;
769 del_val();
770}
771
772inline const ReservedFitsKeyword &FitsKeyword::kw() const { return *kw_; }
773inline Bool FitsKeyword::isreserved() const { return
774 (kw().name() != FITS::ERRWORD && kw().name() != FITS::USER_DEF)
775 ? True : False; }
776inline const char *FitsKeyword::name() const {
777 return isreserved() ? kw().aname() : (namelen_ ? name_ : ""); }
778inline int FitsKeyword::namelen() const { return namelen_; }
779inline Bool FitsKeyword::isindexed() const {return ndx > 0 ? True : False;}
780inline int FitsKeyword::index() const { return ndx; }
781
782inline const char *FitsKeyword::comm() const {
783 return comm_ ? comm_ : ""; }
784inline int FitsKeyword::commlen() const { return commlen_; }
785inline int FitsKeyword::err() const { return (kw().name() == FITS::ERRWORD); }
786inline FITS::ValueType FitsKeyword::type() const { return type_; }
787
788inline Bool FitsKeyword::asBool() const { return bval; }
789inline const char *FitsKeyword::asString() const {
790 return vallen ? (const char *)val : ""; }
791inline int FitsKeyword::valStrlen() const { return vallen; }
792inline Int FitsKeyword::asInt() const {
793 if( type() != FITS::LONG ) {
794 cerr << "Unexpected keyword type in FitsKeyword::asInt()\n";
795 exit(1);
796 }
797 return ival;
798}
799inline float FitsKeyword::asFloat() const {
800 switch( type() ) {
801 case FITS::BYTE:
802 case FITS::SHORT:
803 case FITS::LONG: return (float)ival;
804 case FITS::FLOAT: return fval;
805 case FITS::DOUBLE: return (float)dval;
806 default:
807 cerr << "Unexpected keyword type in asFloat()\n";
808 exit(1);
809 }
810 return 0.0;
811}
812inline double FitsKeyword::asDouble() const {
813 switch( type() ) {
814 case FITS::BYTE:
815 case FITS::SHORT:
816 case FITS::LONG: return (double)ival;
817 case FITS::FLOAT: return (double)fval;
818 case FITS::DOUBLE: return dval;
819 default:
820 cerr << "Unexpected keyword type in asDouble()\n";
821 exit(1);
822 }
823 return 0.0;
824}
826 return *((IComplex *)val); }
827inline Complex FitsKeyword::asComplex() const {
828 return *((Complex *)val); }
829inline DComplex FitsKeyword::asDComplex() const {
830 return *((DComplex *)val); }
831
833 bval = x; type_ = FITS::LOGICAL; return *this; }
835 ival = x; type_ = FITS::LONG; return *this; }
837 fval = x; type_ = FITS::FLOAT; return *this; }
839 dval = x; type_ = FITS::DOUBLE; return *this; }
841 *((IComplex *)val) = x; type_ = FITS::ICOMPLEX; return *this; }
843 *((Complex *)val) = x; type_ = FITS::COMPLEX; return *this; }
845 *((DComplex *)val) = x; type_ = FITS::DCOMPLEX; return *this; }
846
847class ConstFitsKeywordList; // forward declaration
848
849//<summary> linked list of FITS keywords </summary>
850// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
851// </reviewed>
852//<synopsis>
853// A linked list of FITS keywords.
854//</synopsis>
855
857 public:
863
864 // Convert the list to a string containing the 80-byte FITS headers.
865 std::string toString() const;
866
867 // delete the current keyword (the thing returned by curr()) from the list
868 void del();
869
870 // Add (make) a reserved keyword with the given value and optional comment
871 // The comment will be truncated if necessary to fit the available space.
872 // String values must be less than 69 characters. String values longer than
873 // that will result in an ERROR keyword instead of the desired keyword.
874 // <group>
875 void mk(FITS::ReservedName k, Bool v, const char *c = 0);
876 void mk(FITS::ReservedName k, const char *v = 0, const char *c = 0);
877 void mk(FITS::ReservedName k, Int v, const char *c = 0);
878 void mk(FITS::ReservedName k, long v, const char *c = 0);
879 void mk(FITS::ReservedName k, double v, const char *c = 0);
880 // </group>
881
882 // Add (make) an indexed reserved keyword with the given value and optional comment
883 // The comment will be truncated if necessary to fit the available space.
884 // String values must be less than 69 characters. String values longer than
885 // that will result in an ERROR keyword instead of the desired keyword.
886 // <group>
887 void mk(int n, FITS::ReservedName k, Bool v, const char *c = 0);
888 void mk(int n, FITS::ReservedName k, const char *v, const char *c = 0);
889 void mk(int n, FITS::ReservedName k, Int v, const char *c = 0);
890 void mk(int n, FITS::ReservedName k, long v, const char *c = 0);
891 void mk(int n, FITS::ReservedName k, double v, const char *c = 0);
892 // </group>
893
894 // Add (make) a user defined keyword with the given name, value and optional comment.
895 // The comment will be truncated if necessary to fit the available space.
896 // The name must be no longer than 8 characters. Names longer than that will
897 // result in an ERROR keyword instead of the desired keyword.
898 // String values must no longer than 69 characters. String values longer than
899 // that will result in an ERROR keyword instead of the desired keyword.
900 // <group>
901 void mk(const char *n, Bool v, const char *c = 0);
902 void mk(const char *n, const char *v = 0, const char *c = 0);
903 void mk(const char *n, Int v, const char *c = 0);
904 void mk(const char *n, long v, const char *c = 0);
905 void mk(const char *n, float v, const char *c = 0);
906 void mk(const char *n, double v, const char *c = 0);
907 void mk(const char *n, Int r, Int i, const char *c = 0);
908 void mk(const char *n, float r, float i, const char *c = 0);
909 void mk(const char *n, double r, double i, const char *c = 0);
910 // </group>
911
912 // add a spaces line
913 void spaces(const char *n = 0, const char *c = 0);
914
915 // add a comment card
916 void comment(const char *n = 0, const char *c = 0);
917
918 // add a history card
919 void history(const char *c = 0);
920
921 // add the end card. This must be at the end of the list.
922 void end();
923
924 // Retrieve specific keywords -- these also set the current mark
925 //<group>
926 // return the i-th keyword -- keyword numbering starts with 0
928 // return first and next non-indexed reserved keyword
931 // return first and next indexed reserved keyword
934 // return first and next user-defined keyword
935 FitsKeyword * operator () (const char *);
936 FitsKeyword * next(const char *);
937 //</group>
938
939 //<group>
940 Bool isempty() const;
941 void first();
942 void last();
945 FitsKeyword *curr();
946 //</group>
947
948 //<group>
949 void delete_all();
954 //</group>
955
956 //<group>
957 // For parsing a single string
958 void parse(const char *, int);
959 int no_parse_errs() const;
960 const char *parse_err(int) const;
961 //</group>
962
964 private:
968 int total;
970 FitsKeyword &make(const char *nm,
971 FITS::ValueType t, const void *v, const char *c);
973 FITS::ValueType t, const void *v, const char *c);
975 FITS::ValueType t, const void *v, const char *c);
976 // construct an error keyword - this happens when a name is invalid (NULL
977 // or more than 8 characters) or a string value is too long (more than
978 // 69 characters). It is the responsibility of the caller to the
979 // several mk functions to ensure that that doesn't happen. By the time
980 // it gets here, it is assumed that such problems are true errors.
981 // This is used by the private make functions.
983 const void *val, const char *errmsg);
985};
986
987ostream & operator << (ostream &o, FitsKeywordList &); // print the entire list
988
990 total(0), cursor(0) { }
992inline Bool FitsKeywordList::isempty() const { return total == 0 ? True : False; }
993inline void FitsKeywordList::first() { cursor = 0; pos = beg_; }
999 int ndx) { first(); return next(n,ndx); }
1001 first(); return next(w); }
1002inline void FitsKeywordList::parse(const char *s, int l) {
1003 insert(card.parse(s,l)); }
1004inline int FitsKeywordList::no_parse_errs() const { return card.no_errs();}
1005inline const char *FitsKeywordList::parse_err(int n) const {
1006 return card.err(n); }
1007
1008// FitsKeyword constructors for non-indexed Reserved keywords
1009inline void FitsKeywordList::mk(FITS::ReservedName k, Bool v, const char *c) {
1010 insert(make(k,FITS::LOGICAL,&v,c)); }
1011inline void FitsKeywordList::mk(FITS::ReservedName k, const char *v,
1012 const char *c) { insert(make(k,FITS::STRING,v,c)); }
1013inline void FitsKeywordList::mk(FITS::ReservedName k, Int v, const char *c) {
1014 insert(make(k,FITS::LONG,&v,c)); }
1015inline void FitsKeywordList::mk(FITS::ReservedName k, long v, const char *c) {
1016 insert(make(k,FITS::LONG,&v,c)); }
1017inline void FitsKeywordList::mk(FITS::ReservedName k, double v, const char *c) {
1018 insert(make(k,FITS::DOUBLE,&v,c)); }
1019// FitsKeyword constructors for indexed Reserved keywords
1021 const char *c) {
1022 Bool tmp; tmp = v; insert(make(n,k,FITS::LOGICAL,&tmp,c)); }
1023inline void FitsKeywordList::mk(int n, FITS::ReservedName k, const char *v,
1024 const char *c) { insert(make(n,k,FITS::STRING,v,c)); }
1026 const char *c) { insert(make(n,k,FITS::LONG,&v,c)); }
1027inline void FitsKeywordList::mk(int n, FITS::ReservedName k, long v,
1028 const char *c) { insert(make(n,k,FITS::LONG,&v,c)); }
1029inline void FitsKeywordList::mk(int n, FITS::ReservedName k, double v,
1030 const char *c) { insert(make(n,k,FITS::DOUBLE,&v,c)); }
1031// FitsKeyword constructors for User-Defined keywords
1032inline void FitsKeywordList::mk(const char *n, Bool v, const char *c) {
1033 Bool tmp; tmp = v; insert(make(n,FITS::LOGICAL,&tmp,c)); }
1034inline void FitsKeywordList::mk(const char *n, const char *v, const char *c) {
1035 insert(make(n,FITS::STRING,v,c)); }
1036inline void FitsKeywordList::mk(const char *n, Int v, const char *c) {
1037 insert(make(n,FITS::LONG,&v,c)); }
1038inline void FitsKeywordList::mk(const char *n, long v, const char *c) {
1039 insert(make(n,FITS::LONG,&v,c)); }
1040inline void FitsKeywordList::mk(const char *n, float v, const char *c) {
1041 insert(make(n,FITS::FLOAT,&v,c)); }
1042inline void FitsKeywordList::mk(const char *n, double v, const char *c) {
1043 insert(make(n,FITS::DOUBLE,&v,c)); }
1044inline void FitsKeywordList::mk(const char *n, Int r, Int i, const char *c) {
1045 IComplex v(r,i);
1046 insert(make(n,FITS::ICOMPLEX,&v,c)); }
1047inline void FitsKeywordList::mk(const char *n, float r, float i, const char *c)
1048 { Complex v(r,i); insert(make(n,FITS::COMPLEX,&v,c)); }
1049inline void FitsKeywordList::mk(const char *n, double r, double i,
1050 const char *c) { DComplex v(r,i);
1051 insert(make(n,FITS::DCOMPLEX,&v,c)); }
1052// Additional keyword constructors for commentary, etc.
1053inline void FitsKeywordList::spaces(const char *n, const char *c) {
1054 insert((n == 0 ? make(FITS::SPACES,FITS::NOVALUE,0,c) :
1055 (c == 0 ? make(FITS::SPACES,FITS::NOVALUE,0,n) :
1056 make(n,FITS::NOVALUE,0,c)))); }
1057inline void FitsKeywordList::comment(const char *n, const char *c) {
1058 insert((n == 0 ? make(FITS::COMMENT,FITS::NOVALUE,0,c) :
1059 (c == 0 ? make(FITS::COMMENT,FITS::NOVALUE,0,n) :
1060 make(n,FITS::NOVALUE,0,c)))); }
1061inline void FitsKeywordList::history(const char *c) {
1065
1066//<summary> list of read-only FITS keywords </summary>
1067// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
1068// </reviewed>
1069
1071 public:
1073
1074 const FitsKeyword * operator () (int n) { return kw(n); }
1076 return kw(x); }
1078 return kw.next(x); }
1080 return kw(x,n); }
1081 const FitsKeyword * next(const FITS::ReservedName &x, int n) {
1082 return kw.next(x,n); }
1083 const FitsKeyword * operator () (const char *x) { return kw(x); }
1084 const FitsKeyword * next(const char *x) { return kw.next(x); }
1085
1086 Bool isempty() const { return kw.isempty(); }
1087 void first() { kw.first(); }
1088 void last() { kw.last(); }
1089 const FitsKeyword *next() { return kw.next(); }
1090 const FitsKeyword *prev() { return kw.prev(); }
1091 const FitsKeyword *curr() { return kw.curr(); }
1092
1093 private:
1095};
1096
1097//<summary> translator between Keyword lists and fixed FITS cars </summary>
1098// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
1099// </reviewed>
1100//<synopsis>
1101// also contains the parser ???
1102//</synopsis>
1103
1105 public:
1108 FitsKeywordList & parse(const char *,
1110 int build(char *, FitsKeywordList &);
1111 int no_errs() const;
1112 const char *err(int) const;
1113 int err_cardno(int) const;
1114 static void fmtcard(char *, const FitsKeyword &);
1115 private:
1116 int cardno; // the current card number within record
1117 static constexpr int FitsCardSize = 80;
1118 static constexpr int FitsMaxCard = 36;
1119 static constexpr int FitsRecSize = 2880;
1122 const char **err_;
1124 char *blanks;
1125};
1126
1128 delete [] err_; delete [] err_cardno_; delete [] blanks; }
1129inline int FitsKeyCardTranslator::no_errs() const { return no_errs_; }
1130inline const char *FitsKeyCardTranslator::err(int i) const { return err_[i]; }
1131inline int FitsKeyCardTranslator::err_cardno(int i) const {
1132 return err_cardno_[i]; }
1133
1134// <summary>Utility functions for floating point values</summary>
1135// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
1136// </reviewed>
1138{
1139public:
1140 // These functions are useful to tell if some type is a floating point type.
1141 // This is useful in a templated function, where the processing can vary
1142 // depending on whether the type is FP or not (e.g. blank handling).
1143 // <group>
1144 static Bool isFP(const float *);
1145 static Bool isFP(const double *);
1146 static Bool isFP(const void *);
1147 // </group>
1148
1149 // For blanking purposes, we need to be able to get a NaN. The NaN we set
1150 // is all bits on.
1151 // <group>
1152 static void setNaN(double &val);
1153 static void setNaN(float &val);
1154 // </group>
1155};
1156
1157
1158} //# NAMESPACE CASACORE - END
1159
1160# endif
list of read-only FITS keywords
Definition fits.h:1070
ConstFitsKeywordList(FitsKeywordList &x)
Definition fits.h:1072
const FitsKeyword * curr()
Definition fits.h:1091
const FitsKeyword * prev()
Definition fits.h:1090
const FitsKeyword * next(const FITS::ReservedName &x, int n)
Definition fits.h:1081
const FitsKeyword * next(const FITS::ReservedName &x)
Definition fits.h:1077
const FitsKeyword * operator()(int n)
Definition fits.h:1074
const FitsKeyword * next()
Definition fits.h:1089
FitsKeywordList & kw
Definition fits.h:1094
const FitsKeyword * next(const char *x)
Definition fits.h:1084
static void defaultHandler(const char *errMessage, ErrorLevel severity)
The default error handler.
static void l2f(void *, FitsLogical *, int)
static FITS::ValueType getfitstype(NoConvert< double > x)
Definition fits.h:191
static constexpr int mindblexp
Definition fits.h:354
static int get_comment(const char *s, int len, int &begpos)
static FITS::ValueType getfitstype(NoConvert< IComplex > x)
Definition fits.h:195
static void f2l(short *, void *, int)
static void f2l(DComplex *, void *, int)
static int trim_comment(const char *s, int len)
static void get_numeric(const char *s, int len, FitsValueResult &result)
static constexpr int maxexpdig
Definition fits.h:358
ReservedName
FITS Reserved Names.
Definition fits.h:238
static void l2f(void *, float *, int)
static FITS::ValueType getfitstype(NoConvert< float > x)
Definition fits.h:189
static void f2l(FitsBit *, void *, int)
static constexpr int maxfltexp
Definition fits.h:353
static void l2f(void *, char *, int)
static Bool isa_text(char c)
Definition fits.h:368
static void swap2(void *, void *, int)
static int str2fstr(char *, const char *, int)
static void l2f(void *, FitsBit *, int)
static constexpr Int maxInt
Definition fits.h:298
static void f2l(unsigned char *, void *, int)
static void l2f(void *, IComplex *, int)
static void f2l(FitsVADesc *, void *, int)
static void f2l(Int *, void *, int)
static constexpr double mindouble
Definition fits.h:301
static FITS::ValueType getfitstype(NoConvert< short > x)
Definition fits.h:183
static ReservedFitsKeywordCollection & ResWord
Definition fits.h:272
static void f2l(long *, void *, int)
static int fitssize(FITS::ValueType t)
static FITS::ValueType getfitstype(NoConvert< DComplex > x)
Definition fits.h:197
static void swap4(void *, void *, int)
static void l2f(void *, FitsVADesc *, int)
static void l2f(void *, Int *, int)
static void l2f(void *, Complex *, int)
static double tenD(Int, int)
Definition fits.h:374
static int ckaccum(float &, Int, int)
static void f2l(Complex *, void *, int)
static constexpr double maxdouble
Definition fits.h:302
FitsRecType
Types of FITS Records.
Definition fits.h:252
@ UnrecognizableRecord
Definition fits.h:254
@ BadBeginningRecord
Definition fits.h:253
@ SpecialRecord
Definition fits.h:254
static constexpr int maxdblexp
Definition fits.h:355
static FITS::ValueType getfitstype(NoConvert< unsigned char > x)
Definition fits.h:181
static constexpr float tenpowerF[39]
Definition fits.h:346
ValueType
FITS I/O Error message types.
Definition fits.h:167
static FITS::ValueType getfitstype(NoConvert< FitsVADesc > x)
Definition fits.h:199
static Bool isa_letter(char)
Definition fits.h:369
static void fstr2str(char *, const char *, int)
static FITS::ValueType getfitstype(NoConvert< FitsBit > x)
Definition fits.h:177
static void l2f(void *, long *, int)
static FITS::ValueType getfitstype(NoConvert< Complex > x)
Definition fits.h:193
static void l2f(void *, double *, int)
static FITS::ValueType getfitstype(NoConvert< FitsLogical > x)
STRING and FSTRING are used internally in parsing keywords.
Definition fits.h:175
static float tenF(Int, int)
Definition fits.h:378
static FITS::ValueType getfitstype(NoConvert< Int > x)
Definition fits.h:185
static void valstr(ostream &o, const ValueType &ty, const void *val)
static constexpr int minfltexp
Definition fits.h:352
static void f2l(IComplex *, void *, int)
static void l2f(void *, DComplex *, int)
static void f2l(char *, void *, int)
static int ckaccum(double &, Int, int)
static constexpr int maxdigl
Definition fits.h:357
static int get_value_id(const char *s, int l, int &pos)
FitsArrayOption
Options on FITS array manipulations.
Definition fits.h:270
static Bool isa_digit(char c)
Definition fits.h:366
static constexpr double tenpowerD[309]
Definition fits.h:306
static void l2f(void *, short *, int)
static constexpr int maxsigdigits
Definition fits.h:356
static FITS::ValueType getfitstype(NoConvert< long > x)
Definition fits.h:187
static void get_value(const char *s, int len, FitsValueResult &result)
static int chk_comment(const char *s, int len)
static void parse_vatform(const char *s, FITS::ValueType &valType, int &maxelem)
utility function to parse the binary table variable array column (i.e.
static void l2f(void *, unsigned char *, int)
HDUType
Types of FITS Header-Data Units.
Definition fits.h:263
@ ImageExtensionHDU
Definition fits.h:265
@ PrimaryGroupHDU
Definition fits.h:264
@ AsciiTableHDU
Definition fits.h:264
@ BinaryTableHDU
Definition fits.h:265
@ PrimaryTableHDU
Definition fits.h:266
@ PrimaryArrayHDU
Definition fits.h:264
@ UnknownExtensionHDU
Definition fits.h:265
static void get_name(const char *s, int len, FitsNameResult &result)
static constexpr Int minInt
Definition fits.h:297
static void f2l(FitsLogical *, void *, int)
data conversion routines: FITS - local
static constexpr float maxfloat
Definition fits.h:300
FitsDevice
Supported FITS Physical Devices.
Definition fits.h:258
static void swap8(void *, void *, int)
static int digit2bin(char c)
Definition fits.h:367
static int localsize(FITS::ValueType t)
static void f2l(float *, void *, int)
static void f2l(double *, void *, int)
static int letter2bin(char)
Definition fits.h:370
static FITS::ValueType getfitstype(NoConvert< char > x)
Definition fits.h:179
static constexpr float minfloat
Definition fits.h:299
helper class for FITS Binary Tables
Definition fits.h:116
FitsBit(unsigned char x)
Definition fits.h:119
unsigned char bit_array
Definition fits.h:123
FitsBit & operator=(unsigned char x)
Definition fits.h:120
Utility functions for floating point values.
Definition fits.h:1138
static void setNaN(float &val)
static Bool isFP(const double *)
static Bool isFP(const float *)
These functions are useful to tell if some type is a floating point type.
static Bool isFP(const void *)
static void setNaN(double &val)
For blanking purposes, we need to be able to get a NaN.
static constexpr int FitsCardSize
Definition fits.h:1117
static void fmtcard(char *, const FitsKeyword &)
static constexpr int FitsRecSize
Definition fits.h:1119
int err_cardno(int) const
Definition fits.h:1131
FitsKeywordList & parse(const char *, FitsKeywordList &, int, FITSErrorHandler, Bool)
int build(char *, FitsKeywordList &)
static constexpr int FitsMaxCard
Definition fits.h:1118
const char * err(int) const
Definition fits.h:1130
linked list of FITS keywords
Definition fits.h:856
void end()
add the end card.
Definition fits.h:1063
void mk(FITS::ReservedName k, Bool v, const char *c=0)
Add (make) a reserved keyword with the given value and optional comment The comment will be truncated...
Definition fits.h:1009
int rules(FitsKeyword &, FITSErrorHandler errhandler=FITSError::defaultHandler)
FitsKeyword * pos
Definition fits.h:967
FitsKeyword * beg_
Definition fits.h:965
int rules(FITSErrorHandler errhandler=FITSError::defaultHandler)
FitsKeyword * operator()(int)
Retrieve specific keywords – these also set the current mark.
FitsKeyword & make(const char *nm, FITS::ValueType t, const void *v, const char *c)
FitsKeyword * next(const FITS::ReservedName &)
void parse(const char *, int)
For parsing a single string.
Definition fits.h:1002
std::string toString() const
Convert the list to a string containing the 80-byte FITS headers.
FitsKeyword * curr()
Definition fits.h:995
int no_parse_errs() const
Definition fits.h:1004
Bool isempty() const
Definition fits.h:992
FitsKeywordList & operator=(const FitsKeywordList &)
void spaces(const char *n=0, const char *c=0)
add a spaces line
Definition fits.h:1053
void del()
delete the current keyword (the thing returned by curr()) from the list
const char * parse_err(int) const
Definition fits.h:1005
void insert(FitsKeyword &)
void comment(const char *n=0, const char *c=0)
add a comment card
Definition fits.h:1057
FitsKeyword * next(const FITS::ReservedName &, int)
FitsKeyword & makeErrKeyword(const char *name, FITS::ValueType type, const void *val, const char *errmsg)
construct an error keyword - this happens when a name is invalid (NULL or more than 8 characters) or ...
FitsKeyword & make(FITS::ReservedName nm, FITS::ValueType t, const void *v, const char *c)
FitsKeywordList(const FitsKeywordList &)
FitsKeyword * next(const char *)
FitsKeyword & make(int ind, FITS::ReservedName nm, FITS::ValueType t, const void *v, const char *c)
void history(const char *c=0)
add a history card
Definition fits.h:1061
FitsKeywordList(ConstFitsKeywordList &)
FitsKeyword * end_
Definition fits.h:966
FITS keyword.
Definition fits.h:634
FitsKeyword(const FitsKeyword &)
A word about friends: FitsKeywordList accesses the next and prev pointers and the FitsKeyword constru...
Definition fits.h:762
Bool asBool() const
access the value of the keyword
Definition fits.h:788
char * name_
the keyword name if name_ is 0, keyword is not a user defined name if ndx is 0, there is no index
Definition fits.h:709
const char * comm() const
access the keyword comment
Definition fits.h:782
const ReservedFitsKeyword * kw_
Definition fits.h:710
FitsKeyword(const char *, int, FITS::ValueType, const void *, int, const char *, int)
private constructors for use by friends
const ReservedFitsKeyword & kw() const
Definition fits.h:772
char * comm_
the keyword comment if comm_ is 0, there is no comment
Definition fits.h:718
void init(const FitsKeyword &)
FitsKeyword & operator=(const FitsKeyword &)
Definition fits.h:764
double asDouble() const
Definition fits.h:812
FitsKeyword * prev_
Definition fits.h:703
void setval(const FITS::ValueType &, const void *, int)
Int asInt() const
Definition fits.h:792
friend class FitsParse
Definition fits.h:636
Bool isindexed() const
Definition fits.h:779
int namelen() const
Definition fits.h:778
static void err(const char *, const FITS::ValueType &, const void *, const char *)
void name(const char *)
change the name of the keyword
FITS::ValueType type() const
the datatype of the keyword
Definition fits.h:786
const char * asString() const
Definition fits.h:789
FITS::ValueType type_
the keyword value
Definition fits.h:725
int commlen() const
Definition fits.h:784
float asFloat() const
Definition fits.h:799
const void * value() const
void setcomm(const char *, int)
static void memchk(void *)
Bool isreserved() const
Definition fits.h:773
int valStrlen() const
Definition fits.h:791
int err() const
access the error status
Definition fits.h:785
const char * name() const
get info about the name
Definition fits.h:776
DComplex asDComplex() const
Definition fits.h:829
void comm(const char *)
change the comment of the keyword
FitsKeyword * next_
Definition fits.h:702
int index() const
Definition fits.h:780
IComplex asIComplex() const
Definition fits.h:825
FitsKeyword(const ReservedFitsKeyword *, int, FITS::ValueType, const void *, int, const char *, int)
constructs reserved keywords parms: resword, index, val, vallen, comm, commlen
friend class FitsKeywordList
Definition fits.h:635
Complex asComplex() const
Definition fits.h:827
FITS helper class.
Definition fits.h:90
friend ostream & operator<<(ostream &o, const FitsLogical &)
void undefine()
ARO 2021-02-20: Removed the following function, because it seems incorrectly implemented and isn't us...
Definition fits.h:100
FitsLogical & operator=(Bool x)
Definition fits.h:95
FitsLogical(Bool x)
Definition fits.h:94
analyse the name of a header card
Definition fits.h:559
parse a header card
Definition fits.h:606
const char * err(int) const
Definition fits.h:624
int no_errs() const
Definition fits.h:623
int seterr(const char *)
Definition fits.h:625
FitsKeyword & parse(const char *, int)
const char ** err_
Definition fits.h:617
const int max_errs
Definition fits.h:616
friend class FitsKeywordList
Definition fits.h:607
FitsKeyword & mkerr(const char *s, int len)
Variable Length Array Descriptor.
Definition fits.h:130
friend ostream & operator<<(ostream &o, const FitsVADesc &)
FitsVADesc & operator=(const FitsVADesc &x)
Definition fits.h:136
int num() const
Definition fits.h:141
FitsVADesc(int n, int o)
Definition fits.h:139
FitsVADesc(const FitsVADesc &x)
Definition fits.h:134
int offset() const
Definition fits.h:142
void set(int n, int o)
Definition fits.h:140
analyse the value of a header card
Definition fits.h:578
const char * errmsg
Definition fits.h:596
FITS::ValueType type
Definition fits.h:580
void operator=(int)
Definition fits.h:66
collection of reserved FITS keywords
Definition fits.h:421
const ReservedFitsKeyword & history() const
Definition fits.h:549
static constexpr const ReservedFitsKeyword & spaces_item
Definition fits.h:519
int essential_name(const char *, int) const
const ReservedFitsKeyword & operator[](int i) const
Definition fits.h:535
const ReservedFitsKeyword & comment() const
Definition fits.h:547
const ReservedFitsKeyword & get_essential(int, Bool, FITS::ValueType, const void *, int, const char *&) const
const ReservedFitsKeyword & get(FITS::ReservedName, Bool, FITS::ValueType, const void *, int, const char *&) const
static constexpr int resalpha[26]
alphabetic index to table
Definition fits.h:523
static constexpr const ReservedFitsKeyword & user_def_item
Definition fits.h:516
static constexpr const ReservedFitsKeyword & end__item
Definition fits.h:518
const ReservedFitsKeyword & end_item() const
Definition fits.h:543
const ReservedFitsKeyword & match(int, const char *, int, Bool, FITS::ValueType, const void *, int, const char *&) const
static constexpr const ReservedFitsKeyword & error_item
Definition fits.h:517
const char * aname(FITS::ReservedName) const
int rules(const ReservedFitsKeyword &, const char *, int, Bool, FITS::ValueType, const void *, int, const char *&) const
const ReservedFitsKeyword & err_item() const
Definition fits.h:541
int isreserved(const char *, int) const
static constexpr int no_items
Definition fits.h:445
const ReservedFitsKeyword & get(const char *, int, Bool, FITS::ValueType, const void *, int, const char *&) const
const ReservedFitsKeyword & userdef_item() const
Definition fits.h:539
static constexpr const ReservedFitsKeyword & comment_item
Definition fits.h:520
const ReservedFitsKeyword & spaces() const
Definition fits.h:545
static constexpr ReservedFitsKeyword resword[56]
Discussion of Reserved FitsKeyword Table.
Definition fits.h:454
static constexpr const ReservedFitsKeyword & history_item
Definition fits.h:521
reserved FITS keyword
Definition fits.h:387
FITS::ValueType type() const
Definition fits.h:412
FITS::ReservedName name_
Definition fits.h:402
Bool isessential() const
Definition fits.h:414
FITS::ValueType type_
Definition fits.h:405
const char * aname() const
Definition fits.h:410
FITS::ReservedName name() const
void(* FITSErrorHandler)(const char *errMessage, FITSError::ErrorLevel severity)
Define a typedef for the handler function signature for convenience.
Definition FITSError.h:108
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
String name() const
Return the name of the field.
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
void init()
Other internal helper function(s).
int FitsLong
All FITS code seems to assume longs are 4 bytes.
Definition aipsxtype.h:41
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
const String & comment() const
Get the comment of this field.