1 SUBROUTINE GBYTES
(IPACKD
,IUNPKD
,NOFF
,NBITS
,ISKIP
,ITER
)
3 C THIS PROGRAM WRITTEN BY.....
4 C DR. ROBERT C. GAMMILL, CONSULTANT
5 C NATIONAL CENTER FOR ATMOSPHERIC RESEARCH
8 C CHANGES FOR SiliconGraphics IRIS-4D/25
9 C SiliconGraphics 3.3 FORTRAN 77
10 C MARCH 1991, RUSSELL E. JONES
11 C NATIONAL WEATHER SERVICE
13 C THIS IS THE FORTRAN VERSION OF GBYTES.
15 C***********************************************************************
17 C SUBROUTINE GBYTES (IPACKD,IUNPKD,NOFF,NBITS,ISKIP,ITER)
19 C PURPOSE TO UNPACK A SERIES OF BYTES INTO A TARGET
20 C ARRAY. EACH UNPACKED BYTE IS RIGHT-JUSTIFIED
21 C IN ITS TARGET WORD, AND THE REMAINDER OF THE
22 C WORD IS ZERO-FILLED.
24 C USAGE CALL GBYTES (IPACKD,IUNPKD,NOFF,NBITS,NSKIP,
29 C THE WORD OR ARRAY CONTAINING THE PACKED
33 C THE ARRAY WHICH WILL CONTAIN THE UNPACKED
37 C THE INITIAL NUMBER OF BITS TO SKIP, LEFT
38 C TO RIGHT, IN 'IPACKD' IN ORDER TO LOCATE
39 C THE FIRST BYTE TO UNPACK.
42 C NUMBER OF BITS IN THE BYTE TO BE UNPACKED.
43 C MAXIMUM OF 64 BITS ON 64 BIT MACHINE, 32
44 C BITS ON 32 BIT MACHINE.
47 C THE NUMBER OF BITS TO SKIP BETWEEN EACH BYTE
48 C IN 'IPACKD' IN ORDER TO LOCATE THE NEXT BYTE
52 C THE NUMBER OF BYTES TO BE UNPACKED.
56 C CONTAINS THE REQUESTED UNPACKED BYTES.
57 C***********************************************************************
70 JSHIFT
= -1 * NINT
(ALOG
(FLOAT
(NBITSW
)) / ALOG
(2.0))
73 MASKS
(I
) = 2 * MASKS
(I
-1) + 1
79 C NBITS MUST BE LESS THAN OR EQUAL TO NBITSW
85 C INDEX TELLS HOW MANY WORDS INTO THE ARRAY 'IPACKD' THE NEXT BYTE
88 INDEX
= ISHFT
(NOFF
,JSHIFT
)
90 C II TELLS HOW MANY BITS THE BYTE IS FROM THE LEFT SIDE OF THE WORD.
94 C ISTEP IS THE DISTANCE IN BITS FROM THE START OF ONE BYTE TO THE NEXT.
98 C IWORDS TELLS HOW MANY WORDS TO SKIP FROM ONE BYTE TO THE NEXT.
100 IWORDS
= ISTEP
/ NBITSW
102 C IBITS TELLS HOW MANY BITS TO SKIP AFTER SKIPPING IWORDS.
104 IBITS
= MOD
(ISTEP
,NBITSW
)
108 C MOVER SPECIFIES HOW FAR TO THE RIGHT A BYTE MUST BE MOVED IN ORDER
110 C TO BE RIGHT ADJUSTED.
114 C THE BYTE IS SPLIT ACROSS A WORD BREAK.
118 MOVER
= NBITSW
- MOVEL
119 IUNPKD
(I
) = IAND
(IOR
(ISHFT
(IPACKD
(INDEX
+1),MOVEL
),
120 & ISHFT
(IPACKD
(INDEX
+2),-MOVER
)),MASK
)
122 C RIGHT ADJUST THE BYTE.
124 ELSE IF (MOVER
.GT
.0) THEN
125 IUNPKD
(I
) = IAND
(ISHFT
(IPACKD
(INDEX
+1),-MOVER
),MASK
)
127 C THE BYTE IS ALREADY RIGHT ADJUSTED.
130 IUNPKD
(I
) = IAND
(IPACKD
(INDEX
+1),MASK
)
133 C INCREMENT II AND INDEX.
136 INDEX
= INDEX
+ IWORDS
137 IF (II
.GE
.NBITSW
) THEN