35 unsigned char *cpack,
g2int *lcpack)
37 static g2int zero = 0;
39 g2int j, nbits, imin, imax, maxdif, nbittot, left;
40 g2float bscale, dscale, rmax, rmin, temp;
42 static g2float alog2 = 0.69314718;
46 if (idrstmpl[3] <= 0 || idrstmpl[3] > 31)
54 for (j = 1; j < ndpts; j++) {
61 ifld = calloc(ndpts,
sizeof(
g2int));
70 if (nbits == 0 && idrstmpl[1] == 0) {
74 imin = (
g2int)rint(rmin * dscale);
75 imax = (
g2int)rint(rmax * dscale);
77 temp = log((
double)(maxdif + 1)) / alog2;
78 nbits = (
g2int)ceil(temp);
81 for(j = 0; j < ndpts; j++)
82 ifld[j] = (
g2int)rint(fld[j] * dscale) - imin;
84 else if (nbits != 0 && idrstmpl[1] == 0) {
91 temp = log(maxnum / (rmax - rmin)) / alog2;
92 idrstmpl[1] = (
g2int)ceil(-1.0 * temp);
95 for (j = 0; j < ndpts; j++)
96 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
98 else if (nbits == 0 && idrstmpl[1] != 0) {
102 rmin = rmin * dscale;
103 rmax = rmax * dscale;
104 maxdif = (
g2int)rint((rmax - rmin) * bscale);
105 temp = log((
double)(maxdif + 1)) / alog2;
106 nbits = (
g2int)ceil(temp);
108 for (j = 0; j < ndpts; j++)
109 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
111 else if (nbits != 0 && idrstmpl[1] != 0) {
117 rmin = rmin * dscale;
119 for (j = 0; j < ndpts; j++)
120 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
125 sbits(cpack, ifld, 0, nbits, 0, ndpts);
126 nbittot = nbits * ndpts;
127 left = 8 - (nbittot % 8);
129 sbit(cpack, &zero, nbittot, left);
130 nbittot = nbittot + left;
132 *lcpack = nbittot / 8;
140 mkieee(&rmin, idrstmpl, 1);
void sbit(unsigned char *out, g2int *in, g2int iskip, g2int nbyte)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbyte, g2int nskip, g2int n)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.
double int_power(double x, g2int y)
Function similar to C pow() power function.
void mkieee(g2float *a, g2int *rieee, g2int num)
This subroutine stores a list of real values in 32-bit IEEE floating point format.
void simpack(g2float *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...