24 fits_update_key(fptr,
type, name, p, explanation, status);
31 fits_get_num_rows(fptr, &nrows, &status);
32 fits_insert_rows(fptr, nrows, num_rows, &status);
37 int dsp_fits_fill_fits_col(fitsfile *fptr,
char* name,
unsigned char *buf,
int typecode,
long num_elements,
unsigned long rown)
41 fits_get_colnum(fptr, CASESEN, (
char*)(name), &ncol, &status);
42 if(status != COL_NOT_FOUND)
44 fits_write_col(fptr, typecode, ncol, rown, 1, num_elements, buf, &status);
53 fits_get_colnum(fptr, CASESEN, (
char*)(name), &ncols, &status);
54 if(status == COL_NOT_FOUND)
56 fits_get_num_cols(fptr, &ncols, &status);
57 fits_insert_col(fptr, ncols++, name, format, &status);
66 fits_get_colnum(fptr, CASESEN, (
char*)(name), &ncol, &status);
67 while(status != COL_NOT_FOUND)
68 fits_delete_col(fptr, ncol, &status);
73 fitsfile *fptr = NULL;
77 char error_status[64];
81 void* memptr = malloc(memsize);
84 perr(
"Error: failed to allocate memory: %lu", (
unsigned long)(memsize));
87 fits_create_memfile(&fptr, &memptr, &memsize, 2880, realloc, &status);
91 fits_get_errstatus(status, error_status);
92 perr(
"FITS Error: %s", error_status);
99 fits_get_errstatus(status, error_status);
100 perr(
"FITS Error: %s", error_status);
108 fits_get_errstatus(status, error_status);
109 perr(
"FITS Error: %s", error_status);
124 fits_close_file(fptr, &status);
131 int err = 1, n = 0, anynul = 0, status = 0, typecode;
137 fits_get_colname(fptr, 0, column, name, &n, &status);
140 fits_get_coltype(fptr, n, &typecode, &repeat, &width, &status);
142 fits_read_col(fptr, typecode, n, rown, 1, repeat, NULL, value, &anynul, &status);
150 int err = 1, n = 0, anynul = 0, status = 0, x, y, typecode;
154 if(column == NULL || expected == NULL)
156 fits_get_colname(fptr, 0, column, name, &n, &status);
159 fits_get_coltype(fptr, n, &typecode, &repeat, &width, &status);
160 if(typecode != TSTRING)
162 char **value = (
char **)malloc(
sizeof(
char*)*(size_t)repeat);
163 for(x = 0; x < repeat; x++) {
164 value[x] = (
char*) malloc((
size_t)width);
165 fits_read_col_str(fptr, n, rown, 1, 1, NULL, value, &anynul, &status);
166 for(y = 0; strcmp(expected[y],
""); y++) {
167 if(!strcmp(value[x], expected[y])) {
175 for(x = 0; x < repeat; x++)
184 int err = 1, status = 0, y;
186 if(keyname == NULL || expected == NULL)
188 fits_read_key_str(fptr, keyname, value, NULL, &status);
191 for(y = 0; strcmp(expected[y],
""); y++) {
192 if(!strcmp(value, expected[y])) {
207 sscanf(typestr,
"%d%c%d", &w, &c, &r);
279 fits_update_key(fptr, TSTRING,
"EXTNAME", tablename,
"", &status);
280 for(x = 0; x < ncols; x++) {
288 fitsfile *fptr = (fitsfile*)malloc(
sizeof(fitsfile));
289 memset(fptr, 0,
sizeof(fitsfile));
304 long naxes[3] = { 1, 1, 1 };
309 char error_status[64];
311 fits_open_file(&fptr, filename, READONLY, &status);
353 fits_movabs_hdu(fptr, 1, &sdfits_hdu, &status);
354 if(status || sdfits_hdu != BINARY_TBL)
359 fits_read_key_str(fptr,
"EXTNAME", value, comment, &status);
370 fits_get_num_rows(fptr, &nrows, &status);
376 fits_get_num_cols(fptr, &ncols, &status);
383 if(status || nmatrix < 1)
391 for(r = 0; r < nrows; r++) {
392 for(k = 0; k < ncols; k++) {
393 columns[k].
name = (
char*)malloc(150);
394 columns[k].
format = (
char*)malloc(150);
395 columns[k].
unit = (
char*)malloc(150);
396 columns[k].
value = (
char*)malloc(150);
397 columns[k].
comment = (
char*)malloc(150);
401 strcpy(columns[k].name, value);
405 long *sizes =(
long*)malloc(
sizeof(
long)*(size_t)max_dims);
406 fits_read_tdim(fptr, k, max_dims, &dims, sizes, &status);
410 sizes = (
long*)malloc(
sizeof(
long)*(size_t)dims);
411 for(dim = 0; dim < d; dim++)
418 strcpy(columns[k].format, tcs);
420 strcpy(columns[k].unit, tcs);
424 for(dim = 0; dim < dims; dim++) {
425 nelements *= naxes[dim];
427 columns[k].
value = (
char*)malloc(element_size*(
size_t)nelements);
428 fits_read_col(fptr, typecode, k, r, 1, nelements, NULL, columns->
value, &anynul, &status);
429 if(!anynul && !status) {
430 *maxis = (
long*)malloc(
sizeof(
long)*(size_t)dims);
431 for(dim = 0; dim < dims; dim++)
432 *maxis[dim] = naxes[dim];
440 fits_get_eqcoltype(fptr, n, &typecode, &repeat, &width, &status);
444 void *val = &columns[k].
value;
453 fits_close_file(fptr, &status);
462 fits_get_errstatus(status, error_status);
463 perr(
"FITS Error: %s\n", error_status);
int dsp_fits_append_table(fitsfile *fptr, dsp_fits_column *columns, int ncols, char *tablename)
int dsp_fits_check_key(fitsfile *fptr, char *keyname, char **expected)
#define SDFITS_KEYWORD_DATE_OBS
UT date of observation (dd/mm/yy) .
#define SDFITS_TABLE_MAIN
#define SDFITS_KEYWORD_DATAMAX
Max spectral value (K) - for whole file.
#define FITS_TABLE_SDFITS
SDFITS Convention Table.
#define SDFITS_KEYWORD_OBSERVER
Name of observer.
#define SDFITS_KEYWORD_DATAMIN
Min spectral value (K) - for whole file.
dsp_fits_row * dsp_fits_read_sdfits(char *filename, long *num_rows, long *maxes, long **maxis)
read a fits file containing a SDFITS Extension
#define SDFITS_KEYWORD_TELESCOP
int dsp_fits_close_fits(fitsfile *fptr)
Close a fits file pointer.
#define EXTFITS_ELEMENT_LOGICAL
void dsp_fits_update_fits_key(fitsfile *fptr, int type, char *name, void *p, char *explanation, int *status)
Create or update a new fits header key.
#define EXTFITS_KEYWORD_MAXIS(m)
M = number axes in regular matrix, Number pixels on axis m = 1 to M.
#define EXTFITS_ELEMENT_FLOAT
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.
#define EXTFITS_ELEMENT_INT
#define EXTFITS_ELEMENT_COMPLEX
#define EXTFITS_KEYWORD_TMATX(n)
Set to 'T' — column n contains the visibility matrix.
#define EXTFITS_ELEMENT_LONG
#define FITS_KEYWORD_EXTEND
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...
fitsfile * dsp_fits_create_fits(size_t *size, void **buf)
Create an open fits file pointer to be updated later.
#define EXTFITS_KEYWORD_NMATRIX
NMATRIX shall be present with the value 1.
#define EXTFITS_ELEMENT_DBLCOMPLEX
#define EXTFITS_ELEMENT_UINT
#define EXTFITS_ELEMENT_USHORT
#define EXTFITS_ELEMENT_SHORT
#define EXTFITS_ELEMENT_BIT
int dsp_fits_read_typecode(char *typestr, int *typecode, long *width, long *repeat)
Decode a typecode format string.
#define EXTFITS_ELEMENT_STRING
FITS element types.
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.
#define EXTFITS_ELEMENT_SBYTE
size_t dsp_fits_get_element_size(int typecode)
Obtain the single element size in bytes.
#define EXTFITS_ELEMENT_BYTE
#define EXTFITS_ELEMENT_DOUBLE
int dsp_fits_get_value(fitsfile *fptr, char *column, long rown, void **retval)
Obtain the value of the specified field.
Binary table FITS extension column.
char * format
Format string of the content of the column (TFORM)
char * comment
Description of the column or data.
char * name
Name of the column (title, TTYPE)
char * unit
Measure unit of the column elements (TUNIT)
char * value
Default initial value.
Binary table FITS extension row.
size_t num_columns
Columns data.
dsp_fits_column * columns
Columns array.