NCEPLIBS-bufr  11.7.0
 All Data Structures Files Functions Variables Pages
upftbv.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Determine the bit settings equivalent to a numerical
3 C> flag table value.
4 
5 C> Given a Table B mnemonic with flag table units and a
6 C> corresponding numerical data value, this subroutine determines
7 C> the bit settings equivalent to that numerical value.
8 C>
9 C> @author J. Ator
10 C> @date 2005-11-29
11 C>
12 C> @param[in] LUNIT -- integer: Fortran logical unit number for
13 C> BUFR file
14 C> @param[in] NEMO -- character*(*): Table B mnemonic with
15 C> flag table units
16 C> @param[in] VAL -- real*8: Value corresponding to NEMO
17 C> @param[in] MXIB -- integer: Dimensioned size (in integers) of
18 C> IBIT; used by the subroutine to ensure that
19 C> it doesn't overflow the IBIT array
20 C> @param[out] IBIT -- integer(*): Bit numbers which were set to
21 C> "On" (i.e. set to "1") in VAL
22 C> @param[out] NIB -- integer: Number of bit numbers returned in
23 C> IBIT
24 C>
25 C> @remarks
26 C> - This subroutine is the logical inverse of function pkftbv().
27 C> - According to the WMO standard, bits within a bit field are
28 C> numbered from left to right, so bit #1 is always the high-order
29 C> (i.e. most significant) bit in any bit field.
30 C>
31 C> <b>Program history log:</b>
32 C> | Date | Programmer | Comments |
33 C> | -----|------------|----------|
34 C> | 2005-11-29 | J. Ator | Original version |
35 C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
36 C>
37  SUBROUTINE upftbv(LUNIT,NEMO,VAL,MXIB,IBIT,NIB)
38 
39  USE moda_tababd
40 
41  REAL*8 val,r8val,r82i
42 
43  INTEGER ibit (*)
44 
45  CHARACTER*(*) nemo
46  CHARACTER*128 bort_str
47  CHARACTER*1 tab
48 
49 C----------------------------------------------------------------------
50 C----------------------------------------------------------------------
51 
52 C Perform some sanity checks.
53 
54  CALL status(lunit,lun,il,im)
55  IF(il.EQ.0) goto 900
56 
57  CALL nemtab(lun,nemo,idn,tab,n)
58  IF(n.EQ.0) goto 901
59  IF(tabb(n,lun)(71:74).NE.'FLAG') goto 902
60 
61 C Figure out which bits are set.
62 
63  nib = 0
64  r8val = val
65  nbits = valx(tabb(n,lun)(110:112))
66  DO i=(nbits-1),0,-1
67  r82i = (2.)**i
68  IF(abs(r8val-r82i).LT.(0.005)) THEN
69  nib = nib + 1
70  IF(nib.GT.mxib) goto 903
71  ibit(nib) = nbits-i
72  RETURN
73  ELSEIF(r82i.LT.r8val) THEN
74  nib = nib + 1
75  IF(nib.GT.mxib) goto 903
76  ibit(nib) = nbits-i
77  r8val = r8val - r82i
78  ENDIF
79  ENDDO
80 
81  RETURN
82 900 CALL bort('BUFRLIB: UPFTBV - INPUT BUFR FILE IS CLOSED, IT '//
83  . 'MUST BE OPEN FOR INPUT')
84 901 WRITE(bort_str,'("BUFRLIB: UPFTBV - MNEMONIC ",A,'//
85  . '" NOT FOUND IN TABLE B")') nemo
86  CALL bort(bort_str)
87 902 WRITE(bort_str,'("BUFRLIB: UPFTBV - MNEMONIC ",A,'//
88  . '" IS NOT A FLAG TABLE")') nemo
89  CALL bort(bort_str)
90 903 CALL bort('BUFRLIB: UPFTBV - IBIT ARRAY OVERFLOW')
91  END
function valx(STR)
This function decodes a real number from a character string.
Definition: valx.f:25
This module contains array and variable declarations used to store DX BUFR tables internally for mult...
Definition: moda_tababd.F:10
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:55
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:37
subroutine nemtab(LUN, NEMO, IDN, TAB, IRET)
This subroutine returns information about a descriptor from the internal DX BUFR tables, based on the mnemonic associated with that descriptor.
Definition: nemtab.f:44
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22