Open source Very Long Baseline Interferometry
OpenVLBI
fits.h
1/*
2* DSP API - a digital signal processing library for astronomy usage
3* Copyright © 2017-2022 Ilia Platone
4*
5* This program is free software; you can redistribute it and/or
6* modify it under the terms of the GNU Lesser General Public
7* License as published by the Free Software Foundation; either
8* version 3 of the License, or (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13* Lesser General Public License for more details.
14*
15* You should have received a copy of the GNU Lesser General Public License
16* along with this program; if not, write to the Free Software Foundation,
17* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#ifndef _DSP_FITS_H
21#define _DSP_FITS_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#ifndef DLL_EXPORT
28#define DLL_EXPORT extern
29#endif
30
31#include <fitsio.h>
32
38typedef struct
39{
41 char typestr[8];
45 long repeat;
47 long width;
49
51typedef struct
52{
54 char *name;
56 char *format;
58 char *unit;
60 char *value;
62 char *comment;
64 char ** expected;
66
68typedef struct
69{
71 char *name;
73 char *format;
75 char *unit;
77 char *value;
79 char *comment;
81 char ** expected;
83
85typedef struct
86{
92
94typedef struct
95{
97 char *name;
99 char *format;
101 char *unit;
103 char *value;
105 char *comment;
107 struct
108 {
117 } definition;
119
121typedef struct
122{
124 char *name;
126 char *format;
128 char *value;
130 char *comment;
132 struct
133 {
142 } axes_definition;
144
146#ifndef itostr
147#define its(x) #x
148#define itostr(x) its(x)
149#endif
150
152#define EXTFITS_ELEMENT_STRING (dsp_fits_format){"A", TSTRING, 0, 0}
153#define EXTFITS_ELEMENT_LOGICAL (dsp_fits_format){"L", TLOGICAL, 0, 0}
154#define EXTFITS_ELEMENT_BIT (dsp_fits_format){"X", TBIT, 0, 0}
155#define EXTFITS_ELEMENT_BYTE (dsp_fits_format){"B", TBYTE, 0, 0}
156#define EXTFITS_ELEMENT_SBYTE (dsp_fits_format){"S", TSBYTE, 0, 0}
157#define EXTFITS_ELEMENT_SHORT (dsp_fits_format){"I", TSHORT, 0, 0}
158#define EXTFITS_ELEMENT_USHORT (dsp_fits_format){"U", TUSHORT, 0, 0}
159#define EXTFITS_ELEMENT_INT (dsp_fits_format){"J", TINT, 0, 0}
160#define EXTFITS_ELEMENT_UINT (dsp_fits_format){"V", TUINT, 0, 0}
161#define EXTFITS_ELEMENT_LONG (dsp_fits_format){"K", TLONG, 0, 0}
162#define EXTFITS_ELEMENT_FLOAT (dsp_fits_format){"E", TFLOAT, 0, 0}
163#define EXTFITS_ELEMENT_DOUBLE (dsp_fits_format){"D", TDOUBLE, 0, 0}
164#define EXTFITS_ELEMENT_COMPLEX (dsp_fits_format){"C", TCOMPLEX, 0, 0}
165#define EXTFITS_ELEMENT_DBLCOMPLEX (dsp_fits_format){"M", TDBLCOMPLEX, 0, 0}
166
168#define EXTFITS_MEASURE_UNIT_HZ "Hz"
169#define EXTFITS_MEASURE_UNIT_SECOND "sec"
170#define EXTFITS_MEASURE_UNIT_MINUTE "min"
171#define EXTFITS_MEASURE_UNIT_HOUR "hour"
172#define EXTFITS_MEASURE_UNIT_DAY "day"
173#define EXTFITS_MEASURE_UNIT_MONTH "month"
174#define EXTFITS_MEASURE_UNIT_YEAR "year"
175#define EXTFITS_MEASURE_UNIT_JANSKY "Jy"
176#define EXTFITS_MEASURE_UNIT_KELVIN "K"
177#define EXTFITS_MEASURE_UNIT_ANGSTROM "Angstrom"
178#define EXTFITS_MEASURE_UNIT_ARCSEC "arcsec"
179#define EXTFITS_MEASURE_UNIT_ARCMIN "arcmin"
180#define EXTFITS_MEASURE_UNIT_DEGREE "degree"
181#define EXTFITS_MEASURE_UNIT_PERCENT "percent"
182#define EXTFITS_MEASURE_UNIT_METER "meter"
183#define EXTFITS_MEASURE_UNIT_MILLIBAR "millibar"
184
186#define EXTFITS_KEYWORD_TTYPE(n) (dsp_fits_keyword){"TTYPE" itostr(n), "8A", "", "", "Set to 'FLUX'", (char*[]){"FLUX", "DATA", ""}}
188#define EXTFITS_KEYWORD_TUNIT(n) (dsp_fits_keyword){"TUNIT" itostr(n), "8A", "", "", "Shall have the value 'JY' or 'UNCALIB'", (char*[]){""}}
190#define EXTFITS_KEYWORD_TDIM(n) (dsp_fits_keyword){"TDIM" itostr(n), "8A", "", "", "Size in pixels of data buffer", (char*[]){""}}
192#define EXTFITS_KEYWORD_TFORM(n) (dsp_fits_keyword){"TFORM" itostr(n), "8A", "", "", "Shall be a character string", (char*[]){""}}
193
195#define EXTFITS_KEYWORD_CTYPE(m) (dsp_fits_keyword){"CTYPE" itostr(m), EXTFITS_ELEMENT_STRING.typestr, "", "", "Name of regular axis m = 1 to M", (char*[]){""}}
197#define EXTFITS_KEYWORD_CDELT(m) (dsp_fits_keyword){"CDELT" itostr(m), EXTFITS_ELEMENT_FLOAT.typestr, "", "", "Coordinate increment on axis m = 1 to M", (char*[]){""}}
199#define EXTFITS_KEYWORD_CRPIX(m) (dsp_fits_keyword){"CRPIX" itostr(m), EXTFITS_ELEMENT_FLOAT.typestr, "", "", "Reference pixel on axis m = 1 to M", (char*[]){""}}
201#define EXTFITS_KEYWORD_CRVAL(m) (dsp_fits_keyword){"CRVAL" itostr(m), EXTFITS_ELEMENT_FLOAT.typestr, "", "", "Coordinate value at reference pixel on axis m = 1 to M", (char*[]){""}}
202
204#define EXTFITS_KEYWORD_NMATRIX (dsp_fits_keyword){"NMATRIX", EXTFITS_ELEMENT_SHORT.typestr, "", "1", "NMATRIX shall be present with the value 1", (char*[]){"1", ""}}
206#define EXTFITS_KEYWORD_TMATX(n) (dsp_fits_matrix){"TMATX" itostr(n), "8A", "T", "Set to 'T'", {EXTFITS_KEYWORD_TTYPE(n), EXTFITS_KEYWORD_TFORM(n), EXTFITS_KEYWORD_TUNIT(n), EXTFITS_KEYWORD_TDIM(n)}}
208#define EXTFITS_KEYWORD_MAXIS(m) (dsp_fits_axis){"MAXIS" itostr(m), EXTFITS_ELEMENT_SHORT.typestr, "", "", "M = number axes in regular matrix, Number pixels on axis m = 1 to M", {EXTFITS_KEYWORD_CTYPE(m), EXTFITS_KEYWORD_CDELT(m), EXTFITS_KEYWORD_CRPIX(m), EXTFITS_KEYWORD_CRVAL(m)}}
209
211#define EXTFITS_KEYWORD_OBJCTRA (dsp_fits_column){"OBJCTRA", EXTFITS_ELEMENT_STRING.typestr, EXTFITS_MEASURE_UNIT_DEGREE, "", "Target right ascension coordinate", (char*[]){""}}
213#define EXTFITS_KEYWORD_OBJCTDEC (dsp_fits_column){"OBJCTDEC", EXTFITS_ELEMENT_STRING.typestr, EXTFITS_MEASURE_UNIT_DEGREE, "", "Target declination coordinate", (char*[]){""}}
214
215#define FITS_KEYWORD_EXTEND (dsp_fits_keyword){"EXTEND", "A", "", "T", "", (char*[]){""}}
216#define FITS_KEYWORD_EXTNAME (dsp_fits_keyword){"EXTNAME", "", "", "", "", (char*[]){""}}
217
227void dsp_fits_update_fits_key(fitsfile *fptr, int type, char* name, void *value, char* comment, int *status);
228
236long dsp_fits_alloc_fits_rows(fitsfile *fptr, unsigned long num_rows);
237
249int dsp_fits_fill_fits_col(fitsfile *fptr, char* name, unsigned char *buf, int typecode, long num_elements,
250 unsigned long rown);
251
259int dsp_fits_append_fits_col(fitsfile *fptr, char* name, char* format);
260
266void dsp_fits_delete_fits_col(fitsfile *fptr, char* name);
267
273size_t dsp_fits_get_element_size(int typecode);
274
283int dsp_fits_read_typecode(char* typestr, int *typecode, long *width, long *repeat);
284
293int dsp_fits_get_value(fitsfile *fptr, char* column, long rown, void **retval);
294
303int dsp_fits_check_column(fitsfile *fptr, char* column, char **expected, long rown);
304
311fitsfile* dsp_fits_create_fits(size_t *size, void **buf);
312
321int dsp_fits_add_table(fitsfile* fptr, dsp_fits_column *columns, int ncols, const char* tablename);
322
328int dsp_fits_close_fits(fitsfile *fptr);
331#ifdef __cplusplus
332}
333#endif
334
335#endif //_DSP_FITS_H
int dsp_fits_close_fits(fitsfile *fptr)
Close a fits file pointer.
void dsp_fits_update_fits_key(fitsfile *fptr, int type, char *name, void *value, char *comment, int *status)
Create or update a new fits header key.
int dsp_fits_check_column(fitsfile *fptr, char *column, char **expected, long rown)
Check if the value of the specified field corresponds to a subset of values.
int dsp_fits_fill_fits_col(fitsfile *fptr, char *name, unsigned char *buf, int typecode, long num_elements, unsigned long rown)
Fill a column at the given row position with the valued buffer.
long dsp_fits_alloc_fits_rows(fitsfile *fptr, unsigned long num_rows)
Convert an RGB color dsp_t array into a dsp_stream_p array each element containing the single compone...
int dsp_fits_add_table(fitsfile *fptr, dsp_fits_column *columns, int ncols, const char *tablename)
Add a binary table extension into a fits file.
fitsfile * dsp_fits_create_fits(size_t *size, void **buf)
Create an open fits file pointer to be updated later.
int dsp_fits_read_typecode(char *typestr, int *typecode, long *width, long *repeat)
Decode a typecode format string.
void dsp_fits_delete_fits_col(fitsfile *fptr, char *name)
Delete a column from the binary table.
int dsp_fits_append_fits_col(fitsfile *fptr, char *name, char *format)
Add a column to the binary table.
size_t dsp_fits_get_element_size(int typecode)
Obtain the single element size in bytes.
int dsp_fits_get_value(fitsfile *fptr, char *column, long rown, void **retval)
Obtain the value of the specified field.
Binary table FITS Matrix axis.
Definition: fits.h:95
dsp_fits_keyword refpix
Data reference pixel.
Definition: fits.h:114
char * unit
Axis measure unit string.
Definition: fits.h:101
dsp_fits_keyword value
Data reference pixel value.
Definition: fits.h:116
char * name
Axis name.
Definition: fits.h:97
dsp_fits_keyword increment
Data increment step.
Definition: fits.h:112
dsp_fits_keyword name
Data name.
Definition: fits.h:110
char * comment
Axis description.
Definition: fits.h:105
char * value
Axis default value.
Definition: fits.h:103
char * format
Axis format string.
Definition: fits.h:99
Binary table FITS extension column.
Definition: fits.h:69
char * format
Format string of the content of the column (TFORM)
Definition: fits.h:73
char * comment
Description of the column or data.
Definition: fits.h:79
char * name
Name of the column (title, TTYPE)
Definition: fits.h:71
char * unit
Measure unit of the column elements (TUNIT)
Definition: fits.h:75
char ** expected
Expected values if checking when read.
Definition: fits.h:81
char * value
Default initial value.
Definition: fits.h:77
FITS format.
Definition: fits.h:39
int typecode
FITSIO typecode.
Definition: fits.h:43
long repeat
Number of repetitions.
Definition: fits.h:45
long width
Width of each element.
Definition: fits.h:47
FITS keyword.
Definition: fits.h:52
char * name
Name of the keyword.
Definition: fits.h:54
char * format
Format of the content of the keyword.
Definition: fits.h:56
char * comment
Description of the keyword or value.
Definition: fits.h:62
char * value
Value.
Definition: fits.h:60
char * unit
Measure unit of the value.
Definition: fits.h:58
char ** expected
Expected value if checking when read.
Definition: fits.h:64
Binary table FITS Matrix.
Definition: fits.h:122
char * name
Matrix name.
Definition: fits.h:124
char * value
Matrix measure unit string.
Definition: fits.h:128
char * comment
Matrix description.
Definition: fits.h:130
dsp_fits_keyword unit
Axes measure unit.
Definition: fits.h:139
dsp_fits_keyword dims
Axes quantity.
Definition: fits.h:141
dsp_fits_keyword name
Axes name.
Definition: fits.h:135
char * format
Matrix format string.
Definition: fits.h:126
dsp_fits_keyword format
Axes format.
Definition: fits.h:137
Binary table FITS extension row.
Definition: fits.h:86
size_t num_columns
Columns data.
Definition: fits.h:90
dsp_fits_column * columns
Columns array.
Definition: fits.h:88