NCEPLIBS-bufr  12.0.0
ipkm.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Encode an integer value within a character string.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> Encode an integer value within a character string.
7 C>
8 C> This subroutine encodes an integer value within a specified
9 C> number of bytes of a character string, up to a maximum of 8
10 C> bytes.
11 C>
12 C> This subroutine is the logical inverse of subroutine iupm().
13 C>
14 C> @param[in] N - integer: Value to be encoded.
15 C> @param[in] NBYT - integer: Number of bytes of CBAY (up to a
16 C> maximum of 8) within which to encode N.
17 C> @param[out] CBAY - character*(*): String of length NBYT bytes
18 C> containing encoded integer N.
19 C>
20 C> @author J. Woollen @date 1994-01-06
21  RECURSIVE SUBROUTINE ipkm(CBAY,NBYT,N)
22 
23  USE modv_im8b
24 
25  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
26 
27  CHARACTER*128 bort_str
28  CHARACTER*8 cbay,cint
29  equivalence(cint,int)
30 
31 C----------------------------------------------------------------------
32 C----------------------------------------------------------------------
33 
34 C Check for I8 integers.
35 
36  IF(im8b) THEN
37  im8b=.false.
38 
39  CALL x84(n,my_n,1)
40  CALL x84(nbyt,my_nbyt,1)
41  CALL ipkm(cbay,my_nbyt,my_n)
42 
43  im8b=.true.
44  RETURN
45  ENDIF
46 
47  IF(nbyt.GT.nbytw) GOTO 900
48 
49 C Note that the widths of input variable N and local variable INT
50 C will both be equal to the default size of an integer (= NBYTW),
51 C since they aren't specifically declared otherwise.
52 
53  int = irev(ishft(n,(nbytw-nbyt)*8))
54  DO i=1,nbyt
55  cbay(i:i) = cint(i:i)
56  ENDDO
57 
58 C EXITS
59 C -----
60 
61  RETURN
62 900 WRITE(bort_str,'("BUFRLIB: IPKM - NUMBER OF BYTES BEING PACKED '//
63  . ', NBYT (",I4,"), IS > THE INTEGER WORD LENGTH ON THIS '//
64  . 'MACHINE, NBYTW (",I3,")")') nbyt,nbytw
65  CALL bort(bort_str)
66  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive subroutine ipkm(CBAY, NBYT, N)
Encode an integer value within a character string.
Definition: ipkm.f:22
function irev(N)
This function will, when the local machine is "little-endian" (i.e., when it uses a right to left sch...
Definition: irev.F:33
This module declares and initializes the IM8B variable.
logical, public im8b
Status indicator to keep track of whether all future calls to BUFRLIB subroutines and functions from ...
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19