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