public software.psfex

[/] [branches/] [rhl/] [src/] [fits/] [fitscat.h] - Blame information for rev 191

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 bertin
/*
2 157 bertin
*                               fitscat.h
3 2 bertin
*
4 157 bertin
* Main include file for the LDACTools FITS library.
5 2 bertin
*
6 157 bertin
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 2 bertin
*
8 157 bertin
*       This file part of:      AstrOmatic FITS/LDAC library
9 2 bertin
*
10 176 bertin
*       Copyright:              (C) 1995-2012 Emmanuel Bertin -- IAP/CNRS/UPMC
11 2 bertin
*
12 157 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 185 bertin
*       Last modified:          29/08/2012
27 157 bertin
*
28
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
29 2 bertin
 
30
#ifndef _FITSCAT_H_
31
#define _FITSCAT_H_
32
 
33 176 bertin
#include <stdio.h>
34
 
35 2 bertin
#ifdef HAVE_SYS_TYPES_H
36
#include <sys/types.h>
37
#endif
38
 
39
#define MAXCHARS        256     /* max. number of characters */
40 34 bertin
#define WARNING_NMAX    1000    /* max. number of recorded warnings */
41 2 bertin
 
42
/*---------------------------- return messages ------------------------------*/
43
 
44
#ifndef RETURN_OK
45
#define RETURN_OK               0
46
#endif
47
#ifndef RETURN_ERROR
48
#define RETURN_ERROR            (-1)
49
#endif
50
#ifndef RETURN_FATAL_ERROR
51
#define RETURN_FATAL_ERROR      (-2)
52
#endif
53
 
54
/*--------------------------- FITS BitPix coding ----------------------------*/
55
 
56
#define         BP_BYTE         8
57
#define         BP_SHORT        16
58
#define         BP_LONG         32
59 144 bertin
#define         BP_LONGLONG     64
60 2 bertin
#define         BP_FLOAT        (-32)
61
#define         BP_DOUBLE       (-64)
62
 
63
/*-------------------------------- macros -----------------------------------*/
64
 
65
/* Standard FITS name suffix*/
66
 
67
#define         FITS_SUFFIX             ".fits" 
68
 
69
/* size (in bytes) of one FITS block */
70
 
71
#define         FBSIZE          2880L   
72
 
73
/* FITS size after adding padding */
74
 
75
#define         PADTOTAL(x)     (((x-1)/FBSIZE+1)*FBSIZE)
76
 
77
/* extra size to add for padding */
78
 
79
#define         PADEXTRA(x)     ((FBSIZE - (x%FBSIZE))% FBSIZE)
80
 
81
/*--------------------------------- typedefs --------------------------------*/
82
 
83
typedef enum            {H_INT, H_FLOAT, H_EXPO, H_BOOL, H_STRING, H_STRINGS,
84
                        H_COMMENT, H_HCOMMENT, H_KEY}   h_type;
85
                                                /* type of FITS-header data */
86 144 bertin
typedef enum            {T_BYTE, T_SHORT, T_LONG, T_LONGLONG,
87
                        T_FLOAT, T_DOUBLE, T_STRING}
88 2 bertin
                                t_type;         /* Type of data */
89
typedef enum            {WRITE_ONLY, READ_ONLY}
90 185 bertin
                                access_type_t;  /* Type of access */
91 2 bertin
typedef enum            {SHOW_ASCII, SHOW_SKYCAT}
92
                                output_type;    /* Type of output */
93
 
94
typedef float           PIXTYPE;                /* Pixel type */
95 144 bertin
typedef unsigned int    FLAGTYPE;               /* Flag type */
96 2 bertin
 
97 144 bertin
#ifdef  HAVE_UNSIGNED_LONG_LONG_INT
98
typedef unsigned long long              KINGSIZE_T;     /* for large sizes */
99
typedef unsigned long long              ULONGLONG;
100 2 bertin
#else
101 144 bertin
typedef size_t                          KINGSIZE_T;/* better than nothing */
102
typedef union {unsigned int l[2];}      ULONGLONG;
103 2 bertin
#endif
104 144 bertin
#ifdef HAVE_LONG_LONG_INT
105 176 bertin
typedef long long                       SLONGLONG;
106 2 bertin
#else
107 176 bertin
typedef union {int l[2];}               SLONGLONG;
108 2 bertin
#endif
109
 
110 176 bertin
#if defined(_FILE_OFFSET_BITS) && !defined(OFF_T)
111 2 bertin
#define OFF_T   off_t
112
#else
113 176 bertin
#define OFF_T   long
114 2 bertin
#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 4 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 185 bertin
  access_type_t access_type;            /* READ_ONLY or WRITE_ONLY */
153 2 bertin
  }             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 4 bertin
                error_installfunc(void (*func)(char *msg1, char *msg2)),
222 2 bertin
                fixexponent(char *s),
223
                free_body(tabstruct *tab),
224
                free_cat(catstruct **cat, int ncat),
225
                free_key(keystruct *key),
226
                free_tab(tabstruct *tab),
227
                init_writeobj(catstruct *cat, tabstruct *tab, char **pbuf),
228
                install_cleanup(void (*func)(void)),
229
                print_obj(FILE *stream, tabstruct *tab),
230
                read_keys(tabstruct *tab, char **keynames, keystruct **keys,
231
                        int nkeys, unsigned char *mask),
232
                read_basic(tabstruct *tab),
233
                read_body(tabstruct *tab, PIXTYPE *ptr, size_t size),
234 144 bertin
                read_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size),
235 2 bertin
                readbasic_head(tabstruct *tab),
236
                remove_cleanupfilename(char *filename),
237
                save_cat(catstruct *cat, char *filename),
238
                save_tab(catstruct *cat, tabstruct *tab),
239
                show_keys(tabstruct *tab, char **keynames, keystruct **keys,
240
                        int nkeys, unsigned char *mask, FILE *stream,
241
                        int strflag,int banflag, int leadflag,
242
                        output_type o_type),
243
                swapbytes(void *, int, int),
244
                ttypeconv(void *ptrin, void *ptrout,
245
                        t_type ttypein, t_type ttypeout),
246 4 bertin
                voprint_obj(FILE *stream, tabstruct *tab),
247 2 bertin
                warning(char *, char *),
248
                write_body(tabstruct *tab, PIXTYPE *ptr, size_t size),
249 176 bertin
                write_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size),
250 2 bertin
                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 4 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 185 bertin
                open_cat(catstruct *cat, access_type_t at),
296 2 bertin
                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 32 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 176 bertin
extern FLAGTYPE *alloc_ibody(tabstruct *tab,
326
                        void (*func)(FLAGTYPE *ptr, int npix));
327
 
328 2 bertin
extern t_type   ttypeof(char *str);
329
 
330
extern  void    error(int, char *, char *),
331
                swapbytes(void *ptr, int nb, int n),
332
                warning(char *msg1, char *msg2);
333
 
334
 
335
int             bswapflag;
336
 
337
#endif