Loading...
Searching...
No Matches
g2_unpack2.c
Go to the documentation of this file.
#include "grib2_int.h"
#include <stdio.h>
#include <stdlib.h>
g2int
g2_unpack2(unsigned char *cgrib, g2int *iofst, g2int *lencsec2,
unsigned char **csec2)
{
g2int isecnum;
g2int lensec, ipos, j;
*lencsec2 = 0;
*csec2 = NULL;
/* Get Length of Section. */
gbit(cgrib, &lensec, *iofst, 32);
*iofst = *iofst + 32;
*lencsec2 = lensec - 5;
/* Get Section Number. */
gbit(cgrib, &isecnum, *iofst, 8);
*iofst = *iofst + 8;
ipos = *iofst / 8;
if (isecnum != 2)
{
*lencsec2 = 0;
fprintf(stderr, "g2_unpack2: Not Section 2 data.\n");
return G2_UNPACK_BAD_SEC;
}
/* If the length is 0, we are done. */
if (*lencsec2 == 0)
return G2_NO_ERROR;
if (!(*csec2 = malloc(*lencsec2)))
{
*lencsec2 = 0;
return G2_UNPACK_NO_MEM;
}
for (j = 0; j < *lencsec2; j++)
(*csec2)[j] = cgrib[ipos + j];
*iofst = *iofst + (*lencsec2 * 8);
return G2_NO_ERROR;
}
g2_unpack2
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
gbit
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
G2_UNPACK_BAD_SEC
#define G2_UNPACK_BAD_SEC
Bad section number in unpacking function.
Definition grib2.h:463
G2_UNPACK_NO_MEM
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
Definition grib2.h:464
G2_NO_ERROR
#define G2_NO_ERROR
Function succeeded.
Definition grib2.h:437
g2int
int64_t g2int
Long integer type.
Definition grib2.h:32
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.