NCEPLIBS-w3emc  2.11.0
gbytesc.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Get bytes - unpack bits.
3 C> @author Unknown
4 
5 C> Extract arbitrary size values from a packed bit string,
6 C> right justifying each value in the unpacked array.
7 C>
8 C> @param[in] IN Character*1 array input.
9 C> @param[out] IOUT Unpacked array output.
10 C> @param[in] ISKIP Initial number of bits to skip.
11 C> @param[in] NBYTE Number of bits to take.
12 C> @param[in] NSKIP Additional number of bits to skip on each iteration.
13 C> @param[in] N Number of iterations.
14 C>
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 
22 c 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 
30 c 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 
37 c 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 
44 c 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