NCEPLIBS-g2c 1.9.0
Loading...
Searching...
No Matches
drstemplates.c
Go to the documentation of this file.
1
36#include "grib2_int.h"
37
41struct drstemplate
42{
43 g2int template_num;
44 g2int mapdrslen;
45 g2int needext;
47};
48
53static const struct drstemplate templatesdrs[G2C_MAX_DRS_TEMPLATE] =
54{
57 {0, 5, 0, {4, -2, -2, 1, 1}},
58
61 {2, 16, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1}},
62
65 {3, 18, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1, 1, 1}},
66
69 {50, 5, 0, {4, -2, -2, 1, 4}},
70
73 {51, 10, 0, {4, -2, -2, 1, -4, 2, 2, 2, 4, 1}},
74
75 /* 5.1: Matrix values at gridpoint - Simple packing.
76 * Comment from Stephen Gilbert in 2021:
77 *
78 * This encoder/decoder was written in the early days of GRIB2
79 * adoption as a standard. It was used to help WMO validate the
80 * templates in the specification by sharing GRIB2 encoded message
81 * with other organizations to verify that the data could be
82 * transmitted and processed successfully.
83 *
84 * We did not have a use case for DRS template 5.1 at that time
85 * and did not produce any GRIB2 messages using that template. It
86 * appears that other organizations did not work on it as
87 * well. The latest GRIB2 specification still includes the DRS
88 * Template 5.1 definition, but there is a disclaimer to use it
89 * with caution, since it has not yet been validated. I assume we
90 * commented it out because it was not validated, which means it's
91 * definition could possibly change during any validation attempts
92 * in the future.
93 */
94
95 /* {1, 15, 1, {4, -2, -2, 1, 1, 1, 4, 2, 2, 1, 1, 1, 1, 1, 1}}, */
96
99 {40, 7, 0, {4, -2, -2, 1, 1, 1, 1}},
100
103 {41, 5, 0, {4, -2, -2, 1, 1}},
104
107 {42, 8, 0, {4, -2, -2, 1, 1, 1, 1, 2}},
108
113 {40000, 7, 0, {4, -2, -2, 1, 1, 1, 1}},
114
119 {40010, 5, 0, {4, -2, -2, 1, 1}},
120} ;
121
134static g2int
136{
137 g2int j, getdrsindex = -1;
138
139 for (j = 0; j < G2C_MAX_DRS_TEMPLATE; j++)
140 {
141 if (number == templatesdrs[j].template_num)
142 {
143 getdrsindex = j;
144 return(getdrsindex);
145 }
146 }
147
148 return(getdrsindex);
149}
150
166gtemplate *
168{
169 g2int index;
170 gtemplate *new;
171
172 index = getdrsindex(number);
173
174 if (index != -1)
175 {
176 new = malloc(sizeof(gtemplate));
177 new->type = 5;
178 new->num = templatesdrs[index].template_num;
179 new->maplen = templatesdrs[index].mapdrslen;
180 new->needext = templatesdrs[index].needext;
181 new->map = (g2int *)templatesdrs[index].mapdrs;
182 new->extlen = 0;
183 new->ext = NULL;
184 return(new);
185 }
186 else
187 {
188 printf("getdrstemplate: DRS Template 5.%d not defined.\n", (int)number);
189 return(NULL);
190 }
191
192 return(NULL);
193}
194
212gtemplate *
214{
215 gtemplate *new;
216
217 if (getdrsindex(number) == -1)
218 return NULL;
219
220 new = getdrstemplate(number);
221
222 if (!new->needext)
223 return(new);
224
225 /* This template is commented out (see comment in struct
226 * drstemplate for explanation). */
227 /* if (number == 1) */
228 /* { */
229 /* new->extlen = list[10] + list[12]; */
230 /* new->ext = malloc(sizeof(g2int) * new->extlen); */
231 /* for (i = 0; i < new->extlen; i++) */
232 /* { */
233 /* new->ext[i] = 4; */
234 /* } */
235 /* } */
236
237 return new;
238}
239
260int
261g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext)
262{
263 int j, m;
264
265 /* Look through the array of templates to find a matching one. */
266 for (j = 0; j < G2C_MAX_DRS_TEMPLATE; j++)
267 {
268 if (drs_template_num == templatesdrs[j].template_num)
269 {
270 /* Copy maplen and map if the caller wants them. */
271 if (maplen)
272 *maplen = templatesdrs[j].mapdrslen;
273 if (map)
274 for (m = 0; m < templatesdrs[j].mapdrslen; m++)
275 map[m] = templatesdrs[j].mapdrs[m];
276 if (needext)
277 *needext = templatesdrs[j].needext;
278
279 /* Done. */
280 return G2C_NOERROR;
281 }
282 }
283
284 /* If we didn't find a template, return an error. */
285 return G2C_ENOTEMPLATE;
286}
287
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:311
#define G2C_ENOTEMPLATE
Template not found.
Definition grib2.h:512
#define G2C_MAX_DRS_TEMPLATE_MAPLEN
Maximum DRS template map length.
Definition grib2.h:312
int64_t g2int
Long integer type.
Definition grib2.h:32
#define G2C_NOERROR
No error.
Definition grib2.h:491
Header file with internal function prototypes NCEPLIBS-g2c library.
Struct for GRIB template, returned by getgridtemplate().
Definition grib2_int.h:276