NCEPLIBS-g2  3.4.5
g2_gbytesc.f
Go to the documentation of this file.
1 C> @file
2 C> @brief This Fortran module extract or store arbitrary size values
3 C> between packed bit string and unpacked array.
4 C> @author Stephen Gilbert @date 2004-04-27
5 C>
6 
7 C> This subrountine is to extract arbitrary size values from a
8 C> packed bit string, right justifying each value in the unpacked
9 C> array without skip and interations.
10 C>
11 C> @param[in] IN character*1 array input
12 C> @param[out] IOUT unpacked array output
13 C> @param[in] ISKIP initial number of bits to skip
14 C> @param[in] NBYTE number of bits to take
15 C>
16 C> @author Stephen Gilbert @date 2004-04-27
17 C>
18 
19  SUBROUTINE g2_gbytec(IN,IOUT,ISKIP,NBYTE)
20  character*1 in(*)
21  integer iout(*)
22  CALL g2_gbytesc(in,iout,iskip,nbyte,0,1)
23  RETURN
24  END
25 
26 C> This subrountine is to put arbitrary size values into a packed bit
27 C> string, taking the low order bits from each value in the unpacked
28 C> array without skip and interation.
29 C>
30 C> @param[out] OUT packed array output
31 C> @param[in] IN unpacked array input
32 C> @param[in] ISKIP initial number of bits to skip
33 C> @param[in] NBYTE number of bits to pack
34 C>
35 C> @author Stephen Gilbert @date 2004-04-27
36 C>
37 
38  SUBROUTINE g2_sbytec(OUT,IN,ISKIP,NBYTE)
39  character*1 out(*)
40  integer in(*)
41  CALL g2_sbytesc(out,in,iskip,nbyte,0,1)
42  RETURN
43  END
44 
45 C> This subrountine is to extract arbitrary size values from a
46 C> packed bit string, right justifying each value in the unpacked
47 C> array with skip and interation options.
48 C>
49 C> @param[in] IN character*1 array input
50 C> @param[out] IOUT unpacked array output
51 C> @param[in] ISKIP initial number of bits to skip
52 C> @param[in] NBYTE number of bits to take
53 C> @param[in] NSKIP additional number of bits to skip on each iteration
54 C> @param[in] N number of iterations
55 C>
56 C> @author Stephen Gilbert @date 2004-04-27
57 C>
58 
59  SUBROUTINE g2_gbytesc(IN,IOUT,ISKIP,NBYTE,NSKIP,N)
60 
61  character*1 in(*)
62  integer iout(*)
63  integer tbit, bitcnt
64  integer, parameter :: ones(8) = (/ 1,3,7,15,31,63,127,255 /)
65 
66 c nbit is the start position of the field in bits
67  nbit = iskip
68  do i = 1, n
69  bitcnt = nbyte
70  index=nbit/8+1
71  ibit=mod(nbit,8)
72  nbit = nbit + nbyte + nskip
73 
74 c first byte
75  tbit = min(bitcnt,8-ibit)
76  itmp = iand(mova2i(in(index)),ones(8-ibit))
77  if (tbit.ne.8-ibit) itmp = ishft(itmp,tbit-8+ibit)
78  index = index + 1
79  bitcnt = bitcnt - tbit
80 
81 c now transfer whole bytes
82  do while (bitcnt.ge.8)
83  itmp = ior(ishft(itmp,8),mova2i(in(index)))
84  bitcnt = bitcnt - 8
85  index = index + 1
86  enddo
87 
88 c get data from last byte
89  if (bitcnt.gt.0) then
90  itmp = ior(ishft(itmp,bitcnt),iand(ishft(mova2i(in(index)),
91  1 -(8-bitcnt)),ones(bitcnt)))
92  endif
93 
94  iout(i) = itmp
95  enddo
96 
97  RETURN
98  END
99 
100 C> This subrountine is to put arbitrary size values into a packed bit
101 C> string, taking the low order bits from each value in the unpacked
102 C> array with skip and interation options.
103 C>
104 C> @param[out] OUT packed array output
105 C> @param[in] IN unpacked array input
106 C> @param[in] ISKIP initial number of bits to skip
107 C> @param[in] NBYTE number of bits to pack
108 C> @param[in] NSKIP additional number of bits to skip on each iteration
109 C> @param[in] N number of iterations
110 C>
111 C> @author Stephen Gilbert @date 2004-04-27
112 C>
113 
114  SUBROUTINE g2_sbytesc(OUT,IN,ISKIP,NBYTE,NSKIP,N)
115 
116  character*1 out(*)
117  integer in(N), bitcnt, tbit
118  integer, parameter :: ones(8)=(/ 1, 3, 7, 15, 31, 63,127,255/)
119 
120 c number bits from zero to ...
121 c nbit is the last bit of the field to be filled
122 
123  nbit = iskip + nbyte - 1
124  do i = 1, n
125  itmp = in(i)
126  bitcnt = nbyte
127  index=nbit/8+1
128  ibit=mod(nbit,8)
129  nbit = nbit + nbyte + nskip
130 
131 c make byte aligned
132  if (ibit.ne.7) then
133  tbit = min(bitcnt,ibit+1)
134  imask = ishft(ones(tbit),7-ibit)
135  itmp2 = iand(ishft(itmp,7-ibit),imask)
136  itmp3 = iand(mova2i(out(index)), 255-imask)
137  out(index) = char(ior(itmp2,itmp3))
138  bitcnt = bitcnt - tbit
139  itmp = ishft(itmp, -tbit)
140  index = index - 1
141  endif
142 
143 c now byte aligned
144 
145 c do by bytes
146  do while (bitcnt.ge.8)
147  out(index) = char(iand(itmp,255))
148  itmp = ishft(itmp,-8)
149  bitcnt = bitcnt - 8
150  index = index - 1
151  enddo
152 
153 c do last byte
154 
155  if (bitcnt.gt.0) then
156  itmp2 = iand(itmp,ones(bitcnt))
157  itmp3 = iand(mova2i(out(index)), 255-ones(bitcnt))
158  out(index) = char(ior(itmp2,itmp3))
159  endif
160  enddo
161 
162  return
163  end
g2_sbytesc
subroutine g2_sbytesc(OUT, IN, ISKIP, NBYTE, NSKIP, N)
This subrountine is to put arbitrary size values into a packed bit string, taking the low order bits ...
Definition: g2_gbytesc.f:115
g2_sbytec
subroutine g2_sbytec(OUT, IN, ISKIP, NBYTE)
This subrountine is to put arbitrary size values into a packed bit string, taking the low order bits ...
Definition: g2_gbytesc.f:39
g2_gbytec
subroutine g2_gbytec(IN, IOUT, ISKIP, NBYTE)
This subrountine is to extract arbitrary size values from a packed bit string, right justifying each ...
Definition: g2_gbytesc.f:20
g2_gbytesc
subroutine g2_gbytesc(IN, IOUT, ISKIP, NBYTE, NSKIP, N)
This subrountine is to extract arbitrary size values from a packed bit string, right justifying each ...
Definition: g2_gbytesc.f:60