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#ifdef _WIN32
28#define _TCHAR_DEFINED
29#define DLL_EXPORT __declspec(dllexport)
30#else
31#define DLL_EXPORT extern
32#endif
33
34#include <fitsio.h>
35
41typedef struct
42{
44 char typestr[8];
48 long repeat;
50 long width;
52
54typedef struct
55{
57 char *name;
59 char *format;
61 char *unit;
63 char *value;
65 char *comment;
67 char ** expected;
69
71typedef struct
72{
74 char *name;
76 char *format;
78 char *unit;
80 char *value;
82 char *comment;
84 char ** expected;
86
88typedef struct
89{
95
97typedef struct
98{
100 char *name;
102 char *format;
104 char *unit;
106 char *value;
108 char *comment;
110 struct
111 {
120 } definition;
122
124typedef struct
125{
127 char *name;
129 char *format;
131 char *value;
133 char *comment;
135 struct
136 {
145 } axes_definition;
147
149#ifndef itostr
150#define its(x) #x
151#define itostr(x) its(x)
152#endif
153
155#define EXTFITS_ELEMENT_STRING (dsp_fits_format){"A", TSTRING, 0, 0}
156#define EXTFITS_ELEMENT_LOGICAL (dsp_fits_format){"L", TLOGICAL, 0, 0}
157#define EXTFITS_ELEMENT_BIT (dsp_fits_format){"X", TBIT, 0, 0}
158#define EXTFITS_ELEMENT_BYTE (dsp_fits_format){"B", TBYTE, 0, 0}
159#define EXTFITS_ELEMENT_SBYTE (dsp_fits_format){"S", TSBYTE, 0, 0}
160#define EXTFITS_ELEMENT_SHORT (dsp_fits_format){"I", TSHORT, 0, 0}
161#define EXTFITS_ELEMENT_USHORT (dsp_fits_format){"U", TUSHORT, 0, 0}
162#define EXTFITS_ELEMENT_INT (dsp_fits_format){"J", TINT, 0, 0}
163#define EXTFITS_ELEMENT_UINT (dsp_fits_format){"V", TUINT, 0, 0}
164#define EXTFITS_ELEMENT_LONG (dsp_fits_format){"K", TLONG, 0, 0}
165#define EXTFITS_ELEMENT_FLOAT (dsp_fits_format){"E", TFLOAT, 0, 0}
166#define EXTFITS_ELEMENT_DOUBLE (dsp_fits_format){"D", TDOUBLE, 0, 0}
167#define EXTFITS_ELEMENT_COMPLEX (dsp_fits_format){"C", TCOMPLEX, 0, 0}
168#define EXTFITS_ELEMENT_DBLCOMPLEX (dsp_fits_format){"M", TDBLCOMPLEX, 0, 0}
169
171#define EXTFITS_MEASURE_UNIT_HZ "Hz"
172#define EXTFITS_MEASURE_UNIT_SECOND "sec"
173#define EXTFITS_MEASURE_UNIT_MINUTE "min"
174#define EXTFITS_MEASURE_UNIT_HOUR "hour"
175#define EXTFITS_MEASURE_UNIT_DAY "day"
176#define EXTFITS_MEASURE_UNIT_MONTH "month"
177#define EXTFITS_MEASURE_UNIT_YEAR "year"
178#define EXTFITS_MEASURE_UNIT_JANSKY "Jy"
179#define EXTFITS_MEASURE_UNIT_KELVIN "K"
180#define EXTFITS_MEASURE_UNIT_ANGSTROM "Angstrom"
181#define EXTFITS_MEASURE_UNIT_ARCSEC "arcsec"
182#define EXTFITS_MEASURE_UNIT_ARCMIN "arcmin"
183#define EXTFITS_MEASURE_UNIT_DEGREE "degree"
184#define EXTFITS_MEASURE_UNIT_PERCENT "percent"
185#define EXTFITS_MEASURE_UNIT_METER "meter"
186#define EXTFITS_MEASURE_UNIT_MILLIBAR "millibar"
187
189#define EXTFITS_KEYWORD_TTYPE(n) (dsp_fits_keyword){"TTYPE" itostr(n), "8A", "", "", "Set to 'FLUX'", (char*[]){"FLUX", "DATA", ""}}
191#define EXTFITS_KEYWORD_TUNIT(n) (dsp_fits_keyword){"TUNIT" itostr(n), "8A", "", "", "Shall have the value 'JY' or 'UNCALIB'", (char*[]){""}}
193#define EXTFITS_KEYWORD_TDIM(n) (dsp_fits_keyword){"TDIM" itostr(n), "8A", "", "", "Size in pixels of data buffer", (char*[]){""}}
195#define EXTFITS_KEYWORD_TFORM(n) (dsp_fits_keyword){"TFORM" itostr(n), "8A", "", "", "Shall be a character string", (char*[]){""}}
196
198#define EXTFITS_KEYWORD_CTYPE(m) (dsp_fits_keyword){"CTYPE" itostr(m), EXTFITS_ELEMENT_STRING.typestr, "", "", "Name of regular axis m = 1 to M", (char*[]){""}}
200#define EXTFITS_KEYWORD_CDELT(m) (dsp_fits_keyword){"CDELT" itostr(m), EXTFITS_ELEMENT_FLOAT.typestr, "", "", "Coordinate increment on axis m = 1 to M", (char*[]){""}}
202#define EXTFITS_KEYWORD_CRPIX(m) (dsp_fits_keyword){"CRPIX" itostr(m), EXTFITS_ELEMENT_FLOAT.typestr, "", "", "Reference pixel on axis m = 1 to M", (char*[]){""}}
204#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*[]){""}}
205
207#define EXTFITS_KEYWORD_NMATRIX (dsp_fits_keyword){"NMATRIX", EXTFITS_ELEMENT_SHORT.typestr, "", "1", "NMATRIX shall be present with the value 1", (char*[]){"1", ""}}
209#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)}}
211#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)}}
212
214#define EXTFITS_KEYWORD_OBJCTRA (dsp_fits_column){"OBJCTRA", EXTFITS_ELEMENT_STRING.typestr, EXTFITS_MEASURE_UNIT_DEGREE, "", "Target right ascension coordinate", (char*[]){""}}
216#define EXTFITS_KEYWORD_OBJCTDEC (dsp_fits_column){"OBJCTDEC", EXTFITS_ELEMENT_STRING.typestr, EXTFITS_MEASURE_UNIT_DEGREE, "", "Target declination coordinate", (char*[]){""}}
217
218#define FITS_KEYWORD_EXTEND (dsp_fits_keyword){"EXTEND", "A", "", "T", "", (char*[]){""}}
219#define FITS_KEYWORD_EXTNAME (dsp_fits_keyword){"EXTNAME", "", "", "", "", (char*[]){""}}
220
230DLL_EXPORT void dsp_fits_update_fits_key(fitsfile *fptr, int type, char* name, void *value, char* comment, int *status);
231
239DLL_EXPORT long dsp_fits_alloc_fits_rows(fitsfile *fptr, unsigned long num_rows);
240
252DLL_EXPORT int dsp_fits_fill_fits_col(fitsfile *fptr, char* name, unsigned char *buf, int typecode, long num_elements,
253 unsigned long rown);
254
262DLL_EXPORT int dsp_fits_append_fits_col(fitsfile *fptr, char* name, char* format);
263
269DLL_EXPORT void dsp_fits_delete_fits_col(fitsfile *fptr, char* name);
270
276DLL_EXPORT size_t dsp_fits_get_element_size(int typecode);
277
286DLL_EXPORT int dsp_fits_read_typecode(char* typestr, int *typecode, long *width, long *repeat);
287
296DLL_EXPORT int dsp_fits_get_value(fitsfile *fptr, char* column, long rown, void **retval);
297
306DLL_EXPORT int dsp_fits_check_column(fitsfile *fptr, char* column, char **expected, long rown);
307
314DLL_EXPORT fitsfile* dsp_fits_create_fits(size_t *size, void **buf);
315
324DLL_EXPORT int dsp_fits_add_table(fitsfile* fptr, dsp_fits_column *columns, int ncols, const char* tablename);
325
331DLL_EXPORT int dsp_fits_close_fits(fitsfile *fptr);
334#ifdef __cplusplus
335}
336#endif
337
338#endif //_DSP_FITS_H
DLL_EXPORT 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.
DLL_EXPORT int dsp_fits_close_fits(fitsfile *fptr)
Close a fits file pointer.
DLL_EXPORT int dsp_fits_append_fits_col(fitsfile *fptr, char *name, char *format)
Add a column to the binary table.
DLL_EXPORT 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.
DLL_EXPORT int dsp_fits_get_value(fitsfile *fptr, char *column, long rown, void **retval)
Obtain the value of the specified field.
DLL_EXPORT 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...
DLL_EXPORT int dsp_fits_read_typecode(char *typestr, int *typecode, long *width, long *repeat)
Decode a typecode format string.
DLL_EXPORT 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.
DLL_EXPORT fitsfile * dsp_fits_create_fits(size_t *size, void **buf)
Create an open fits file pointer to be updated later.
DLL_EXPORT 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.
DLL_EXPORT size_t dsp_fits_get_element_size(int typecode)
Obtain the single element size in bytes.
DLL_EXPORT void dsp_fits_delete_fits_col(fitsfile *fptr, char *name)
Delete a column from the binary table.
Binary table FITS Matrix axis.
Definition: fits.h:98
dsp_fits_keyword refpix
Data reference pixel.
Definition: fits.h:117
char * unit
Axis measure unit string.
Definition: fits.h:104
dsp_fits_keyword value
Data reference pixel value.
Definition: fits.h:119
char * name
Axis name.
Definition: fits.h:100
dsp_fits_keyword increment
Data increment step.
Definition: fits.h:115
dsp_fits_keyword name
Data name.
Definition: fits.h:113
char * comment
Axis description.
Definition: fits.h:108
char * value
Axis default value.
Definition: fits.h:106
char * format
Axis format string.
Definition: fits.h:102
Binary table FITS extension column.
Definition: fits.h:72
char * format
Format string of the content of the column (TFORM)
Definition: fits.h:76
char * comment
Description of the column or data.
Definition: fits.h:82
char * name
Name of the column (title, TTYPE)
Definition: fits.h:74
char * unit
Measure unit of the column elements (TUNIT)
Definition: fits.h:78
char ** expected
Expected values if checking when read.
Definition: fits.h:84
char * value
Default initial value.
Definition: fits.h:80
FITS format.
Definition: fits.h:42
int typecode
FITSIO typecode.
Definition: fits.h:46
long repeat
Number of repetitions.
Definition: fits.h:48
long width
Width of each element.
Definition: fits.h:50
FITS keyword.
Definition: fits.h:55
char * name
Name of the keyword.
Definition: fits.h:57
char * format
Format of the content of the keyword.
Definition: fits.h:59
char * comment
Description of the keyword or value.
Definition: fits.h:65
char * value
Value.
Definition: fits.h:63
char * unit
Measure unit of the value.
Definition: fits.h:61
char ** expected
Expected value if checking when read.
Definition: fits.h:67
Binary table FITS Matrix.
Definition: fits.h:125
char * name
Matrix name.
Definition: fits.h:127
char * value
Matrix measure unit string.
Definition: fits.h:131
char * comment
Matrix description.
Definition: fits.h:133
dsp_fits_keyword unit
Axes measure unit.
Definition: fits.h:142
dsp_fits_keyword dims
Axes quantity.
Definition: fits.h:144
dsp_fits_keyword name
Axes name.
Definition: fits.h:138
char * format
Matrix format string.
Definition: fits.h:129
dsp_fits_keyword format
Axes format.
Definition: fits.h:140
Binary table FITS extension row.
Definition: fits.h:89
size_t num_columns
Columns data.
Definition: fits.h:93
dsp_fits_column * columns
Columns array.
Definition: fits.h:91