NCEPLIBS-bufr  12.0.0
upftbv.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Determine the bit settings equivalent to a numerical flag table value.
3 C>
4 C> @author J. Ator @date 2005-11-29
5 
6 C> Given a Table B mnemonic with flag table units and a
7 C> corresponding numerical data value, this subroutine determines
8 C> the bit settings equivalent to that numerical value.
9 C>
10 C> This subroutine is the logical inverse of function pkftbv().
11 C>
12 C> According to the WMO standard, bits within a bit field are
13 C> numbered from left to right, so bit #1 is always the high-order
14 C> (i.e. most significant) bit in any bit field.
15 C>
16 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
17 C> @param[in] NEMO - character*(*): Table B mnemonic with flag table units.
18 C> @param[in] VAL - real*8: Value corresponding to NEMO.
19 C> @param[in] MXIB - integer: Dimensioned size (in integers) of IBIT in the calling
20 C> program; used by the subroutine to ensure that it doesn't overflow the IBIT array.
21 C> @param[out] IBIT - integer: Bit numbers which were set to "On" (i.e. set to "1")
22 C> in VAL.
23 C> @param[out] NIB - integer: Number of bit numbers returned in IBIT.
24 C>
25 C> @author J. Ator @date 2005-11-29
26 
27  RECURSIVE SUBROUTINE upftbv(LUNIT,NEMO,VAL,MXIB,IBIT,NIB)
28 
29  USE modv_im8b
30 
31  USE moda_tababd
32 
33  real*8 val, r8val, r82i
34 
35  INTEGER ibit(*), nib(*)
36 
37  CHARACTER*(*) nemo
38  CHARACTER*128 bort_str
39  CHARACTER*1 tab
40 
41 C----------------------------------------------------------------------
42 C----------------------------------------------------------------------
43 
44 C Check for I8 integers.
45 
46  IF(im8b) THEN
47  im8b=.false.
48 
49  CALL x84(lunit,my_lunit,1)
50  CALL x84(mxib,my_mxib,1)
51  CALL upftbv( my_lunit, nemo, val, my_mxib*2, ibit, nib )
52  CALL x48(ibit,ibit,nib(1))
53  CALL x48(nib,nib,1)
54 
55  im8b=.true.
56  RETURN
57  ENDIF
58 
59 C Perform some sanity checks.
60 
61  CALL status(lunit,lun,il,im)
62  IF(il.EQ.0) GOTO 900
63 
64  CALL nemtab(lun,nemo,idn,tab,n)
65  IF(n.EQ.0) GOTO 901
66  IF(tabb(n,lun)(71:74).NE.'FLAG') GOTO 902
67 
68 C Figure out which bits are set.
69 
70  nib(1) = 0
71  r8val = val
72  CALL strnum(tabb(n,lun)(110:112),nbits,iersn)
73  DO i=(nbits-1),0,-1
74  r82i = (2.)**i
75  IF(abs(r8val-r82i).LT.(0.005)) THEN
76  nib(1) = nib(1) + 1
77  IF(nib(1).GT.mxib) GOTO 903
78  ibit(nib(1)) = nbits-i
79  RETURN
80  ELSEIF(r82i.LT.r8val) THEN
81  nib(1) = nib(1) + 1
82  IF(nib(1).GT.mxib) GOTO 903
83  ibit(nib(1)) = nbits-i
84  r8val = r8val - r82i
85  ENDIF
86  ENDDO
87 
88  RETURN
89 900 CALL bort('BUFRLIB: UPFTBV - INPUT BUFR FILE IS CLOSED, IT '//
90  . 'MUST BE OPEN FOR INPUT')
91 901 WRITE(bort_str,'("BUFRLIB: UPFTBV - MNEMONIC ",A,'//
92  . '" NOT FOUND IN TABLE B")') nemo
93  CALL bort(bort_str)
94 902 WRITE(bort_str,'("BUFRLIB: UPFTBV - MNEMONIC ",A,'//
95  . '" IS NOT A FLAG TABLE")') nemo
96  CALL bort(bort_str)
97 903 CALL bort('BUFRLIB: UPFTBV - IBIT ARRAY OVERFLOW')
98  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
This module contains array and variable declarations used to store DX BUFR tables internally for mult...
character *128, dimension(:,:), allocatable tabb
Table B entries for each internal I/O stream.
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 nemtab(LUN, NEMO, IDN, TAB, IRET)
Get information about a descriptor, based on the mnemonic.
Definition: nemtab.f:29
recursive subroutine status(LUNIT, LUN, IL, IM)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
Definition: status.f:36
recursive subroutine strnum(str, num, iret)
Decode an integer from a character string.
Definition: strnum.F90:24
recursive subroutine upftbv(LUNIT, NEMO, VAL, MXIB, IBIT, NIB)
Given a Table B mnemonic with flag table units and a corresponding numerical data value,...
Definition: upftbv.f:28
subroutine x48(IIN4, IOUT8, NVAL)
Encode one or more 4-byte integer values as 8-byte integer values.
Definition: x48.F:19
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19