NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
w3fi58.f
Go to the documentation of this file.
1C> @file
2C> @brief Pack positive differences in least bits.
3C> @author Robert Allard @date 1987-09-02
4
5C> Converts an array of integer numbers into an array of
6C> positive differences (number(s) - minimum value) and packs the
7C> magnitude of each difference right-adjusted into the least
8C> number of bits that holds the largest difference.
9C>
10C> Program history log:
11C> - Robert Allard 1987-09-02
12C> - Ralph Jones 1988-10-02 Converted to cdc cyber 205 ftn200 fortran.
13C> - Ralph Jones 1990-05-17 Converted to cray cft77 fortran.
14C> - Ralph Jones 1990-05-18 Change name vbimpk to w3lib name w3fi58()
15C> - Mark Iredell 1996-05-14 Generalized computation of nbits.
16C> - Ebisuzaki 1998-06-30 Linux port.
17C>
18C> @param[in] IFIELD Array of integer data for processing.
19C> @param[in] NPTS Number of data values to process in IFIELD (and nwork)
20C> where, npts > 0.
21C> @param[out] NWORK Work array with integer difference
22C> @param[out] NPFLD Array for packed data (character*1)
23C> (user is responsible for an adequate dimension.)
24C> @param[out] NBITS Number of bits used to pack data where, 0 < nbits < 32
25C> (the maximum difference without overflow is 2**31 -1)
26C> @param[out] LEN Number of packed bytes in npfld (set to 0 if no packing)
27C> where, len = (nbits * npts + 7) / 8 without remainder
28C> @param[out] KMIN Minimum value (subtracted from each datum). If this
29C> packed data is being used for grib data, the
30C> programer will have to convert the KMIN value to an
31C> IBM370 32 bit floating point number.
32C>
33C> @note LEN = 0, NBITS = 0, and no packing performed if
34C> - (1) KMAX = KMIN (a constant field)
35C> - (2) NPTS < 1 (see input argument)
36C>
37C> @author Robert Allard @date 1987-09-02
38 SUBROUTINE w3fi58(IFIELD,NPTS,NWORK,NPFLD,NBITS,LEN,KMIN)
39C
40 parameter(alog2=0.69314718056)
41 INTEGER IFIELD(*)
42 CHARACTER*1 NPFLD(*)
43 INTEGER NWORK(*)
44C
45 DATA kzero / 0 /
46C
47C / / / / / /
48C
49 len = 0
50 nbits = 0
51 IF (npts.LE.0) GO TO 3000
52C
53C FIND THE MAX-MIN VALUES IN INTEGER FIELD (IFIELD).
54C
55 kmax = ifield(1)
56 kmin = kmax
57 DO 1000 i = 2,npts
58 kmax = max(kmax,ifield(i))
59 kmin = min(kmin,ifield(i))
60 1000 CONTINUE
61C
62C IF A CONSTANT FIELD, RETURN WITH NO PACKING AND 'LEN' AND 'NBITS' SET
63C TO ZERO.
64C
65 IF (kmax.EQ.kmin) GO TO 3000
66C
67C DETERMINE LARGEST DIFFERENCE IN IFIELD AND FLOAT (BIGDIF).
68C
69 bigdif = kmax - kmin
70C
71C NBITS IS COMPUTED AS THE LEAST INTEGER SUCH THAT
72C BIGDIF < 2**NBITS
73C
74 nbits=log(bigdif+0.5)/alog2+1
75C
76C FORM DIFFERENCES IN NWORK ARRAY.
77C
78 DO 2000 k = 1,npts
79 nwork(k) = ifield(k) - kmin
80 2000 CONTINUE
81C
82C PACK EACH MAGNITUDE IN NBITS (NBITS = THE LEAST POWER OF 2 OR 'N')
83C
84 len=(nbits*npts-1)/8+1
85 CALL sbytesc(npfld,nwork,0,nbits,0,npts)
86C
87C ADD ZERO-BITS AT END OF PACKED DATA TO INSURE A BYTE BOUNDARY.
88C
89 noff = nbits * npts
90 nzero=len*8-noff
91 IF(nzero.GT.0) CALL sbytec(npfld,kzero,noff,nzero)
92C
93 3000 CONTINUE
94 RETURN
95C
96 END
subroutine sbytec(out, in, iskip, nbyte)
This is a wrapper for sbytesc()
Definition sbytec.f:14
subroutine sbytesc(out, in, iskip, nbyte, nskip, n)
Store bytes - pack bits: Put arbitrary size values into a packed bit string, taking the low order bit...
Definition sbytesc.f:17
subroutine w3fi58(ifield, npts, nwork, npfld, nbits, len, kmin)
Converts an array of integer numbers into an array of positive differences (number(s) - minimum value...
Definition w3fi58.f:39