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