NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
sbyte.f
Go to the documentation of this file.
1C> @file
2C> @brief This is the fortran 32 bit version of sbyte().
3C> @author Robert Gammill @date 1972-07
4
5C> @param[out] IOUT
6C> @param[in] IN Unpacked array input
7C> @param[in] ISKIP Initial number of bits to skip
8C> @param[in] NBYTE Number of bits to pack
9C>
10C> @author Robert Gammill @date 1972-07
11 SUBROUTINE sbyte(IOUT,IN,ISKIP,NBYTE)
12 INTEGER IN
13 INTEGER IOUT(*)
14 INTEGER MASKS(32)
15C
16 SAVE
17C
18 DATA nbitsw/32/
19C
20C DATA MASKS /Z'00000001',Z'00000003',Z'00000007',Z'0000000F',
21C & Z'0000001F',Z'0000003F',Z'0000007F',Z'000000FF',
22C & Z'000001FF',Z'000003FF',Z'000007FF',Z'00000FFF',
23C & Z'00001FFF',Z'00003FFF',Z'00007FFF',Z'0000FFFF',
24C & Z'0001FFFF',Z'0003FFFF',Z'0007FFFF',Z'000FFFFF',
25C & Z'001FFFFF',Z'003FFFFF',Z'007FFFFF',Z'00FFFFFF',
26C & Z'01FFFFFF',Z'03FFFFFF',Z'07FFFFFF',Z'0FFFFFFF',
27C & Z'1FFFFFFF',Z'3FFFFFFF',Z'7FFFFFFF',Z'FFFFFFFF'/
28C
29C MASK TABLE PUT IN DECIMAL SO IT WILL COMPILE ON AN 32 BIT
30C COMPUTER
31C
32 DATA masks / 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047,
33 & 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287,
34 & 1048575, 2097151, 4194303, 8388607, 16777215, 33554431,
35 & 67108863, 134217727, 268435455, 536870911, 1073741823,
36 & 2147483647, -1/
37C
38C NBYTE MUST BE LESS THAN OR EQUAL TO NBITSW
39C
40 icon = nbitsw - nbyte
41 IF (icon.LT.0) RETURN
42 mask = masks(nbyte)
43C
44C INDEX TELLS HOW MANY WORDS INTO IOUT THE NEXT BYTE IS TO BE STORED.
45C
46 index = ishft(iskip,-5)
47C
48C II TELLS HOW MANY BITS IN FROM THE LEFT SIDE OF THE WORD TO STORE IT.
49C
50 ii = mod(iskip,nbitsw)
51C
52 j = iand(mask,in)
53 movel = icon - ii
54C
55C BYTE IS TO BE STORED IN MIDDLE OF WORD. SHIFT LEFT.
56C
57 IF (movel.GT.0) THEN
58 msk = ishft(mask,movel)
59 iout(index+1) = ior(iand(not(msk),iout(index+1)),
60 & ishft(j,movel))
61C
62C THE BYTE IS TO BE SPLIT ACROSS A WORD BREAK.
63C
64 ELSE IF (movel.LT.0) THEN
65 msk = masks(nbyte+movel)
66 iout(index+1) = ior(iand(not(msk),iout(index+1)),
67 & ishft(j,movel))
68 itemp = iand(masks(nbitsw+movel),iout(index+2))
69 iout(index+2) = ior(itemp,ishft(j,nbitsw+movel))
70C
71C BYTE IS TO BE STORED RIGHT-ADJUSTED.
72C
73 ELSE
74 iout(index+1) = ior(iand(not(mask),iout(index+1)),j)
75 ENDIF
76C
77 RETURN
78 END
subroutine sbyte(iout, in, iskip, nbyte)
Definition sbyte.f:12