NCEPLIBS-g2c 2.0.0
Loading...
Searching...
No Matches
g2_unpack1.c
Go to the documentation of this file.
1
9#include "grib2_int.h"
10#include <stdio.h>
11#include <stdlib.h>
12
55g2_unpack1(unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen)
56{
57
58 g2int i, lensec, nbits, isecnum;
59 /* The map holds the number of bytes used by each value in section
60 * 1. */
61 g2int mapid[13] = {2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1};
62
63 *idslen = 13;
64
65 gbit(cgrib, &lensec, *iofst, 32); /* Get Length of Section */
66 *iofst = *iofst + 32;
67 gbit(cgrib, &isecnum, *iofst, 8); /* Get Section Number */
68 *iofst = *iofst + 8;
69
70 if (isecnum != 1)
71 {
72 *idslen = 13;
73 fprintf(stderr, "g2_unpack1: Not Section 1 data.\n");
74 return G2_UNPACK_BAD_SEC;
75 }
76
77 /* Unpack each value into array ids from the appropriate number of
78 * octets, which are specified in` corresponding entries in array
79 * mapid. */
80 if (!(*ids = calloc(*idslen, sizeof(g2int))))
81 return G2_UNPACK_NO_MEM;
82
83 for (i = 0; i < *idslen; i++)
84 {
85 nbits = mapid[i] * 8;
86 gbit(cgrib, *ids + i, *iofst, nbits);
87 *iofst = *iofst + nbits;
88 }
89
90 return G2_NO_ERROR;
91}
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
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.