NCEPLIBS-g2c  1.7.0
drstemplates.c
Go to the documentation of this file.
1 
35 #include <stdlib.h>
36 #include "grib2_int.h"
37 
38 #define MAXDRSTEMP 9
39 #define MAXDRSMAPLEN 200
44 struct drstemplate
45 {
46  g2int template_num;
47  g2int mapdrslen;
48  g2int needext;
49  g2int mapdrs[MAXDRSMAPLEN];
50 };
51 
56 static const struct drstemplate templatesdrs[MAXDRSTEMP] =
57 {
60  { 0, 5, 0, {4,-2,-2,1,1} },
61 
64  { 2, 16, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1} },
65 
68  { 3, 18, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1,1,1} },
69 
72  { 50, 5, 0, {4,-2,-2,1,4} },
73 
76  { 51, 10, 0, {4,-2,-2,1,-4,2,2,2,4,1} },
77 
78  /* 5.1: Matrix values at gridpoint - Simple packing.
79  * Comment from Stephen Gilbert in 2021:
80  *
81  * This encoder/decoder was written in the early days of GRIB2
82  * adoption as a standard. It was used to help WMO validate the
83  * templates in the specification by sharing GRIB2 encoded message
84  * with other organizations to verify that the data could be
85  * transmitted and processed successfully.
86  *
87  * We did not have a use case for DRS template 5.1 at that time
88  * and did not produce any GRIB2 messages using that template. It
89  * appears that other organizations did not work on it as
90  * well. The latest GRIB2 specification still includes the DRS
91  * Template 5.1 definition, but there is a disclaimer to use it
92  * with caution, since it has not yet been validated. I assume we
93  * commented it out because it was not validated, which means it's
94  * definition could possibly change during any validation attempts
95  * in the future.
96  */
97 
98  /* { 1, 15, 1, {4,-2,-2,1,1,1,4,2,2,1,1,1,1,1,1} }, */
99 
102  { 40, 7, 0, {4,-2,-2,1,1,1,1} },
103 
106  { 41, 5, 0, {4,-2,-2,1,1} },
107 
112  { 40000, 7, 0, {4,-2,-2,1,1,1,1} },
113 
118  { 40010, 5, 0, {4,-2,-2,1,1} }
119 } ;
120 
133 static g2int
135 {
136  g2int j, getdrsindex = -1;
137 
138  for (j = 0; j < MAXDRSTEMP; j++)
139  {
140  if (number == templatesdrs[j].template_num)
141  {
142  getdrsindex = j;
143  return(getdrsindex);
144  }
145  }
146 
147  return(getdrsindex);
148 }
149 
165 gtemplate *
167 {
168  g2int index;
169  gtemplate *new;
170 
171  index = getdrsindex(number);
172 
173  if (index != -1)
174  {
175  new = malloc(sizeof(gtemplate));
176  new->type = 5;
177  new->num = templatesdrs[index].template_num;
178  new->maplen = templatesdrs[index].mapdrslen;
179  new->needext = templatesdrs[index].needext;
180  new->map = (g2int *)templatesdrs[index].mapdrs;
181  new->extlen = 0;
182  new->ext = NULL;
183  return(new);
184  }
185  else
186  {
187  printf("getdrstemplate: DRS Template 5.%d not defined.\n", (int)number);
188  return(NULL);
189  }
190 
191  return(NULL);
192 }
193 
211 gtemplate *
212 extdrstemplate(g2int number, g2int *list)
213 {
214  gtemplate *new;
215 
216  if (getdrsindex(number) == -1)
217  return NULL;
218 
219  new = getdrstemplate(number);
220 
221  if (!new->needext)
222  return(new);
223 
224  /* This template is commented out (see comment in struct
225  * drstemplate for explanation). */
226  /* if (number == 1) */
227  /* { */
228  /* new->extlen = list[10] + list[12]; */
229  /* new->ext = malloc(sizeof(g2int) * new->extlen); */
230  /* for (i = 0; i < new->extlen; i++) */
231  /* { */
232  /* new->ext[i] = 4; */
233  /* } */
234  /* } */
235 
236  return new;
237 }
getdrstemplate
gtemplate * getdrstemplate(g2int number)
This subroutine returns DRS template information for a specified Data Representation Template.
Definition: drstemplates.c:166
MAXDRSMAPLEN
#define MAXDRSMAPLEN
maximum template map length
Definition: drstemplates.c:39
templatesdrs
static const struct drstemplate templatesdrs[MAXDRSTEMP]
Stuct holding data for GRIB2 Data Representation Section (DRS) template.
Definition: drstemplates.c:56
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
extdrstemplate
gtemplate * extdrstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Data Representation Template,...
Definition: drstemplates.c:212
getdrsindex
static g2int getdrsindex(g2int number)
This function returns the index of specified Data Representation Template.
Definition: drstemplates.c:134
g2int
int64_t g2int
Long integer type.
Definition: grib2.h:28
MAXDRSTEMP
#define MAXDRSTEMP
maximum number of templates
Definition: drstemplates.c:38
gtemplate
Struct for GRIB template.
Definition: grib2_int.h:28