NCEPLIBS-g2c 2.0.0
Loading...
Searching...
No Matches
g2_unpack2.c
Go to the documentation of this file.
1
6#include "grib2_int.h"
7#include <stdio.h>
8#include <stdlib.h>
9
37g2_unpack2(unsigned char *cgrib, g2int *iofst, g2int *lencsec2,
38 unsigned char **csec2)
39{
40 g2int isecnum;
41 g2int lensec, ipos, j;
42
43 *lencsec2 = 0;
44 *csec2 = NULL;
45
46 /* Get Length of Section. */
47 gbit(cgrib, &lensec, *iofst, 32);
48 *iofst = *iofst + 32;
49 *lencsec2 = lensec - 5;
50
51 /* Get Section Number. */
52 gbit(cgrib, &isecnum, *iofst, 8);
53 *iofst = *iofst + 8;
54 ipos = *iofst / 8;
55
56 if (isecnum != 2)
57 {
58 *lencsec2 = 0;
59 fprintf(stderr, "g2_unpack2: Not Section 2 data.\n");
60 return G2_UNPACK_BAD_SEC;
61 }
62
63 /* If the length is 0, we are done. */
64 if (*lencsec2 == 0)
65 return G2_NO_ERROR;
66
67 if (!(*csec2 = malloc(*lencsec2)))
68 {
69 *lencsec2 = 0;
70 return G2_UNPACK_NO_MEM;
71 }
72
73 for (j = 0; j < *lencsec2; j++)
74 (*csec2)[j] = cgrib[ipos + j];
75
76 *iofst = *iofst + (*lencsec2 * 8);
77
78 return G2_NO_ERROR;
79}
g2int g2_unpack2(unsigned char *cgrib, g2int *iofst, g2int *lencsec2, unsigned char **csec2)
Unpack Section 2 (Local Use Section) of a GRIB2 message.
Definition g2_unpack2.c:37
void gbit(unsigned char *in, g2int *iout, g2int iskip, g2int nbits)
Get arbitrary size values from a packed bit string, right justifying each value in the unpacked iout ...
Definition gbits.c:20
#define G2_UNPACK_BAD_SEC
Bad section number in unpacking function.
Definition grib2.h:449
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
Definition grib2.h:450
#define G2_NO_ERROR
Function succeeded.
Definition grib2.h:423
int64_t g2int
Long integer type.
Definition grib2.h:32
Header file with internal function prototypes NCEPLIBS-g2c library.