1 SUBROUTINE SBYTE
(IPACKD
,IUNPKD
,NOFF
,NBITS
)
2 C THIS PROGRAM WRITTEN BY.....
3 C DR. ROBERT C. GAMMILL, CONSULTANT
4 C NATIONAL CENTER FOR ATMOSPHERIC RESEARCH
7 C THIS IS THE FORTRAN 32 bit VERSION OF SBYTE.
8 C Changes for SiliconGraphics IRIS-4D/25
9 C SiliconGraphics 3.3 FORTRAN 77
10 C MARCH 1991 RUSSELL E. JONES
11 C NATIONAL WEATHER SERVICE
13 C***********************************************************************
15 C SUBROUTINE SBYTE (IPACKD,IUNPKD,NOFF,NBITS)
17 C PURPOSE GIVEN A BYTE, RIGHT-JUSTIFIED IN A WORD, TO
18 C PACK THE BYTE INTO A TARGET WORD OR ARRAY.
19 C BITS SURROUNDING THE BYTE IN THE TARGET
22 C USAGE CALL SBYTE (IPACKD,IUNPKD,NOFF,NBITS)
26 C THE WORD OR ARRAY WHICH WILL CONTAIN THE
27 C PACKED BYTE. BYTE MAY CROSS WORD BOUNDARIES.
30 C THE WORD CONTAINING THE RIGHT-JUSTIFIED BYTE
34 C THE NUMBER OF BITS TO SKIP, LEFT TO RIGHT,
35 C IN 'IPACKD' IN ORDER TO LOCATE WHERE THE
36 C BYTE IS TO BE PACKED.
39 C NUMBER OF BITS IN THE BYTE TO BE PACKED.
40 C MAXIMUM OF 64 BITS ON 64 BIT MACHINE, 32
41 C BITS ON 32 BIT MACHINE.
44 C WORD OR CONSECUTIVE WORDS CONTAINING THE
46 C***********************************************************************
58 JSHIFT
= -1 * NINT
(ALOG
(FLOAT
(NBITSW
)) / ALOG
(2.0))
61 MASKS
(I
) = 2 * MASKS
(I
-1) + 1
67 C NBITS MUST BE LESS THAN OR EQUAL TO NBITSW
73 C INDEX TELLS HOW MANY WORDS INTO IOUT THE NEXT BYTE IS TO BE STORED.
75 INDEX
= ISHFT
(NOFF
,JSHIFT
)
77 C II TELLS HOW MANY BITS IN FROM THE LEFT SIDE OF THE WORD TO STORE IT.
84 C BYTE IS TO BE STORED IN MIDDLE OF WORD. SHIFT LEFT.
87 MSK
= ISHFT
(MASK
,MOVEL
)
88 IPACKD
(INDEX
+1) = IOR
(IAND
(NOT
(MSK
),IPACKD
(INDEX
+1)),
91 C THE BYTE IS TO BE SPLIT ACROSS A WORD BREAK.
93 ELSE IF (MOVEL
.LT
.0) THEN
94 MSK
= MASKS
(NBITS
+MOVEL
)
95 IPACKD
(INDEX
+1) = IOR
(IAND
(NOT
(MSK
),IPACKD
(INDEX
+1)),
97 ITEMP
= IAND
(MASKS
(NBITSW
+MOVEL
),IPACKD
(INDEX
+2))
98 IPACKD
(INDEX
+2) = IOR
(ITEMP
,ISHFT
(J
,NBITSW
+MOVEL
))
100 C BYTE IS TO BE STORED RIGHT-ADJUSTED.
103 IPACKD
(INDEX
+1) = IOR
(IAND
(NOT
(MASK
),IPACKD
(INDEX
+1)),J
)