[3880] | 1 | /** |
---|
| 2 | * (C) Copyright 2014- ECMWF. |
---|
| 3 | * |
---|
| 4 | * This software is licensed under the terms of the Apache Licence Version 2.0 |
---|
| 5 | * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
---|
| 6 | * |
---|
| 7 | * In applying this licence, ECMWF does not waive the privileges and immunities |
---|
| 8 | * granted to it by virtue of its status as an intergovernmental organisation |
---|
| 9 | * nor does it submit to any jurisdiction. |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | /* privpub.h */ |
---|
| 14 | |
---|
| 15 | #ifndef _PRIVPUB_H_ |
---|
| 16 | #define _PRIVPUB_H_ |
---|
| 17 | |
---|
| 18 | #include <stdio.h> |
---|
| 19 | #include <stdbool.h> |
---|
| 20 | #include <string.h> |
---|
| 21 | #include <errno.h> |
---|
| 22 | #include <signal.h> |
---|
| 23 | #include <unistd.h> |
---|
| 24 | #include <sys/types.h> |
---|
| 25 | |
---|
| 26 | #if !defined(IO_BUFSIZE_DEFAULT) |
---|
| 27 | /* The default I/O-buffer size = 4MBytes (unless overridden through ioassign) */ |
---|
| 28 | #define IO_BUFSIZE_DEFAULT 4194304 |
---|
| 29 | #endif |
---|
| 30 | |
---|
| 31 | #define NIL "(nil)" |
---|
| 32 | |
---|
| 33 | #define PERROR(msg) \ |
---|
| 34 | fprintf(stderr,"%s: %s (in %s:%d) : errno#%d\n",msg?msg:NIL,strerror(errno),__FILE__, __LINE__,errno) |
---|
| 35 | |
---|
| 36 | #if defined(VPP5000) || defined(VPP) |
---|
| 37 | /* Fujitsu VPP doesn't have snprintf, so we created one in file ifsaux/support/endian.c */ |
---|
| 38 | /* For ODB/SQL compiler the same code sits in odb/compiler/odb98.c */ |
---|
| 39 | extern int snprintf(char *str, size_t size, const char *format, ...); |
---|
| 40 | #endif |
---|
| 41 | |
---|
| 42 | #if defined(NO_TRUNC) || defined(VPP) || defined(SV2) |
---|
| 43 | /* For systems without trunc() -function [an extension of ANSI-C, but usually available] */ |
---|
| 44 | #define trunc(x) ((x) - fmod((x),1)) |
---|
| 45 | #else |
---|
| 46 | #if !defined(__cplusplus) |
---|
| 47 | extern double trunc(double d); |
---|
| 48 | #endif |
---|
| 49 | #endif |
---|
| 50 | |
---|
| 51 | #define PRIVATE static |
---|
| 52 | #define PUBLIC |
---|
| 53 | |
---|
| 54 | /* fprintf even if "fp" was NULL */ |
---|
| 55 | extern int ODB_fprintf(FILE *fp, const char *format, ...); |
---|
| 56 | |
---|
| 57 | /* Fortran90 compatible NINT-function */ |
---|
| 58 | |
---|
| 59 | #define F90nint(x) ( ((x) > 0) ? (int)((x) + 0.5) : (int)((x) - 0.5) ) |
---|
| 60 | |
---|
| 61 | /* Pi related stuff */ |
---|
| 62 | |
---|
| 63 | #define pi ((double)3.14159265358979323844e0) |
---|
| 64 | #define half_pi (pi / 2) |
---|
| 65 | #define two_pi (2 * pi) |
---|
| 66 | #define four_pi (4 * pi) |
---|
| 67 | #define pi_over_180 (pi/180) |
---|
| 68 | #define recip_pi_over_180 (180/pi) |
---|
| 69 | |
---|
| 70 | /* Radians to degrees & degrees to radians (formerly in odb.h) */ |
---|
| 71 | |
---|
| 72 | #define R2D(x) ( (180/pi) * ( ((x) > pi) ? ((x) - 2*pi) : (x) ) ) |
---|
| 73 | #define D2R(x) ( (pi/180) * ( ((x) > 180) ? ((x) - 360) : (x) ) ) |
---|
| 74 | |
---|
| 75 | /* Radius of the Earth both in meters and kilometres (formerly in odb.h) */ |
---|
| 76 | |
---|
| 77 | #define R_Earth ((double)6371000e0) |
---|
| 78 | #define R_Earth_km ((double)6371e0) |
---|
| 79 | |
---|
| 80 | /* Some common things ... */ |
---|
| 81 | |
---|
| 82 | #undef MIN |
---|
| 83 | #define MIN(a,b) ( ((a) < (b)) ? (a) : (b) ) |
---|
| 84 | |
---|
| 85 | #undef MAX |
---|
| 86 | #define MAX(a,b) ( ((a) > (b)) ? (a) : (b) ) |
---|
| 87 | |
---|
| 88 | #undef ABS |
---|
| 89 | #define ABS(x) ( ((x) >= 0) ? (x) : -(x) ) |
---|
| 90 | |
---|
| 91 | #undef RNDUP_DIV |
---|
| 92 | #define RNDUP_DIV(i,n) (( (i) + (n) - 1 ) / (n)) |
---|
| 93 | |
---|
| 94 | #undef RNDUP |
---|
| 95 | #define RNDUP(i,n) ( RNDUP_DIV(i,n) * (n)) |
---|
| 96 | |
---|
| 97 | #define STRLEN(x) (((const char *)(x)) ? (int)strlen(x) : (int)0) |
---|
| 98 | |
---|
| 99 | #define _POOLNO "$pool#" |
---|
| 100 | #define _NPOOLS "$npools#" |
---|
| 101 | #define _NTABLES "$ntables#" |
---|
| 102 | #define _UNIQNUM "$uniq#" |
---|
| 103 | #define _ROWNUM "$row#" |
---|
| 104 | #define _COLNUM "$col#" |
---|
| 105 | #define _NROWS "$nrows#" |
---|
| 106 | #define _NCOLS "$ncols#" |
---|
| 107 | |
---|
| 108 | #define IS_BSNUM(s) ((s) && *(s) == '\\' && STRLEN(s) >= 2 && isdigit((s)[1])) |
---|
| 109 | #define IS_HASH(s) ((s) && *(s) == '#') |
---|
| 110 | #define IS_DOLLAR(s) ((s) && *(s) == '$') |
---|
| 111 | #define IS_TABLE(s) ((s) && (s)[0] == '@') |
---|
| 112 | |
---|
| 113 | #define IS_POOLNO(s) ((s) && (((s)[0] == '$' && (s)[1] == '#')|| strequ(s,_POOLNO))) |
---|
| 114 | #define IS_(sym,s) strequ(s,_##sym) |
---|
| 115 | #define IS_USDHASH(s) ((s) && (s)[0] == '$' && (s)[STRLEN(s)-1] == '#') |
---|
| 116 | #define IS_USDDOTHASH(s) (IS_USDHASH(s) && strchr(s,'.') && (strchr(s,'.') == strrchr(s,'.'))) |
---|
| 117 | |
---|
| 118 | static const char ODB_OFFSET_CHAR[] = "#"; |
---|
| 119 | #define GET_OFFSET(s) ((!(s) || IS_DOLLAR(s) || IS_HASH(s) || IS_USDHASH(s)) ? NULL : strrchr(s,*ODB_OFFSET_CHAR)) |
---|
| 120 | |
---|
| 121 | /* Timers */ |
---|
| 122 | |
---|
| 123 | extern double util_cputime_(); |
---|
| 124 | extern double util_walltime_(); |
---|
| 125 | |
---|
| 126 | #ifdef RS6K |
---|
| 127 | extern void xl__trbk_(); |
---|
| 128 | #else |
---|
| 129 | #define xl__trbk_() |
---|
| 130 | #endif |
---|
| 131 | |
---|
| 132 | extern void abor1fl_(const char *filename, const int *linenum, |
---|
| 133 | const char *s, |
---|
| 134 | int filenamelen, int slen); |
---|
| 135 | extern void abor1_(const char *s, int slen); |
---|
| 136 | |
---|
| 137 | #define ABOR1(txt) { \ |
---|
| 138 | const char *t = (txt); \ |
---|
| 139 | xl__trbk_(); t ? abor1_(t, strlen(t)) : abor1_("",0); } |
---|
| 140 | |
---|
| 141 | #define ABOR1FL(txt) { \ |
---|
| 142 | const char *t = (txt); \ |
---|
| 143 | int linenum=__LINE__; \ |
---|
| 144 | t ? abor1fl_(__FILE__, &linenum, t, sizeof(__FILE__)-1, strlen(t)) \ |
---|
| 145 | : abor1fl_(__FILE__, &linenum, "", sizeof(__FILE__)-1, 0); \ |
---|
| 146 | _exit(1); /* Should never end up here */ } |
---|
| 147 | |
---|
| 148 | #define RAISE(x) { \ |
---|
| 149 | xl__trbk_(); \ |
---|
| 150 | if ((x) == SIGABRT) { \ |
---|
| 151 | const char *txt = "*** Fatal error; aborting (SIGABRT) ..."; \ |
---|
| 152 | ABOR1FL(txt); \ |
---|
| 153 | _exit(1); /* Should never end up here */ \ |
---|
| 154 | } \ |
---|
| 155 | else raise(x); \ |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /* No. of bits for "int" */ |
---|
| 159 | #define MAXBITS 32 |
---|
| 160 | |
---|
| 161 | /* No. of bits per 1-byte */ |
---|
| 162 | #define BITS_PER_BYTE 8 |
---|
| 163 | |
---|
| 164 | #ifndef O_LOCK_DONE |
---|
| 165 | #define O_LOCK_DONE |
---|
| 166 | |
---|
| 167 | /* OpenMP/ODB lock type */ |
---|
| 168 | /* Keep consistent with "ifsaux/include/drhook.h" */ |
---|
| 169 | /* Be ALSO consistent with OML_LOCK_KIND in ifsaux/module/oml_mod.F90 */ |
---|
| 170 | |
---|
| 171 | typedef long long int o_lock_t; /* i.e. 64-bit integer */ |
---|
| 172 | |
---|
| 173 | #define INIT_LOCKID_WITH_NAME(mylock, lockname) \ |
---|
| 174 | coml_init_lockid_with_name_(mylock, lockname, strlen(lockname)) |
---|
| 175 | |
---|
| 176 | extern void coml_set_debug_(const int *konoff, int *kret); |
---|
| 177 | extern void coml_init_lock_(); |
---|
| 178 | extern void coml_init_lockid_(o_lock_t *mylock); |
---|
| 179 | extern void coml_init_lockid_with_name_(o_lock_t *mylock, const char *name, int name_len); |
---|
| 180 | extern void coml_set_lock_(); |
---|
| 181 | extern void coml_set_lockid_(o_lock_t *mylock); |
---|
| 182 | extern void coml_unset_lock_(); |
---|
| 183 | extern void coml_unset_lockid_(o_lock_t *mylock); |
---|
| 184 | extern void coml_test_lock_(int *is_set); |
---|
| 185 | extern void coml_test_lockid_(int *is_set, o_lock_t *mylock); |
---|
| 186 | extern void coml_in_parallel_(int *is_parallel_region); |
---|
| 187 | |
---|
| 188 | #endif /* #ifndef O_LOCK_DONE */ |
---|
| 189 | |
---|
| 190 | /* OpenMP-stuff */ |
---|
| 191 | |
---|
| 192 | /* My thread-id [1 .. $OMP_NUM_THREADS] as in ifsaux/module/oml_mod.F90 */ |
---|
| 193 | extern int |
---|
| 194 | get_thread_id_(); /* From "ifsaux/utilities/get_thread_id.F90" */ |
---|
| 195 | |
---|
| 196 | /* Static number of threads allocated i.e. $OMP_NUM_THREADS */ |
---|
| 197 | extern int |
---|
| 198 | get_max_threads_(); /* From "ifsaux/utilities/get_max_threads.F90" */ |
---|
| 199 | |
---|
| 200 | /* The current number of threads allocated <= $OMP_NUM_THREADS */ |
---|
| 201 | extern int |
---|
| 202 | get_num_threads_(); /* From "ifsaux/utilities/get_num_threads.F90" */ |
---|
| 203 | |
---|
| 204 | #define DEF_IT int it = get_thread_id_() |
---|
| 205 | #define IT (it-1) |
---|
| 206 | #define DEF_INUMT int inumt = get_max_threads_() |
---|
| 207 | |
---|
| 208 | /* 0 (zero) Celsius in Kelvin */ |
---|
| 209 | |
---|
| 210 | #define ZERO_POINT ((double)273.15e0) |
---|
| 211 | |
---|
| 212 | /* Aggregate function flags */ |
---|
| 213 | |
---|
| 214 | #define ODB_AGGR_NONE 0x0000000 |
---|
| 215 | |
---|
| 216 | #define ODB_AGGRMASK_DISTINCT 0x0100000 |
---|
| 217 | #define ODB_AGGRMASK_BOOLEAN 0x1000000 |
---|
| 218 | |
---|
| 219 | #define ODB_AGGR_COUNT 0x0000001 |
---|
| 220 | #define ODB_AGGR_COUNT_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_COUNT) |
---|
| 221 | |
---|
| 222 | #define ODB_AGGR_BCOUNT (ODB_AGGRMASK_BOOLEAN | ODB_AGGR_COUNT) |
---|
| 223 | #define ODB_AGGR_BCOUNT_DISTINCT (ODB_AGGRMASK_BOOLEAN | ODB_AGGR_COUNT_DISTINCT) |
---|
| 224 | |
---|
| 225 | #define ODB_AGGR_MIN 0x0000002 |
---|
| 226 | #define ODB_AGGR_MAX 0x0000004 |
---|
| 227 | |
---|
| 228 | #define ODB_AGGR_SUM 0x0000008 |
---|
| 229 | #define ODB_AGGR_SUM_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_SUM) |
---|
| 230 | |
---|
| 231 | #define ODB_AGGR_AVG 0x0000010 |
---|
| 232 | #define ODB_AGGR_AVG_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_AVG) |
---|
| 233 | |
---|
| 234 | #define ODB_AGGR_STDEV 0x0000020 |
---|
| 235 | #define ODB_AGGR_STDEV_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_STDEV) |
---|
| 236 | |
---|
| 237 | #define ODB_AGGR_RMS 0x0000040 |
---|
| 238 | #define ODB_AGGR_RMS_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_RMS) |
---|
| 239 | |
---|
| 240 | #define ODB_AGGR_DOTP 0x0000080 |
---|
| 241 | #define ODB_AGGR_DOTP_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_DOTP) |
---|
| 242 | |
---|
| 243 | #define ODB_AGGR_NORM 0x0000100 |
---|
| 244 | #define ODB_AGGR_NORM_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_NORM) |
---|
| 245 | |
---|
| 246 | #define ODB_AGGR_VAR 0x0000200 |
---|
| 247 | #define ODB_AGGR_VAR_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_VAR) |
---|
| 248 | |
---|
| 249 | #define ODB_AGGR_COVAR 0x0000400 |
---|
| 250 | #define ODB_AGGR_CORR 0x0000800 |
---|
| 251 | |
---|
| 252 | #define ODB_AGGR_LINREGR_A 0x0001000 |
---|
| 253 | #define ODB_AGGR_LINREGR_B 0x0002000 |
---|
| 254 | |
---|
| 255 | #define ODB_AGGR_MEDIAN 0x0010000 |
---|
| 256 | #define ODB_AGGR_MEDIAN_DISTINCT (ODB_AGGRMASK_DISTINCT | ODB_AGGR_MEDIAN) |
---|
| 257 | |
---|
| 258 | #define ODB_AGGR_MINLOC 0x0020000 |
---|
| 259 | #define ODB_AGGR_MAXLOC 0x0040000 |
---|
| 260 | |
---|
| 261 | #define ODB_AGGR_DENSITY 0x0080000 |
---|
| 262 | |
---|
| 263 | #define ODB_tag_delim ";" |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | #ifdef __cplusplus |
---|
| 267 | typedef bool Bool; |
---|
| 268 | #else |
---|
| 269 | /* typedef enum { false=0, true=1 } Bool; */ |
---|
| 270 | typedef _Bool Bool; /* Std on C99 */ |
---|
| 271 | #endif |
---|
| 272 | |
---|
| 273 | /* char : Normally occupies 1 byte */ |
---|
| 274 | |
---|
| 275 | typedef unsigned int boolean; |
---|
| 276 | |
---|
| 277 | typedef boolean Boolean; |
---|
| 278 | |
---|
| 279 | typedef unsigned char byte; |
---|
| 280 | typedef byte byte1; |
---|
| 281 | #if !defined(RS6K) |
---|
| 282 | typedef unsigned char uchar; |
---|
| 283 | #endif |
---|
| 284 | typedef char integer1; |
---|
| 285 | typedef unsigned char uinteger1; |
---|
| 286 | |
---|
| 287 | /* short : Normally occupies 2 bytes */ |
---|
| 288 | |
---|
| 289 | typedef short integer2; |
---|
| 290 | #if !defined(RS6K) && !defined(LINUX) && !defined(HPPA) && !defined(VPP) && !defined(SUN4) && !defined(NECSX) && !defined(SV2) |
---|
| 291 | typedef unsigned short int ushort; |
---|
| 292 | #endif |
---|
| 293 | typedef unsigned short uinteger2; |
---|
| 294 | |
---|
| 295 | /* int : Normally occupies 4 bytes */ |
---|
| 296 | |
---|
| 297 | /* typedef unsigned int uint; (defined via system include files) */ |
---|
| 298 | typedef int integer4; |
---|
| 299 | typedef unsigned int uinteger4; |
---|
| 300 | |
---|
| 301 | /* typedef unsigned long ulong; (defined via system include files) */ |
---|
| 302 | |
---|
| 303 | /* long long: A non-standard way to access 8 byte integer(s) */ |
---|
| 304 | |
---|
| 305 | typedef long long int longlong; |
---|
| 306 | typedef long long int ll_t; |
---|
| 307 | typedef unsigned long long int ulonglong; |
---|
| 308 | typedef unsigned long long int u_ll_t; |
---|
| 309 | typedef long long int integer8; |
---|
| 310 | typedef unsigned long long int uinteger8; |
---|
| 311 | |
---|
| 312 | /* float : 32-bit flp (normally IEEE-754), 4 bytes */ |
---|
| 313 | |
---|
| 314 | typedef float real4; |
---|
| 315 | |
---|
| 316 | /* double : 64-bit flp (normally IEEE-754), 8 bytes */ |
---|
| 317 | |
---|
| 318 | typedef double real8; |
---|
| 319 | |
---|
| 320 | /* Formula alias double : For use by SELECT-expressions (29-Jun-2006/SS) */ |
---|
| 321 | |
---|
| 322 | typedef double Formula; |
---|
| 323 | |
---|
| 324 | /* Supported data types */ |
---|
| 325 | /* Moved here from odb.h on 7-Jan-2004/SS */ |
---|
| 326 | |
---|
| 327 | typedef int number; |
---|
| 328 | typedef int pk1int; |
---|
| 329 | typedef int pk2int; |
---|
| 330 | typedef int pk3int; |
---|
| 331 | typedef int pk4int; |
---|
| 332 | typedef int pk5int; |
---|
| 333 | typedef int pk9int; |
---|
| 334 | |
---|
| 335 | typedef pk1int linkoffset_t; /* also follows packing#1 */ |
---|
| 336 | typedef pk1int linklen_t; /* also follows packing#1 */ |
---|
| 337 | |
---|
| 338 | /* |
---|
| 339 | typedef unsigned int Bitfield; |
---|
| 340 | typedef unsigned int hex4; |
---|
| 341 | |
---|
| 342 | We can't have (at least the above) unsigned ints since the following |
---|
| 343 | substitution for unsigned int u and double d gets incorrect on RS6K, |
---|
| 344 | when d < 0 [... the IBM-s.o.b. RS6K sets the result to zero !!] |
---|
| 345 | |
---|
| 346 | u = d ; |
---|
| 347 | |
---|
| 348 | what appears to be working is, but very weird is: |
---|
| 349 | u = (int)d; |
---|
| 350 | |
---|
| 351 | but we don't want to use this cast-operator, since its introduction |
---|
| 352 | would add even more confusion |
---|
| 353 | |
---|
| 354 | ==> lets make Bitfield and hex4 signed ints (29-May-2002/SS) |
---|
| 355 | |
---|
| 356 | */ |
---|
| 357 | |
---|
| 358 | typedef int Bitfield; |
---|
| 359 | typedef int hex4; |
---|
| 360 | |
---|
| 361 | typedef hex4 bufr; |
---|
| 362 | typedef hex4 grib; |
---|
| 363 | |
---|
| 364 | typedef integer4 integer; |
---|
| 365 | |
---|
| 366 | /* These inherit corresponding packing method */ |
---|
| 367 | |
---|
| 368 | typedef pk1int yyyymmdd; |
---|
| 369 | typedef pk1int hhmmss; |
---|
| 370 | |
---|
| 371 | typedef double pk2real; |
---|
| 372 | typedef double pk3real; |
---|
| 373 | typedef double pk4real; |
---|
| 374 | typedef double pk5real; |
---|
| 375 | typedef double pk9real; |
---|
| 376 | typedef pk3real string; |
---|
| 377 | /* typedef double string; */ |
---|
| 378 | |
---|
| 379 | typedef double pk11real; |
---|
| 380 | typedef double pk12real; |
---|
| 381 | typedef double pk13real; |
---|
| 382 | typedef double pk14real; |
---|
| 383 | typedef double pk15real; |
---|
| 384 | typedef double pk16real; |
---|
| 385 | typedef double pk17real; |
---|
| 386 | typedef double pk18real; |
---|
| 387 | typedef double pk19real; |
---|
| 388 | |
---|
| 389 | typedef double pk21real; |
---|
| 390 | typedef double pk22real; |
---|
| 391 | typedef double pk23real; |
---|
| 392 | typedef double pk24real; |
---|
| 393 | typedef double pk25real; |
---|
| 394 | typedef double pk26real; |
---|
| 395 | typedef double pk27real; |
---|
| 396 | typedef double pk28real; |
---|
| 397 | typedef double pk29real; |
---|
| 398 | |
---|
| 399 | typedef double pk31real; |
---|
| 400 | typedef double pk32real; |
---|
| 401 | typedef double pk33real; |
---|
| 402 | typedef double pk34real; |
---|
| 403 | typedef double pk35real; |
---|
| 404 | typedef double pk36real; |
---|
| 405 | typedef double pk37real; |
---|
| 406 | typedef double pk38real; |
---|
| 407 | typedef double pk39real; |
---|
| 408 | |
---|
| 409 | typedef real8 real; |
---|
| 410 | |
---|
| 411 | /* S2D-business */ |
---|
| 412 | |
---|
| 413 | #define S2D "S2D_" |
---|
| 414 | #define S2DLEN (sizeof(S2D)-1) /* i.e. strlen(S2D) */ |
---|
| 415 | |
---|
| 416 | #define S2Dlc "s2d_" |
---|
| 417 | #define S2DlcLEN (sizeof(S2Dlc)-1) /* i.e. strlen(S2Dlc) */ |
---|
| 418 | |
---|
| 419 | #define S2D_all_blanks (0x2020202020202020ull) |
---|
| 420 | |
---|
| 421 | typedef union { |
---|
| 422 | double dval; |
---|
| 423 | u_ll_t llu; |
---|
| 424 | uint ival[2]; |
---|
| 425 | char str[9]; |
---|
| 426 | char *saddr; |
---|
| 427 | } S2D_Union; |
---|
| 428 | |
---|
| 429 | typedef struct { |
---|
| 430 | uint ival[2]; |
---|
| 431 | } S2D_Type; |
---|
| 432 | |
---|
| 433 | #define MASK_0 0U /* 0 */ |
---|
| 434 | #define MASK_1 1U /* 1 */ |
---|
| 435 | #define MASK_2 3U /* 11 */ |
---|
| 436 | #define MASK_3 7U /* 111 */ |
---|
| 437 | #define MASK_4 15U /* 1111 */ |
---|
| 438 | #define MASK_5 31U /* 11111 */ |
---|
| 439 | #define MASK_6 63U /* 111111 */ |
---|
| 440 | #define MASK_7 127U /* 1111111 */ |
---|
| 441 | #define MASK_8 255U /* 11111111 */ |
---|
| 442 | #define MASK_9 511U /* 111111111 */ |
---|
| 443 | #define MASK_10 1023U /* 1111111111 */ |
---|
| 444 | #define MASK_11 2047U /* 11111111111 */ |
---|
| 445 | #define MASK_12 4095U /* 111111111111 */ |
---|
| 446 | #define MASK_13 8191U /* 1111111111111 */ |
---|
| 447 | #define MASK_14 16383U /* 11111111111111 */ |
---|
| 448 | #define MASK_15 32767U /* 111111111111111 */ |
---|
| 449 | #define MASK_16 65535U /* 1111111111111111 */ |
---|
| 450 | #define MASK_17 131071U /* 11111111111111111 */ |
---|
| 451 | #define MASK_18 262143U /* 111111111111111111 */ |
---|
| 452 | #define MASK_19 524287U /* 1111111111111111111 */ |
---|
| 453 | #define MASK_20 1048575U /* 11111111111111111111 */ |
---|
| 454 | #define MASK_21 2097151U /* 111111111111111111111 */ |
---|
| 455 | #define MASK_22 4194303U /* 1111111111111111111111 */ |
---|
| 456 | #define MASK_23 8388607U /* 11111111111111111111111 */ |
---|
| 457 | #define MASK_24 16777215U /* 111111111111111111111111 */ |
---|
| 458 | #define MASK_25 33554431U /* 1111111111111111111111111 */ |
---|
| 459 | #define MASK_26 67108863U /* 11111111111111111111111111 */ |
---|
| 460 | #define MASK_27 134217727U /* 111111111111111111111111111 */ |
---|
| 461 | #define MASK_28 268435455U /* 1111111111111111111111111111 */ |
---|
| 462 | #define MASK_29 536870911U /* 11111111111111111111111111111 */ |
---|
| 463 | #define MASK_30 1073741823U /* 111111111111111111111111111111 */ |
---|
| 464 | #define MASK_31 2147483647U /* 1111111111111111111111111111111 */ |
---|
| 465 | #define MASK_32 4294967295U /* 11111111111111111111111111111111 */ |
---|
| 466 | |
---|
| 467 | #define MASK(n) MASK_##n |
---|
| 468 | |
---|
| 469 | #define IOR(x,y) ((x) | (y)) |
---|
| 470 | #define IAND(x,y) ((x) & (y)) |
---|
| 471 | |
---|
| 472 | #define ISHFTL(x,n) ((x) << (n)) |
---|
| 473 | #define ISHFTR(x,n) ((x) >> (n)) |
---|
| 474 | |
---|
| 475 | #define GET_BITS(x, pos, len) IAND(ISHFTR((int)(x), pos), MASK(len)) |
---|
| 476 | |
---|
| 477 | #define PUT_BITS(to, x, pos, len) \ |
---|
| 478 | to = IOR(IAND(to, ~(ISHFTL(MASK(len), pos))), \ |
---|
| 479 | IAND((int)(x), ISHFTL(MASK(len), pos))) |
---|
| 480 | |
---|
| 481 | #define BYTESIZE(x) (x##len * sizeof(*x)) |
---|
| 482 | #define BYTESIZE2(x,elemsize) (x##len * (elemsize)) |
---|
| 483 | |
---|
| 484 | typedef struct { |
---|
| 485 | #ifdef LITTLE |
---|
| 486 | unsigned int pmethod:8; /* Value 0 .. 255 ; |
---|
| 487 | 0 means not packed; |
---|
| 488 | 1,2,3,5,9,11-19,21-29 methods implemented |
---|
| 489 | 255 means not really packed, but PCMA-header exists for MDI's */ |
---|
| 490 | |
---|
| 491 | unsigned int signbit:1; /* signed = 1, unsigned = 0 */ |
---|
| 492 | |
---|
| 493 | unsigned int byte_swappable:1; /* byte swapping applicable = 1, N/A i.e. raw data = 0 */ |
---|
| 494 | |
---|
| 495 | unsigned int precision_bits:6; /* power of 2 for length of data; range = [0..63] bits */ |
---|
| 496 | |
---|
| 497 | unsigned int base_type:2; /* other = 0, int = 1, flp = 2, complex flp = 3 |
---|
| 498 | notes: |
---|
| 499 | - if other, look for other_type |
---|
| 500 | - precion_bits used for length as 2^precision_bits |
---|
| 501 | - if int, check also signed/unsigned part |
---|
| 502 | */ |
---|
| 503 | |
---|
| 504 | unsigned int other_type:14; /* used when base_type == 0 ; currently defined |
---|
| 505 | undefined = 00 000 000 000 000 = 0 = 0x0 |
---|
| 506 | Bitfield = 00 000 000 000 001 = 1 = 0x1 |
---|
| 507 | (note: also precision_bits must be 5 i.e. 2^5 == 32; |
---|
| 508 | preferably unsigned) |
---|
| 509 | string = 00 000 000 000 010 = 2 = 0x2 |
---|
| 510 | (note: alias to char(8); |
---|
| 511 | also precision_bits should be 3 i.e. 2^3 == 8 bytes; |
---|
| 512 | byte_swappable must be == 0 i.e. raw) |
---|
| 513 | yyyymmdd = 00 000 000 000 100 = 4 = 0x4 |
---|
| 514 | (note: preferably unsigned) |
---|
| 515 | hhmmss = 00 000 000 001 000 = 8 = 0x8 |
---|
| 516 | (note: preferably unsigned) |
---|
| 517 | linkoffset_t = 00 000 000 010 000 = 16 = 0x10 |
---|
| 518 | (note: preferably unsigned) |
---|
| 519 | linklen_t = 00 000 000 100 000 = 32 = 0x20 |
---|
| 520 | (note: preferably unsigned) |
---|
| 521 | bufr-data = 00 000 001 000 000 = 64 = 0x40 |
---|
| 522 | (note: also byte_swappable must be == 0 i.e. raw; |
---|
| 523 | also precision_bits must be 5 i.e. 2^5 == 32) |
---|
| 524 | grib-data = 00 000 010 000 000 = 128 = 0x80 |
---|
| 525 | (note: also byte_swappable must be == 0 i.e. raw; |
---|
| 526 | also precision_bits must be 5 i.e. 2^5 == 32) |
---|
| 527 | blob = 00 000 100 000 000 = 256 = 0x100 |
---|
| 528 | (note: precision_bits used for length; up to 2^16 bytes; enough ?; |
---|
| 529 | byte_swappable must be == 0 i.e. raw) |
---|
| 530 | long blob = 00 001 000 000 000 = 512 = 0x200 |
---|
| 531 | (note: precision_bits used for length; up to 2^31 bytes; enough ?; |
---|
| 532 | byte_swappable must be == 0 i.e. raw) |
---|
| 533 | char = 00 010 000 000 000 = 1024 = 0x400 |
---|
| 534 | (note: precision_bits used for length; |
---|
| 535 | byte_swappable must be == 0 i.e. raw) |
---|
| 536 | varchar = 00 100 000 000 000 = 2048 = 0x800 |
---|
| 537 | (note: precision_bits used for maximum length; |
---|
| 538 | byte_swappable must be == 0 i.e. raw) |
---|
| 539 | reserved_1 = 01 000 000 000 000 = 4096 = 0x1000 |
---|
| 540 | reserved_2 = 10 000 000 000 000 = 8192 = 0x2000 |
---|
| 541 | */ |
---|
| 542 | #else /* Big endian */ |
---|
| 543 | unsigned int other_type:14; |
---|
| 544 | unsigned int base_type:2; |
---|
| 545 | unsigned int precision_bits:6; |
---|
| 546 | unsigned int byte_swappable:1; |
---|
| 547 | unsigned int signbit:1; |
---|
| 548 | unsigned int pmethod:8; |
---|
| 549 | #endif |
---|
| 550 | } odb_types_t; |
---|
| 551 | |
---|
| 552 | PUBLIC uint get_dtnum(const char *dt); |
---|
| 553 | PUBLIC int get_dtsize(const char *dt); |
---|
| 554 | |
---|
| 555 | #define EXTRACT_PMETHOD(x) GET_BITS(x,0,8) |
---|
| 556 | #define EXTRACT_DATATYPE(x) GET_BITS(x,8,24) |
---|
| 557 | #define EXTRACT_SIGNBIT(x) GET_BITS(x,8,1) |
---|
| 558 | #define EXTRACT_SWAPPABLE(x) GET_BITS(x,9,1) |
---|
| 559 | #define EXTRACT_PRECISION(x) GET_BITS(x,10,6) |
---|
| 560 | #define EXTRACT_BASETYPE(x) GET_BITS(x,16,2) |
---|
| 561 | #define EXTRACT_OTHERTYPE(x) GET_BITS(x,18,14) |
---|
| 562 | |
---|
| 563 | /* The following is a product of ../tools/typebits.c -program output */ |
---|
| 564 | |
---|
| 565 | /* signbit=0, byte_swappable=0, precision_bits=0, base_type=0, other_type=0x0 (0) */ |
---|
| 566 | #define DATATYPE_UNDEF 0x0 /* (0 dec) undef */ |
---|
| 567 | |
---|
| 568 | /* signbit=0, byte_swappable=0, precision_bits=0, base_type=1, other_type=0x0 (0) */ |
---|
| 569 | #define DATATYPE_BIT 0x100 /* (256 dec) bit : 1 bits, 0 bytes */ |
---|
| 570 | |
---|
| 571 | /* signbit=1, byte_swappable=1, precision_bits=3, base_type=1, other_type=0x0 (0) */ |
---|
| 572 | #define DATATYPE_INT1 0x10f /* (271 dec) char : 8 bits, 1 bytes */ |
---|
| 573 | |
---|
| 574 | /* signbit=1, byte_swappable=1, precision_bits=4, base_type=1, other_type=0x0 (0) */ |
---|
| 575 | #define DATATYPE_INT2 0x113 /* (275 dec) short : 16 bits, 2 bytes */ |
---|
| 576 | |
---|
| 577 | /* signbit=1, byte_swappable=1, precision_bits=5, base_type=1, other_type=0x0 (0) */ |
---|
| 578 | #define DATATYPE_INT4 0x117 /* (279 dec) int : 32 bits, 4 bytes */ |
---|
| 579 | |
---|
| 580 | /* signbit=1, byte_swappable=1, precision_bits=6, base_type=1, other_type=0x0 (0) */ |
---|
| 581 | #define DATATYPE_INT8 0x11b /* (283 dec) long long : 64 bits, 8 bytes */ |
---|
| 582 | |
---|
| 583 | /* signbit=0, byte_swappable=1, precision_bits=3, base_type=1, other_type=0x0 (0) */ |
---|
| 584 | #define DATATYPE_UINT1 0x10e /* (270 dec) uchar : 8 bits, 1 bytes */ |
---|
| 585 | |
---|
| 586 | /* signbit=0, byte_swappable=1, precision_bits=4, base_type=1, other_type=0x0 (0) */ |
---|
| 587 | #define DATATYPE_UINT2 0x112 /* (274 dec) ushort : 16 bits, 2 bytes */ |
---|
| 588 | |
---|
| 589 | /* signbit=0, byte_swappable=1, precision_bits=5, base_type=1, other_type=0x0 (0) */ |
---|
| 590 | #define DATATYPE_UINT4 0x116 /* (278 dec) uint : 32 bits, 4 bytes */ |
---|
| 591 | |
---|
| 592 | /* signbit=0, byte_swappable=1, precision_bits=6, base_type=1, other_type=0x0 (0) */ |
---|
| 593 | #define DATATYPE_UINT8 0x11a /* (282 dec) ulonglong : 64 bits, 8 bytes */ |
---|
| 594 | |
---|
| 595 | /* signbit=0, byte_swappable=1, precision_bits=5, base_type=2, other_type=0x0 (0) */ |
---|
| 596 | #define DATATYPE_REAL4 0x216 /* (534 dec) float : 32 bits, 4 bytes */ |
---|
| 597 | |
---|
| 598 | /* signbit=0, byte_swappable=1, precision_bits=6, base_type=2, other_type=0x0 (0) */ |
---|
| 599 | #define DATATYPE_REAL8 0x21a /* (538 dec) double : 64 bits, 8 bytes */ |
---|
| 600 | |
---|
| 601 | /* signbit=0, byte_swappable=1, precision_bits=7, base_type=2, other_type=0x0 (0) */ |
---|
| 602 | #define DATATYPE_REAL16 0x21e /* (542 dec) long double : 128 bits, 16 bytes */ |
---|
| 603 | |
---|
| 604 | /* signbit=0, byte_swappable=1, precision_bits=6, base_type=3, other_type=0x0 (0) */ |
---|
| 605 | #define DATATYPE_CMPLX4 0x31a /* (794 dec) complex4 : 64 bits, 8 bytes */ |
---|
| 606 | |
---|
| 607 | /* signbit=0, byte_swappable=1, precision_bits=7, base_type=3, other_type=0x0 (0) */ |
---|
| 608 | #define DATATYPE_CMPLX8 0x31e /* (798 dec) complex8 : 128 bits, 16 bytes */ |
---|
| 609 | |
---|
| 610 | /* signbit=0, byte_swappable=1, precision_bits=8, base_type=3, other_type=0x0 (0) */ |
---|
| 611 | #define DATATYPE_CMPLX16 0x322 /* (802 dec) complex16 : 256 bits, 32 bytes */ |
---|
| 612 | |
---|
| 613 | /* signbit=0, byte_swappable=1, precision_bits=5, base_type=0, other_type=0x1 (1) */ |
---|
| 614 | #define DATATYPE_BITFIELD 0x416 /* (1046 dec) Bitfield : 32 bits, 4 bytes */ |
---|
| 615 | |
---|
| 616 | /* signbit=0, byte_swappable=0, precision_bits=6, base_type=0, other_type=0x2 (2) */ |
---|
| 617 | #define DATATYPE_STRING 0x818 /* (2072 dec) string : 64 bits, 8 bytes */ |
---|
| 618 | |
---|
| 619 | /* signbit=0, byte_swappable=1, precision_bits=5, base_type=0, other_type=0x4 (4) */ |
---|
| 620 | #define DATATYPE_YYYYMMDD 0x1016 /* (4118 dec) yyyymmdd : 32 bits, 4 bytes */ |
---|
| 621 | |
---|
| 622 | /* signbit=0, byte_swappable=1, precision_bits=5, base_type=0, other_type=0x8 (8) */ |
---|
| 623 | #define DATATYPE_HHMMSS 0x2016 /* (8214 dec) hhmmss : 32 bits, 4 bytes */ |
---|
| 624 | |
---|
| 625 | /* signbit=1, byte_swappable=1, precision_bits=5, base_type=0, other_type=0x10 (16) */ |
---|
| 626 | #define DATATYPE_LINKOFFSET 0x4017 /* (16407 dec) linkoffset_t : 32 bits, 4 bytes */ |
---|
| 627 | |
---|
| 628 | /* signbit=1, byte_swappable=1, precision_bits=5, base_type=0, other_type=0x20 (32) */ |
---|
| 629 | #define DATATYPE_LINKLEN 0x8017 /* (32791 dec) linklen_t : 32 bits, 4 bytes */ |
---|
| 630 | |
---|
| 631 | /* signbit=0, byte_swappable=1, precision_bits=5, base_type=0, other_type=0x40 (64) */ |
---|
| 632 | #define DATATYPE_BUFR 0x10016 /* (65558 dec) bufr : 32 bits, 4 bytes */ |
---|
| 633 | |
---|
| 634 | /* signbit=0, byte_swappable=1, precision_bits=5, base_type=0, other_type=0x80 (128) */ |
---|
| 635 | #define DATATYPE_GRIB 0x20016 /* (131094 dec) grib : 32 bits, 4 bytes */ |
---|
| 636 | |
---|
| 637 | /* signbit=0, byte_swappable=0, precision_bits=19, base_type=0, other_type=0x100 (256) */ |
---|
| 638 | #define DATATYPE_BLOB 0x4004c /* (262220 dec) blob64kB : 65536 bytes */ |
---|
| 639 | |
---|
| 640 | /* signbit=0, byte_swappable=0, precision_bits=34, base_type=0, other_type=0x200 (512) */ |
---|
| 641 | #define DATATYPE_LONGBLOB 0x80088 /* (524424 dec) blob2GB : 2147483648 bytes */ |
---|
| 642 | |
---|
| 643 | /* signbit=0, byte_swappable=0, precision_bits=11, base_type=0, other_type=0x400 (1024) */ |
---|
| 644 | #define DATATYPE_CHAR 0x10002c /* (1048620 dec) char(1:255) : 256 bytes */ |
---|
| 645 | |
---|
| 646 | /* signbit=0, byte_swappable=0, precision_bits=11, base_type=0, other_type=0x800 (2048) */ |
---|
| 647 | #define DATATYPE_VARCHAR 0x20002c /* (2097196 dec) varchar(1:255) : 256 bytes */ |
---|
| 648 | |
---|
| 649 | #endif |
---|