1 SUBROUTINE GBYTE
(IN
,IOUT
,ISKIP
,NBYTE
)
4 CALL GBYTES
(IN
,IOUT
,ISKIP
,NBYTE
,0,1)
8 SUBROUTINE SBYTE
(OUT
,IN
,ISKIP
,NBYTE
)
11 CALL SBYTES
(OUT
,IN
,ISKIP
,NBYTE
,0,1)
15 SUBROUTINE GBYTES
(IN
,IOUT
,ISKIP
,NBYTE
,NSKIP
,N
)
16 C Get bytes - unpack bits: Extract arbitrary size values from a
17 C packed bit string, right justifying each value in the unpacked
19 C IN = character*1 array input
20 C IOUT = unpacked array output
21 C ISKIP = initial number of bits to skip
22 C NBYTE = number of bits to take
23 C NSKIP = additional number of bits to skip on each iteration
24 C N = number of iterations
30 integer, parameter :: ones
(8) = (/ 1,3,7,15,31,63,127,255 /)
32 c nbit is the start position of the field in bits
38 nbit
= nbit
+ nbyte
+ nskip
41 tbit
= min
(bitcnt
,8-ibit
)
42 itmp
= iand
(mov_a2i
(in
(index
)),ones
(8-ibit
))
43 if (tbit
.ne
.8-ibit
) itmp
= ishft
(itmp
,tbit
-8+ibit
)
45 bitcnt
= bitcnt
- tbit
47 c now transfer whole bytes
48 do while (bitcnt
.ge
.8)
49 itmp
= ior
(ishft
(itmp
,8),mov_a2i
(in
(index
)))
54 c get data from last byte
56 itmp
= ior
(ishft
(itmp
,bitcnt
),iand
(ishft
(mov_a2i
(in
(index
)),
57 1 -(8-bitcnt
)),ones
(bitcnt
)))
66 SUBROUTINE SBYTES
(OUT
,IN
,ISKIP
,NBYTE
,NSKIP
,N
)
67 C Store bytes - pack bits: Put arbitrary size values into a
68 C packed bit string, taking the low order bits from each value
69 C in the unpacked array.
70 C IOUT = packed array output
71 C IN = unpacked array input
72 C ISKIP = initial number of bits to skip
73 C NBYTE = number of bits to pack
74 C NSKIP = additional number of bits to skip on each iteration
75 C N = number of iterations
79 integer in
(N
), bitcnt
, tbit
80 integer, parameter :: ones
(8)=(/ 1, 3, 7, 15, 31, 63,127,255/)
82 c number bits from zero to ...
83 c nbit is the last bit of the field to be filled
85 nbit
= iskip
+ nbyte
- 1
91 nbit
= nbit
+ nbyte
+ nskip
95 tbit
= min
(bitcnt
,ibit
+1)
96 imask
= ishft
(ones
(tbit
),7-ibit
)
97 itmp2
= iand
(ishft
(itmp
,7-ibit
),imask
)
98 itmp3
= iand
(mov_a2i
(out
(index
)), 255-imask
)
99 out
(index
) = char
(ior
(itmp2
,itmp3
))
100 bitcnt
= bitcnt
- tbit
101 itmp
= ishft
(itmp
, -tbit
)
108 do while (bitcnt
.ge
.8)
109 out
(index
) = char
(iand
(itmp
,255))
110 itmp
= ishft
(itmp
,-8)
117 if (bitcnt
.gt
.0) then
118 itmp2
= iand
(itmp
,ones
(bitcnt
))
119 itmp3
= iand
(mov_a2i
(out
(index
)), 255-ones
(bitcnt
))
120 out
(index
) = char
(ior
(itmp2
,itmp3
))