43 unsigned char *cpack,
g2int *lcpack)
46 static g2int zero = 0;
47 g2int *ifld, *gref, *glen, *gwidth;
48 g2int *jmin, *jmax, *lbit;
49 g2int i, j, n, imin, imax, left;
50 g2int isd, itemp, ilmax, ngwidthref = 0, nbitsgwidth = 0;
51 g2int nglenref = 0, nglenlast = 0, iofst, ival1, ival2;
52 g2int minsd, nbitsd = 0, maxorig, nbitorig, ngroups;
53 g2int lg, ng, igmax, iwmax, nbitsgref;
54 g2int glength, grpwidth, nbitsglen = 0;
55 g2int kfildo, minpk, inc, maxgrps, ibit, jbit, kbit, novref, lbitref;
56 g2int missopt, miss1, miss2, ier;
57 float bscale, dscale, rmax, rmin, temp;
58 static float alog2 =
ALOG2;
67 for (j = 1; j < ndpts; j++)
81 ifld = calloc(ndpts,
sizeof(
g2int));
82 gref = calloc(ndpts,
sizeof(
g2int));
83 gwidth = calloc(ndpts,
sizeof(
g2int));
84 glen = calloc(ndpts,
sizeof(
g2int));
89 imin = (
g2int)rint(rmin * dscale);
92 for (j = 0; j < ndpts; j++)
93 ifld[j] = (
g2int)rint(fld[j] * dscale) - imin;
99 for (j = 0; j < ndpts; j++)
100 ifld[j] = (
g2int)rint(((fld[j] * dscale) - rmin) * bscale);
107 if (idrstmpl[16] != 1 && idrstmpl[16] != 2)
109 if (idrstmpl[16] == 1)
112 for (j = ndpts - 1; j > 0; j--)
113 ifld[j] = ifld[j] - ifld[j - 1];
116 else if (idrstmpl[16] == 2)
120 for (j = ndpts - 1; j > 1; j--)
121 ifld[j] = ifld[j] - (2 * ifld[j - 1]) + ifld[j - 2];
129 for (j = isd; j < ndpts; j++)
132 for (j = isd; j < ndpts; j++)
133 ifld[j] = ifld[j] - minsd;
136 temp = log((
double)(abs(minsd) + 1)) / alog2;
137 nbitsd = (
g2int)ceil(temp) + 1;
142 if (idrstmpl[16] == 2 && ival2 > ival1)
144 temp = log((
double)(maxorig + 1)) / alog2;
145 nbitorig = (
g2int)ceil(temp) + 1;
146 if (nbitorig > nbitsd)
150 if ((nbitsd % 8) != 0)
151 nbitsd = nbitsd + (8 - (nbitsd % 8));
160 sbit(cpack, &ival1, iofst, nbitsd);
161 iofst = iofst + nbitsd;
165 sbit(cpack, &one, iofst, 1);
168 sbit(cpack, &itemp, iofst, nbitsd - 1);
169 iofst = iofst + nbitsd - 1;
171 if (idrstmpl[16] == 2)
176 sbit(cpack, &ival2, iofst, nbitsd);
177 iofst = iofst + nbitsd;
181 sbit(cpack, &one, iofst, 1);
184 sbit(cpack, &itemp, iofst, nbitsd - 1);
185 iofst = iofst + nbitsd - 1;
192 sbit(cpack, &minsd, iofst, nbitsd);
193 iofst = iofst + nbitsd;
197 sbit(cpack, &one, iofst, 1);
200 sbit(cpack, &itemp, iofst, nbitsd - 1);
201 iofst = iofst + nbitsd - 1;
210 maxgrps = (ndpts / minpk) + 1;
211 jmin = calloc(maxgrps,
sizeof(
g2int));
212 jmax = calloc(maxgrps,
sizeof(
g2int));
213 lbit = calloc(maxgrps,
sizeof(
g2int));
215 pack_gp(&kfildo, ifld, &ndpts, &missopt, &minpk, &inc, &miss1, &miss2,
216 jmin, jmax, lbit, glen, &maxgrps, &ngroups, &ibit, &jbit,
217 &kbit, &novref, &lbitref, &ier);
218 for (ng = 0; ng < ngroups; ng++)
219 glen[ng] = glen[ng] + novref;
227 for (ng = 0; ng < ngroups; ng++)
233 for (lg = 1; lg < glen[ng]; lg++)
235 if (ifld[j] < gref[ng])
243 if (gref[ng] != imax)
245 temp = log((
double)(imax - gref[ng] + 1)) / alog2;
246 gwidth[ng] = (
g2int)ceil(temp);
252 for (lg = 0; lg < glen[ng]; lg++)
254 ifld[j] = ifld[j] - gref[ng];
265 for (j = 1; j < ngroups; j++)
270 temp = log((
double)(igmax + 1)) / alog2;
271 nbitsgref = (
g2int)ceil(temp);
272 sbits(cpack, gref, iofst, nbitsgref, 0, ngroups);
273 itemp = nbitsgref * ngroups;
274 iofst = iofst + itemp;
276 if ((itemp % 8) != 0)
278 left = 8 - (itemp % 8);
279 sbit(cpack, &zero, iofst, left);
280 iofst = iofst + left;
290 ngwidthref = gwidth[0];
291 for (j = 1; j < ngroups; j++)
293 if (gwidth[j] > iwmax)
295 if (gwidth[j] < ngwidthref)
296 ngwidthref = gwidth[j];
298 if (iwmax != ngwidthref)
300 temp = log((
double)(iwmax - ngwidthref + 1)) / alog2;
301 nbitsgwidth = (
g2int)ceil(temp);
302 for (i = 0; i < ngroups; i++)
303 gwidth[i] = gwidth[i] - ngwidthref;
304 sbits(cpack, gwidth, iofst, nbitsgwidth, 0, ngroups);
305 itemp = nbitsgwidth * ngroups;
306 iofst = iofst + itemp;
308 if ((itemp % 8) != 0)
310 left = 8 - (itemp % 8);
311 sbit(cpack, &zero, iofst, left);
312 iofst = iofst + left;
318 for (i = 0; i < ngroups; i++)
327 for (j = 1; j < ngroups - 1; j++)
331 if (glen[j] < nglenref)
334 nglenlast = glen[ngroups - 1];
335 if (ilmax != nglenref)
337 temp = log((
double)(ilmax - nglenref + 1)) / alog2;
338 nbitsglen = (
g2int)ceil(temp);
339 for (i = 0; i < ngroups - 1; i++)
340 glen[i] = glen[i] - nglenref;
341 sbits(cpack, glen, iofst, nbitsglen, 0, ngroups);
342 itemp = nbitsglen * ngroups;
343 iofst = iofst + itemp;
345 if ((itemp % 8) != 0)
347 left = 8 - (itemp % 8);
348 sbit(cpack, &zero, iofst, left);
349 iofst = iofst + left;
355 for (i = 0; i < ngroups; i++)
361 for (ng = 0; ng < ngroups; ng++)
363 glength = glen[ng] + nglenref;
364 if (ng == (ngroups - 1))
366 grpwidth = gwidth[ng] + ngwidthref;
369 sbits(cpack, ifld + n, iofst, grpwidth, 0, glength);
370 iofst = iofst + (grpwidth * glength);
375 if ((iofst % 8) != 0)
377 left = 8 - (iofst % 8);
378 sbit(cpack, &zero, iofst, left);
379 iofst = iofst + left;
402 mkieee(&rmin, idrstmpl, 1);
403 idrstmpl[3] = nbitsgref;
409 idrstmpl[9] = ngroups;
410 idrstmpl[10] = ngwidthref;
411 idrstmpl[11] = nbitsgwidth;
412 idrstmpl[12] = nglenref;
414 idrstmpl[14] = nglenlast;
415 idrstmpl[15] = nbitsglen;
418 idrstmpl[17] = nbitsd / 8;
int pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, g2int *is523, g2int *minpk, g2int *inc, g2int *missp, g2int *misss, g2int *jmin, g2int *jmax, g2int *lbit, g2int *nov, g2int *ndg, g2int *lx, g2int *ibit, g2int *jbit, g2int *kbit, g2int *novref, g2int *lbitref, g2int *ier)
Determines groups of variable size, but at least of size minpk, the associated max (jmax( )) and min ...