NCEPLIBS-bufr  11.7.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> | Date | Programmer | Comments |
19 C> | -----|------------|----------|
20 C> | 1994-01-06 | J. Woollen | Original author |
21 C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine ABORT with call to new internal routine bort() |
22 C> | 2003-11-04 | J. Woollen | Modified to be endian-independent |
23 C> | 2003-11-04 | J. Ator | Added documentation |
24 C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
25 C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added documentation; outputs more complete diagnostic info when routine terminates abnormally |
26 C>
27  SUBROUTINE ipkm(CBAY,NBYT,N)
28 
29  COMMON /hrdwrd/ nbytw,nbitw,iord(8)
30 
31  CHARACTER*128 bort_str
32  CHARACTER*8 cbay,cint
33  equivalence(cint,int)
34 
35 C----------------------------------------------------------------------
36 C----------------------------------------------------------------------
37 
38  IF(nbyt.GT.nbytw) goto 900
39 
40 C Note that the widths of input variable N and local variable INT
41 C will both be equal to the default size of an integer (= NBYTW),
42 C since they aren't specifically declared otherwise.
43 
44  int = irev(ishft(n,(nbytw-nbyt)*8))
45  DO i=1,nbyt
46  cbay(i:i) = cint(i:i)
47  ENDDO
48 
49 C EXITS
50 C -----
51 
52  RETURN
53 900 WRITE(bort_str,'("BUFRLIB: IPKM - NUMBER OF BYTES BEING PACKED '//
54  . ', NBYT (",I4,"), IS > THE INTEGER WORD LENGTH ON THIS '//
55  . 'MACHINE, NBYTW (",I3,")")') nbyt,nbytw
56  CALL bort(bort_str)
57  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:27
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22