37 unsigned char *cpack,
g2int *lcpack)
39 static g2int zero = 0;
41 g2int j, nbits, imin, imax, maxdif, nbittot, left;
42 float bscale, dscale, rmax, rmin, temp;
44 static float alog2 =
ALOG2;
46 LOG((3,
"simpack ndpts %ld", ndpts));
50 if (idrstmpl[3] <= 0 || idrstmpl[3] > 31)
58 for (j = 1; j < ndpts; j++)
66 ifld = calloc(ndpts,
sizeof(
g2int));
76 if (nbits == 0 && idrstmpl[1] == 0)
81 imin = (
g2int)rint(rmin * dscale);
82 imax = (
g2int)rint(rmax * dscale);
84 temp = log((
double)(maxdif + 1)) / alog2;
85 nbits = (
g2int)ceil(temp);
88 for (j = 0; j < ndpts; j++)
89 ifld[j] = (
g2int)rint(fld[j] * dscale) - imin;
91 else if (nbits != 0 && idrstmpl[1] == 0)
99 temp = log(maxnum / (rmax - rmin)) / alog2;
100 idrstmpl[1] = (
g2int)ceil(-1.0 * temp);
103 for (j = 0; j < ndpts; j++)
104 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
106 else if (nbits == 0 && idrstmpl[1] != 0)
111 rmin = rmin * dscale;
112 rmax = rmax * dscale;
113 maxdif = (
g2int)rint((rmax - rmin) * bscale);
114 temp = log((
double)(maxdif + 1)) / alog2;
115 nbits = (
g2int)ceil(temp);
117 for (j = 0; j < ndpts; j++)
118 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
120 else if (nbits != 0 && idrstmpl[1] != 0)
127 rmin = rmin * dscale;
129 for (j = 0; j < ndpts; j++)
130 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
135 sbits(cpack, ifld, 0, nbits, 0, ndpts);
136 nbittot = nbits * ndpts;
137 left = 8 - (nbittot % 8);
140 sbit(cpack, &zero, nbittot, left);
141 nbittot = nbittot + left;
143 *lcpack = nbittot / 8;
152 mkieee(&rmin, idrstmpl, 1);
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n)
Store arbitrary size values into a packed bit string, taking the low order bits from each value in th...
void sbit(unsigned char *out, g2int *in, g2int iskip, g2int nbits)
Store arbitrary size values into a packed bit string, taking the low order bits from each value in th...
void mkieee(float *a, g2int *rieee, g2int num)
Store a list of real values in 32-bit IEEE floating point format.
void simpack(float *fld, g2int ndpts, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
Packs a data field using the simple packing algorithm.