NCEPLIBS-w3emc  2.11.0
gbyte.f
Go to the documentation of this file.
1 C> @file
2 C> @brief This is the fortran version of gbyte.
3 C> @author Dr. Robert C. Gammill @date 1972-05-DD
4 
5 C> This is the fortran version of gbyte
6 C>
7 C> Program history log:
8 C> - Russell E. Jones 1991-03-DD
9 C> Changes for SiliconGraphics IRIS-4D/25
10 C> SiliconGraphics 3.3 FORTRAN 77.
11 C>
12 C> To unpack a byte into a target word. The unpacked byte is right-justified
13 C> in the target word, and the remainder of the word is zero-filled.
14 C>
15 C> @param[in] IPACKD The word or array containing the byte to be unpacked.
16 C>
17 C> @param[out] IUNPKD The word which will contain the unpacked byte.
18 C>
19 C> @param[in] NOFF The number of bits to skip, left to right, in IPACKD
20 C> in order to locate the byte to be unpacked.
21 C>
22 C> @param[in] NBITS Number of bits in the byte to be unpacked. Maximum of
23 C> 64 bits on 64 bit machine, 32 bits on 32 bit machine.
24 C>
25 C> @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)
30 C
31  SAVE
32 C
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
45 C
46 C NBITS MUST BE LESS THAN OR EQUAL TO NBITSW
47 C
48  icon = nbitsw - nbits
49  IF (icon.LT.0) RETURN
50  mask = masks(nbits)
51 C
52 C INDEX TELLS HOW MANY WORDS INTO THE ARRAY 'IPACKD' THE NEXT BYTE
53 C APPEARS.
54 C
55  index = ishft(noff,jshift)
56 C
57 C II TELLS HOW MANY BITS THE BYTE IS FROM THE LEFT SIDE OF THE WORD.
58 C
59  ii = mod(noff,nbitsw)
60 C
61 C MOVER SPECIFIES HOW FAR TO THE RIGHT NBITS MUST BE MOVED IN ORDER
62 C
63 C TO BE RIGHT ADJUSTED.
64 C
65  mover = icon - ii
66 C
67  IF (mover.GT.0) THEN
68  iunpkd = iand(ishft(ipackd(index+1),-mover),mask)
69 C
70 C THE BYTE IS SPLIT ACROSS A WORD BREAK.
71 C
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)
77 C
78 C THE BYTE IS ALREADY RIGHT ADJUSTED.
79 C
80  ELSE
81  iunpkd = iand(ipackd(index+1),mask)
82  ENDIF
83 C
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