35 unsigned char *cpack,
g2int *lcpack)
37 static g2int zero = 0;
39 g2int j, nbits, imin, imax, maxdif, nbittot, left;
40 float bscale, dscale, rmax, rmin, temp;
42 static float alog2 =
ALOG2;
44 LOG((3,
"simpack ndpts %ld", ndpts));
48 if (idrstmpl[3] <= 0 || idrstmpl[3] > 31)
56 for (j = 1; j < ndpts; j++) {
63 ifld = calloc(ndpts,
sizeof(
g2int));
72 if (nbits == 0 && idrstmpl[1] == 0) {
76 imin = (
g2int)rint(rmin * dscale);
77 imax = (
g2int)rint(rmax * dscale);
79 temp = log((
double)(maxdif + 1)) / alog2;
80 nbits = (
g2int)ceil(temp);
83 for(j = 0; j < ndpts; j++)
84 ifld[j] = (
g2int)rint(fld[j] * dscale) - imin;
86 else if (nbits != 0 && idrstmpl[1] == 0) {
93 temp = log(maxnum / (rmax - rmin)) / alog2;
94 idrstmpl[1] = (
g2int)ceil(-1.0 * temp);
97 for (j = 0; j < ndpts; j++)
98 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
100 else if (nbits == 0 && idrstmpl[1] != 0) {
104 rmin = rmin * dscale;
105 rmax = rmax * dscale;
106 maxdif = (
g2int)rint((rmax - rmin) * bscale);
107 temp = log((
double)(maxdif + 1)) / alog2;
108 nbits = (
g2int)ceil(temp);
110 for (j = 0; j < ndpts; j++)
111 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
113 else if (nbits != 0 && idrstmpl[1] != 0) {
119 rmin = rmin * dscale;
121 for (j = 0; j < ndpts; j++)
122 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
127 sbits(cpack, ifld, 0, nbits, 0, ndpts);
128 nbittot = nbits * ndpts;
129 left = 8 - (nbittot % 8);
131 sbit(cpack, &zero, nbittot, left);
132 nbittot = nbittot + left;
134 *lcpack = nbittot / 8;
142 mkieee(&rmin, idrstmpl, 1);
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
void sbit(unsigned char *out, g2int *in, g2int iskip, g2int nbits)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
int64_t g2int
Long integer type.
Header file with internal function prototypes NCEPLIBS-g2c library.
void mkieee(float *a, g2int *rieee, g2int num)
This subroutine stores a list of real values in 32-bit IEEE floating point format.
double int_power(double x, g2int y)
Function similar to C pow() power function.
#define LOG(e)
Ignore logging to stdout.
void simpack(float *fld, g2int ndpts, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field using the simple packing algorithm as defined in the GRIB2 docu...