NCEPLIBS-bufr  12.0.0
ipks.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Pack a real*8 value into an integer
3 C> by applying the proper scale and reference values.
4 C>
5 C> @author J. Ator @date 2012-03-02
6 
7 C> This function packs a real*8 user value into a BUFR
8 C> integer by applying the proper scale and reference values.
9 C> Normally the scale and reference values are obtained from index
10 C> node of the internal jump/link table arrays isc(*) and irf(*);
11 C> however, the reference value in irf(*) will be overridden if a
12 C> 2-03 operator is in effect for this node.
13 C>
14 C> @param[in] VAL - real*8: user value
15 C> @param[in] NODE - integer: index into internal jump/link tables
16 C>
17 C> @return - integer*8: packed BUFR integer
18 C>
19 C> @remarks
20 C> - This function is the logical inverse of function ups().
21 C>
22 C> @author J. Ator @date 2012-03-02
23  FUNCTION ipks(VAL,NODE)
24 
25  USE moda_tables
26  USE moda_nrv203
27 
28  integer(8) imask, ipks
29  real*8 ten,val
30 
31  DATA ten /10./
32 
33 C-----------------------------------------------------------------------
34 
35  ipks = nint(val * ten**isc(node),8) - irf(node)
36 
37  IF ( nnrv .GT. 0 ) THEN
38 
39 C There are redefined reference values in the jump/link table,
40 C so we need to check if this node is affected by any of them.
41 
42  DO jj = 1, nnrv
43  IF ( node .EQ. inodnrv(jj) ) THEN
44 
45 C This node contains a redefined reference value.
46 C Per the rules of BUFR, negative values should be encoded
47 C as positive integers with the left-most bit set to 1.
48 
49  nrv(jj) = nint(val)
50  IF ( nrv(jj) .LT. 0 ) THEN
51  imask = 2_8**(ibt(node)-1)
52  ipks = ior(abs(nrv(jj)),imask)
53  ELSE
54  ipks = nrv(jj)
55  END IF
56  RETURN
57  ELSE IF ( ( tag(node)(1:8) .EQ. tagnrv(jj) ) .AND.
58  . ( node .GE. isnrv(jj) ) .AND.
59  . ( node .LE. ienrv(jj) ) ) THEN
60 
61 C The corresponding redefinded reference value needs to
62 C be used when encoding this value.
63 
64  ipks = nint(val * ten**isc(node),8) - nrv(jj)
65  RETURN
66  END IF
67  END DO
68 
69  END IF
70 
71  RETURN
72  END
integer(8) function ipks(VAL, NODE)
This function packs a real*8 user value into a BUFR integer by applying the proper scale and referenc...
Definition: ipks.f:24
This module contains array and variable declarations for use with any 2-03-YYY (change reference valu...
integer, dimension(:), allocatable ienrv
End of entry range in jump/link table, within which the corresponding new reference value in nrv will...
character *8, dimension(:), allocatable tagnrv
Table B mnemonic to which the corresponding new reference value in nrv applies.
integer, dimension(:), allocatable isnrv
Start of entry range in jump/link table, within which the corresponding new reference value in nrv wi...
integer nnrv
Number of entries in the jump/link table which contain new reference values (up to a maximum of MXNRV...
integer *8, dimension(:), allocatable nrv
New reference values corresponding to inodnrv.
integer, dimension(:), allocatable inodnrv
Entries within jump/link table which contain new reference values.
This module contains array and variable declarations used to store the internal jump/link table.
integer, dimension(:), allocatable irf
Reference values corresponding to tag and typ:
integer, dimension(:), allocatable isc
Scale factors corresponding to tag and typ:
integer, dimension(:), allocatable ibt
Bit widths corresponding to tag and typ:
character *10, dimension(:), allocatable tag
Mnemonics in the jump/link table.