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++) {
65 ifld = calloc(ndpts,
sizeof(
g2int));
74 if (nbits == 0 && idrstmpl[1] == 0) {
78 imin = (
g2int)rint(rmin * dscale);
79 imax = (
g2int)rint(rmax * dscale);
81 temp = log((
double)(maxdif + 1)) / alog2;
82 nbits = (
g2int)ceil(temp);
85 for(j = 0; j < ndpts; j++)
86 ifld[j] = (
g2int)rint(fld[j] * dscale) - imin;
88 else if (nbits != 0 && idrstmpl[1] == 0) {
95 temp = log(maxnum / (rmax - rmin)) / alog2;
96 idrstmpl[1] = (
g2int)ceil(-1.0 * temp);
99 for (j = 0; j < ndpts; j++)
100 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
102 else if (nbits == 0 && idrstmpl[1] != 0) {
106 rmin = rmin * dscale;
107 rmax = rmax * dscale;
108 maxdif = (
g2int)rint((rmax - rmin) * bscale);
109 temp = log((
double)(maxdif + 1)) / alog2;
110 nbits = (
g2int)ceil(temp);
112 for (j = 0; j < ndpts; j++)
113 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
115 else if (nbits != 0 && idrstmpl[1] != 0) {
121 rmin = rmin * dscale;
123 for (j = 0; j < ndpts; j++)
124 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
129 sbits(cpack, ifld, 0, nbits, 0, ndpts);
130 nbittot = nbits * ndpts;
131 left = 8 - (nbittot % 8);
133 sbit(cpack, &zero, nbittot, left);
134 nbittot = nbittot + left;
136 *lcpack = nbittot / 8;
144 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.