NCEPLIBS-g2c  1.7.0
getdim.c
Go to the documentation of this file.
1 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "grib2_int.h"
10 
28 g2int
29 getdim(unsigned char *csec3, g2int *width, g2int *height, g2int *iscan)
30 {
31  g2int *igdstmpl = NULL, *list_opt = NULL;
32  g2int *igds = NULL;
33  g2int iofst, igdtlen, num_opt, jerr;
34 
35  iofst = 0; /* set offset to beginning of section */
36  if (!(jerr = g2_unpack3(csec3, &iofst, &igds, &igdstmpl, &igdtlen,
37  &list_opt, &num_opt)))
38  {
39  switch (igds[4]) /* Template number */
40  {
41  case 0: /* Lat/Lon */
42  case 1:
43  case 2:
44  case 3:
45  {
46  *width = igdstmpl[7];
47  *height = igdstmpl[8];
48  *iscan = igdstmpl[18];
49  break;
50  }
51  case 10: /* Mercator */
52  {
53  *width = igdstmpl[7];
54  *height = igdstmpl[8];
55  *iscan = igdstmpl[15];
56  break;
57  }
58  case 20: /* Polar Stereographic */
59  {
60  *width = igdstmpl[7];
61  *height = igdstmpl[8];
62  *iscan = igdstmpl[17];
63  break;
64  }
65  case 30: /* Lambert Conformal */
66  {
67  *width = igdstmpl[7];
68  *height = igdstmpl[8];
69  *iscan = igdstmpl[17];
70  break;
71  }
72  case 40: /* Gaussian */
73  case 41:
74  case 42:
75  case 43:
76  {
77  *width = igdstmpl[7];
78  *height = igdstmpl[8];
79  *iscan = igdstmpl[18];
80  break;
81  }
82  case 90: /* Space View/Orthographic */
83  {
84  *width = igdstmpl[7];
85  *height = igdstmpl[8];
86  *iscan = igdstmpl[16];
87  break;
88  }
89  case 110: /* Equatorial Azimuthal */
90  {
91  *width = igdstmpl[7];
92  *height = igdstmpl[8];
93  *iscan = igdstmpl[15];
94  break;
95  }
96  default:
97  {
98  *width = 0;
99  *height = 0;
100  *iscan = 0;
101  break;
102  }
103  } /* end switch */
104  }
105  else
106  {
107  *width = 0;
108  *height = 0;
109  }
110 
111  if (igds)
112  free(igds);
113  if (igdstmpl)
114  free(igdstmpl);
115  if (list_opt)
116  free(list_opt);
117 
118  return 0;
119 }
getdim
g2int getdim(unsigned char *csec3, g2int *width, g2int *height, g2int *iscan)
This subroutine returns the dimensions and scanning mode of a grid definition packed in GRIB2 Grid De...
Definition: getdim.c:29
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
g2int
int64_t g2int
Long integer type.
Definition: grib2.h:28
g2_unpack3
g2int g2_unpack3(unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, g2int *mapgridlen, g2int **ideflist, g2int *idefnum)
This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.
Definition: g2_unpack3.c:57