NCEPLIBS-g2c  1.6.4
drstemplates.c
Go to the documentation of this file.
1 
15 #include <stdlib.h>
16 #include "grib2.h"
17 #include "drstemplates.h"
18 
31 g2int
33 {
34  g2int j, getdrsindex = -1;
35 
36  for (j = 0; j < MAXDRSTEMP; j++)
37  {
38  if (number == templatesdrs[j].template_num)
39  {
40  getdrsindex = j;
41  return(getdrsindex);
42  }
43  }
44 
45  return(getdrsindex);
46 }
47 
63 gtemplate *
65 {
66  g2int index;
67  gtemplate *new;
68 
69  index = getdrsindex(number);
70 
71  if (index != -1)
72  {
73  new = malloc(sizeof(gtemplate));
74  new->type = 5;
75  new->num = templatesdrs[index].template_num;
76  new->maplen = templatesdrs[index].mapdrslen;
77  new->needext = templatesdrs[index].needext;
78  new->map = (g2int *)templatesdrs[index].mapdrs;
79  new->extlen = 0;
80  new->ext = NULL;
81  return(new);
82  }
83  else
84  {
85  printf("getdrstemplate: DRS Template 5.%d not defined.\n", (int)number);
86  return(NULL);
87  }
88 
89  return(NULL);
90 }
91 
109 gtemplate *
110 extdrstemplate(g2int number, g2int *list)
111 {
112  gtemplate *new;
113  g2int index, i;
114 
115  index = getdrsindex(number);
116  if (index == -1)
117  return(0);
118 
119  new = getdrstemplate(number);
120 
121  if (!new->needext)
122  return(new);
123 
124  if (number == 1)
125  {
126  new->extlen = list[10] + list[12];
127  new->ext = malloc(sizeof(g2int) * new->extlen);
128  for (i = 0; i < new->extlen; i++)
129  {
130  new->ext[i] = 4;
131  }
132  }
133  return(new);
134 }
gtemplate * extdrstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Data Representation Template,...
Definition: drstemplates.c:110
g2int getdrsindex(g2int number)
This function returns the index of specified Data Representation Template.
Definition: drstemplates.c:32
gtemplate * getdrstemplate(g2int number)
This subroutine returns DRS template information for a specified Data Representation Template.
Definition: drstemplates.c:64
This C struct contains info on all the available GRIB2 Data Representation Templates used in Section ...
const struct drstemplate templatesdrs[MAXDRSTEMP]
Stuct holding data for GRIB2 Data Representation Section (DRS) template.
Definition: drstemplates.h:54
g2int needext
Whether the Template needs to be extended.
Definition: drstemplates.h:46
g2int mapdrslen
Length of map of the template.
Definition: drstemplates.h:45
#define MAXDRSTEMP
maximum number of templates
Definition: drstemplates.h:36
g2int template_num
The number of entries in the template.
Definition: drstemplates.h:44
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.
Definition: grib2.h:20
Struct for GRIB template.
Definition: grib2.h:28