Loading...
Searching...
No Matches
g2_unpack1.c
Go to the documentation of this file.
#include "grib2_int.h"
#include <stdio.h>
#include <stdlib.h>
g2int
g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen)
{
g2int i, lensec, nbits, isecnum;
/* The map holds the number of bytes used by each value in section
* 1. */
g2int mapid[13] = {2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1};
*idslen = 13;
gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */
*iofst = *iofst + 32;
gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */
*iofst = *iofst + 8;
if (isecnum != 1)
{
*idslen = 13;
fprintf(stderr, "g2_unpack1: Not Section 1 data.\n");
return G2_UNPACK_BAD_SEC;
}
/* Unpack each value into array ids from the appropriate number of
* octets, which are specified in` corresponding entries in array
* mapid. */
if (!(*ids = calloc(*idslen, sizeof(g2int))))
return G2_UNPACK_NO_MEM;
for (i = 0; i < *idslen; i++)
{
nbits = mapid[i] * 8;
gbit(cgrib, *ids + i, *iofst, nbits);
*iofst = *iofst + nbits;
}
return G2_NO_ERROR;
}
g2_unpack1
g2int g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen)
Unpacks Section 1 - Identification Section of a GRIB2 message.
Definition g2_unpack1.c:55
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:457
G2_UNPACK_NO_MEM
#define G2_UNPACK_NO_MEM
Error allocating memory in unpack function.
Definition grib2.h:458
G2_NO_ERROR
#define G2_NO_ERROR
Function succeeded.
Definition grib2.h:431
g2int
int64_t g2int
Long integer type.
Definition grib2.h:32
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.