NCEPLIBS-g2c 2.1.0
Loading...
Searching...
No Matches
drstemplates.c
Go to the documentation of this file.
1
37#include "grib2_int.h"
38
42struct drstemplate
43{
44 g2int template_num;
45 g2int mapdrslen;
46 g2int needext;
48};
49
54static const struct drstemplate templatesdrs[G2C_MAX_DRS_TEMPLATE] =
55 {
58 {0, 5, 0, {4, -2, -2, 1, 1}},
59
62 {2, 16, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1}},
63
66 {3, 18, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1, 1, 1}},
67
70 {50, 5, 0, {4, -2, -2, 1, 4}},
71
74 {51, 10, 0, {4, -2, -2, 1, -4, 2, 2, 2, 4, 1}},
75
76 /* 5.1: Matrix values at gridpoint - Simple packing.
77 * Comment from Stephen Gilbert in 2021:
78 *
79 * This encoder/decoder was written in the early days of GRIB2
80 * adoption as a standard. It was used to help WMO validate the
81 * templates in the specification by sharing GRIB2 encoded message
82 * with other organizations to verify that the data could be
83 * transmitted and processed successfully.
84 *
85 * We did not have a use case for DRS template 5.1 at that time
86 * and did not produce any GRIB2 messages using that template. It
87 * appears that other organizations did not work on it as
88 * well. The latest GRIB2 specification still includes the DRS
89 * Template 5.1 definition, but there is a disclaimer to use it
90 * with caution, since it has not yet been validated. I assume we
91 * commented it out because it was not validated, which means it's
92 * definition could possibly change during any validation attempts
93 * in the future.
94 */
95
96 /* {1, 15, 1, {4, -2, -2, 1, 1, 1, 4, 2, 2, 1, 1, 1, 1, 1, 1}}, */
97
100 {40, 7, 0, {4, -2, -2, 1, 1, 1, 1}},
101
104 {41, 5, 0, {4, -2, -2, 1, 1}},
105
108 {42, 8, 0, {4, -2, -2, 1, 1, 1, 1, 2}},
109
112 {53, 11, 0, {4, -2, -2, 1, 1, 1, -4, 2, 2, 4, 1}},
113
118 {40000, 7, 0, {4, -2, -2, 1, 1, 1, 1}},
119
124 {40010, 5, 0, {4, -2, -2, 1, 1}},
125};
126
139static g2int
141{
142 g2int j, getdrsindex = -1;
143
144 for (j = 0; j < G2C_MAX_DRS_TEMPLATE; j++)
145 {
146 if (number == templatesdrs[j].template_num)
147 {
148 getdrsindex = j;
149 return (getdrsindex);
150 }
151 }
152
153 return (getdrsindex);
154}
155
171gtemplate *
173{
174 g2int index;
175 gtemplate *new;
176
177 index = getdrsindex(number);
178
179 if (index != -1)
180 {
181 new = malloc(sizeof(gtemplate));
182 new->type = 5;
183 new->num = templatesdrs[index].template_num;
184 new->maplen = templatesdrs[index].mapdrslen;
185 new->needext = templatesdrs[index].needext;
186 new->map = (g2int *)templatesdrs[index].mapdrs;
187 new->extlen = 0;
188 new->ext = NULL;
189 return (new);
190 }
191 else
192 {
193 printf("getdrstemplate: DRS Template 5.%d not defined.\n", (int)number);
194 return (NULL);
195 }
196
197 return (NULL);
198}
199
217gtemplate *
219{
220 gtemplate *new;
221
222 if (getdrsindex(number) == -1)
223 return NULL;
224
225 new = getdrstemplate(number);
226
227 if (!new->needext)
228 return (new);
229
230 /* This template is commented out (see comment in struct
231 * drstemplate for explanation). */
232 /* if (number == 1) */
233 /* { */
234 /* new->extlen = list[10] + list[12]; */
235 /* new->ext = malloc(sizeof(g2int) * new->extlen); */
236 /* for (i = 0; i < new->extlen; i++) */
237 /* { */
238 /* new->ext[i] = 4; */
239 /* } */
240 /* } */
241
242 return new;
243}
244
265int
266g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext)
267{
268 int j, m;
269
270 /* Look through the array of templates to find a matching one. */
271 for (j = 0; j < G2C_MAX_DRS_TEMPLATE; j++)
272 {
273 if (drs_template_num == templatesdrs[j].template_num)
274 {
275 /* Copy maplen and map if the caller wants them. */
276 if (maplen)
277 *maplen = templatesdrs[j].mapdrslen;
278 if (map)
279 for (m = 0; m < templatesdrs[j].mapdrslen; m++)
280 map[m] = templatesdrs[j].mapdrs[m];
281 if (needext)
282 *needext = templatesdrs[j].needext;
283
284 /* Done. */
285 return G2C_NOERROR;
286 }
287 }
288
289 /* If we didn't find a template, return an error. */
290 return G2C_ENOTEMPLATE;
291}
static const struct drstemplate templatesdrs[G2C_MAX_DRS_TEMPLATE]
Stuct holding data for GRIB2 Data Representation Section (DRS) template.
static g2int getdrsindex(g2int number)
This function returns the index of specified Data Representation Template.
gtemplate * getdrstemplate(g2int number)
This subroutine returns DRS template information for a specified Data Representation Template.
int g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext)
Get DRS template information.
gtemplate * extdrstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Data Representation Template,...
#define G2C_MAX_DRS_TEMPLATE
Maximum number of DRS templates.
Definition grib2.h:296
#define G2C_ENOTEMPLATE
Template not found.
Definition grib2.h:505
#define G2C_MAX_DRS_TEMPLATE_MAPLEN
Maximum DRS template map length.
Definition grib2.h:297
int64_t g2int
Long integer type.
Definition grib2.h:32
#define G2C_NOERROR
No error.
Definition grib2.h:484
Header file with internal function prototypes NCEPLIBS-g2c library.
Struct for GRIB template, returned by getgridtemplate().
Definition grib2_int.h:278