NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
gbyte.f
Go to the documentation of this file.
1C> @file
2C> @brief This is the fortran version of gbyte.
3C> @author Dr. Robert C. Gammill @date 1972-05-DD
4
5C> This is the fortran version of gbyte
6C>
7C> Program history log:
8C> - Russell E. Jones 1991-03-DD
9C> Changes for SiliconGraphics IRIS-4D/25
10C> SiliconGraphics 3.3 FORTRAN 77.
11C>
12C> To unpack a byte into a target word. The unpacked byte is right-justified
13C> in the target word, and the remainder of the word is zero-filled.
14C>
15C> @param[in] IPACKD The word or array containing the byte to be unpacked.
16C>
17C> @param[out] IUNPKD The word which will contain the unpacked byte.
18C>
19C> @param[in] NOFF The number of bits to skip, left to right, in IPACKD
20C> in order to locate the byte to be unpacked.
21C>
22C> @param[in] NBITS Number of bits in the byte to be unpacked. Maximum of
23C> 64 bits on 64 bit machine, 32 bits on 32 bit machine.
24C>
25C> @author Dr. Robert C. Gammill @date 1972-05-DD
26 SUBROUTINE gbyte(IPACKD,IUNPKD,NOFF,NBITS)
27 INTEGER IPACKD(*)
28 INTEGER IUNPKD
29 INTEGER MASKS(64)
30C
31 SAVE
32C
33 DATA ifirst/1/
34 IF(ifirst.EQ.1) THEN
35 CALL w3fi01(lw)
36 nbitsw = 8 * lw
37 jshift = -1 * nint(alog(float(nbitsw)) / alog(2.0))
38 masks(1) = 1
39 DO i=2,nbitsw-1
40 masks(i) = 2 * masks(i-1) + 1
41 ENDDO
42 masks(nbitsw) = -1
43 ifirst = 0
44 ENDIF
45C
46C NBITS MUST BE LESS THAN OR EQUAL TO NBITSW
47C
48 icon = nbitsw - nbits
49 IF (icon.LT.0) RETURN
50 mask = masks(nbits)
51C
52C INDEX TELLS HOW MANY WORDS INTO THE ARRAY 'IPACKD' THE NEXT BYTE
53C APPEARS.
54C
55 index = ishft(noff,jshift)
56C
57C II TELLS HOW MANY BITS THE BYTE IS FROM THE LEFT SIDE OF THE WORD.
58C
59 ii = mod(noff,nbitsw)
60C
61C MOVER SPECIFIES HOW FAR TO THE RIGHT NBITS MUST BE MOVED IN ORDER
62C
63C TO BE RIGHT ADJUSTED.
64C
65 mover = icon - ii
66C
67 IF (mover.GT.0) THEN
68 iunpkd = iand(ishft(ipackd(index+1),-mover),mask)
69C
70C THE BYTE IS SPLIT ACROSS A WORD BREAK.
71C
72 ELSE IF (mover.LT.0) THEN
73 movel = - mover
74 mover = nbitsw - movel
75 iunpkd = iand(ior(ishft(ipackd(index+1),movel),
76 & ishft(ipackd(index+2),-mover)),mask)
77C
78C THE BYTE IS ALREADY RIGHT ADJUSTED.
79C
80 ELSE
81 iunpkd = iand(ipackd(index+1),mask)
82 ENDIF
83C
84 RETURN
85 END
subroutine gbyte(ipackd, iunpkd, noff, nbits)
This is the fortran version of gbyte.
Definition gbyte.f:27
subroutine w3fi01(lw)
Determines the number of bytes in a full word for the particular machine (IBM or cray).
Definition w3fi01.f:19