This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
funtoolsP.h
343 lines (309 loc) · 9.99 KB
/
funtoolsP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
* Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
*/
/*
*
* funtools.h
*
*/
#ifndef __funtoolsP_h
#define __funtoolsP_h
#if HAVE_CONFIG_H
#include "conf.h"
#endif
#include <stdio.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#if HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <sys/types.h>
#include "prsetup.h"
#define USE_XFILEIO 1
#include "fitsy.h"
#undef USE_XFILEIO
#include "wcs.h"
#include "filter.h"
#include "file.h"
#include "swap.h"
#include "word.h"
#include "parse.h"
#include "xalloc.h"
#include "mkrtemp.h"
#include "NaN.h"
#include "xlaunch.h"
#ifndef MAXINT
#define MAXINT 2147483647
#endif
#ifndef MININT
#define MININT (-MAXINT - 1)
#endif
#ifndef MAXDBL
#define MAXDBL 1.7976931348623157E+308
#endif
#ifndef MINDBL
#define MINDBL (-MAXDBL)
#endif
/* blocking types */
#define FUN_SUM 1
#define FUN_AVG 2
/* merge types */
#define MERGE_UPDATE 1
#define MERGE_REPLACE 2
#define MERGE_APPEND 4
/* special "region" column info */
#define COL_REGION_NAME "$REGION"
#define COL_REGION_ONAME "REGION"
#define COL_REGION_ID -1
#define COL_NUM_NAME "$N"
#define COL_NUM_ONAME "N"
#define COL_NUM_ID -2
#define COL_UNKNOWN_ID -100
/* image data types */
#define TY_CHAR 1
#define TY_USHORT -2
#define TY_SHORT 2
#define TY_INT 4
#define TY_LONG 8
#define TY_FLOAT -4
#define TY_DOUBLE -8
/* list types for multi-file list support */
#define LIST_NONE 0
#define LIST_FILEORDER 1
#define LIST_SORT 2
#define LIST_TRYSORT 3
#define LIST_UNSORT 4
/* values for scaled flag */
#define FUN_SCALE_EXISTS 1
#define FUN_SCALE_APPLIED 2
/* for a table, do we have an array of structs or a struct of arrays? */
#define FUN_ORG_AOS 1
#define FUN_ORG_SOA 2
/* the usual */
#ifndef DEFAULT_TMPDIR
#define DEFAULT_TMPDIR "/tmp"
#endif
/* max number of ifun links to a single ifun struct */
#define FUN_MAXBFUN 1024
/* max number of columns in a file */
#define FUN_MAXCOL 1000
/* max buffer size when allocating memory to read rows */
#define FUN_MAXBUFSIZE 5000000
/* validation */
#define FUN_MAGIC 14285
#define FUN_VALID(fun) (fun && (*(short *)fun == FUN_MAGIC))
/* save buffer for reading multiple input files from one FunOpen() */
typedef struct savebufstruct{
struct savebufstruct *next;
int type;
int nrow;
char *ebuf;
unsigned char *rbuf;
} *SaveBuf, SaveBufRec;
/* columns record */
typedef struct funcolrec {
char *name;
int order;
int type;
int from;
int ofrom;
int mode;
int n;
int offset;
int width;
int tcol;
int tindex;
int poff;
double tlmin;
double tlmax;
double binsiz;
int doblank; /* do we have a BLANK value? */
int tblank; /* blank value */
int scaled; /* valid bscale, bzero values exist */
double tscale; /* bscale value */
double tzero; /* bzero value */
char *tunit;
char *tctyp;
char *tcrvl;
char *tcdlt;
char *tcrpx;
char *tcrot;
char *vla;
} *FunCol, FunColRec;
/*
*
*
* funtools record structure
*
*/
typedef struct funrec {
/* magic MUST be first */
short magic; /* magic number identifying this as fun */
/* top level file info */
char *fname; /* file name */
char *mode; /* open mode */
int type; /* file type -- see above */
int bitpix; /* FITS bitpix defines data type */
double min1, max1; /* x limits for whole image or table */
double min2, max2; /* y limits for whole image or table */
double binsiz1, binsiz2; /* binsize for tables */
int dims; /* number of image dimensions */
int dim1, dim2; /* image dimensions */
int endian; /* 0=little, 1=big */
char *filter; /* filter info from bracket spec */
FITSHead header; /* underlying fitsy handle */
FITSHead theader; /* temp fitsy handle */
FITSHead primary; /* fitsy handle for *output* of primary */
GIO gio; /* I/O handle */
struct WorldCoor *wcs; /* WCS info -- converted to image */
struct WorldCoor *wcs0; /* WCS info -- unconverted to image */
char *activate; /* activation flag */
off_t datastart; /* starting position in file for data */
/* param-specific info */
int doprim; /* write to primary header */
int doraw; /* get raw value */
/* image-specific info */
off_t curpos; /* current position into image */
int primio; /* flag that the primary header was written */
int dtype; /* type of data -- see fits.h */
int dlen; /* length of data buffer */
int dpad; /* length of data padding */
int doblank; /* do we have a BLANK value? */
int blank; /* blank value */
int scaled; /* valid bscale, bzero values exist */
double bscale; /* bscale value */
double bzero; /* bzero value */
/* table-specific info */
char *bincols; /* binning columns string */
int bin[3]; /* pointers to column offsets for binning */
int vbin; /* column offset for val column when binning */
int vop; /* operator to apply to vcol binning */
int overflow; /* how many times we overflowed when binning */
int ncol; /* current nuber of selected columns */
int rowsize; /* size in bytes of selected column records */
int maxbufsize; /* max size of buffer holding columns */
int transparent; /* is mask transparent? */
int org; /* array of structs or struct of arrays? */
int idx; /* should we use filter index if found? */
FunCol *cols; /* selected columns */
off_t headpos; /* position in file for header start */
/* array/table specific info */
int total; /* number of rows in input table */
int left; /* number of rows left to process in table */
int io; /* count of number of putrows */
int skip; /* bytes to skip (for arrays) */
off_t bytes; /* count of bytes output via putrows */
/* text file info */
int nparser; /* number of parsers */
Parse *parsers; /* array of parsers */
/* raw row data buffer */
int rawsize; /* size in bytes of one (input) table row */
int rawbufsize; /* size in bytes of evbuf holding raw rows */
unsigned char *rawbuf; /* raw row buffer */
int dofilt; /* whether to run events through the filter */
Filter filt; /* filter handle */
int nmask; /* number of image masks */
FilterMask masks; /* image masks */
/* binning/section info */
int x0, x1, y0, y1, block, btype;
int odims;
int odim1, odim2;
int obitpix, odtype;
/* input/output info */
/* whether we convert data when moving from file to native */
int iconvert, oconvert;
/* input fun struct that we used to open */
struct funrec *ifun;
/* back-links to structs which use this struct as a reference */
struct funrec *bfun[FUN_MAXBFUN];
/* flag that we are copying all extensions from input */
int icopy;
/* whether we merge back into raw input data */
int merge;
/* operations performed on this handle */
int ops;
/* list support */
int ltype; /* see LIST_XXX above */
int lmem; /* amount of memory for saved buffers */
int ifd; /* ifd of this gio for select() */
struct funrec *head; /* list head, where "global" info resides */
struct funrec *current; /* currently active member: stored in head */
struct funrec *next; /* next member in linked list */
SaveBuf save; /* linked list of save buffers */
FILE *lefp; /* temp file for saved overflow (user data) */
FILE *lrfp; /* temp file for saved overflow (raw data) */
/* view support */
char *view; /* original view */
char *vcols; /* view columns */
char *vfmt; /* view format */
} *Fun, FunRec;
#define FUNTOOLS_PRIVATE 1
_PRbeg
/* funopen.c */
Fun _FunFITSOpen _PRx((Fun ifun, char *fname, char *mode));
/* funim.c */
void *_FunImageMask _PRx((Fun fun, void *buf, int rstart, int rstop,
FilterMask masks, int nmask, char *mode));
int _FunImagePutHeader _PRx((Fun fun, int dim1, int dim2, int bitpix));
/* funtab.c */
void *_FunRead _PRx((Fun fun, char *buf, size_t size, size_t get, size_t *got));
void _FunSaveNaxis2 _PRx((Fun fun));
int _FunFixNaxis2 _PRx((Fun fun));
int _FunTablePutHeader _PRx((Fun fun));
/* funcol.c */
void _FunColumnHeader _PRx((Fun fun, FunCol *cols, int ncol));
void _FunColumnFree _PRx((Fun fun));
/* funcopy.c */
void _FunCopyBinDelete _PRx((FITSHead header, int n));
int _FunCopy2ImageHeader _PRx((Fun from, Fun to));
/* funutils.c */
int _FunPrimaryExtension _PRx((Fun fun));
void _FunParseSection _PRx((Fun fun, char *section,
int *min1, int *max1, int *min2, int *max2,
int *block, int *btype, char *tail, int maxlen));
int _FunColumnDims _PRx((char *s, int type, double *tlmin, double *tlmax,
double *binsiz, int *dims,
double *tscale, double *tzero, int *scaled));
void _FunColumnType _PRx((char *s, int *type, int *n,
double *tlmin, double *tlmax,
double *binsiz, int *dims,
double *tscale, double *tzero, int *scaled,
int *ptype, int *poff));
int _FunFile _PRx((char *lbuf, char *tbuf, int len, int *lptr));
void * _FunSwap _PRx((void *obuf, void *ibuf, int width, int type));
/* funtext.c */
Fun FunTextOpen _PRx((char *fname, char *mode, char *iline, GIO ifd));
int FunTextParam _PRx((char *pdelims, char *lbuf,
char *kbuf, char *vbuf, char *cbuf, int maxlen));
void FunTextParamHeader _PRx((FITSHead theader, char *lbuf,
char *key, char *val, char *com, int pgot));
/* funopenp.c */
Fun _FunNew _PRx((void));
int _FunSpecialFile _PRx((char *fname, char *type,
char *name, char *tail, char *extn, int mlen));
int _FunRowNum _PRx((Fun fun, char *tail, char *env));
int _FunTableBinCols _PRx((Fun fun, char *tail, char *env));
int _FunTableValCol _PRx((Fun fun, char *tail, char *env));
FITSHead _FunRawEvHeader _PRx((Fun fun,
char *iname, char *iext, char *eventdef));
off_t _FunImageSkip _PRx((Fun fun, char *tail));
Fun _FunValid _PRx((Fun fun));
void _FunFree _PRx((Fun fun, int flag));
int _FunImageSize _PRx((Fun fun));
int _FunMaxBufSize _PRx((Fun fun, char *tail));
int _FunOpenCommon _PRx((Fun fun));
/* funvu.c */
int FunView _PRx((Fun fun, char *view, char *vmode, char *fname, int fmax));
_PRend
#include "funtools.h"
#endif /* __funtoolsP.h */