NCEPLIBS-g2  3.4.7
g2_gbytesc.F90
Go to the documentation of this file.
1 
5 
19 subroutine g2_gbytec(in, iout, iskip, nbits)
20  implicit none
21 
22  character*1, intent(in) :: in(*)
23  integer, intent(inout) :: iout(*)
24  integer, intent(in) :: iskip, nbits
25  call g2_gbytesc(in, iout, iskip, nbits, 0, 1)
26 end subroutine g2_gbytec
27 
41 subroutine g2_sbytec(out, in, iskip, nbits)
42  implicit none
43 
44  character*1, intent(inout) :: out(*)
45  integer, intent(in) :: in(*)
46  integer, intent(in) :: iskip, nbits
47  call g2_sbytesc(out, in, iskip, nbits, 0, 1)
48 end subroutine g2_sbytec
49 
62 subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n)
63  implicit none
64 
65  character*1, intent(in) :: in(*)
66  integer, intent(out) :: iout(*)
67  integer, intent(in) :: iskip, nbits, nskip, n
68  integer :: tbit, bitcnt
69  integer, parameter :: ones(8) = (/ 1, 3, 7, 15, 31, 63, 127, 255 /)
70 
71  integer :: nbit, i, index, ibit, itmp
72  integer, external :: mova2i
73 
74  ! nbit is the start position of the field in bits
75  nbit = iskip
76  do i = 1, n
77  bitcnt = nbits
78  index = nbit / 8 + 1
79  ibit = mod(nbit, 8)
80  nbit = nbit + nbits + nskip
81 
82  ! first byte
83  tbit = min(bitcnt, 8 - ibit)
84  itmp = iand(mova2i(in(index)), ones(8 - ibit))
85  if (tbit .ne. 8 - ibit) itmp = ishft(itmp, tbit - 8 + ibit)
86  index = index + 1
87  bitcnt = bitcnt - tbit
88 
89  ! now transfer whole bytes
90  do while (bitcnt .ge. 8)
91  itmp = ior(ishft(itmp,8), mova2i(in(index)))
92  bitcnt = bitcnt - 8
93  index = index + 1
94  enddo
95 
96  ! get data from last byte
97  if (bitcnt .gt. 0) then
98  itmp = ior(ishft(itmp, bitcnt), iand(ishft(mova2i(in(index)), &
99  - (8 - bitcnt)), ones(bitcnt)))
100  endif
101 
102  iout(i) = itmp
103  enddo
104 
105 end subroutine g2_gbytesc
106 
119 subroutine g2_sbytesc(out, in, iskip, nbits, nskip, n)
120  implicit none
121 
122  character*1, intent(out) :: out(*)
123  integer, intent(in) :: in(n)
124  integer, intent(in) :: iskip, nbits, nskip, n
125 
126  integer :: bitcnt, tbit
127  integer, parameter :: ones(8)=(/ 1, 3, 7, 15, 31, 63, 127, 255/)
128  integer :: nbit, i, itmp, index, ibit, imask, itmp2, itmp3
129  integer, external :: mova2i
130 
131  ! number bits from zero to ...
132  ! nbit is the last bit of the field to be filled
133  nbit = iskip + nbits - 1
134  do i = 1, n
135  itmp = in(i)
136  bitcnt = nbits
137  index = nbit / 8 + 1
138  ibit = mod(nbit, 8)
139  nbit = nbit + nbits + nskip
140 
141  ! make byte aligned
142  if (ibit .ne. 7) then
143  tbit = min(bitcnt, ibit + 1)
144  imask = ishft(ones(tbit), 7 - ibit)
145  itmp2 = iand(ishft(itmp, 7 - ibit),imask)
146  itmp3 = iand(mova2i(out(index)), 255 - imask)
147  out(index) = char(ior(itmp2, itmp3))
148  bitcnt = bitcnt - tbit
149  itmp = ishft(itmp, -tbit)
150  index = index - 1
151  endif
152 
153  ! now byte aligned
154 
155  ! do by bytes
156  do while (bitcnt .ge. 8)
157  out(index) = char(iand(itmp, 255))
158  itmp = ishft(itmp, -8)
159  bitcnt = bitcnt - 8
160  index = index - 1
161  enddo
162 
163  ! do last byte
164  if (bitcnt .gt. 0) then
165  itmp2 = iand(itmp, ones(bitcnt))
166  itmp3 = iand(mova2i(out(index)), 255 - ones(bitcnt))
167  out(index) = char(ior(itmp2, itmp3))
168  endif
169  enddo
170 
171 end subroutine g2_sbytesc
subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked a...
Definition: g2_gbytesc.F90:63
subroutine g2_gbytec(in, iout, iskip, nbits)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked a...
Definition: g2_gbytesc.F90:20
subroutine g2_sbytec(out, in, iskip, nbits)
Put arbitrary size values into a packed bit string, taking the low order bits from each value in the ...
Definition: g2_gbytesc.F90:42
subroutine g2_sbytesc(out, in, iskip, nbits, nskip, n)
Put arbitrary size values into a packed bit string, taking the low order bits from each value in the ...
Definition: g2_gbytesc.F90:120