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.
44typedef 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
93 public:
94 FitsLogical() : v('\0') {}
95 FitsLogical(Bool x) : v(x == True ? 'T' : 'F') {}
97 v = (x == True ? 'T' : 'F');
98 return *this;
99 }
100
103 void undefine() { v = '\0'; }
104 operator Bool() const { return v == 'T'; }
105
106 protected:
107 char v;
108};
109
110//<summary> helper class for FITS Binary Tables </summary>
111// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
112// </reviewed>
113//<synopsis>
114// This class is not intended for general use. It only has meaning
115// in the context of FITS Binary tables. There its use is incorporated
116// into the concept of a FitsField, where FitsBit is given a specialized
117// interpretation.
118//</synopsis>
119
120class FitsBit {
121 public:
123 FitsBit(unsigned char x) : bit_array(x) {}
124 FitsBit &operator=(unsigned char x) {
125 bit_array = x;
126 return *this;
127 }
128 operator unsigned char() const { return bit_array; }
129
130 protected:
131 unsigned char bit_array;
132};
133
134//<summary> Variable Length Array Descriptor </summary>
135// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
136// </reviewed>
137
139 friend ostream &operator<<(ostream &o, const FitsVADesc &);
140
141 public:
147 return *this;
148 }
149 FitsVADesc(int n, int o) : no_elements(n), rel_offset(o) {}
150 void set(int n, int o) {
151 no_elements = n;
152 rel_offset = o;
153 }
154 int num() const { return no_elements; }
155 int offset() const { return rel_offset; }
156
157 protected:
160};
161
162//<summary> static functions and enumerations </summary>
163// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
164// </reviewed>
165//<synopsis>
166// Many of the static functions are utility functions used internally in the
167// implementation of the member functions of the FITS classes. They are placed
168// in a single class to encapsulate them and to avoid adding many names to the
169// global name space. More important, from the user's perspective, are the
170// enumerations. They form the basic vocabulary of a FITS application. For example,
171// instead of referring to the FITS <src>NAXIS</src> keyword,
172// <src>FITS::NAXIS</src> should be used
173//</synopsis>
174
175class FITS {
176 public:
177 // FITS I/O Error message types
178
179 // Basic FITS Data Types for keywords and data
183 BIT = 2,
184 CHAR = 3,
185 BYTE = 4,
186 SHORT = 5,
187 LONG = 6,
188 FLOAT = 7,
193 VADESC = 12,
197 }; // REAL means either FLOAT or DOUBLE
198 // STRING and FSTRING are used internally in parsing keywords
199
201 x = 0;
202 return FITS::LOGICAL;
203 }
205 x = 0;
206 return FITS::BIT;
207 }
209 x = 0;
210 return FITS::CHAR;
211 }
213 x = 0;
214 return FITS::BYTE;
215 }
217 x = 0;
218 return FITS::SHORT;
219 }
221 x = 0;
222 return FITS::LONG;
223 }
225 x = 0;
226 return FITS::LONG;
227 }
229 x = 0;
230 return FITS::FLOAT;
231 }
233 x = 0;
234 return FITS::DOUBLE;
235 }
237 x = 0;
238 return FITS::COMPLEX;
239 }
241 x = 0;
242 return FITS::ICOMPLEX;
243 }
245 x = 0;
246 return FITS::DCOMPLEX;
247 }
249 x = 0;
250 return FITS::VADESC;
251 }
252
255
256 // data conversion routines: FITS - local
257 static void f2l(FitsLogical *, void *, int);
258 static void l2f(void *, FitsLogical *, int);
259 static void f2l(FitsBit *, void *, int);
260 static void l2f(void *, FitsBit *, int);
261 static void f2l(char *, void *, int);
262 static void l2f(void *, char *, int);
263 static void f2l(unsigned char *, void *, int);
264 static void l2f(void *, unsigned char *, int);
265 static void f2l(short *, void *, int);
266 static void l2f(void *, short *, int);
267 static void f2l(Int *, void *, int);
268 static void l2f(void *, Int *, int);
269 static void f2l(long *, void *, int);
270 static void l2f(void *, long *, int);
271 static void f2l(float *, void *, int);
272 static void l2f(void *, float *, int);
273 static void f2l(double *, void *, int);
274 static void l2f(void *, double *, int);
275 static void f2l(Complex *, void *, int);
276 static void l2f(void *, Complex *, int);
277 static void f2l(IComplex *, void *, int);
278 static void l2f(void *, IComplex *, int);
279 static void f2l(DComplex *, void *, int);
280 static void l2f(void *, DComplex *, int);
281 static void f2l(FitsVADesc *, void *, int);
282 static void l2f(void *, FitsVADesc *, int);
283 static void swap2(void *, void *, int);
284 static void swap4(void *, void *, int);
285 static void swap8(void *, void *, int);
286
287 // FITS Reserved Names. PZERO is named strangely because it can conflict with
288 // a standard #define in sys/param.h.
347
348 // Types of FITS Records
357
358 // Supported FITS Physical Devices
360
361 // Types of FITS Header-Data Units
372
373 // Options on FITS array manipulations
374 enum FitsArrayOption { NoOpt = 0, CtoF = 1, FtoC = 2 };
375
377 static void valstr(ostream &o, const ValueType &ty, const void *val);
378 static Bool isa_digit(char c);
379 static int digit2bin(char c);
380 static Bool isa_text(char c);
381 static Bool isa_letter(char);
382 static int letter2bin(char);
383 static void fstr2str(char *, const char *, int);
384 static int str2fstr(char *, const char *, int);
385 static void get_name(const char *s, int len, FitsNameResult &result);
386 static int get_value_id(const char *s, int l, int &pos);
387 static void get_value(const char *s, int len, FitsValueResult &result);
388 static int trim_comment(const char *s, int len);
389 static int chk_comment(const char *s, int len);
390 static int get_comment(const char *s, int len, int &begpos);
391 static void get_numeric(const char *s, int len, FitsValueResult &result);
392 // utility function to parse the binary table variable array
393 // column (i.e. uses the heap) of the form nPt(dddd) where n
394 // is either 0 or 1, t is one of the standard FITS binary table
395 // column types and dddd is the maximum number of elements used
396 // by this column. If there is a format error in the input
397 // string (*s), then valType will have the value NOVALUE and
398 // maxelem will be -1.
399 static void parse_vatform(const char *s, FITS::ValueType &valType, int &maxelem);
400 static constexpr Int minInt = INT_MIN;
401 static constexpr Int maxInt = INT_MAX;
402 static constexpr float minfloat = FLT_MIN;
403 static constexpr float maxfloat = FLT_MAX;
404 static constexpr double mindouble = DBL_MIN;
405 static constexpr double maxdouble = DBL_MAX;
406
407 private:
408 FITS();
409 static constexpr double tenpowerD[309] = {
410 1.0, 1.0E1, 1.0E2, 1.0E3, 1.0E4, 1.0E5, 1.0E6, 1.0E7, 1.0E8, 1.0E9,
411 1.0E10, 1.0E11, 1.0E12, 1.0E13, 1.0E14, 1.0E15, 1.0E16, 1.0E17, 1.0E18, 1.0E19,
412 1.0E20, 1.0E21, 1.0E22, 1.0E23, 1.0E24, 1.0E25, 1.0E26, 1.0E27, 1.0E28, 1.0E29,
413 1.0E30, 1.0E31, 1.0E32, 1.0E33, 1.0E34, 1.0E35, 1.0E36, 1.0E37, 1.0E38, 1.0E39,
414 1.0E40, 1.0E41, 1.0E42, 1.0E43, 1.0E44, 1.0E45, 1.0E46, 1.0E47, 1.0E48, 1.0E49,
415 1.0E50, 1.0E51, 1.0E52, 1.0E53, 1.0E54, 1.0E55, 1.0E56, 1.0E57, 1.0E58, 1.0E59,
416 1.0E60, 1.0E61, 1.0E62, 1.0E63, 1.0E64, 1.0E65, 1.0E66, 1.0E67, 1.0E68, 1.0E69,
417 1.0E70, 1.0E71, 1.0E72, 1.0E73, 1.0E74, 1.0E75, 1.0E76, 1.0E77, 1.0E78, 1.0E79,
418 1.0E80, 1.0E81, 1.0E82, 1.0E83, 1.0E84, 1.0E85, 1.0E86, 1.0E87, 1.0E88, 1.0E89,
419 1.0E90, 1.0E91, 1.0E92, 1.0E93, 1.0E94, 1.0E95, 1.0E96, 1.0E97, 1.0E98, 1.0E99,
420 1.0E100, 1.0E101, 1.0E102, 1.0E103, 1.0E104, 1.0E105, 1.0E106, 1.0E107, 1.0E108, 1.0E109,
421 1.0E110, 1.0E111, 1.0E112, 1.0E113, 1.0E114, 1.0E115, 1.0E116, 1.0E117, 1.0E118, 1.0E119,
422 1.0E120, 1.0E121, 1.0E122, 1.0E123, 1.0E124, 1.0E125, 1.0E126, 1.0E127, 1.0E128, 1.0E129,
423 1.0E130, 1.0E131, 1.0E132, 1.0E133, 1.0E134, 1.0E135, 1.0E136, 1.0E137, 1.0E138, 1.0E139,
424 1.0E140, 1.0E141, 1.0E142, 1.0E143, 1.0E144, 1.0E145, 1.0E146, 1.0E147, 1.0E148, 1.0E149,
425 1.0E150, 1.0E151, 1.0E152, 1.0E153, 1.0E154, 1.0E155, 1.0E156, 1.0E157, 1.0E158, 1.0E159,
426 1.0E160, 1.0E161, 1.0E162, 1.0E163, 1.0E164, 1.0E165, 1.0E166, 1.0E167, 1.0E168, 1.0E169,
427 1.0E170, 1.0E171, 1.0E172, 1.0E173, 1.0E174, 1.0E175, 1.0E176, 1.0E177, 1.0E178, 1.0E179,
428 1.0E180, 1.0E181, 1.0E182, 1.0E183, 1.0E184, 1.0E185, 1.0E186, 1.0E187, 1.0E188, 1.0E189,
429 1.0E190, 1.0E191, 1.0E192, 1.0E193, 1.0E194, 1.0E195, 1.0E196, 1.0E197, 1.0E198, 1.0E199,
430 1.0E200, 1.0E201, 1.0E202, 1.0E203, 1.0E204, 1.0E205, 1.0E206, 1.0E207, 1.0E208, 1.0E209,
431 1.0E210, 1.0E211, 1.0E212, 1.0E213, 1.0E214, 1.0E215, 1.0E216, 1.0E217, 1.0E218, 1.0E219,
432 1.0E220, 1.0E221, 1.0E222, 1.0E223, 1.0E224, 1.0E225, 1.0E226, 1.0E227, 1.0E228, 1.0E229,
433 1.0E230, 1.0E231, 1.0E232, 1.0E233, 1.0E234, 1.0E235, 1.0E236, 1.0E237, 1.0E238, 1.0E239,
434 1.0E240, 1.0E241, 1.0E242, 1.0E243, 1.0E244, 1.0E245, 1.0E246, 1.0E247, 1.0E248, 1.0E249,
435 1.0E250, 1.0E251, 1.0E252, 1.0E253, 1.0E254, 1.0E255, 1.0E256, 1.0E257, 1.0E258, 1.0E259,
436 1.0E260, 1.0E261, 1.0E262, 1.0E263, 1.0E264, 1.0E265, 1.0E266, 1.0E267, 1.0E268, 1.0E269,
437 1.0E270, 1.0E271, 1.0E272, 1.0E273, 1.0E274, 1.0E275, 1.0E276, 1.0E277, 1.0E278, 1.0E279,
438 1.0E280, 1.0E281, 1.0E282, 1.0E283, 1.0E284, 1.0E285, 1.0E286, 1.0E287, 1.0E288, 1.0E289,
439 1.0E290, 1.0E291, 1.0E292, 1.0E293, 1.0E294, 1.0E295, 1.0E296, 1.0E297, 1.0E298, 1.0E299,
440 1.0E300, 1.0E301, 1.0E302, 1.0E303, 1.0E304, 1.0E305, 1.0E306, 1.0E307, 1.0E308};
441 static constexpr float tenpowerF[39] = {
442 1.0F, 1.0E1F, 1.0E2F, 1.0E3F, 1.0E4F, 1.0E5F, 1.0E6F, 1.0E7F, 1.0E8F, 1.0E9F,
443 1.0E10F, 1.0E11F, 1.0E12F, 1.0E13F, 1.0E14F, 1.0E15F, 1.0E16F, 1.0E17F, 1.0E18F, 1.0E19F,
444 1.0E20F, 1.0E21F, 1.0E22F, 1.0E23F, 1.0E24F, 1.0E25F, 1.0E26F, 1.0E27F, 1.0E28F, 1.0E29F,
445 1.0E30F, 1.0E31F, 1.0E32F, 1.0E33F, 1.0E34F, 1.0E35F, 1.0E36F, 1.0E37F, 1.0E38F};
446 static constexpr int minfltexp = -38;
447 static constexpr int maxfltexp = 38;
448 static constexpr int mindblexp = -308;
449 static constexpr int maxdblexp = 308;
450 static constexpr int maxsigdigits = 17;
451 static constexpr int maxdigl = 9; // max digits in a long
452 static constexpr int maxexpdig = 3; // max digits in an exponent
453 static double tenD(Int, int);
454 static float tenF(Int, int);
455 static int ckaccum(double &, Int, int);
456 static int ckaccum(float &, Int, int);
457};
458
459inline FITS::FITS() {} // just a dummy function to prevent instantiation
460inline Bool FITS::isa_digit(char c) { return isdigit(c) ? True : False; }
461inline int FITS::digit2bin(char c) { return c - '0'; }
462inline Bool FITS::isa_text(char c) { return isprint(c) ? True : False; }
463inline Bool FITS::isa_letter(char c) { return isupper(c) ? True : False; }
464inline int FITS::letter2bin(char c) { return c - 'A'; }
465
466ostream &operator<<(ostream &, const FITS::ValueType &);
467
468inline double FITS::tenD(Int numb, int pow) {
469 return (pow > 0) ? (((double)numb) * tenpowerD[pow])
470 : ((pow < 0) ? (((double)numb) / tenpowerD[-pow]) : ((double)numb));
471}
472inline float FITS::tenF(Int numb, int pow) {
473 return (pow > 0) ? (((float)numb) * tenpowerF[pow])
474 : ((pow < 0) ? (((float)numb) / tenpowerF[-pow]) : ((float)numb));
475}
476
477//<summary> reserved FITS keyword </summary>
478// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
479// </reviewed>
480
482 public:
483 const char *aname() const;
485 int namesize() const;
486 FITS::ValueType type() const;
487 Bool isindexed() const;
488 Bool isessential() const;
489#if defined(TURBOCPP)
490 // It is best for the following to be private, but
491 // C-Front won't allow an initializer list if they are private.
492 // This issue isn't that crucial since functions in
493 // ReservedFitsKeywordCollection always return const items.
494 private:
495#endif
497 const char *aname_;
500 Bool isindexed_; // 0 = NOT INDEXED, 1 = INDEXED
501 Bool isessential_; // 0 = NO, 1 = YES
502};
503
504inline const char *ReservedFitsKeyword::aname() const { return aname_; }
505inline int ReservedFitsKeyword::namesize() const { return namesize_; }
509
510//<summary> collection of reserved FITS keywords </summary>
511// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
512// </reviewed>
513
515 public:
516 const ReservedFitsKeyword &operator[](int i) const;
517 int no() const;
519 const char *&) const;
520 const ReservedFitsKeyword &get(const char *, int, Bool, FITS::ValueType, const void *, int,
521 const char *&) const;
522 const char *aname(FITS::ReservedName) const;
523 int essential_name(const char *, int) const;
524 const ReservedFitsKeyword &get_essential(int, Bool, FITS::ValueType, const void *, int,
525 const char *&) const;
526 int isreserved(const char *, int) const;
527 Bool isunique(int) const;
529 const ReservedFitsKeyword &userdef_item() const;
530 const ReservedFitsKeyword &err_item() const;
531 const ReservedFitsKeyword &end_item() const;
532 const ReservedFitsKeyword &spaces() const;
533 const ReservedFitsKeyword &comment() const;
534 const ReservedFitsKeyword &history() const;
535 int rules(const ReservedFitsKeyword &, const char *, int, Bool, FITS::ValueType, const void *,
536 int, const char *&) const;
537
538 private:
539 static constexpr int no_items = 56; // number of entries in the table
540 // Discussion of Reserved FitsKeyword Table
541 //
542 // 1. The reserved name itself (name_) is not unique; there may
543 // be more than one entry with the same reserved name.
544 // 2. The combination of reserved name, the data type, and whether
545 // it is indexed or not (name_, type_, isindexed_) is unique
546 // within the table.
547 // 3. The table is sorted by reserved name + type + isindexed.
548 static constexpr ReservedFitsKeyword resword[56] = {
549 // key aname namesize isindexed Section
550 // | | | type | isessential in|NOST
551 // \|/ \|/ \|/\|/ \|/ \|/ \|/
552 // ------ ------ - ------- ----- ----- ------------
553 /* 0 */ {FITS::USER_DEF, "", 0, FITS::NOVALUE, False, False},
554 /* 1 */ {FITS::AUTHOR, "AUTHOR", 6, FITS::STRING, False, False}, // 5.2.2.3
555 /* 2 */ {FITS::BITPIX, "BITPIX", 6, FITS::LONG, False, True}, // 5.2.1.1
556 /* 3 */ {FITS::BLANK, "BLANK", 5, FITS::LONG, False, False}, // 5.2.2.5
557 /* 4 */ {FITS::BLOCKED, "BLOCKED", 7, FITS::LOGICAL, False, False}, // 5.2.2.1
558 /* 5 */ {FITS::BSCALE, "BSCALE", 6, FITS::REAL, False, False}, // 5.2.2.5
559 /* 6 */ {FITS::BUNIT, "BUNIT", 5, FITS::STRING, False, False}, // 5.2.2.5
560 /* 7 */ {FITS::BZERO, "BZERO", 5, FITS::REAL, False, False}, // 5.2.2.5
561 /* 8 */ {FITS::CDELT, "CDELT", 5, FITS::REAL, True, False}, // 5.2.2.5
562 /* 9 */ {FITS::COMMENT, "COMMENT", 7, FITS::NOVALUE, False, False}, // 5.2.2.4
563 /* 10 */ {FITS::CROTA, "CROTA", 5, FITS::REAL, True, False}, // 5.2.2.5
564 /* 11 */ {FITS::CRPIX, "CRPIX", 5, FITS::REAL, True, False}, // 5.2.2.5
565 /* 12 */ {FITS::CRVAL, "CRVAL", 5, FITS::REAL, True, False}, // 5.2.2.5
566 /* 13 */ {FITS::CTYPE, "CTYPE", 5, FITS::STRING, True, False}, // 5.2.2.5
567 /* 14 */ {FITS::DATAMAX, "DATAMAX", 7, FITS::REAL, False, False}, // 5.2.2.5
568 /* 15 */ {FITS::DATAMIN, "DATAMIN", 7, FITS::REAL, False, False}, // 5.2.2.5
569 /* 16 */ {FITS::DATE, "DATE", 4, FITS::STRING, False, False}, // 5.2.2.1
570 /* 17 */ {FITS::DATE_OBS, "DATE-OBS", 8, FITS::STRING, False, False}, // 5.2.2.2
571 /* 18 */ {FITS::END, "END", 3, FITS::NOVALUE, False, True}, // 5.2.1.1
572 /* 19 */ {FITS::EPOCH, "EPOCH", 5, FITS::REAL, False, False}, // 5.2.2.2
573 /* 20 */ {FITS::EQUINOX, "EQUINOX", 7, FITS::REAL, False, False}, // 5.2.2.2
574 /* 21 */ {FITS::EXTEND, "EXTEND", 6, FITS::LOGICAL, False, True}, // 5.2.1.2
575 /* 22 */ {FITS::EXTLEVEL, "EXTLEVEL", 8, FITS::LONG, False, False}, // 5.2.2.6
576 /* 23 */ {FITS::EXTNAME, "EXTNAME", 7, FITS::STRING, False, False}, // 5.2.2.6
577 /* 24 */ {FITS::EXTVER, "EXTVER", 6, FITS::LONG, False, False}, // 5.2.2.6
578 /* 25 */ {FITS::GCOUNT, "GCOUNT", 6, FITS::LONG, False, True}, // 5.2.1.2
579 /* 26 */ {FITS::GROUPS, "GROUPS", 6, FITS::LOGICAL, False, True}, // 7.1.1.6
580 /* 27 */ {FITS::HISTORY, "HISTORY", 7, FITS::NOVALUE, False, False}, // 5.2.2.4
581 /* 28 */ {FITS::INSTRUME, "INSTRUME", 8, FITS::STRING, False, False}, // 5.2.2.2
582 /* 29 */ {FITS::NAXIS, "NAXIS", 5, FITS::LONG, False, True}, // 5.2.1.1
583 /* 30 */ {FITS::NAXIS, "NAXIS", 5, FITS::LONG, True, True}, // 5.2.1.1
584 /* 31 */ {FITS::OBJECT, "OBJECT", 6, FITS::STRING, False, False}, // 5.2.2.2
585 /* 32 */ {FITS::OBSERVER, "OBSERVER", 8, FITS::STRING, False, False}, // 5.2.2.2
586 /* 33 */ {FITS::ORIGIN, "ORIGIN", 6, FITS::STRING, False, False}, // 5.2.2.1
587 /* 34 */ {FITS::PCOUNT, "PCOUNT", 6, FITS::LONG, False, True}, // 5.2.1.2
588 /* 35 */ {FITS::PSCAL, "PSCAL", 5, FITS::REAL, True, False}, // 7.1.2.2
589 /* 36 */ {FITS::PTYPE, "PTYPE", 5, FITS::STRING, True, False}, // 7.1.2.1
590 /* 37 */ {FITS::PZERO_FITS, "PZERO", 5, FITS::REAL, True, False}, // 7.1.2.3
591 /* 38 */ {FITS::REFERENC, "REFERENC", 8, FITS::STRING, False, False}, // 5.2.2.3
592 /* 39 */ {FITS::SIMPLE, "SIMPLE", 6, FITS::LOGICAL, False, True}, // 5.2.1.1
593 /* 40 */ {FITS::SPACES, " ", 8, FITS::NOVALUE, False, False}, // 5.2.2.4
594 /* 41 */ {FITS::TBCOL, "TBCOL", 5, FITS::LONG, True, False}, // 8.1.1
595 /* 42 */ {FITS::TDIM, "TDIM", 4, FITS::STRING, True, False}, // A.4, A.9.1
596 /* 43 */ {FITS::TDISP, "TDISP", 5, FITS::STRING, True, False}, // A.4
597 /* 44 */ {FITS::TELESCOP, "TELESCOP", 8, FITS::STRING, False, False}, // 5.2.2.2
598 /* 45 */ {FITS::TFIELDS, "TFIELDS", 7, FITS::LONG, False, False}, // 8.1.1
599 /* 46 */ {FITS::TFORM, "TFORM", 5, FITS::STRING, True, False}, // 8.1.1
600 /* 47 */ {FITS::THEAP, "THEAP", 5, FITS::LONG, False, False}, // A.4, A.9.2
601 /* 48 */ {FITS::TNULL, "TNULL", 5, FITS::STRING, True, False}, // 8.1.2
602 /* 49 */ {FITS::TNULL, "TNULL", 5, FITS::LONG, True, False}, // A.4
603 /* 50 */ {FITS::TSCAL, "TSCAL", 5, FITS::REAL, True, False}, // 8.1.2
604 /* 51 */ {FITS::TTYPE, "TTYPE", 5, FITS::STRING, True, False}, // 8.1.2
605 /* 52 */ {FITS::TUNIT, "TUNIT", 5, FITS::STRING, True, False}, // 8.1.2
606 /* 53 */ {FITS::TZERO, "TZERO", 5, FITS::REAL, True, False}, // 8.1.2
607 /* 54 */ {FITS::XTENSION, "XTENSION", 8, FITS::STRING, False, True}, // 5.2.1.2
608 /* 55 */ {FITS::ERRWORD, "", 0, FITS::NOVALUE, False, False} // last
609 };
610 static constexpr const ReservedFitsKeyword &user_def_item = resword[0]; // user-defined keyword
611 static constexpr const ReservedFitsKeyword &error_item = resword[55]; // error in keyword
612 static constexpr const ReservedFitsKeyword &end__item = resword[18];
613 static constexpr const ReservedFitsKeyword &spaces_item = resword[40];
614 static constexpr const ReservedFitsKeyword &comment_item = resword[9];
615 static constexpr const ReservedFitsKeyword &history_item = resword[27];
616 // alphabetic index to table
617 static constexpr int resalpha[26] = {
618 // A B C D E F G H I J K L M N O P Q R
619 1, 2, 8, 14, 18, 0, 25, 27, 28, 0, 0, 0, 0, 29, 31, 34, 0, 38,
620 // S T U V W X Y Z
621 39, 41, 0, 0, 0, 54, 0, 0};
622 const ReservedFitsKeyword &match(int, const char *, int, Bool, FITS::ValueType, const void *, int,
623 const char *&) const;
624};
625
627 return resword[i];
628}
629inline int ReservedFitsKeywordCollection::no() const { return no_items; }
631 return (Bool)(resword[i + 1].name() != resword[i].name());
632}
651
652//<summary> analyse the name of a header card </summary>
653// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
654// </reviewed>
655//<synopsis>
656// Analyse the name of a header card
657//</synopsis>
658
660 public:
661 Bool isaname; // 1 if there is a name present, otherwise 0
662 int begpos; // beginning position of name
663 int endpos; // ending position of name
664 Bool isaindex; // whether an index is present or not
665 int index; // index if present
666 int len; // length of name without index
667 enum ErrMsg { OK = 0, NO_0_NDX };
669};
670
671//<summary> analyse the value of a header card </summary>
672// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
673// </reviewed>
674//<synopsis>
675// Analyse the value of a header card
676//</synopsis>
677
679 public:
681 union {
683 int s[2]; // for strings, s[0] is offset, s[1] length
685 float f;
686 double d;
687 };
688 Complex c;
690 DComplex dc;
691 int begpos; // beginning position of value
692 int endpos; // ending position of value
693 Bool isa_point; // 1 if a point, otherwise 0
694 int pointpos; // position of point, if any
695 int no_sig; // number of significant digits
696 const char *errmsg; // error message, if any
697};
698
699//<summary> parse a header card </summary>
700// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
701// </reviewed>
702//<synopsis>
703// parse a header card
704//</synopsis>
705
707 friend class FitsKeywordList;
708
709 public:
710 FitsKeyword &parse(const char *, int); // Parsing one string
711 int no_errs() const;
712 const char *err(int) const;
713
714 private:
715 FitsParse(int = 10);
716 ~FitsParse();
718 const int max_errs;
719 const char **err_;
720 int seterr(const char *);
721 FitsKeyword &mkerr(const char *s, int len);
722};
723
724inline FitsParse::~FitsParse() { delete[] err_; }
725inline int FitsParse::no_errs() const { return no_errs_; }
726inline const char *FitsParse::err(int i) const { return err_[i]; }
727inline int FitsParse::seterr(const char *s) {
728 return no_errs_ < max_errs ? (err_[no_errs_++] = s, 0) : -1;
729}
730
731//<summary> FITS keyword </summary>
732// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
733// </reviewed>
734//<synopsis>
735// A FITS keyword contains a name, a value and a comment.
736//</synopsis>
738 friend class FitsKeywordList;
739 friend class FitsParse;
740 // A word about friends: FitsKeywordList accesses the next and prev
741 // pointers and the FitsKeyword constructors.
742 // FitsParse only accesses the FitsKeyword constructors.
743
744 public:
745 FitsKeyword(const FitsKeyword &);
747 ~FitsKeyword();
748
749 //<group>
750 // get info about the name
751 const char *name() const;
752 int namelen() const;
753 Bool isreserved() const;
754 Bool isindexed() const;
755 const ReservedFitsKeyword &kw() const;
756 int index() const;
757 //</group>
758
759 //<group>
760 // access the keyword comment
761 const char *comm() const;
762 int commlen() const;
763 //</group>
764
765 // access the error status
766 int err() const;
767
768 // the datatype of the keyword
769 FITS::ValueType type() const;
770
771 // access the value of the keyword
772 //<group>
773 Bool asBool() const;
774 const char *asString() const;
775 int valStrlen() const;
776 Int asInt() const;
777 float asFloat() const;
778 double asDouble() const;
779 IComplex asIComplex() const;
780 Complex asComplex() const;
781 DComplex asDComplex() const;
782 const void *value() const;
783 //</group>
784
785 // change the value of the keyword
786 //<group>
788 FitsKeyword &operator=(const char *);
790 FitsKeyword &operator=(float);
791 FitsKeyword &operator=(double);
793 FitsKeyword &operator=(Complex);
794 FitsKeyword &operator=(DComplex);
795 //</group>
796
797 // change the comment of the keyword
798 void comm(const char *);
799
800 // change the name of the keyword
801 void name(const char *);
802
803 private:
806
807 //<group>
808 // the keyword name
809 // if name_ is 0, keyword is not a user defined name
810 // if ndx is 0, there is no index
811 char *name_;
813 int ndx;
814 short namelen_;
815 //</group>
816
817 //<group>
818 // the keyword comment
819 // if comm_ is 0, there is no comment
820 char *comm_;
821 short commlen_;
822 //</group>
823
824 //<group>
825 // the keyword value
827 union {
830 float fval;
831 double dval;
832 };
833 void *val; // pointer to allocated value, if any
834 short vallen; // only used for string data
835 void del_val(); // does an appropriate delete based on type
836 //</group>
837
838 void init(const FitsKeyword &);
839 void setval(const FITS::ValueType &, const void *, int);
840 void setcomm(const char *, int);
841 static void err(const char *, const FITS::ValueType &, const void *, const char *);
842 static void memchk(void *);
843
844 //<group>
845 // private constructors for use by friends
846
847 // constructs user-defined keywords
848 // parms: name, namelen, type, val, vallen, comm, commlen
849 FitsKeyword(const char *, int, FITS::ValueType, const void *, int, const char *, int);
850 // constructs reserved keywords
851 // parms: resword, index, val, vallen, comm, commlen
852 FitsKeyword(const ReservedFitsKeyword *, int, FITS::ValueType, const void *, int, const char *,
853 int);
854 //</group>
855};
856
857ostream &operator<<(ostream &, const FitsKeyword &);
858
860 : next_(0), prev_(0), name_(0), kw_(0), comm_(0), val(0) {
861 init(k);
862}
864 delete[] name_;
865 delete[] comm_;
866 del_val();
867 init(k);
868 return *this;
869}
871 delete[] name_;
872 delete[] comm_;
873 del_val();
874}
875
876inline const ReservedFitsKeyword &FitsKeyword::kw() const { return *kw_; }
878 return (kw().name() != FITS::ERRWORD && kw().name() != FITS::USER_DEF) ? True : False;
879}
880inline const char *FitsKeyword::name() const {
881 return isreserved() ? kw().aname() : (namelen_ ? name_ : "");
882}
883inline int FitsKeyword::namelen() const { return namelen_; }
884inline Bool FitsKeyword::isindexed() const { return ndx > 0 ? True : False; }
885inline int FitsKeyword::index() const { return ndx; }
886
887inline const char *FitsKeyword::comm() const { return comm_ ? comm_ : ""; }
888inline int FitsKeyword::commlen() const { return commlen_; }
889inline int FitsKeyword::err() const { return (kw().name() == FITS::ERRWORD); }
890inline FITS::ValueType FitsKeyword::type() const { return type_; }
891
892inline Bool FitsKeyword::asBool() const { return bval; }
893inline const char *FitsKeyword::asString() const { return vallen ? (const char *)val : ""; }
894inline int FitsKeyword::valStrlen() const { return vallen; }
895inline Int FitsKeyword::asInt() const {
896 if (type() != FITS::LONG) {
897 cerr << "Unexpected keyword type in FitsKeyword::asInt()\n";
898 exit(1);
899 }
900 return ival;
901}
902inline float FitsKeyword::asFloat() const {
903 switch (type()) {
904 case FITS::BYTE:
905 case FITS::SHORT:
906 case FITS::LONG:
907 return (float)ival;
908 case FITS::FLOAT:
909 return fval;
910 case FITS::DOUBLE:
911 return (float)dval;
912 default:
913 cerr << "Unexpected keyword type in asFloat()\n";
914 exit(1);
915 }
916 return 0.0;
917}
918inline double FitsKeyword::asDouble() const {
919 switch (type()) {
920 case FITS::BYTE:
921 case FITS::SHORT:
922 case FITS::LONG:
923 return (double)ival;
924 case FITS::FLOAT:
925 return (double)fval;
926 case FITS::DOUBLE:
927 return dval;
928 default:
929 cerr << "Unexpected keyword type in asDouble()\n";
930 exit(1);
931 }
932 return 0.0;
933}
934inline IComplex FitsKeyword::asIComplex() const { return *((IComplex *)val); }
935inline Complex FitsKeyword::asComplex() const { return *((Complex *)val); }
936inline DComplex FitsKeyword::asDComplex() const { return *((DComplex *)val); }
937
939 bval = x;
941 return *this;
942}
944 ival = x;
946 return *this;
947}
949 fval = x;
951 return *this;
952}
954 dval = x;
956 return *this;
957}
959 *((IComplex *)val) = x;
961 return *this;
962}
964 *((Complex *)val) = x;
966 return *this;
967}
969 *((DComplex *)val) = x;
971 return *this;
972}
973
974class ConstFitsKeywordList; // forward declaration
975
976//<summary> linked list of FITS keywords </summary>
977// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
978// </reviewed>
979//<synopsis>
980// A linked list of FITS keywords.
981//</synopsis>
982
984 public:
990
991 // Convert the list to a string containing the 80-byte FITS headers.
992 std::string toString() const;
993
994 // delete the current keyword (the thing returned by curr()) from the list
995 void del();
996
997 // Add (make) a reserved keyword with the given value and optional comment
998 // The comment will be truncated if necessary to fit the available space.
999 // String values must be less than 69 characters. String values longer than
1000 // that will result in an ERROR keyword instead of the desired keyword.
1001 // <group>
1002 void mk(FITS::ReservedName k, Bool v, const char *c = 0);
1003 void mk(FITS::ReservedName k, const char *v = 0, const char *c = 0);
1004 void mk(FITS::ReservedName k, Int v, const char *c = 0);
1005 void mk(FITS::ReservedName k, long v, const char *c = 0);
1006 void mk(FITS::ReservedName k, double v, const char *c = 0);
1007 // </group>
1008
1009 // Add (make) an indexed reserved keyword with the given value and optional comment
1010 // The comment will be truncated if necessary to fit the available space.
1011 // String values must be less than 69 characters. String values longer than
1012 // that will result in an ERROR keyword instead of the desired keyword.
1013 // <group>
1014 void mk(int n, FITS::ReservedName k, Bool v, const char *c = 0);
1015 void mk(int n, FITS::ReservedName k, const char *v, const char *c = 0);
1016 void mk(int n, FITS::ReservedName k, Int v, const char *c = 0);
1017 void mk(int n, FITS::ReservedName k, long v, const char *c = 0);
1018 void mk(int n, FITS::ReservedName k, double v, const char *c = 0);
1019 // </group>
1020
1021 // Add (make) a user defined keyword with the given name, value and optional comment.
1022 // The comment will be truncated if necessary to fit the available space.
1023 // The name must be no longer than 8 characters. Names longer than that will
1024 // result in an ERROR keyword instead of the desired keyword.
1025 // String values must no longer than 69 characters. String values longer than
1026 // that will result in an ERROR keyword instead of the desired keyword.
1027 // <group>
1028 void mk(const char *n, Bool v, const char *c = 0);
1029 void mk(const char *n, const char *v = 0, const char *c = 0);
1030 void mk(const char *n, Int v, const char *c = 0);
1031 void mk(const char *n, long v, const char *c = 0);
1032 void mk(const char *n, float v, const char *c = 0);
1033 void mk(const char *n, double v, const char *c = 0);
1034 void mk(const char *n, Int r, Int i, const char *c = 0);
1035 void mk(const char *n, float r, float i, const char *c = 0);
1036 void mk(const char *n, double r, double i, const char *c = 0);
1037 // </group>
1038
1039 // add a spaces line
1040 void spaces(const char *n = 0, const char *c = 0);
1041
1042 // add a comment card
1043 void comment(const char *n = 0, const char *c = 0);
1044
1045 // add a history card
1046 void history(const char *c = 0);
1047
1048 // add the end card. This must be at the end of the list.
1049 void end();
1050
1051 // Retrieve specific keywords -- these also set the current mark
1052 //<group>
1053 // return the i-th keyword -- keyword numbering starts with 0
1055 // return first and next non-indexed reserved keyword
1058 // return first and next indexed reserved keyword
1061 // return first and next user-defined keyword
1062 FitsKeyword *operator()(const char *);
1063 FitsKeyword *next(const char *);
1064 //</group>
1065
1066 //<group>
1067 Bool isempty() const;
1068 void first();
1069 void last();
1072 FitsKeyword *curr();
1073 //</group>
1074
1075 //<group>
1080 //</group>
1081
1082 //<group>
1083 // For parsing a single string
1084 void parse(const char *, int);
1085 int no_parse_errs() const;
1086 const char *parse_err(int) const;
1087 //</group>
1088
1090
1091 private:
1097 FitsKeyword &make(const char *nm, FITS::ValueType t, const void *v, const char *c);
1098 FitsKeyword &make(FITS::ReservedName nm, FITS::ValueType t, const void *v, const char *c);
1099 FitsKeyword &make(int ind, FITS::ReservedName nm, FITS::ValueType t, const void *v,
1100 const char *c);
1101 // construct an error keyword - this happens when a name is invalid (NULL
1102 // or more than 8 characters) or a string value is too long (more than
1103 // 69 characters). It is the responsibility of the caller to the
1104 // several mk functions to ensure that that doesn't happen. By the time
1105 // it gets here, it is assumed that such problems are true errors.
1106 // This is used by the private make functions.
1107 FitsKeyword &makeErrKeyword(const char *name, FITS::ValueType type, const void *val,
1108 const char *errmsg);
1110};
1111
1112ostream &operator<<(ostream &o, FitsKeywordList &); // print the entire list
1113
1116inline Bool FitsKeywordList::isempty() const { return total == 0 ? True : False; }
1118 cursor = 0;
1119 pos = beg_;
1120}
1122 cursor = total;
1123 pos = end_;
1124}
1127 first();
1128 return next(n);
1129}
1131 first();
1132 return next(n, ndx);
1133}
1135 first();
1136 return next(w);
1137}
1138inline void FitsKeywordList::parse(const char *s, int l) { insert(card.parse(s, l)); }
1139inline int FitsKeywordList::no_parse_errs() const { return card.no_errs(); }
1140inline const char *FitsKeywordList::parse_err(int n) const { return card.err(n); }
1141
1142// FitsKeyword constructors for non-indexed Reserved keywords
1143inline void FitsKeywordList::mk(FITS::ReservedName k, Bool v, const char *c) {
1144 insert(make(k, FITS::LOGICAL, &v, c));
1145}
1146inline void FitsKeywordList::mk(FITS::ReservedName k, const char *v, const char *c) {
1147 insert(make(k, FITS::STRING, v, c));
1148}
1149inline void FitsKeywordList::mk(FITS::ReservedName k, Int v, const char *c) {
1150 insert(make(k, FITS::LONG, &v, c));
1151}
1152inline void FitsKeywordList::mk(FITS::ReservedName k, long v, const char *c) {
1153 insert(make(k, FITS::LONG, &v, c));
1154}
1155inline void FitsKeywordList::mk(FITS::ReservedName k, double v, const char *c) {
1156 insert(make(k, FITS::DOUBLE, &v, c));
1157}
1158// FitsKeyword constructors for indexed Reserved keywords
1159inline void FitsKeywordList::mk(int n, FITS::ReservedName k, Bool v, const char *c) {
1160 Bool tmp;
1161 tmp = v;
1162 insert(make(n, k, FITS::LOGICAL, &tmp, c));
1163}
1164inline void FitsKeywordList::mk(int n, FITS::ReservedName k, const char *v, const char *c) {
1165 insert(make(n, k, FITS::STRING, v, c));
1166}
1167inline void FitsKeywordList::mk(int n, FITS::ReservedName k, Int v, const char *c) {
1168 insert(make(n, k, FITS::LONG, &v, c));
1169}
1170inline void FitsKeywordList::mk(int n, FITS::ReservedName k, long v, const char *c) {
1171 insert(make(n, k, FITS::LONG, &v, c));
1172}
1173inline void FitsKeywordList::mk(int n, FITS::ReservedName k, double v, const char *c) {
1174 insert(make(n, k, FITS::DOUBLE, &v, c));
1175}
1176// FitsKeyword constructors for User-Defined keywords
1177inline void FitsKeywordList::mk(const char *n, Bool v, const char *c) {
1178 Bool tmp;
1179 tmp = v;
1180 insert(make(n, FITS::LOGICAL, &tmp, c));
1181}
1182inline void FitsKeywordList::mk(const char *n, const char *v, const char *c) {
1183 insert(make(n, FITS::STRING, v, c));
1184}
1185inline void FitsKeywordList::mk(const char *n, Int v, const char *c) {
1186 insert(make(n, FITS::LONG, &v, c));
1187}
1188inline void FitsKeywordList::mk(const char *n, long v, const char *c) {
1189 insert(make(n, FITS::LONG, &v, c));
1190}
1191inline void FitsKeywordList::mk(const char *n, float v, const char *c) {
1192 insert(make(n, FITS::FLOAT, &v, c));
1193}
1194inline void FitsKeywordList::mk(const char *n, double v, const char *c) {
1195 insert(make(n, FITS::DOUBLE, &v, c));
1196}
1197inline void FitsKeywordList::mk(const char *n, Int r, Int i, const char *c) {
1198 IComplex v(r, i);
1199 insert(make(n, FITS::ICOMPLEX, &v, c));
1200}
1201inline void FitsKeywordList::mk(const char *n, float r, float i, const char *c) {
1202 Complex v(r, i);
1203 insert(make(n, FITS::COMPLEX, &v, c));
1204}
1205inline void FitsKeywordList::mk(const char *n, double r, double i, const char *c) {
1206 DComplex v(r, i);
1207 insert(make(n, FITS::DCOMPLEX, &v, c));
1208}
1209// Additional keyword constructors for commentary, etc.
1210inline void FitsKeywordList::spaces(const char *n, const char *c) {
1211 insert((n == 0
1213 : (c == 0 ? make(FITS::SPACES, FITS::NOVALUE, 0, n) : make(n, FITS::NOVALUE, 0, c))));
1214}
1215inline void FitsKeywordList::comment(const char *n, const char *c) {
1216 insert((
1217 n == 0 ? make(FITS::COMMENT, FITS::NOVALUE, 0, c)
1218 : (c == 0 ? make(FITS::COMMENT, FITS::NOVALUE, 0, n) : make(n, FITS::NOVALUE, 0, c))));
1219}
1220inline void FitsKeywordList::history(const char *c) {
1222}
1224
1225//<summary> list of read-only FITS keywords </summary>
1226// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
1227// </reviewed>
1228
1230 public:
1232
1233 const FitsKeyword *operator()(int n) { return kw(n); }
1234 const FitsKeyword *operator()(const FITS::ReservedName &x) { return kw(x); }
1235 const FitsKeyword *next(const FITS::ReservedName &x) { return kw.next(x); }
1236 const FitsKeyword *operator()(const FITS::ReservedName &x, int n) { return kw(x, n); }
1237 const FitsKeyword *next(const FITS::ReservedName &x, int n) { return kw.next(x, n); }
1238 const FitsKeyword *operator()(const char *x) { return kw(x); }
1239 const FitsKeyword *next(const char *x) { return kw.next(x); }
1240
1241 Bool isempty() const { return kw.isempty(); }
1242 void first() { kw.first(); }
1243 void last() { kw.last(); }
1244 const FitsKeyword *next() { return kw.next(); }
1245 const FitsKeyword *prev() { return kw.prev(); }
1246 const FitsKeyword *curr() { return kw.curr(); }
1247
1248 private:
1250};
1251
1252//<summary> translator between Keyword lists and fixed FITS cars </summary>
1253// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
1254// </reviewed>
1255//<synopsis>
1256// also contains the parser ???
1257//</synopsis>
1258
1260 public:
1264 int build(char *, FitsKeywordList &);
1265 int no_errs() const;
1266 const char *err(int) const;
1267 int err_cardno(int) const;
1268 static void fmtcard(char *, const FitsKeyword &);
1269
1270 private:
1271 int cardno; // the current card number within record
1272 static constexpr int FitsCardSize = 80;
1273 static constexpr int FitsMaxCard = 36;
1274 static constexpr int FitsRecSize = 2880;
1277 const char **err_;
1279 char *blanks;
1280};
1281
1283 delete[] err_;
1284 delete[] err_cardno_;
1285 delete[] blanks;
1286}
1287inline int FitsKeyCardTranslator::no_errs() const { return no_errs_; }
1288inline const char *FitsKeyCardTranslator::err(int i) const { return err_[i]; }
1289inline int FitsKeyCardTranslator::err_cardno(int i) const { return err_cardno_[i]; }
1290
1291// <summary>Utility functions for floating point values</summary>
1292// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
1293// </reviewed>
1295 public:
1296 // These functions are useful to tell if some type is a floating point type.
1297 // This is useful in a templated function, where the processing can vary
1298 // depending on whether the type is FP or not (e.g. blank handling).
1299 // <group>
1300 static Bool isFP(const float *);
1301 static Bool isFP(const double *);
1302 static Bool isFP(const void *);
1303 // </group>
1304
1305 // For blanking purposes, we need to be able to get a NaN. The NaN we set
1306 // is all bits on.
1307 // <group>
1308 static void setNaN(double &val);
1309 static void setNaN(float &val);
1310 // </group>
1311};
1312
1313} // namespace casacore
1314
1315#endif
list of read-only FITS keywords
Definition fits.h:1229
const FitsKeyword * operator()(const char *x)
Definition fits.h:1238
ConstFitsKeywordList(FitsKeywordList &x)
Definition fits.h:1231
const FitsKeyword * curr()
Definition fits.h:1246
const FitsKeyword * prev()
Definition fits.h:1245
const FitsKeyword * next(const FITS::ReservedName &x, int n)
Definition fits.h:1237
const FitsKeyword * next(const FITS::ReservedName &x)
Definition fits.h:1235
const FitsKeyword * operator()(const FITS::ReservedName &x)
Definition fits.h:1234
const FitsKeyword * operator()(const FITS::ReservedName &x, int n)
Definition fits.h:1236
const FitsKeyword * operator()(int n)
Definition fits.h:1233
const FitsKeyword * next()
Definition fits.h:1244
FitsKeywordList & kw
Definition fits.h:1249
const FitsKeyword * next(const char *x)
Definition fits.h:1239
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:232
static constexpr int mindblexp
Definition fits.h:448
static int get_comment(const char *s, int len, int &begpos)
static FITS::ValueType getfitstype(NoConvert< IComplex > x)
Definition fits.h:240
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:452
ReservedName
FITS Reserved Names.
Definition fits.h:289
static void l2f(void *, float *, int)
static FITS::ValueType getfitstype(NoConvert< float > x)
Definition fits.h:228
static void f2l(FitsBit *, void *, int)
static constexpr int maxfltexp
Definition fits.h:447
static void l2f(void *, char *, int)
static Bool isa_text(char c)
Definition fits.h:462
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:401
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:404
static FITS::ValueType getfitstype(NoConvert< short > x)
Definition fits.h:216
static ReservedFitsKeywordCollection & ResWord
Definition fits.h:376
static void f2l(long *, void *, int)
static int fitssize(FITS::ValueType t)
static FITS::ValueType getfitstype(NoConvert< DComplex > x)
Definition fits.h:244
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:468
static int ckaccum(float &, Int, int)
static void f2l(Complex *, void *, int)
static constexpr double maxdouble
Definition fits.h:405
FitsRecType
Types of FITS Records.
Definition fits.h:349
@ UnrecognizableRecord
Definition fits.h:353
@ BadBeginningRecord
Definition fits.h:351
@ SpecialRecord
Definition fits.h:354
static constexpr int maxdblexp
Definition fits.h:449
static FITS::ValueType getfitstype(NoConvert< unsigned char > x)
Definition fits.h:212
static constexpr float tenpowerF[39]
Definition fits.h:441
ValueType
FITS I/O Error message types.
Definition fits.h:180
static FITS::ValueType getfitstype(NoConvert< FitsVADesc > x)
Definition fits.h:248
static Bool isa_letter(char)
Definition fits.h:463
static void fstr2str(char *, const char *, int)
static FITS::ValueType getfitstype(NoConvert< FitsBit > x)
Definition fits.h:204
static void l2f(void *, long *, int)
static FITS::ValueType getfitstype(NoConvert< Complex > x)
Definition fits.h:236
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:200
static float tenF(Int, int)
Definition fits.h:472
static FITS::ValueType getfitstype(NoConvert< Int > x)
Definition fits.h:220
static void valstr(ostream &o, const ValueType &ty, const void *val)
static constexpr int minfltexp
Definition fits.h:446
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:451
static int get_value_id(const char *s, int l, int &pos)
FitsArrayOption
Options on FITS array manipulations.
Definition fits.h:374
static Bool isa_digit(char c)
Definition fits.h:460
static constexpr double tenpowerD[309]
Definition fits.h:409
static void l2f(void *, short *, int)
static constexpr int maxsigdigits
Definition fits.h:450
static FITS::ValueType getfitstype(NoConvert< long > x)
Definition fits.h:224
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:362
@ ImageExtensionHDU
Definition fits.h:368
@ PrimaryGroupHDU
Definition fits.h:365
@ AsciiTableHDU
Definition fits.h:366
@ BinaryTableHDU
Definition fits.h:367
@ PrimaryTableHDU
Definition fits.h:370
@ PrimaryArrayHDU
Definition fits.h:364
@ UnknownExtensionHDU
Definition fits.h:369
static void get_name(const char *s, int len, FitsNameResult &result)
static constexpr Int minInt
Definition fits.h:400
static void f2l(FitsLogical *, void *, int)
data conversion routines: FITS - local
static constexpr float maxfloat
Definition fits.h:403
FitsDevice
Supported FITS Physical Devices.
Definition fits.h:359
static void swap8(void *, void *, int)
static int digit2bin(char c)
Definition fits.h:461
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:464
static FITS::ValueType getfitstype(NoConvert< char > x)
Definition fits.h:208
static constexpr float minfloat
Definition fits.h:402
helper class for FITS Binary Tables
Definition fits.h:120
FitsBit(unsigned char x)
Definition fits.h:123
unsigned char bit_array
Definition fits.h:131
FitsBit & operator=(unsigned char x)
Definition fits.h:124
Utility functions for floating point values.
Definition fits.h:1294
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:1272
static void fmtcard(char *, const FitsKeyword &)
static constexpr int FitsRecSize
Definition fits.h:1274
int err_cardno(int) const
Definition fits.h:1289
FitsKeywordList & parse(const char *, FitsKeywordList &, int, FITSErrorHandler, Bool)
int build(char *, FitsKeywordList &)
static constexpr int FitsMaxCard
Definition fits.h:1273
const char * err(int) const
Definition fits.h:1288
linked list of FITS keywords
Definition fits.h:983
void end()
add the end card.
Definition fits.h:1223
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:1143
int rules(FitsKeyword &, FITSErrorHandler errhandler=FITSError::defaultHandler)
FitsKeyword * pos
Definition fits.h:1094
FitsKeyword * beg_
Definition fits.h:1092
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:1138
std::string toString() const
Convert the list to a string containing the 80-byte FITS headers.
FitsKeyword * curr()
Definition fits.h:1125
int no_parse_errs() const
Definition fits.h:1139
Bool isempty() const
Definition fits.h:1116
FitsKeywordList & operator=(const FitsKeywordList &)
void spaces(const char *n=0, const char *c=0)
add a spaces line
Definition fits.h:1210
void del()
delete the current keyword (the thing returned by curr()) from the list
const char * parse_err(int) const
Definition fits.h:1140
void insert(FitsKeyword &)
void comment(const char *n=0, const char *c=0)
add a comment card
Definition fits.h:1215
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:1220
FitsKeywordList(ConstFitsKeywordList &)
FitsKeyword * end_
Definition fits.h:1093
FITS keyword.
Definition fits.h:737
FitsKeyword(const FitsKeyword &)
A word about friends: FitsKeywordList accesses the next and prev pointers and the FitsKeyword constru...
Definition fits.h:859
Bool asBool() const
access the value of the keyword
Definition fits.h:892
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:811
const char * comm() const
access the keyword comment
Definition fits.h:887
const ReservedFitsKeyword * kw_
Definition fits.h:812
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:876
char * comm_
the keyword comment if comm_ is 0, there is no comment
Definition fits.h:820
void init(const FitsKeyword &)
FitsKeyword & operator=(const FitsKeyword &)
Definition fits.h:863
double asDouble() const
Definition fits.h:918
FitsKeyword * prev_
Definition fits.h:805
void setval(const FITS::ValueType &, const void *, int)
Int asInt() const
Definition fits.h:895
friend class FitsParse
Definition fits.h:739
Bool isindexed() const
Definition fits.h:884
int namelen() const
Definition fits.h:883
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:890
const char * asString() const
Definition fits.h:893
FITS::ValueType type_
the keyword value
Definition fits.h:826
int commlen() const
Definition fits.h:888
float asFloat() const
Definition fits.h:902
const void * value() const
void setcomm(const char *, int)
FitsKeyword & operator=(const char *)
static void memchk(void *)
Bool isreserved() const
Definition fits.h:877
int valStrlen() const
Definition fits.h:894
int err() const
access the error status
Definition fits.h:889
const char * name() const
get info about the name
Definition fits.h:880
DComplex asDComplex() const
Definition fits.h:936
void comm(const char *)
change the comment of the keyword
FitsKeyword * next_
Definition fits.h:804
int index() const
Definition fits.h:885
IComplex asIComplex() const
Definition fits.h:934
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:738
Complex asComplex() const
Definition fits.h:935
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:103
FitsLogical & operator=(Bool x)
Definition fits.h:96
FitsLogical(Bool x)
Definition fits.h:95
analyse the name of a header card
Definition fits.h:659
parse a header card
Definition fits.h:706
const char * err(int) const
Definition fits.h:726
int no_errs() const
Definition fits.h:725
int seterr(const char *)
Definition fits.h:727
FitsKeyword & parse(const char *, int)
const char ** err_
Definition fits.h:719
const int max_errs
Definition fits.h:718
friend class FitsKeywordList
Definition fits.h:707
FitsKeyword & mkerr(const char *s, int len)
Variable Length Array Descriptor.
Definition fits.h:138
friend ostream & operator<<(ostream &o, const FitsVADesc &)
FitsVADesc & operator=(const FitsVADesc &x)
Definition fits.h:144
int num() const
Definition fits.h:154
FitsVADesc(int n, int o)
Definition fits.h:149
FitsVADesc(const FitsVADesc &x)
Definition fits.h:143
int offset() const
Definition fits.h:155
void set(int n, int o)
Definition fits.h:150
analyse the value of a header card
Definition fits.h:678
const char * errmsg
Definition fits.h:696
FITS::ValueType type
Definition fits.h:680
void operator=(int)
Definition fits.h:66
collection of reserved FITS keywords
Definition fits.h:514
const ReservedFitsKeyword & history() const
Definition fits.h:648
static constexpr const ReservedFitsKeyword & spaces_item
Definition fits.h:613
int essential_name(const char *, int) const
const ReservedFitsKeyword & operator[](int i) const
Definition fits.h:626
const ReservedFitsKeyword & comment() const
Definition fits.h:645
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:617
static constexpr const ReservedFitsKeyword & user_def_item
Definition fits.h:610
static constexpr const ReservedFitsKeyword & end__item
Definition fits.h:612
const ReservedFitsKeyword & end_item() const
Definition fits.h:639
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:611
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:636
int isreserved(const char *, int) const
static constexpr int no_items
Definition fits.h:539
const ReservedFitsKeyword & get(const char *, int, Bool, FITS::ValueType, const void *, int, const char *&) const
const ReservedFitsKeyword & userdef_item() const
Definition fits.h:633
static constexpr const ReservedFitsKeyword & comment_item
Definition fits.h:614
const ReservedFitsKeyword & spaces() const
Definition fits.h:642
static constexpr ReservedFitsKeyword resword[56]
Discussion of Reserved FitsKeyword Table.
Definition fits.h:548
static constexpr const ReservedFitsKeyword & history_item
Definition fits.h:615
reserved FITS keyword
Definition fits.h:481
FITS::ValueType type() const
Definition fits.h:506
FITS::ReservedName name_
Definition fits.h:496
Bool isessential() const
Definition fits.h:508
FITS::ValueType type_
Definition fits.h:499
const char * aname() const
Definition fits.h:504
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:106
For temporary backward namespace compatibility, use casa as alias for casacore.
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.