NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
ipkm.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Encode an integer value within a character string.
3 
4 C> This subroutine encodes an integer value within a specified
5 C> number of bytes of a character string, up to a maximum of 8
6 C> bytes.
7 C>
8 C> @author J. Woollen
9 C> @date 1994-01-06
10 C>
11 C> @param[in] N - integer: Value to be encoded
12 C> @param[in] NBYT - integer: Number of bytes of CBAY (up to a
13 C> maximum of 8) within which to encode N
14 C> @param[out] CBAY - character*(*): String of length NBYT bytes
15 C> containing encoded integer N
16 C>
17 C> <b>Program history log:</b>
18 C> - 1994-01-06 J. Woollen -- Original author
19 C> - 1998-07-08 J. Woollen -- Replaced call to Cray library routine ABORT
20 C> with call to new internal routine bort()
21 C> - 2003-11-04 J. Woollen -- Modified to be endian-independent
22 C> - 2003-11-04 J. Ator -- Added documentation
23 C> - 2003-11-04 S. Bender -- Added remarks and routine interdependencies
24 C> - 2003-11-04 D. Keyser -- Unified/portable for WRF; added history
25 C> documentation; outputs more complete
26 C> diagnostic info when routine terminates
27 C> abnormally
28 C>
29  SUBROUTINE ipkm(CBAY,NBYT,N)
30 
31  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
32 
33  CHARACTER*128 bort_str
34  CHARACTER*8 cbay,cint
35  equivalence(cint,int)
36 
37 C----------------------------------------------------------------------
38 C----------------------------------------------------------------------
39 
40  IF(nbyt.GT.nbytw) goto 900
41 
42 C Note that the widths of input variable N and local variable INT
43 C will both be equal to the default size of an integer (= NBYTW),
44 C since they aren't specifically declared otherwise.
45 
46  int = irev(ishft(n,(nbytw-nbyt)*8))
47  DO i=1,nbyt
48  cbay(i:i) = cint(i:i)
49  ENDDO
50 
51 C EXITS
52 C -----
53 
54  RETURN
55 900 WRITE(bort_str,'("BUFRLIB: IPKM - NUMBER OF BYTES BEING PACKED '//
56  . ', NBYT (",I4,"), IS > THE INTEGER WORD LENGTH ON THIS '//
57  . 'MACHINE, NBYTW (",I3,")")') nbyt,nbytw
58  CALL bort(bort_str)
59  END
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
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
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23