1 SUBROUTINE W3FI58
(IFIELD
,NPTS
,NWORK
,NPFLD
,NBITS
,LEN
,KMIN
)
2 C$$$ SUBPROGRAM DOCUMENTATION BLOCK ***
4 C SUBPROGRAM: W3FI58 - PACK POSITIVE DIFFERENCES IN LEAST BITS
5 C PRGMMR: ALLARD, R. ORG: NMC411 DATE: JULY 1987
7 C ABSTRACT: CONVERTS AN ARRAY OF INTEGER NUMBERS INTO AN ARRAY OF
8 C POSITIVE DIFFERENCES (NUMBER(S) - MINIMUM VALUE) AND PACKS THE
9 C MAGNITUDE OF EACH DIFFERENCE RIGHT-ADJUSTED INTO THE LEAST
10 C NUMBER OF BITS THAT HOLDS THE LARGEST DIFFERENCE.
12 C PROGRAM HISTORY LOG:
14 C 88-10-02 R.E.JONES CONVERTED TO CDC CYBER 205 FTN200 FORTRAN
15 C 90-05-17 R.E.JONES CONVERTED TO CRAY CFT77 FORTRAN
16 C 90-05-18 R.E.JONES CHANGE NAME VBIMPK TO W3LIB NAME W3FI58
17 C 98-03-10 B. VUONG REMOVE THE CDIR$ INTEGER=64 DIRECTIVE
18 C 96-05-14 IREDELL GENERALIZED COMPUTATION OF NBITS
20 C USAGE: CALL W3FI58(IFIELD,NPTS,NWORK,NPFLD,NBITS,LEN,KMIN)
24 C IFIELD - ARRAY OF INTEGER DATA FOR PROCESSING
25 C NPTS - NUMBER OF DATA VALUES TO PROCESS IN IFIELD (AND NWORK)
30 C NWORK - WORK ARRAY WITH INTEGER DIFFERENCE
31 C NPFLD - ARRAY FOR PACKED DATA
32 C (USER IS RESPONSIBLE FOR AN ADEQUATE DIMENSION.)
33 C NBITS - NUMBER OF BITS USED TO PACK DATA WHERE, 0 < NBITS < 32
34 C (THE MAXIMUM DIFFERENCE WITHOUT OVERFLOW IS 2**31 -1)
35 C LEN - NUMBER OF PACKED BYTES IN NPFLD (SET TO 0 IF NO PACKING)
36 C WHERE, LEN = (NBITS * NPTS + 7) / 8 WITHOUT REMAINDER
37 C KMIN - MINIMUM VALUE (SUBTRACTED FROM EACH DATUM). IF THIS
38 C PACKED DATA IS BEING USED FOR GRIB DATA, THE
39 C PROGRAMER WILL HAVE TO CONVERT THE KMIN VALUE TO AN
40 C IBM370 32 BIT FLOATING POINT NUMBER.
44 C W3LIB: SBYTES, SBYTE
48 C NOTE: LEN = 0, NBITS = 0, AND NO PACKING PERFORMED IF
50 C (1) KMAX = KMIN (A CONSTANT FIELD)
51 C (2) NPTS < 1 (SEE INPUT ARGUMENT)
54 C LANGUAGE: CRAY CFT77 FORTRAN
55 C MACHINE: CRAY Y-MP8/832
64 PARAMETER(ALOG2
=0.69314718056)
70 IF (NPTS
.LE
.0) GO TO 3000
72 C FIND THE MAX-MIN VALUES IN INTEGER FIELD (IFIELD).
77 KMAX
= MAX
(KMAX
,IFIELD
(I
))
78 KMIN
= MIN
(KMIN
,IFIELD
(I
))
81 C IF A CONSTANT FIELD, RETURN WITH NO PACKING AND 'LEN' AND 'NBITS' SET
84 IF (KMAX
.EQ
.KMIN
) GO TO 3000
86 C DETERMINE LARGEST DIFFERENCE IN IFIELD AND FLOAT (BIGDIF).
90 C NBITS IS COMPUTED AS THE LEAST INTEGER SUCH THAT
93 NBITS
=LOG
(BIGDIF
+0.5)/ALOG2
+1
95 C FORM DIFFERENCES IN NWORK ARRAY.
98 NWORK
(K
) = IFIELD
(K
) - KMIN
101 C PACK EACH MAGNITUDE IN NBITS (NBITS = THE LEAST POWER OF 2 OR 'N')
103 LEN
=(NBITS*NPTS
-1)/8+1
104 CALL SBYTES
(NPFLD
,NWORK
,0,NBITS
,0,NPTS
)
106 C ADD ZERO-BITS AT END OF PACKED DATA TO INSURE A BYTE BOUNDARY.
110 IF(NZERO
.GT
.0) CALL SBYTE
(NPFLD
,KZERO
,NOFF
,NZERO
)