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;
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);