NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
gbytesc.f
Go to the documentation of this file.
1C> @file
2C> @brief Get bytes - unpack bits.
3C> @author Unknown
4
5C> Extract arbitrary size values from a packed bit string,
6C> right justifying each value in the unpacked array.
7C>
8C> @param[in] IN Character*1 array input.
9C> @param[out] IOUT Unpacked array output.
10C> @param[in] ISKIP Initial number of bits to skip.
11C> @param[in] NBYTE Number of bits to take.
12C> @param[in] NSKIP Additional number of bits to skip on each iteration.
13C> @param[in] N Number of iterations.
14C>
15 SUBROUTINE gbytesc(IN,IOUT,ISKIP,NBYTE,NSKIP,N)
16 character*1 in(*)
17 integer iout(*)
18 integer ones(8), tbit, bitcnt
19 save ones
20 data ones/1,3,7,15,31,63,127,255/
21
22c nbit is the start position of the field in bits
23 nbit = iskip
24 do i = 1, n
25 bitcnt = nbyte
26 index=nbit/8+1
27 ibit=mod(nbit,8)
28 nbit = nbit + nbyte + nskip
29
30c first byte
31 tbit = min(bitcnt,8-ibit)
32 itmp = iand(mova2i(in(index)),ones(8-ibit))
33 if (tbit.ne.8-ibit) itmp = ishft(itmp,tbit-8+ibit)
34 index = index + 1
35 bitcnt = bitcnt - tbit
36
37c now transfer whole bytes
38 do while (bitcnt.ge.8)
39 itmp = ior(ishft(itmp,8),mova2i(in(index)))
40 bitcnt = bitcnt - 8
41 index = index + 1
42 enddo
43
44c get data from last byte
45 if (bitcnt.gt.0) then
46 itmp = ior(ishft(itmp,bitcnt),iand(ishft(mova2i(in(index)),
47 1 -(8-bitcnt)),ones(bitcnt)))
48 endif
49
50 iout(i) = itmp
51 enddo
52
53 RETURN
54 END
subroutine gbytesc(in, iout, iskip, nbyte, nskip, n)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked a...
Definition gbytesc.f:16
integer function mova2i(a)
This Function copies a bit string from a Character*1 variable to an integer variable.
Definition mova2i.f:25