| 1 |
2 |
bertin |
/*
|
| 2 |
233 |
bertin |
* fitscat.h
|
| 3 |
2 |
bertin |
*
|
| 4 |
233 |
bertin |
* Main include file for the LDACTools FITS library.
|
| 5 |
2 |
bertin |
*
|
| 6 |
233 |
bertin |
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 7 |
2 |
bertin |
*
|
| 8 |
233 |
bertin |
* This file part of: AstrOmatic FITS/LDAC library
|
| 9 |
2 |
bertin |
*
|
| 10 |
235 |
bertin |
* Copyright: (C) 1995-2010 Emmanuel Bertin -- IAP/CNRS/UPMC
|
| 11 |
2 |
bertin |
*
|
| 12 |
233 |
bertin |
* License: GNU General Public License
|
| 13 |
|
|
*
|
| 14 |
|
|
* AstrOmatic software is free software: you can redistribute it and/or
|
| 15 |
|
|
* modify it under the terms of the GNU General Public License as
|
| 16 |
|
|
* published by the Free Software Foundation, either version 3 of the
|
| 17 |
|
|
* License, or (at your option) any later version.
|
| 18 |
|
|
* AstrOmatic software is distributed in the hope that it will be useful,
|
| 19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
* GNU General Public License for more details.
|
| 22 |
|
|
* You should have received a copy of the GNU General Public License
|
| 23 |
|
|
* along with AstrOmatic software.
|
| 24 |
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
| 25 |
|
|
*
|
| 26 |
|
|
* Last modified: 09/10/2010
|
| 27 |
|
|
*
|
| 28 |
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
| 29 |
2 |
bertin |
|
| 30 |
|
|
#ifndef _FITSCAT_H_
|
| 31 |
|
|
#define _FITSCAT_H_
|
| 32 |
|
|
|
| 33 |
|
|
#ifdef HAVE_SYS_TYPES_H
|
| 34 |
|
|
#include <sys/types.h>
|
| 35 |
|
|
#endif
|
| 36 |
|
|
|
| 37 |
|
|
#define MAXCHARS 256 /* max. number of characters */
|
| 38 |
173 |
bertin |
#define WARNING_NMAX 1000 /* max. number of recorded warnings */
|
| 39 |
2 |
bertin |
|
| 40 |
|
|
/*---------------------------- return messages ------------------------------*/
|
| 41 |
|
|
|
| 42 |
|
|
#ifndef RETURN_OK
|
| 43 |
|
|
#define RETURN_OK 0
|
| 44 |
|
|
#endif
|
| 45 |
|
|
#ifndef RETURN_ERROR
|
| 46 |
|
|
#define RETURN_ERROR (-1)
|
| 47 |
|
|
#endif
|
| 48 |
|
|
#ifndef RETURN_FATAL_ERROR
|
| 49 |
|
|
#define RETURN_FATAL_ERROR (-2)
|
| 50 |
|
|
#endif
|
| 51 |
|
|
|
| 52 |
|
|
/*--------------------------- FITS BitPix coding ----------------------------*/
|
| 53 |
|
|
|
| 54 |
|
|
#define BP_BYTE 8
|
| 55 |
|
|
#define BP_SHORT 16
|
| 56 |
|
|
#define BP_LONG 32
|
| 57 |
215 |
bertin |
#define BP_LONGLONG 64
|
| 58 |
2 |
bertin |
#define BP_FLOAT (-32)
|
| 59 |
|
|
#define BP_DOUBLE (-64)
|
| 60 |
|
|
|
| 61 |
|
|
/*-------------------------------- macros -----------------------------------*/
|
| 62 |
|
|
|
| 63 |
|
|
/* Standard FITS name suffix*/
|
| 64 |
|
|
|
| 65 |
|
|
#define FITS_SUFFIX ".fits"
|
| 66 |
|
|
|
| 67 |
|
|
/* size (in bytes) of one FITS block */
|
| 68 |
|
|
|
| 69 |
|
|
#define FBSIZE 2880L
|
| 70 |
|
|
|
| 71 |
|
|
/* FITS size after adding padding */
|
| 72 |
|
|
|
| 73 |
|
|
#define PADTOTAL(x) (((x-1)/FBSIZE+1)*FBSIZE)
|
| 74 |
|
|
|
| 75 |
|
|
/* extra size to add for padding */
|
| 76 |
|
|
|
| 77 |
|
|
#define PADEXTRA(x) ((FBSIZE - (x%FBSIZE))% FBSIZE)
|
| 78 |
|
|
|
| 79 |
|
|
/*--------------------------------- typedefs --------------------------------*/
|
| 80 |
|
|
|
| 81 |
|
|
typedef enum {H_INT, H_FLOAT, H_EXPO, H_BOOL, H_STRING, H_STRINGS,
|
| 82 |
|
|
H_COMMENT, H_HCOMMENT, H_KEY} h_type;
|
| 83 |
|
|
/* type of FITS-header data */
|
| 84 |
215 |
bertin |
typedef enum {T_BYTE, T_SHORT, T_LONG, T_LONGLONG,
|
| 85 |
|
|
T_FLOAT, T_DOUBLE, T_STRING}
|
| 86 |
2 |
bertin |
t_type; /* Type of data */
|
| 87 |
|
|
typedef enum {WRITE_ONLY, READ_ONLY}
|
| 88 |
|
|
access_type; /* Type of access */
|
| 89 |
|
|
typedef enum {SHOW_ASCII, SHOW_SKYCAT}
|
| 90 |
|
|
output_type; /* Type of output */
|
| 91 |
|
|
|
| 92 |
|
|
typedef float PIXTYPE; /* Pixel type */
|
| 93 |
173 |
bertin |
typedef unsigned int FLAGTYPE; /* Flag type */
|
| 94 |
2 |
bertin |
|
| 95 |
215 |
bertin |
#ifdef HAVE_UNSIGNED_LONG_LONG_INT
|
| 96 |
|
|
typedef unsigned long long KINGSIZE_T; /* for large sizes */
|
| 97 |
|
|
typedef unsigned long long ULONGLONG;
|
| 98 |
2 |
bertin |
#else
|
| 99 |
215 |
bertin |
typedef size_t KINGSIZE_T;/* better than nothing */
|
| 100 |
|
|
typedef union {unsigned int l[2];} ULONGLONG;
|
| 101 |
2 |
bertin |
#endif
|
| 102 |
215 |
bertin |
#ifdef HAVE_LONG_LONG_INT
|
| 103 |
|
|
typedef long long KINGLONG; /* for large sizes */
|
| 104 |
|
|
typedef long long LONGLONG;
|
| 105 |
2 |
bertin |
#else
|
| 106 |
215 |
bertin |
typedef long KINGLONG;/* better than nothing */
|
| 107 |
|
|
typedef union {int l[2];} LONGLONG;
|
| 108 |
2 |
bertin |
#endif
|
| 109 |
|
|
|
| 110 |
|
|
#if _FILE_OFFSET_BITS
|
| 111 |
|
|
#define OFF_T off_t
|
| 112 |
|
|
#else
|
| 113 |
|
|
#define OFF_T KINGLONG
|
| 114 |
|
|
#endif
|
| 115 |
|
|
|
| 116 |
|
|
/*------------------------------- constants ---------------------------------*/
|
| 117 |
|
|
|
| 118 |
|
|
extern const int t_size[]; /* size in bytes per t_type (see fitshead.c) */
|
| 119 |
|
|
|
| 120 |
|
|
/*---------------------------------- key ------------------------------------*/
|
| 121 |
|
|
|
| 122 |
|
|
typedef struct structkey
|
| 123 |
|
|
{
|
| 124 |
|
|
char name[80]; /* name */
|
| 125 |
|
|
char comment[80]; /* a comment */
|
| 126 |
|
|
void *ptr; /* pointer to the data */
|
| 127 |
|
|
h_type htype; /* standard ``h_type'' (display) */
|
| 128 |
|
|
t_type ttype; /* standard ``t_type'' (storage) */
|
| 129 |
|
|
char printf[80]; /* printing format (C Convention) */
|
| 130 |
|
|
char unit[80]; /* physical unit */
|
| 131 |
11 |
bertin |
char voucd[80]; /* VO ucd */
|
| 132 |
|
|
char vounit[80]; /* VO unit */
|
| 133 |
2 |
bertin |
int naxis; /* number of dimensions */
|
| 134 |
|
|
int *naxisn; /* pointer to an array of dim. */
|
| 135 |
|
|
int nobj; /* number of objects */
|
| 136 |
|
|
int nbytes; /* number of bytes per element */
|
| 137 |
|
|
long pos; /* position within file */
|
| 138 |
|
|
struct structkey *prevkey; /* previous key within the chain */
|
| 139 |
|
|
struct structkey *nextkey; /* next key within the chain */
|
| 140 |
|
|
struct structtab *tab; /* (original) parent tab */
|
| 141 |
|
|
int allocflag; /* true if ptr dynamically allocated */
|
| 142 |
|
|
} keystruct;
|
| 143 |
|
|
|
| 144 |
|
|
/*------------------------------- catalog ---------------------------------*/
|
| 145 |
|
|
|
| 146 |
|
|
typedef struct structcat
|
| 147 |
|
|
{
|
| 148 |
|
|
char filename[MAXCHARS]; /* file name */
|
| 149 |
|
|
FILE *file; /* pointer to the file structure */
|
| 150 |
|
|
struct structtab *tab; /* pointer to the first table */
|
| 151 |
|
|
int ntab; /* number of tables included */
|
| 152 |
|
|
access_type access_type; /* READ_ONLY or WRITE_ONLY */
|
| 153 |
|
|
} catstruct;
|
| 154 |
|
|
|
| 155 |
|
|
/*-------------------------------- table ----------------------------------*/
|
| 156 |
|
|
|
| 157 |
|
|
typedef struct structtab
|
| 158 |
|
|
{
|
| 159 |
|
|
int bitpix; /* bits per element */
|
| 160 |
|
|
int bytepix; /* bytes per element */
|
| 161 |
|
|
int bitsgn; /* = 0 if unsigned data */
|
| 162 |
|
|
double bscale; /* data scale factor */
|
| 163 |
|
|
double bzero; /* data offset parameter */
|
| 164 |
|
|
int blank; /* integer code for undefined values */
|
| 165 |
|
|
int blankflag; /* set if a blank keyword was found */
|
| 166 |
|
|
enum {COMPRESS_NONE, COMPRESS_BASEBYTE, COMPRESS_PREVPIX}
|
| 167 |
|
|
compress_type; /* image compression type */
|
| 168 |
|
|
char *compress_buf; /* de-compression buffer */
|
| 169 |
|
|
char *compress_bufptr; /* present pixel in buffer */
|
| 170 |
|
|
int compress_curval; /* current pixel or checksum value */
|
| 171 |
|
|
int compress_checkval; /* foreseen pixel or checksum value */
|
| 172 |
|
|
size_t compress_npix; /* remaining pixels in buffer */
|
| 173 |
|
|
int naxis; /* number of dimensions */
|
| 174 |
|
|
int *naxisn; /* array of dimensions */
|
| 175 |
|
|
int tfields; /* number of fields */
|
| 176 |
|
|
int pcount, gcount; /* alignment of the data */
|
| 177 |
|
|
KINGSIZE_T tabsize; /* total table size (bytes) */
|
| 178 |
|
|
char xtension[82]; /* FITS extension type */
|
| 179 |
|
|
char extname[82]; /* FITS extension name */
|
| 180 |
|
|
char *headbuf; /* buffer containing the header */
|
| 181 |
|
|
int headnblock; /* number of FITS blocks */
|
| 182 |
|
|
char *bodybuf; /* buffer containing the body */
|
| 183 |
|
|
OFF_T bodypos; /* position of the body in the file */
|
| 184 |
|
|
OFF_T headpos; /* position of the head in the file */
|
| 185 |
|
|
struct structcat *cat; /* (original) parent catalog */
|
| 186 |
|
|
struct structtab *prevtab, *nexttab; /* previous and next tab in chain */
|
| 187 |
|
|
int seg; /* segment position */
|
| 188 |
|
|
int nseg; /* number of tab segments */
|
| 189 |
|
|
keystruct *key; /* pointer to keys */
|
| 190 |
|
|
int nkey; /* number of keys */
|
| 191 |
|
|
int swapflag; /* mapped to a swap file ? */
|
| 192 |
|
|
char swapname[MAXCHARS]; /* name of the swapfile */
|
| 193 |
|
|
unsigned int bodysum; /* Checksum of the FITS body */
|
| 194 |
|
|
} tabstruct;
|
| 195 |
|
|
|
| 196 |
|
|
|
| 197 |
|
|
/*------------------------------- functions ---------------------------------*/
|
| 198 |
|
|
|
| 199 |
|
|
extern catstruct *new_cat(int ncat),
|
| 200 |
|
|
*read_cat(char *filename),
|
| 201 |
|
|
*read_cats(char **filenames, int ncat);
|
| 202 |
|
|
|
| 203 |
|
|
extern tabstruct *asc2bin_tab(catstruct *catin, char *tabinname,
|
| 204 |
|
|
catstruct *catout, char *taboutname),
|
| 205 |
|
|
*init_readobj(tabstruct *tab, char **pbuf),
|
| 206 |
|
|
*name_to_tab(catstruct *cat, char *tabname, int seg),
|
| 207 |
|
|
*new_tab(char *tabname),
|
| 208 |
|
|
*pos_to_tab(catstruct *cat, int pos, int seg);
|
| 209 |
|
|
|
| 210 |
|
|
extern keystruct *name_to_key(tabstruct *tab, char *keyname),
|
| 211 |
|
|
*new_key(char *keyname),
|
| 212 |
|
|
*pos_to_key(tabstruct *tab, int pos),
|
| 213 |
|
|
*read_key(tabstruct *tab, char *keyname);
|
| 214 |
|
|
|
| 215 |
|
|
extern void add_cleanupfilename(char *filename),
|
| 216 |
|
|
cleanup_files(void),
|
| 217 |
|
|
copy_tab_fromptr(tabstruct *tabin, catstruct *catout, int pos),
|
| 218 |
|
|
encode_checksum(unsigned int sum, char *str),
|
| 219 |
|
|
end_readobj(tabstruct *keytab, tabstruct *tab, char *buf),
|
| 220 |
|
|
end_writeobj(catstruct *cat, tabstruct *tab, char *buf),
|
| 221 |
|
|
error(int, char *, char *),
|
| 222 |
11 |
bertin |
error_installfunc(void (*func)(char *msg1, char *msg2)),
|
| 223 |
2 |
bertin |
fixexponent(char *s),
|
| 224 |
|
|
free_body(tabstruct *tab),
|
| 225 |
|
|
free_cat(catstruct **cat, int ncat),
|
| 226 |
|
|
free_key(keystruct *key),
|
| 227 |
|
|
free_tab(tabstruct *tab),
|
| 228 |
|
|
init_writeobj(catstruct *cat, tabstruct *tab, char **pbuf),
|
| 229 |
|
|
install_cleanup(void (*func)(void)),
|
| 230 |
|
|
print_obj(FILE *stream, tabstruct *tab),
|
| 231 |
|
|
read_keys(tabstruct *tab, char **keynames, keystruct **keys,
|
| 232 |
|
|
int nkeys, unsigned char *mask),
|
| 233 |
|
|
read_basic(tabstruct *tab),
|
| 234 |
|
|
read_body(tabstruct *tab, PIXTYPE *ptr, size_t size),
|
| 235 |
173 |
bertin |
read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size),
|
| 236 |
2 |
bertin |
readbasic_head(tabstruct *tab),
|
| 237 |
|
|
remove_cleanupfilename(char *filename),
|
| 238 |
|
|
save_cat(catstruct *cat, char *filename),
|
| 239 |
|
|
save_tab(catstruct *cat, tabstruct *tab),
|
| 240 |
|
|
show_keys(tabstruct *tab, char **keynames, keystruct **keys,
|
| 241 |
|
|
int nkeys, unsigned char *mask, FILE *stream,
|
| 242 |
|
|
int strflag,int banflag, int leadflag,
|
| 243 |
|
|
output_type o_type),
|
| 244 |
|
|
swapbytes(void *, int, int),
|
| 245 |
|
|
ttypeconv(void *ptrin, void *ptrout,
|
| 246 |
|
|
t_type ttypein, t_type ttypeout),
|
| 247 |
11 |
bertin |
voprint_obj(FILE *stream, tabstruct *tab),
|
| 248 |
2 |
bertin |
warning(char *, char *),
|
| 249 |
|
|
write_body(tabstruct *tab, PIXTYPE *ptr, size_t size),
|
| 250 |
|
|
write_checksum(tabstruct *tab);
|
| 251 |
|
|
|
| 252 |
|
|
extern char *tdisptoprintf(char *tdisp, char *str),
|
| 253 |
|
|
*printftotdisp(char *cprintf, char *str),
|
| 254 |
|
|
*fitsnfind(char *fitsbuf, char *str, int nblock),
|
| 255 |
|
|
**tabs_list(catstruct *cat, int *n),
|
| 256 |
12 |
bertin |
**keys_list(tabstruct *tab, int *n),
|
| 257 |
|
|
*warning_history(void);
|
| 258 |
2 |
bertin |
|
| 259 |
|
|
extern unsigned int
|
| 260 |
|
|
compute_blocksum(char *buf, unsigned int sum),
|
| 261 |
|
|
compute_bodysum(tabstruct *tab, unsigned int sum),
|
| 262 |
|
|
decode_checksum(char *str);
|
| 263 |
|
|
|
| 264 |
|
|
extern int about_cat(catstruct *cat, FILE *stream),
|
| 265 |
|
|
about_tab(catstruct *cat, char *tabname, FILE *stream),
|
| 266 |
|
|
addhistoryto_cat(catstruct *cat, char *str),
|
| 267 |
|
|
add_key(keystruct *key, tabstruct *tab, int pos),
|
| 268 |
|
|
addkeyto_head(tabstruct *tab, keystruct *key),
|
| 269 |
|
|
addkeywordto_head(tabstruct *tab, char *keyword,char *comment),
|
| 270 |
|
|
add_tab(tabstruct *tab, catstruct *cat, int pos),
|
| 271 |
|
|
blank_keys(tabstruct *tab),
|
| 272 |
|
|
close_cat(catstruct *cat),
|
| 273 |
|
|
copy_key(tabstruct *tabin, char *keyname, tabstruct *tabout,
|
| 274 |
|
|
int pos),
|
| 275 |
|
|
copy_tab(catstruct *catin, char *tabname, int seg,
|
| 276 |
|
|
catstruct *catout, int pos),
|
| 277 |
|
|
copy_tabs(catstruct *catin, catstruct *catout),
|
| 278 |
|
|
copy_tabs_blind(catstruct *catin, catstruct *catout),
|
| 279 |
|
|
ext_head(tabstruct *tab),
|
| 280 |
|
|
findkey(char *, char *, int),
|
| 281 |
|
|
findnkey(char *, char *, int, int),
|
| 282 |
|
|
fitsadd(char *fitsbuf, char *keyword, char *comment),
|
| 283 |
|
|
fitsfind(char *fitsbuf, char *keyword),
|
| 284 |
|
|
fitspick(char *fitsbuf, char *keyword, void *ptr,
|
| 285 |
|
|
h_type *htype, t_type *ttype, char *comment),
|
| 286 |
|
|
fitsread(char *fitsbuf, char *keyword, void *ptr,
|
| 287 |
|
|
h_type htype, t_type ttype),
|
| 288 |
|
|
fitsremove(char *fitsbuf, char *keyword),
|
| 289 |
|
|
fitswrite(char *fitsbuf, char *keyword, void *ptr,
|
| 290 |
|
|
h_type htype, t_type ttype),
|
| 291 |
|
|
get_head(tabstruct *tab),
|
| 292 |
|
|
inherit_cat(catstruct *catin, catstruct *catout),
|
| 293 |
|
|
init_cat(catstruct *cat),
|
| 294 |
|
|
map_cat(catstruct *cat),
|
| 295 |
|
|
open_cat(catstruct *cat, access_type at),
|
| 296 |
|
|
pad_tab(catstruct *cat, KINGSIZE_T size),
|
| 297 |
|
|
prim_head(tabstruct *tab),
|
| 298 |
|
|
readbintabparam_head(tabstruct *tab),
|
| 299 |
|
|
read_field(tabstruct *tab, char **keynames, keystruct **keys,
|
| 300 |
|
|
int nkeys, int field, tabstruct *ftab),
|
| 301 |
|
|
read_obj(tabstruct *keytab, tabstruct *tab, char *buf),
|
| 302 |
|
|
read_obj_at(tabstruct *keytab, tabstruct *tab, char *buf,
|
| 303 |
|
|
long pos),
|
| 304 |
|
|
remove_key(tabstruct *tab, char *keyname),
|
| 305 |
|
|
remove_keys(tabstruct *tab),
|
| 306 |
173 |
bertin |
removekeywordfrom_head(tabstruct *tab, char *keyword),
|
| 307 |
2 |
bertin |
remove_tab(catstruct *cat, char *tabname, int seg),
|
| 308 |
|
|
remove_tabs(catstruct *cat),
|
| 309 |
|
|
save_head(catstruct *cat, tabstruct *tab),
|
| 310 |
|
|
set_maxram(size_t maxram),
|
| 311 |
|
|
set_maxvram(size_t maxvram),
|
| 312 |
|
|
set_swapdir(char *dirname),
|
| 313 |
|
|
tab_row_len(char *, char *),
|
| 314 |
|
|
tformof(char *str, t_type ttype, int n),
|
| 315 |
|
|
tsizeof(char *str),
|
| 316 |
|
|
update_head(tabstruct *tab),
|
| 317 |
|
|
update_tab(tabstruct *tab),
|
| 318 |
|
|
verify_checksum(tabstruct *tab),
|
| 319 |
|
|
write_obj(tabstruct *tab, char *buf),
|
| 320 |
|
|
wstrncmp(char *, char *, int);
|
| 321 |
|
|
|
| 322 |
|
|
extern PIXTYPE *alloc_body(tabstruct *tab,
|
| 323 |
|
|
void (*func)(PIXTYPE *ptr, int npix));
|
| 324 |
|
|
|
| 325 |
|
|
extern t_type ttypeof(char *str);
|
| 326 |
|
|
|
| 327 |
|
|
extern void error(int, char *, char *),
|
| 328 |
|
|
swapbytes(void *ptr, int nb, int n),
|
| 329 |
|
|
warning(char *msg1, char *msg2);
|
| 330 |
|
|
|
| 331 |
|
|
|
| 332 |
|
|
int bswapflag;
|
| 333 |
|
|
|
| 334 |
|
|
#endif
|