1 | /* FILE: grib_lookup.h |
---|
2 | Decoder Lookup Table (ie. g1tab_128_2.2) shows how to convert from GRIB |
---|
3 | units to DB units; |
---|
4 | Encoder Lookup Table (ie. neons2grib.2.2) shows how to convert from DB |
---|
5 | units to GRIB units; |
---|
6 | |
---|
7 | Revisions: |
---|
8 | 12/96 A.Nakajima +debug print |
---|
9 | 07/97 atn: +LPRINT, +List_xxx; |
---|
10 | ...............................................................*/ |
---|
11 | #include <stdio.h> |
---|
12 | #include <limits.h> |
---|
13 | #include <float.h> |
---|
14 | |
---|
15 | #ifndef TABLES_H |
---|
16 | #define TABLES_H |
---|
17 | #define ADD_DEC 1L |
---|
18 | #define ADD_ENC 2L |
---|
19 | #define NEW_ENTRY 3L |
---|
20 | #define NO_NUM INT_MAX /* +32767 */ |
---|
21 | #define NO_FNUM FLT_MAX /* 1E+37 */ |
---|
22 | #define LPRINT if (logfile!=NULL) fprintf |
---|
23 | |
---|
24 | enum { |
---|
25 | NOTFOUND, FOUND, NULL_OK, NO_NULL, NO_SPACE, SPACE_OK, YES, NO, |
---|
26 | OK, SKIP, ABORT |
---|
27 | }; |
---|
28 | |
---|
29 | /* |
---|
30 | * Use this to index the db_tbl_name[] array, so any changes would |
---|
31 | * require updating db_tbl_name[] also. |
---|
32 | * To add new Parm tables, insert it before the Model_Type; |
---|
33 | */ |
---|
34 | enum struct_types { |
---|
35 | Parm0_Type=0, ParmA_Type, ParmB_Type,ParmC_Type, ParmD_Type, ParmE_Type, |
---|
36 | Model_Type, Level_Type, Geom_Type |
---|
37 | }; |
---|
38 | #define MAX_PARM_TBLS (ParmE_Type-Parm0_Type + 1) |
---|
39 | |
---|
40 | static char *db_tbl_name[]= { |
---|
41 | "PARMTBL-0","PARMTBL-A","PARMTBL-B","PARMTBL-C","PARMTBL-D","PARMTBL-E", |
---|
42 | "MODEL-TBL","LEVEL-TBL","GEOM-TBL" |
---|
43 | }; |
---|
44 | |
---|
45 | #define NPARM 256 |
---|
46 | #define NLEV 256 |
---|
47 | #define NGEOM 256 |
---|
48 | #define NMODEL 256 |
---|
49 | #define NOCTR 256 |
---|
50 | #define NCTRS 256 |
---|
51 | |
---|
52 | #define EMPTY_PARM(x) (!(x)->grib_dsc[0] && !(x)->db_name[0]) |
---|
53 | #define EMPTY_LEVEL(x) (!(x)->grib_dsc[0] && !(x)->db_name[0]) |
---|
54 | #define EMPTY_MODEL(x) (!(x)->grib_dsc[0] && !(x)->db_name[0]) |
---|
55 | #define EMPTY_GEOM(x) (!(x)->grib_dsc[0] && !(x)->db_name[0]) |
---|
56 | |
---|
57 | #define PARMTBL_INDX(Parm_id, Parm_sub) \ |
---|
58 | (Parm_id>249 && Parm_sub!=0 ? ((Parm_id-249)*NPARM+Parm_sub):Parm_id) |
---|
59 | #define LIST_GEOM(unit,cell) \ |
---|
60 | fprintf((unit),"Geom=%03d:\n grib_dsc='%s'\n db_name='%s'\n\n",\ |
---|
61 | (cell)->usGeom_id, (cell)->grib_dsc, (cell)->db_name); |
---|
62 | #define LIST_PARM(unit,curr_Type,cell) \ |
---|
63 | fprintf ((unit), \ |
---|
64 | "%s Parm_id=%d, Parm_sub=%d (Index= %d):\n" \ |
---|
65 | " Descr='%s' Unit='%s'\n" \ |
---|
66 | " DBName='%s' Scl=%.3f Offs=%.3f DSF=%d\n\n", \ |
---|
67 | db_tbl_name[curr_Type], \ |
---|
68 | (cell)->usParm_id, (cell)->usParm_sub, \ |
---|
69 | PARMTBL_INDX ((cell)->usParm_id,(cell)->usParm_sub), \ |
---|
70 | (cell)->grib_dsc, (cell)->grib_unit_dsc, (cell)->db_name, \ |
---|
71 | (cell)->fScale, (cell)->fOffset, (cell)->sDSF); |
---|
72 | #define LIST_LVL(unit,cell) \ |
---|
73 | fprintf ((unit), \ |
---|
74 | "Level=%03d: '%s' %d octs\n name1='%s'\n" \ |
---|
75 | " name2='%s'\n db_name='%s' Scl=%.3f Offs=%.3f\n\n", \ |
---|
76 | (cell)->usLevel_id, (cell)->grib_dsc, (cell)->num_octets, \ |
---|
77 | (cell)->lvl_name_1, (cell)->lvl_name_2, (cell)->db_name, \ |
---|
78 | (cell)->fScale, (cell)->fOffset); |
---|
79 | #define LIST_MODEL(unit,cell) \ |
---|
80 | fprintf ((unit), \ |
---|
81 | "Model=%03d:\n grib_dscr='%s'\n db_name='%s'\n\n",\ |
---|
82 | (cell)->usModel_id, (cell)->grib_dsc, (cell)->db_name); |
---|
83 | |
---|
84 | /****************************************************************** |
---|
85 | The following structs hold Parameter, Level, Model and Geom info; |
---|
86 | They are loaded from the external 'lookup tables'; |
---|
87 | The following structs are used as ARRAY of structures, where # elements |
---|
88 | depends on what type of structs they are (usually 256 as defined in |
---|
89 | the # defines lines above; |
---|
90 | ******************************************************************/ |
---|
91 | |
---|
92 | typedef struct parm_defn { /**** PARAMETER: GRIB vs. Neons */ |
---|
93 | /* for a given ParmId & ParmSub, get Index within Db_Parm_Tbl |
---|
94 | via PARMTBL_INDX(Parm_id, Parm_sub) |
---|
95 | Index 249 through 255 denote Sub-Tables Defs only when Parm_sub > 0; |
---|
96 | In that case usParm_id tells which Sub-Tbl we're in and usParm_sub |
---|
97 | tells which element of that Table to access; |
---|
98 | SubTbl-A usParm_id 249 usParm_sub |
---|
99 | |
---|
100 | and |
---|
101 | Db_Parm_Tbl[0-249,255], |
---|
102 | { usParm_id = usGribCode (1-255); SubParm=0; } |
---|
103 | Db_Parm_Tbl[250-254], |
---|
104 | { usParm_id = 249/250/251/252/253/254; SubParm= usGribCode; } |
---|
105 | for Main Parameter defns (Db_Parm_Tbl[0-255], |
---|
106 | { usParm_id= usGribCode (1-255); SubParm=0; } |
---|
107 | Sub-Tbls A/B/C/D/E defns (Db_Parm_Tbl[256-511], [512-767] ...) |
---|
108 | { usParm_id= 250/251/252/253/254; Parmsub= usGribCode(1-255);} |
---|
109 | where usGribCode is between 0-255 (DECODR: 1st col, ENCODR= 3rd col) |
---|
110 | */ |
---|
111 | |
---|
112 | unsigned short usParm_id; /* see above */ |
---|
113 | unsigned short usParm_sub;/* see above */ |
---|
114 | |
---|
115 | char grib_dsc[75]; /* DECODR: field parameter - 2nd col */ |
---|
116 | char grib_unit_dsc[25]; /* DECODR: units - 3rd col */ |
---|
117 | |
---|
118 | char db_name[31]; /* ENCODR: neons field name 1st col */ |
---|
119 | /*char chTable_code; /- ENCODR: 0/a/b/c/d/e table 2nd col */ |
---|
120 | float fScale; /* ENCODR: binary Scale Fctor 4th col */ |
---|
121 | float fOffset; /* ENCODR: Unit offset 5th col */ |
---|
122 | short sDSF; /* ENCODR: Decimal scalefactor 6th col */ |
---|
123 | } PARM_DEFN; |
---|
124 | |
---|
125 | |
---|
126 | typedef struct lvl_defn { /**** LEVEL: GRIB vs. Neons */ |
---|
127 | unsigned short usLevel_id; /* DECDR: line1 col1 & ENCDR: 2nd col */ |
---|
128 | char grib_dsc[100]; /* DECDR: meaning of code figure line1: 2nd col*/ |
---|
129 | int num_octets; /* DECDR: #octets for contents- line1: 3rd col*/ |
---|
130 | char lvl_name_1[100]; /* DECDR: contents of octets 11 & 12 : line2 */ |
---|
131 | char lvl_name_2[100]; /* DECDR: contents of octets 11 & 12 : line3 */ |
---|
132 | |
---|
133 | char db_name[31]; /* ENCODR: db db_name 1st col */ |
---|
134 | float fScale; /* ENCODR: binary Scale Fctor 3rd col */ |
---|
135 | float fOffset; /* ENCODR: offset 4th col */ |
---|
136 | } LVL_DEFN; |
---|
137 | |
---|
138 | typedef struct mdl_defn { /**** MODEL: GRIB vs. Neons */ |
---|
139 | unsigned short usModel_id;/* ENCDR & DECDR: 1st col */ |
---|
140 | char grib_dsc[61]; /* DECDR: 2nd col */ |
---|
141 | char db_name[31]; /* ENCDR: 2nd col */ |
---|
142 | } MODEL_DEFN; |
---|
143 | |
---|
144 | typedef struct geom_defn { /*** GEOM : Grib vs. Neons ****/ |
---|
145 | unsigned short usGeom_id; /* ENCDR & DECODR TBL: 1st col */ |
---|
146 | char grib_dsc[61]; /* DECODR LOOKUP TBL: 2nd col */ |
---|
147 | char db_name [31]; /* ENCDR LOOKUP TBL: 2nd col */ |
---|
148 | } GEOM_DEFN; |
---|
149 | /*................................................................*/ |
---|
150 | |
---|
151 | typedef struct ctr_defn { /**** ORIGINATING CENTERS INFO *****/ |
---|
152 | char ctr_dsc[100]; /* orig_ctrs: description of center */ |
---|
153 | } CTR_DEFN; |
---|
154 | #endif |
---|