NCEPLIBS-w3emc  2.11.0
sbytesc.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Put arbitrary size values into a packed bit string.
3 C> @author Unknown
4 
5 C> Store bytes - pack bits: Put arbitrary size values into a
6 C> packed bit string, taking the low order bits from each value
7 C> in the unpacked array.
8 C> @param OUT = packed array output.
9 C> @param IN = unpacked array input.
10 C> @param ISKIP = initial number of bits to skip.
11 C> @param NBYTE = number of bits to pack.
12 C> @param NSKIP = additional number of bits to skip on each iteration.
13 C> @param N = number of iterations.
14 C>
15 C> @author Unknown
16  SUBROUTINE sbytesc(OUT,IN,ISKIP,NBYTE,NSKIP,N)
17  character*1 out(*)
18  integer in(N), bitcnt, ones(8), tbit
19  save ones
20  data ones/ 1, 3, 7, 15, 31, 63,127,255/
21 
22 c number bits from zero to ...
23 c nbit is the last bit of the field to be filled
24 
25  nbit = iskip + nbyte - 1
26  do i = 1, n
27  itmp = in(i)
28  bitcnt = nbyte
29  index=nbit/8+1
30  ibit=mod(nbit,8)
31  nbit = nbit + nbyte + nskip
32 
33 c make byte aligned
34  if (ibit.ne.7) then
35  tbit = min(bitcnt,ibit+1)
36  imask = ishft(ones(tbit),7-ibit)
37  itmp2 = iand(ishft(itmp,7-ibit),imask)
38  itmp3 = iand(mova2i(out(index)), 255-imask)
39  out(index) = char(ior(itmp2,itmp3))
40  bitcnt = bitcnt - tbit
41  itmp = ishft(itmp, -tbit)
42  index = index - 1
43  endif
44 
45 c now byte aligned
46 
47 c do by bytes
48  do while (bitcnt.ge.8)
49  out(index) = char(iand(itmp,255))
50  itmp = ishft(itmp,-8)
51  bitcnt = bitcnt - 8
52  index = index - 1
53  enddo
54 
55 c do last byte
56 
57  if (bitcnt.gt.0) then
58  itmp2 = iand(itmp,ones(bitcnt))
59  itmp3 = iand(mova2i(out(index)), 255-ones(bitcnt))
60  out(index) = char(ior(itmp2,itmp3))
61  endif
62  enddo
63 
64  return
65  end
integer function mova2i(a)
This Function copies a bit string from a Character*1 variable to an integer variable.
Definition: mova2i.f:25
subroutine sbytesc(OUT, IN, ISKIP, NBYTE, NSKIP, N)
Store bytes - pack bits: Put arbitrary size values into a packed bit string, taking the low order bit...
Definition: sbytesc.f:17