Open source Very Long Baseline Interferometry
OpenVLBI
Loading...
Searching...
No Matches
fits.h
1/* OpenVLBI - Open Source Very Long Baseline Interferometry
2* Copyright © 2017-2023 Ilia Platone
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License along
15* with this program; if not, write to the Free Software Foundation, Inc.,
16* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17*/
18
19#ifndef _DSP_FITS_H
20#define _DSP_FITS_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#ifdef _WIN32
27#define _TCHAR_DEFINED
28#endif
29
30#include <fitsio.h>
31
37typedef struct
38{
40 char typestr[8];
44 long repeat;
46 long width;
48
50typedef struct
51{
53 char *name;
55 char *format;
57 char *unit;
59 char *value;
61 char *comment;
63 char ** expected;
65
67typedef struct
68{
70 char *name;
72 char *format;
74 char *unit;
76 char *value;
78 char *comment;
80 char ** expected;
82
84typedef struct
85{
91
118
120typedef struct
121{
123 char *name;
125 char *format;
127 char *value;
129 char *comment;
131 struct
132 {
141 } axes_definition;
143
145#ifndef itostr
146#define its(x) #x
147#define itostr(x) its(x)
148#endif
149
151#define EXTFITS_ELEMENT_STRING (dsp_fits_format){"A", TSTRING, 0, 0}
152#define EXTFITS_ELEMENT_LOGICAL (dsp_fits_format){"L", TLOGICAL, 0, 0}
153#define EXTFITS_ELEMENT_BIT (dsp_fits_format){"X", TBIT, 0, 0}
154#define EXTFITS_ELEMENT_BYTE (dsp_fits_format){"B", TBYTE, 0, 0}
155#define EXTFITS_ELEMENT_SBYTE (dsp_fits_format){"S", TSBYTE, 0, 0}
156#define EXTFITS_ELEMENT_SHORT (dsp_fits_format){"I", TSHORT, 0, 0}
157#define EXTFITS_ELEMENT_USHORT (dsp_fits_format){"U", TUSHORT, 0, 0}
158#define EXTFITS_ELEMENT_INT (dsp_fits_format){"J", TINT, 0, 0}
159#define EXTFITS_ELEMENT_UINT (dsp_fits_format){"V", TUINT, 0, 0}
160#define EXTFITS_ELEMENT_LONG (dsp_fits_format){"K", TLONG, 0, 0}
161#define EXTFITS_ELEMENT_FLOAT (dsp_fits_format){"E", TFLOAT, 0, 0}
162#define EXTFITS_ELEMENT_DOUBLE (dsp_fits_format){"D", TDOUBLE, 0, 0}
163#define EXTFITS_ELEMENT_COMPLEX (dsp_fits_format){"C", TCOMPLEX, 0, 0}
164#define EXTFITS_ELEMENT_DBLCOMPLEX (dsp_fits_format){"M", TDBLCOMPLEX, 0, 0}
165
167#define EXTFITS_MEASURE_UNIT_HZ "Hz"
168#define EXTFITS_MEASURE_UNIT_SECOND "sec"
169#define EXTFITS_MEASURE_UNIT_MINUTE "min"
170#define EXTFITS_MEASURE_UNIT_HOUR "hour"
171#define EXTFITS_MEASURE_UNIT_DAY "day"
172#define EXTFITS_MEASURE_UNIT_MONTH "month"
173#define EXTFITS_MEASURE_UNIT_YEAR "year"
174#define EXTFITS_MEASURE_UNIT_JANSKY "Jy"
175#define EXTFITS_MEASURE_UNIT_KELVIN "K"
176#define EXTFITS_MEASURE_UNIT_ANGSTROM "Angstrom"
177#define EXTFITS_MEASURE_UNIT_ARCSEC "arcsec"
178#define EXTFITS_MEASURE_UNIT_ARCMIN "arcmin"
179#define EXTFITS_MEASURE_UNIT_DEGREE "degree"
180#define EXTFITS_MEASURE_UNIT_PERCENT "percent"
181#define EXTFITS_MEASURE_UNIT_METER "meter"
182#define EXTFITS_MEASURE_UNIT_MILLIBAR "millibar"
183
185#define EXTFITS_KEYWORD_TTYPE(n) (dsp_fits_keyword){"TTYPE" itostr(n), "8A", "", "", "Set to 'FLUX'", (char*[]){"FLUX", "DATA", ""}}
187#define EXTFITS_KEYWORD_TUNIT(n) (dsp_fits_keyword){"TUNIT" itostr(n), "8A", "", "", "Shall have the value 'JY' or 'UNCALIB'", (char*[]){""}}
189#define EXTFITS_KEYWORD_TDIM(n) (dsp_fits_keyword){"TDIM" itostr(n), "8A", "", "", "Size in pixels of data buffer", (char*[]){""}}
191#define EXTFITS_KEYWORD_TFORM(n) (dsp_fits_keyword){"TFORM" itostr(n), "8A", "", "", "Shall be a character string", (char*[]){""}}
192
194#define EXTFITS_KEYWORD_CTYPE(m) (dsp_fits_keyword){"CTYPE" itostr(m), EXTFITS_ELEMENT_STRING.typestr, "", "", "Name of regular axis m = 1 to M", (char*[]){""}}
196#define EXTFITS_KEYWORD_CDELT(m) (dsp_fits_keyword){"CDELT" itostr(m), EXTFITS_ELEMENT_FLOAT.typestr, "", "", "Coordinate increment on axis m = 1 to M", (char*[]){""}}
198#define EXTFITS_KEYWORD_CRPIX(m) (dsp_fits_keyword){"CRPIX" itostr(m), EXTFITS_ELEMENT_FLOAT.typestr, "", "", "Reference pixel on axis m = 1 to M", (char*[]){""}}
200#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*[]){""}}
201
203#define EXTFITS_KEYWORD_NMATRIX (dsp_fits_keyword){"NMATRIX", EXTFITS_ELEMENT_SHORT.typestr, "", "1", "NMATRIX shall be present with the value 1", (char*[]){"1", ""}}
205#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)}}
207#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)}}
208
210#define EXTFITS_KEYWORD_OBJCTRA (dsp_fits_column){"OBJCTRA", EXTFITS_ELEMENT_STRING.typestr, EXTFITS_MEASURE_UNIT_DEGREE, "", "Target right ascension coordinate", (char*[]){""}}
212#define EXTFITS_KEYWORD_OBJCTDEC (dsp_fits_column){"OBJCTDEC", EXTFITS_ELEMENT_STRING.typestr, EXTFITS_MEASURE_UNIT_DEGREE, "", "Target declination coordinate", (char*[]){""}}
213
214#define FITS_KEYWORD_EXTEND (dsp_fits_keyword){"EXTEND", "A", "", "T", "", (char*[]){""}}
215#define FITS_KEYWORD_EXTNAME (dsp_fits_keyword){"EXTNAME", "", "", "", "", (char*[]){""}}
216
226DLL_EXPORT void dsp_fits_update_fits_key(fitsfile *fptr, int type, char* name, void *value, char* comment, int *status);
227
235DLL_EXPORT long dsp_fits_alloc_fits_rows(fitsfile *fptr, unsigned long num_rows);
236
248DLL_EXPORT int dsp_fits_fill_fits_col(fitsfile *fptr, char* name, unsigned char *buf, int typecode, long num_elements,
249 unsigned long rown);
250
258DLL_EXPORT int dsp_fits_append_fits_col(fitsfile *fptr, char* name, char* format);
259
265DLL_EXPORT void dsp_fits_delete_fits_col(fitsfile *fptr, char* name);
266
272DLL_EXPORT size_t dsp_fits_get_element_size(int typecode);
273
282DLL_EXPORT int dsp_fits_read_typecode(char* typestr, int *typecode, long *width, long *repeat);
283
292DLL_EXPORT int dsp_fits_get_value(fitsfile *fptr, char* column, long rown, void **retval);
293
302DLL_EXPORT int dsp_fits_check_column(fitsfile *fptr, char* column, char **expected, long rown);
303
310DLL_EXPORT fitsfile* dsp_fits_create_fits(size_t *size, void **buf);
311
320DLL_EXPORT int dsp_fits_add_table(fitsfile* fptr, dsp_fits_column *columns, int ncols, const char* tablename);
321
327DLL_EXPORT int dsp_fits_close_fits(fitsfile *fptr);
330#ifdef __cplusplus
331}
332#endif
333
334#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:94
dsp_fits_keyword refpix
Data reference pixel.
Definition fits.h:113
char * unit
Axis measure unit string.
Definition fits.h:100
dsp_fits_keyword value
Data reference pixel value.
Definition fits.h:115
char * name
Axis name.
Definition fits.h:96
dsp_fits_keyword increment
Data increment step.
Definition fits.h:111
dsp_fits_keyword name
Data name.
Definition fits.h:109
char * comment
Axis description.
Definition fits.h:104
char * value
Axis default value.
Definition fits.h:102
char * format
Axis format string.
Definition fits.h:98
Binary table FITS extension column.
Definition fits.h:68
char * format
Format string of the content of the column (TFORM)
Definition fits.h:72
char * comment
Description of the column or data.
Definition fits.h:78
char * name
Name of the column (title, TTYPE)
Definition fits.h:70
char * unit
Measure unit of the column elements (TUNIT)
Definition fits.h:74
char ** expected
Expected values if checking when read.
Definition fits.h:80
char * value
Default initial value.
Definition fits.h:76
FITS format.
Definition fits.h:38
int typecode
FITSIO typecode.
Definition fits.h:42
long repeat
Number of repetitions.
Definition fits.h:44
long width
Width of each element.
Definition fits.h:46
FITS keyword.
Definition fits.h:51
char * name
Name of the keyword.
Definition fits.h:53
char * format
Format of the content of the keyword.
Definition fits.h:55
char * comment
Description of the keyword or value.
Definition fits.h:61
char * value
Value.
Definition fits.h:59
char * unit
Measure unit of the value.
Definition fits.h:57
char ** expected
Expected value if checking when read.
Definition fits.h:63
Binary table FITS Matrix.
Definition fits.h:121
char * name
Matrix name.
Definition fits.h:123
char * value
Matrix measure unit string.
Definition fits.h:127
char * comment
Matrix description.
Definition fits.h:129
dsp_fits_keyword unit
Axes measure unit.
Definition fits.h:138
dsp_fits_keyword dims
Axes quantity.
Definition fits.h:140
dsp_fits_keyword name
Axes name.
Definition fits.h:134
char * format
Matrix format string.
Definition fits.h:125
dsp_fits_keyword format
Axes format.
Definition fits.h:136
Binary table FITS extension row.
Definition fits.h:85
size_t num_columns
Columns data.
Definition fits.h:89
dsp_fits_column * columns
Columns array.
Definition fits.h:87