Loading...
Searching...
No Matches
drstemplates.c
Go to the documentation of this file.
#include "grib2_int.h"
struct drstemplate
{
g2int template_num;
g2int mapdrslen;
g2int needext;
g2int mapdrs[G2C_MAX_DRS_TEMPLATE_MAPLEN];
};
static const struct drstemplate templatesdrs[G2C_MAX_DRS_TEMPLATE] =
{
{0, 5, 0, {4, -2, -2, 1, 1}},
{2, 16, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1}},
{3, 18, 0, {4, -2, -2, 1, 1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 4, 1, 1, 1}},
{50, 5, 0, {4, -2, -2, 1, 4}},
{51, 10, 0, {4, -2, -2, 1, -4, 2, 2, 2, 4, 1}},
/* 5.1: Matrix values at gridpoint - Simple packing.
* Comment from Stephen Gilbert in 2021:
*
* This encoder/decoder was written in the early days of GRIB2
* adoption as a standard. It was used to help WMO validate the
* templates in the specification by sharing GRIB2 encoded message
* with other organizations to verify that the data could be
* transmitted and processed successfully.
*
* We did not have a use case for DRS template 5.1 at that time
* and did not produce any GRIB2 messages using that template. It
* appears that other organizations did not work on it as
* well. The latest GRIB2 specification still includes the DRS
* Template 5.1 definition, but there is a disclaimer to use it
* with caution, since it has not yet been validated. I assume we
* commented it out because it was not validated, which means it's
* definition could possibly change during any validation attempts
* in the future.
*/
/* {1, 15, 1, {4, -2, -2, 1, 1, 1, 4, 2, 2, 1, 1, 1, 1, 1, 1}}, */
{40, 7, 0, {4, -2, -2, 1, 1, 1, 1}},
{41, 5, 0, {4, -2, -2, 1, 1}},
{42, 8, 0, {4, -2, -2, 1, 1, 1, 1, 2}},
{53, 11, 0, {4, -2, -2, 1, 1, 1, -4, 2, 2, 4, 1}},
{40000, 7, 0, {4, -2, -2, 1, 1, 1, 1}},
{40010, 5, 0, {4, -2, -2, 1, 1}},
};
static g2int
getdrsindex(g2int number)
{
g2int j, getdrsindex = -1;
for (j = 0; j < G2C_MAX_DRS_TEMPLATE; j++)
{
if (number == templatesdrs[j].template_num)
{
getdrsindex = j;
return (getdrsindex);
}
}
return (getdrsindex);
}
gtemplate *
getdrstemplate(g2int number)
{
g2int index;
gtemplate *new;
index = getdrsindex(number);
if (index != -1)
{
new = malloc(sizeof(gtemplate));
new->type = 5;
new->num = templatesdrs[index].template_num;
new->maplen = templatesdrs[index].mapdrslen;
new->needext = templatesdrs[index].needext;
new->map = (g2int *)templatesdrs[index].mapdrs;
new->extlen = 0;
new->ext = NULL;
return (new);
}
else
{
printf("getdrstemplate: DRS Template 5.%d not defined.\n", (int)number);
return (NULL);
}
return (NULL);
}
gtemplate *
extdrstemplate(g2int number, g2int *list)
{
gtemplate *new;
if (getdrsindex(number) == -1)
return NULL;
new = getdrstemplate(number);
if (!new->needext)
return (new);
/* This template is commented out (see comment in struct
* drstemplate for explanation). */
/* if (number == 1) */
/* { */
/* new->extlen = list[10] + list[12]; */
/* new->ext = malloc(sizeof(g2int) * new->extlen); */
/* for (i = 0; i < new->extlen; i++) */
/* { */
/* new->ext[i] = 4; */
/* } */
/* } */
return new;
}
int
g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext)
{
int j, m;
/* Look through the array of templates to find a matching one. */
for (j = 0; j < G2C_MAX_DRS_TEMPLATE; j++)
{
if (drs_template_num == templatesdrs[j].template_num)
{
/* Copy maplen and map if the caller wants them. */
if (maplen)
*maplen = templatesdrs[j].mapdrslen;
if (map)
for (m = 0; m < templatesdrs[j].mapdrslen; m++)
map[m] = templatesdrs[j].mapdrs[m];
if (needext)
*needext = templatesdrs[j].needext;
/* Done. */
return G2C_NOERROR;
}
}
/* If we didn't find a template, return an error. */
return G2C_ENOTEMPLATE;
}
templatesdrs
static const struct drstemplate templatesdrs[G2C_MAX_DRS_TEMPLATE]
Stuct holding data for GRIB2 Data Representation Section (DRS) template.
Definition drstemplates.c:54
getdrsindex
static g2int getdrsindex(g2int number)
This function returns the index of specified Data Representation Template.
Definition drstemplates.c:140
getdrstemplate
gtemplate * getdrstemplate(g2int number)
This subroutine returns DRS template information for a specified Data Representation Template.
Definition drstemplates.c:172
g2c_get_drs_template
int g2c_get_drs_template(int drs_template_num, int *maplen, int *map, int *needext)
Get DRS template information.
Definition drstemplates.c:266
extdrstemplate
gtemplate * extdrstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Data Representation Template,...
Definition drstemplates.c:218
G2C_MAX_DRS_TEMPLATE
#define G2C_MAX_DRS_TEMPLATE
Maximum number of DRS templates.
Definition grib2.h:296
G2C_ENOTEMPLATE
#define G2C_ENOTEMPLATE
Template not found.
Definition grib2.h:505
G2C_MAX_DRS_TEMPLATE_MAPLEN
#define G2C_MAX_DRS_TEMPLATE_MAPLEN
Maximum DRS template map length.
Definition grib2.h:297
g2int
int64_t g2int
Long integer type.
Definition grib2.h:32
G2C_NOERROR
#define G2C_NOERROR
No error.
Definition grib2.h:484
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
gtemplate
Struct for GRIB template, returned by getgridtemplate().
Definition grib2_int.h:278