1 SUBROUTINE SBYTES
(IPACKD
,IUNPKD
,NOFF
,NBITS
,ISKIP
,ITER
)
2 C THIS PROGRAM WRITTEN BY.....
3 C DR. ROBERT C. GAMMILL, CONSULTANT
4 C NATIONAL CENTER FOR ATMOSPHERIC RESEARCH
6 C THIS IS THE FORTRAN VERSIONS OF SBYTES.
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,ISKIP,ITER)
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 THE NUMBER OF BITS TO SKIP BETWEEN EACH BYTE
45 C IN 'IUNPKD' IN ORDER TO LOCATE THE NEXT BYTE
49 C THE NUMBER OF BYTES TO BE PACKED.
52 C WORD OR CONSECUTIVE WORDS CONTAINING THE
55 C***********************************************************************
67 JSHIFT
= -1 * NINT
(ALOG
(FLOAT
(NBITSW
)) / ALOG
(2.0))
70 MASKS
(I
) = 2 * MASKS
(I
-1) + 1
76 C NBITS MUST BE LESS THAN OR EQUAL TO NBITSW
82 C INDEX TELLS HOW MANY WORDS INTO IOUT THE NEXT BYTE IS TO BE STORED.
84 INDEX
= ISHFT
(NOFF
,JSHIFT
)
86 C II TELLS HOW MANY BITS IN FROM THE LEFT SIDE OF THE WORD TO STORE IT.
90 C ISTEP IS THE DISTANCE IUNPKD BITS FROM ONE BYTE POSITION TO THE NEXT.
94 C IWORDS TELLS HOW MANY WORDS TO SKIP FROM ONE BYTE TO THE NEXT.
96 IWORDS
= ISTEP
/ NBITSW
98 C IBITS TELLS HOW MANY BITS TO SKIP AFTER SKIPPING IWORDS.
100 IBITS
= MOD
(ISTEP
,NBITSW
)
103 J
= IAND
(MASK
,IUNPKD
(I
))
106 C BYTE IS TO BE STORED IN MIDDLE OF WORD. SHIFT LEFT.
109 MSK
= ISHFT
(MASK
,MOVEL
)
110 IPACKD
(INDEX
+1) = IOR
(IAND
(NOT
(MSK
),IPACKD
(INDEX
+1)),
113 C THE BYTE IS TO BE SPLIT ACROSS A WORD BREAK.
115 ELSE IF (MOVEL
.LT
.0) THEN
116 MSK
= MASKS
(NBITS
+MOVEL
)
117 IPACKD
(INDEX
+1) = IOR
(IAND
(NOT
(MSK
),IPACKD
(INDEX
+1)),
119 ITEMP
= IAND
(MASKS
(NBITSW
+MOVEL
),IPACKD
(INDEX
+2))
120 IPACKD
(INDEX
+2) = IOR
(ITEMP
,ISHFT
(J
,NBITSW
+MOVEL
))
122 C BYTE IS TO BE STORED RIGHT-ADJUSTED.
125 IPACKD
(INDEX
+1) = IOR
(IAND
(NOT
(MASK
),IPACKD
(INDEX
+1)),J
)
129 INDEX
= INDEX
+ IWORDS
130 IF (II
.GE
.NBITSW
) THEN