NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
pkc.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Encode a character string within an integer array.
3 
4 C> This subroutine encodes a character string within a specified
5 C> number of bits of an integer array, starting at the bit
6 C> immediately after a specified bit within the array.
7 C>
8 C> @author J. Woollen
9 C> @date 1994-01-06
10 C>
11 C> @param[in] CHR - character*(*): String to be encoded
12 C> @param[in] NCHR - integer: Number of bytes of IBAY within
13 C> which to encode CHR (i.e. the number of
14 C> characters in CHR)
15 C> @param[out] IBAY - integer(*): Array containing encoded CHR
16 C> @param[in,out] IBIT - integer: Bit pointer within IBAY
17 C> - On input, IBIT points to the bit within
18 C> IBAY after which to begin encoding CHR.
19 C> - On output, IBIT points to the last bit
20 C> of IBAY which contains the encoded CHR.
21 C>
22 C> @remarks
23 C> - This subroutine is the logical inverse of subroutine upc().
24 C> - On input, there is no requirement that IBIT must point to the first
25 C> bit of a byte within IBAY. Correspondingly, on output there is no
26 C> guarantee that the NCHR characters of CHR will be aligned on byte
27 C> boundaries when encoded within IBAY.
28 C>
29 C> <b>Program history log:</b>
30 C> - 1994-01-06 J. Woollen -- Original author
31 C> - 1998-07-08 J. Woollen -- Replaced call to Cray library routine ABORT
32 C> with call to new internal routine bort()
33 C> - 2003-11-04 J. Woollen -- Modified to be endian-independent
34 C> - 2003-11-04 J. Ator -- Added documentation
35 C> - 2003-11-04 S. Bender -- Added remarks and routine interdependencies
36 C> - 2003-11-04 D. Keyser -- Unified/portable for WRF; added history
37 C> documentation; outputs more complete
38 C> diagnostic info when routine terminates
39 C> abnormally; use bort2() instead of bort()
40 C> - 2004-08-18 J. Ator -- Modified to be compatible with writlc()
41 C>
42  SUBROUTINE pkc(CHR,NCHR,IBAY,IBIT)
43 
44  COMMON /charac/ iascii,iatoe(0:255),ietoa(0:255)
45  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
46 
47  CHARACTER*(*) chr
48  CHARACTER*1 cval(8)
49  dimension ibay(*),ival(2)
50  equivalence(cval,ival)
51 
52 C----------------------------------------------------------------------
53 C----------------------------------------------------------------------
54 
55  lb = iord(nbytw)
56 
57 C LB now points to the "low-order" (i.e. least significant) byte
58 C within a machine word.
59 
60  ival(1) = 0
61  nbit = 8
62 
63  DO i=1,nchr
64  IF(i.LE.len(chr)) THEN
65  cval(lb) = chr(i:i)
66  ELSE
67  cval(lb) = ' '
68  ENDIF
69 
70 C If the machine is EBCDIC, then translate character CVAL(LB) from
71 C EBCDIC to ASCII.
72 
73  IF(iascii.EQ.0) CALL ipkm(cval(lb),1,ietoa(iupm(cval(lb),8)))
74 
75  nwd = ibit/nbitw + 1
76  nbt = mod(ibit,nbitw)
77  int = ishft(ival(1),nbitw-nbit)
78  int = ishft(int,-nbt)
79  msk = ishft( -1,nbitw-nbit)
80  msk = ishft(msk,-nbt)
81  ibay(nwd) = irev(ior(iand(irev(ibay(nwd)),not(msk)),int))
82  IF(nbt+nbit.GT.nbitw) THEN
83 
84 C This character will not fit within the current word (i.e.
85 C array member) of IBAY, because there are less than 8 bits of
86 C space left. Store as many bits as will fit within the current
87 C word and then store the remaining bits within the next word.
88 
89  int = ishft(ival(1),2*nbitw-(nbt+nbit))
90  msk = ishft( -1,2*nbitw-(nbt+nbit))
91  ibay(nwd+1) = irev(ior(iand(irev(ibay(nwd+1)),not(msk)),int))
92  ENDIF
93  ibit = ibit + nbit
94  ENDDO
95 
96 C EXITS
97 C -----
98 
99  RETURN
100  END
subroutine pkc(CHR, NCHR, IBAY, IBIT)
This subroutine encodes a character string within a specified number of bits of an integer array...
Definition: pkc.f:42
function irev(N)
THIS FUNCTION WILL, WHEN THE LOCAL MACHINE IS &quot;LITTLE- ENDIAN&quot; (I.E., USES A RIGHT TO LEFT SCHEME ...
Definition: irev.F:50
function iupm(CBAY, NBITS)
THIS FUNCTION UNPACKS AND RETURNS A BINARY INTEGER WORD CONTAINED WITHIN NBITS BITS OF A CHARACTER ST...
Definition: iupm.f:40
subroutine ipkm(CBAY, NBYT, N)
This subroutine encodes an integer value within a specified number of bytes of a character string...
Definition: ipkm.f:29