NCEPLIBS-g2c  1.7.0
gridtemplates.c
Go to the documentation of this file.
1 
40 #include <stdlib.h>
41 #include "grib2_int.h"
42 #define MAXGRIDTEMP 31
43 #define MAXGRIDMAPLEN 200
48 struct gridtemplate
49 {
50  g2int template_num;
51  g2int mapgridlen;
52  g2int needext;
53  g2int mapgrid[MAXGRIDMAPLEN];
54 };
55 
59 static const struct gridtemplate templatesgrid[MAXGRIDTEMP] =
60 {
61  /* 3.0: Lat/Lon grid */
62  { 0, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} },
63  /* 3.1: Rotated Lat/Lon grid */
64  { 1, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4} },
65  /* 3.2: Stretched Lat/Lon grid */
66  { 2, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4} },
67  /* 3.3: Stretched & Rotated Lat/Lon grid */
68  { 3, 25, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4} },
69  /* Added GDT 3.4,3.5 (08/05/2013) */
70  /* 3.4: Variable resolution Latitude/Longitude */
71  { 4, 13, 1, {1,1,4,1,4,1,4,4,4,4,4,1,1} },
72  /* 3.5: Variable resolution rotate Latitude/Longitude */
73  { 5, 16, 1, {1,1,4,1,4,1,4,4,4,4,4,1,1,-4,4,4} },
74  /* 3.12: Transverse Mercator */
75  {12, 22, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,1,4,4,-4,-4,-4,-4} },
76  /* 3.101: General unstructured grid */
77  {101, 4, 0, {1,4,1,-4} },
78  /* 3.140: Lambert Azimuthal Equal Area Projection */
79  {140, 17, 0, {1,1,4,1,4,1,4,4,4,-4,4,4,4,1,4,4,1} },
80 
81  /* 3.10: Mercator */
82  {10, 19, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,-4,4,1,4,4,4} },
83  /* 3.20: Polar Stereographic Projection */
84  {20, 18, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1} },
85  /* 3.30: Lambert Conformal */
86  {30, 22, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4} },
87  /* 3.31: Albers equal area */
88  {31, 22, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4} },
89  /* 3.40: Guassian Lat/Lon */
90  {40, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} },
91  /* 3.41: Rotated Gaussian Lat/Lon */
92  {41, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4} },
93  /* 3.42: Stretched Gaussian Lat/Lon */
94  {42, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4} },
95  /* 3.43: Stretched and Rotated Gaussian Lat/Lon */
96  {43, 25, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4} },
97  /* 3.50: Spherical Harmonic Coefficients */
98  {50, 5, 0, {4,4,4,1,1} },
99  /* 3.51: Rotated Spherical Harmonic Coefficients */
100  {51, 8, 0, {4,4,4,1,1,-4,4,4} },
101  /* 3.52: Stretched Spherical Harmonic Coefficients */
102  {52, 8, 0, {4,4,4,1,1,-4,4,-4} },
103  /* 3.53: Stretched and Rotated Spherical Harmonic Coefficients */
104  {53, 11, 0, {4,4,4,1,1,-4,4,4,-4,4,-4} },
105  /* 3.90: Space View Perspective or orthographic */
106  {90, 21, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,4,4,4,4,1,4,4,4,4} },
107  /* 3.100: Triangular grid based on an icosahedron */
108  {100, 11, 0, {1,1,2,1,-4,4,4,1,1,1,4} },
109  /* 3.110: Equatorial Azimuthal equidistant */
110  {110, 16, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,4,4,1,1} },
111  /* 3.120: Azimuth-range projection */
112  {120, 7, 1, {4,4,-4,4,4,4,1} },
113  /* 3.204: Curvilinear Orthogonal Grid */
114  {204, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} },
115  /* 3.32768: Rot Lat/Lon E-grid (Arakawa) */
116  {32768, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} },
117  /* 3.32769: Rot Lat/Lon Non-E Staggered grid (Arakawa) */
118  {32769, 21, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,4,4} },
119  /* 3.1000: Cross Section Grid */
120  {1000, 20, 1, {1,1,4,1,4,1,4,4,4,4,-4,4,1,4,4,1,2,1,1,2} },
121  /* 3.1100: Hovmoller Diagram Grid */
122  {1100, 28, 0, {1,1,4,1,4,1,4,4,4,4,-4,4,1,-4,4,1,4,1,-4,1,1,-4,2,1,1,1,1,1} },
123  /* 3.1200: Time Section Grid */
124  {1200, 16, 1, {4,1,-4,1,1,-4,2,1,1,1,1,1,2,1,1,2} }
125 } ;
126 
141 static g2int
143 {
144  g2int j, getgridindex = -1;
145 
146  for (j = 0; j < MAXGRIDTEMP; j++)
147  {
148  if (number == templatesgrid[j].template_num)
149  {
150  getgridindex = j;
151  return(getgridindex);
152  }
153  }
154 
155  return(getgridindex);
156 }
157 
179 gtemplate *
181 {
182  g2int index;
183  gtemplate *new;
184 
185  index = getgridindex(number);
186 
187  if (index != -1)
188  {
189  new = malloc(sizeof(gtemplate));
190  new->type = 3;
191  new->num = templatesgrid[index].template_num;
192  new->maplen = templatesgrid[index].mapgridlen;
193  new->needext = templatesgrid[index].needext;
194  new->map = (g2int *)templatesgrid[index].mapgrid;
195  new->extlen = 0;
196  new->ext = NULL;
197  return(new);
198  }
199  else
200  {
201  printf("getgridtemplate: GDT Template 3.%d not defined.\n", (int)number);
202  return(NULL);
203  }
204 
205  return(NULL);
206 }
207 
228 gtemplate *
230 {
231  gtemplate *new;
232  g2int index, i;
233 
234  index = getgridindex(number);
235  if (index == -1)
236  return(0);
237 
238  new = getgridtemplate(number);
239 
240  if (!new->needext)
241  return(new);
242 
243  if (number == 120)
244  {
245  new->extlen = list[1] * 2;
246  new->ext = malloc(sizeof(g2int) * new->extlen);
247  for (i = 0; i < new->extlen; i++)
248  {
249  if (i % 2 == 0)
250  new->ext[i] = 2;
251  else
252  new->ext[i] = -2;
253  }
254  }
255  else if (number == 4)
256  {
257  new->extlen = list[7];
258  new->ext = malloc(sizeof(g2int) * new->extlen);
259  for (i = 0; i < new->extlen; i++)
260  {
261  new->ext[i] = 4;
262  }
263  new->extlen = list[8];
264  new->ext = malloc(sizeof(g2int) * new->extlen);
265  for (i = 0; i < new->extlen; i++)
266  {
267  new->ext[i] = -4;
268  }
269  }
270  else if (number == 5)
271  {
272  new->extlen = list[7];
273  new->ext = malloc(sizeof(g2int) * new->extlen);
274  for (i = 0; i < new->extlen; i++)
275  {
276  new->ext[i] = 4;
277  }
278  new->extlen = list[8];
279  new->ext = malloc(sizeof(g2int) * new->extlen);
280  for (i = 0; i < new->extlen; i++)
281  {
282  new->ext[i] = -4;
283  }
284  }
285  else if (number == 1000)
286  {
287  new->extlen = list[19];
288  new->ext = malloc(sizeof(g2int) * new->extlen);
289  for (i = 0; i < new->extlen; i++)
290  {
291  new->ext[i] = 4;
292  }
293  }
294  else if (number == 1200)
295  {
296  new->extlen = list[15];
297  new->ext = malloc(sizeof(g2int) * new->extlen);
298  for (i = 0; i < new->extlen; i++)
299  {
300  new->ext[i] = 4;
301  }
302  }
303 
304  return(new);
305 }
extgridtemplate
gtemplate * extgridtemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Grid Definition Template,...
Definition: gridtemplates.c:229
gtemplate::needext
g2int needext
Indicates whether or not the template needs to be extended.
Definition: grib2_int.h:46
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
MAXGRIDMAPLEN
#define MAXGRIDMAPLEN
Maximum template map length.
Definition: gridtemplates.c:43
templatesgrid
static const struct gridtemplate templatesgrid[MAXGRIDTEMP]
Templates grid.
Definition: gridtemplates.c:59
g2int
int64_t g2int
Long integer type.
Definition: grib2.h:28
MAXGRIDTEMP
#define MAXGRIDTEMP
Maximum number of templates.
Definition: gridtemplates.c:42
getgridindex
static g2int getgridindex(g2int number)
This function returns the index of specified Grid Definition Template in array templates for [Section...
Definition: gridtemplates.c:142
getgridtemplate
gtemplate * getgridtemplate(g2int number)
This subroutine returns grid template information for a specified Grid Definition Template for [Secti...
Definition: gridtemplates.c:180
gtemplate
Struct for GRIB template.
Definition: grib2_int.h:28