NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
w3ai40.f
Go to the documentation of this file.
1C> @file
2C> @brief Constant size binary string packer.
3C> @author Robert Allard @date 1980-04-01
4
5C> Packs constant size binary strings into an array. This
6C> packing replaces bits in the part of the output array indicated
7C> by the offset value. W3AI40 is the reverse of W3AI41. (see W3AI32
8C> to pack variable size binary strings.)
9C>
10C> Program history log:
11C> - Robert Allard 1980-04-01 Asmembler language version.
12C> - Ralph Jones 1984-07-05 Recompiled for nas-9050.
13C> - Ralph Jones 1989-11-04 Wrote fortran version of w3ai40 to pack
14C> constant size binary strings.
15C> - Ralph Jones 1989-11-05 Convert to cray cft77 fortran.
16C> - Boi Vuong 1998-03-10 Remove the cdir$ integer=64 directive.
17C>
18C> @param[in] KFLD Integer input array of right adjusted strings.
19C> @param[in] KLEN Integer number of bits per string (0 < klen < 33).
20C> @param[in] KNUM Integer number of strings in 'kfld' to pack.
21C> @param[in] KOFF Integer number specifying the bit offset of the
22C> first output string. the offset value is reset to
23C> include the low order bit of the last packed string.
24C> @param[out] KOUT Integer output array to hold packed string(s).
25C>
26C> exit states:
27C> error - koff < 0 if klen has an illegal value or knum < 1
28C> then kout has no strings stored.
29C>
30C> @note This subroutine should be written in assembler language.
31C> The fortran version runs two or three times slower than the asembler
32C> version. The fortran version can be converted to run on other
33C> computers with a few changes. The bit manipulation functions are the
34C> same in IBM370 vs fortran 4.1, microsoft fortran 4.10, vax fortran.
35C> Most modern fortran compiler have and, or, shift functions. If you
36C> are running on a pc, vax and your input was made on a IBM370, apollo
37C> sun, h.p.. etc. you may have to add more code to reverse the order of
38C> bytes in an integer word. NCAR sbytes() can be used instead of this
39C> subroutine. Please use NCAR sbytes() subroutine instead of this
40C> subroutine.
41C>
42C> @author Robert Allard @date 1980-04-01
43 SUBROUTINE w3ai40(KFLD,KOUT,KLEN,KNUM,KOFF)
44C
45 INTEGER KFLD(*)
46 INTEGER KOUT(*)
47 INTEGER BIT
48 INTEGER OFFSET
49 INTEGER WRD
50C
51 DATA mask /-1/
52C
53 offset = koff
54 IF (offset.LT.0) RETURN
55 IF (klen.GT.64.OR.klen.LT.1) THEN
56 koff = -1
57 RETURN
58 ENDIF
59C
60 IF (knum.LT.1) THEN
61 koff = -1
62 RETURN
63 ENDIF
64C
65 jcount = 64 - klen
66 length = klen
67 maskwd = ishft(mask,jcount)
68C
69 DO 100 i = 1,knum
70 wrd = ishft(offset,-6) + 1
71 bit = mod(offset,64)
72 mask8 = not(ishft(maskwd,-bit))
73 offset = offset + length
74 jtemp = iand(kout(wrd),mask8)
75 ncount = 64 - bit
76 IF (ncount.LT.length) THEN
77 mask9 = not(ishft(maskwd,ncount))
78 ntemp = iand(kout(wrd+1),mask9)
79 ENDIF
80 itemp = ishft(ishft(kfld(i),jcount),-bit)
81 kout(wrd) = ior(itemp,jtemp)
82 IF (ncount.LT.length) THEN
83 itemp = ishft(kfld(i),(jcount+ncount))
84 kout(wrd+1) = ior(itemp,ntemp)
85 ENDIF
86 100 CONTINUE
87 koff = offset
88 RETURN
89 END
subroutine w3ai40(kfld, kout, klen, knum, koff)
Packs constant size binary strings into an array.
Definition w3ai40.f:44