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