NCEPLIBS-g2c  1.6.4
gridtemplates.c
Go to the documentation of this file.
1 
18 #include <stdlib.h>
19 #include "grib2.h"
20 #include "gridtemplates.h"
21 
36 g2int
38 {
39  g2int j, getgridindex = -1;
40 
41  for (j = 0; j < MAXGRIDTEMP; j++)
42  {
43  if (number == templatesgrid[j].template_num)
44  {
45  getgridindex = j;
46  return(getgridindex);
47  }
48  }
49 
50  return(getgridindex);
51 }
52 
74 gtemplate *
76 {
77  g2int index;
78  gtemplate *new;
79 
80  index = getgridindex(number);
81 
82  if (index != -1)
83  {
84  new = malloc(sizeof(gtemplate));
85  new->type = 3;
86  new->num = templatesgrid[index].template_num;
87  new->maplen = templatesgrid[index].mapgridlen;
88  new->needext = templatesgrid[index].needext;
89  new->map = (g2int *)templatesgrid[index].mapgrid;
90  new->extlen = 0;
91  new->ext = NULL;
92  return(new);
93  }
94  else
95  {
96  printf("getgridtemplate: GDT Template 3.%d not defined.\n", (int)number);
97  return(NULL);
98  }
99 
100  return(NULL);
101 }
102 
123 gtemplate *
125 {
126  gtemplate *new;
127  g2int index, i;
128 
129  index = getgridindex(number);
130  if (index == -1)
131  return(0);
132 
133  new = getgridtemplate(number);
134 
135  if (!new->needext)
136  return(new);
137 
138  if (number == 120)
139  {
140  new->extlen = list[1] * 2;
141  new->ext = malloc(sizeof(g2int) * new->extlen);
142  for (i = 0; i < new->extlen; i++)
143  {
144  if (i % 2 == 0)
145  new->ext[i] = 2;
146  else
147  new->ext[i] = -2;
148  }
149  }
150  else if (number == 4)
151  {
152  new->extlen = list[7];
153  new->ext = malloc(sizeof(g2int) * new->extlen);
154  for (i = 0; i < new->extlen; i++)
155  {
156  new->ext[i] = 4;
157  }
158  new->extlen = list[8];
159  new->ext = malloc(sizeof(g2int) * new->extlen);
160  for (i = 0; i < new->extlen; i++)
161  {
162  new->ext[i] = -4;
163  }
164  }
165  else if (number == 5)
166  {
167  new->extlen = list[7];
168  new->ext = malloc(sizeof(g2int) * new->extlen);
169  for (i = 0; i < new->extlen; i++)
170  {
171  new->ext[i] = 4;
172  }
173  new->extlen = list[8];
174  new->ext = malloc(sizeof(g2int) * new->extlen);
175  for (i = 0; i < new->extlen; i++)
176  {
177  new->ext[i] = -4;
178  }
179  }
180  else if (number == 1000)
181  {
182  new->extlen = list[19];
183  new->ext = malloc(sizeof(g2int) * new->extlen);
184  for (i = 0; i < new->extlen; i++)
185  {
186  new->ext[i] = 4;
187  }
188  }
189  else if (number == 1200)
190  {
191  new->extlen = list[15];
192  new->ext = malloc(sizeof(g2int) * new->extlen);
193  for (i = 0; i < new->extlen; i++)
194  {
195  new->ext[i] = 4;
196  }
197  }
198 
199  return(new);
200 }
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.
Definition: grib2.h:20
Struct for GRIB template.
Definition: grib2.h:28
gtemplate * extgridtemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Grid Definition Template,...
g2int getgridindex(g2int number)
This function returns the index of specified Grid Definition Template in array templates for [Section...
Definition: gridtemplates.c:37
gtemplate * getgridtemplate(g2int number)
This subroutine returns grid template information for a specified Grid Definition Template for [Secti...
Definition: gridtemplates.c:75
This header file contains info on all the available GRIB2 Grid Definition Templates used in Section 3...
g2int template_num
Template number.
Definition: gridtemplates.h:51
#define MAXGRIDTEMP
Maximum number of templates.
Definition: gridtemplates.h:43
g2int needext
Does template need extension?
Definition: gridtemplates.h:53
g2int mapgridlen
The number of entries in the template.
Definition: gridtemplates.h:52
const struct gridtemplate templatesgrid[MAXGRIDTEMP]
Templates grid.
Definition: gridtemplates.h:60