NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
sbytesc.f
Go to the documentation of this file.
1C> @file
2C> @brief Put arbitrary size values into a packed bit string.
3C> @author Unknown
4
5C> Store bytes - pack bits: Put arbitrary size values into a
6C> packed bit string, taking the low order bits from each value
7C> in the unpacked array.
8C> @param OUT = packed array output.
9C> @param IN = unpacked array input.
10C> @param ISKIP = initial number of bits to skip.
11C> @param NBYTE = number of bits to pack.
12C> @param NSKIP = additional number of bits to skip on each iteration.
13C> @param N = number of iterations.
14C>
15C> @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
22c number bits from zero to ...
23c 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
33c 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
45c now byte aligned
46
47c 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
55c 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