00001 #ifndef _DR_H
00002 #define _DR_H
00003
00004
00005
00006
00007
00008 #define dr_lib_version ("0.0")
00009
00010
00011
00012
00013
00014 #if defined __linux__
00015 # define IEEE
00016 # define IEEE_EL
00017 # undef IEEE_EB
00018
00019 #else
00020 # undef IEEE
00021 # undef IEEE_EL
00022 # undef IEEE_EB
00023 #endif
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #if defined IEEE_EL
00034 typedef union {
00035 double d;
00036 struct {
00037 unsigned int frac2:32;
00038 unsigned int frac1:16;
00039 unsigned int frac : 3;
00040 unsigned int quiet: 1;
00041 unsigned int exp :11;
00042 unsigned int sign : 1;
00043 } NaN_mask;
00044 struct {
00045 unsigned int frac1:32;
00046 unsigned int frac :20;
00047 unsigned int exp :11;
00048 unsigned int sign : 1;
00049 } fp_mask;
00050 } dNaN;
00051 typedef union {
00052 float f;
00053 struct {
00054 unsigned int frac1:16;
00055 unsigned int frac : 6;
00056 unsigned int quiet: 1;
00057 unsigned int exp : 8;
00058 unsigned int sign : 1;
00059 } NaN_mask;
00060 struct {
00061 unsigned int frac :23;
00062 unsigned int exp : 8;
00063 unsigned int sign : 1;
00064 } fp_mask;
00065 } fNaN;
00066
00067 #elif defined IEEE_EB
00068 typedef union {
00069 double d;
00070 struct {
00071 unsigned int sign : 1;
00072 unsigned int exp :11;
00073 unsigned int quiet: 1;
00074 unsigned int frac : 3;
00075 unsigned int frac1:16;
00076 unsigned int frac2:32;
00077 } NaN_mask;
00078 struct {
00079 unsigned int sign : 1;
00080 unsigned int exp :11;
00081 unsigned int frac :20;
00082 unsigned int frac1:32;
00083 } fp_mask;
00084 } dNaN;
00085 typedef union {
00086 float f;
00087 struct {
00088 unsigned int sign : 1;
00089 unsigned int exp : 8;
00090 unsigned int quiet: 1;
00091 unsigned int frac : 6;
00092 unsigned int frac1:16;
00093 } NaN_mask;
00094 struct {
00095 unsigned int sign : 1;
00096 unsigned int exp : 8;
00097 unsigned int frac :23;
00098 } fp_mask;
00099 } fNaN;
00100
00101 #elif defined vax
00102 typedef union {
00103 double d;
00104 struct {
00105 unsigned int frac : 6;
00106 unsigned int quiet: 1;
00107 unsigned int exp : 8;
00108 unsigned int sign : 1;
00109 unsigned int frac1:16;
00110 unsigned int frac2:32;
00111 } NaN_mask;
00112 struct {
00113 unsigned int frac : 7;
00114 unsigned int exp : 8;
00115 unsigned int sign : 1;
00116 unsigned int frac1:16;
00117 unsigned int frac2:32;
00118 } fp_mask;
00119 } dNaN;
00120 typedef union {
00121 float f;
00122 struct {
00123 unsigned int frac : 6;
00124 unsigned int quiet: 1;
00125 unsigned int exp : 8;
00126 unsigned int sign : 1;
00127 unsigned int frac1:16;
00128 } NaN_mask;
00129 struct {
00130 unsigned int frac : 7;
00131 unsigned int exp : 8;
00132 unsigned int sign : 1;
00133 unsigned int frac1:16;
00134 } fp_mask;
00135 } fNaN;
00136 #endif
00137
00138
00139
00140
00141
00142 #if defined IEEE
00143 # define IsdNaN(X) ((((dNaN *)&(X))->fp_mask.exp == 0x7ff) && \
00144 ((((dNaN *)&(X))->fp_mask.frac != 0x0) || \
00145 (((dNaN *)&(X))->fp_mask.frac1 != 0x0)))
00146 # define IsdqNaN(X) ((((dNaN *)&(X))->fp_mask.exp == 0x7ff) && \
00147 (((dNaN *)&(X))->NaN_mask.quiet != 0x0))
00148 # define IsdsNaN(X) ((((dNaN *)&(X))->fp_mask.exp == 0x7ff) && \
00149 (((dNaN *)&(X))->NaN_mask.quiet == 0x0) && \
00150 ((((dNaN *)&(X))->fp_mask.frac != 0x0) || \
00151 (((dNaN *)&(X))->fp_mask.frac1 != 0x0)))
00152 # define IsfNaN(X) ((((fNaN *)&(X))->fp_mask.exp == 0xff) && \
00153 (((fNaN *)&(X))->fp_mask.frac != 0x0))
00154 # define IsfqNaN(X) ((((fNaN *)&(X))->fp_mask.exp == 0xff) && \
00155 (((fNaN *)&(X))->NaN_mask.quiet != 0x0))
00156 # define IsfsNaN(X) ((((fNaN *)&(X))->fp_mask.exp == 0xff) && \
00157 (((fNaN *)&(X))->NaN_mask.quiet == 0x0) && \
00158 (((fNaN *)&(X))->fp_mask.frac != 0x0))
00159 # define IsdNaNorINF(X) (((dNaN *)&(X))->fp_mask.exp == 0x7ff)
00160 #endif
00161
00162
00163
00164
00165
00166
00167 #define is_B_MISSING(v) (v == B_MISSING)
00168 #define is_S_MISSING(v) (v == S_MISSING)
00169 #define is_I_MISSING(v) (v == I_MISSING)
00170 #define is_UB_MISSING(v) (v == UB_MISSING)
00171 #define is_US_MISSING(v) (v == US_MISSING)
00172 #define is_UI_MISSING(v) (v == UI_MISSING)
00173 #define is_F_MISSING(v) (IsfNaN(v))
00174 #define is_D_MISSING(v) (IsdNaN(v))
00175 #define is_C_MISSING(v) (IsfNaN((v).r) || IsfNaN((v).i))
00176
00177 #define is_T_MISSING(v) (v == T_MISSING)
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 #include "timeio.h"
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 #define B_MISSING (-128)
00200 #define S_MISSING (-32768)
00201 #define I_MISSING (-2147483647-1)
00202 #define F_MISSING (dr_A_Quiet_fNaN())
00203 #define D_MISSING (dr_A_Quiet_dNaN())
00204
00205 #define T_MISSING (-211087684800.0)
00206 #define T_MISSING_STR ("-4712.01.01_12:00:00.000_UT")
00207
00208
00209
00210
00211
00212 typedef struct FCOMPLEX {
00213 float r, i;
00214 } fcomplex;
00215
00216
00217
00218
00219
00220 typedef struct attribute {
00221 struct attribute *next;
00222 char *name;
00223 void *value;
00224 char *format;
00225 char *comment;
00226 int datatype;
00227 } ATTRIBUTES;
00228
00229
00230 typedef struct color {
00231 int BitsPerPixel;
00232 int *Red;
00233 int *Green;
00234 int *Blue;
00235 } DR_COLOR;
00236
00237
00238 typedef struct dr {
00239 int rank;
00240 int *length;
00241 void *fillval;
00242 void *data;
00243 int data_avail;
00244 int datatype;
00245 int datumsize;
00246 ATTRIBUTES *attrib;
00247 double bscale;
00248 double bzero;
00249 int scaling;
00250 char *comment;
00251 char *history;
00252 DR_COLOR *color_table;
00253 } DR;
00254
00255
00256
00257
00258
00259
00260 typedef struct _ll {
00261 struct _ll *next;
00262 } _llist;
00263
00264
00265
00266
00267
00268 typedef int (*_llistFn)(_llist *ll, void *obj);
00269
00270 #define DR_MAXSTRING (1023)
00271 #define DR_MAXRANK (100)
00272
00273 #define DR_VOID (0)
00274 #define DR_BYTE (1)
00275 #define DR_SHORT (3)
00276 #define DR_INT (5)
00277 #define DR_LONG (7)
00278 #define DR_FLOAT (9)
00279 #define DR_DOUBLE (10)
00280 #define DR_COMPLEX (11)
00281 #define DR_STRING (12)
00282 #define DR_TIME (13)
00283 #define DR_LOGICAL (14)
00284
00285
00286
00287
00288
00289 #define NO_ERROR (0)
00290 #define MODULE_ABORT (1)
00291 #define READ_FAILURE (34)
00292 #define WRITE_FAILURE (35)
00293 #define MALLOC_FAILURE (41)
00294
00295 #define FILE_POINTER_NULL (100)
00296 #define DR_POINTER_NULL (200)
00297 #define ATTR_POINTER_NULL (201)
00298 #define DR_DATA_POINTER_NULL (202)
00299 #define DR_DATA_POINTER_EXISTS (203)
00300 #define DR_CREATE_FAILURE (210)
00301 #define DR_RANK_ERROR (220)
00302 #define DR_INVALID_DATATYPE (230)
00303 #define ATTRIBUTE_NOT_FOUND (240)
00304 #define ATTRNAME_NULL (241)
00305 #define ATTRVALUE_NULL (242)
00306
00307 #define DATA_OUT_OF_RANGE (321)
00308
00309 #define THIS_SHOULDNT_HAPPEN (1020)
00310 #define MAKES_NO_SENSE (1021)
00311 #define DOESNOT_COMPUTE (1022)
00312 #define NOT_IMPLEMENTED (1023)
00313
00314 #define FITS_ERROR (1600)
00315 #define FITS_NONCONFORMING (1601)
00316
00317
00318 DR *dr_get_fits(char *filename);
00319 char *dr_getkey_str(DR *dr, char *key);
00320 char *DR_getkey_str(DR *dr, char *key);
00321 double dr_getkey_double(DR *dr, char *key);
00322 int dr_getkey_int(DR *dr, char *key);
00323 TIME dr_getkey_time(DR *dr, char *key);
00324 TIME dr_getkey_time_interval(DR *dr, char *key);
00325 int dr_setkey_str(DR *dr, char *key, char *str);
00326 int dr_setkey_int(DR *dr, char *key, int val);
00327 int dr_setkey_double(DR *dr, char *key, double val);
00328 int dr_setkey_time(DR *dr, char *key, TIME time);
00329 int dr_setkey_time_interval(DR *dr, char *key, TIME time);
00330 char *dr_attrname (ATTRIBUTES *attr);
00331 void *dr_attrvalue (ATTRIBUTES *attr);
00332 char *dr_attrvalue_str (ATTRIBUTES *attr);
00333 ATTRIBUTES *dr_next_attr (ATTRIBUTES *attr);
00334 ATTRIBUTES *dr_search_attr (DR *dr, char *key);
00335 int dr_setkey_drmstype(DR *dr, char *name, DRMS_Keyword_t *key);
00336 int dr_write_fits_to_drms_segment(DR *dr, char *fitsname, DRMS_Record_t *rec, int segno);
00337 void dr_free (DR **drptr);
00338 DR *dr_read_fits (FILE *in, int *status);
00339 DR *dr_read_fits_header (FILE *in, int *status);
00340 long dr_data_length (DR *dr);
00341 int read_fits_head (DR *dr, FILE *fp);
00342 double dr_bscale (DR *dr);
00343 double dr_bzero (DR *dr);
00344 void *dr_data (DR *dr);
00345 int dr_datatype (DR *dr);
00346 int dr_numbytes (DR *dr);
00347 int dr_rank (DR *dr);
00348 int *dr_length (DR *dr);
00349 int dr_dim_n (DR *dr, int n);
00350 long dr_data_length (DR *dr);
00351 int dr_sizeof (int datatype);
00352 void *dr_malloc_fillvalue (int datatype);
00353
00354 #endif