NCEPLIBS-bufr  12.0.1
getvalnb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read one data value from a data subset.
3 C>
4 C> @author J. Ator @date 2012-09-12
5 
6 C> This function can be used to read a data value corresponding to
7 C> a specific occurrence of a mnemonic within a data subset, based on
8 C> its position relative to a different mnemonic within the subset.
9 C>
10 C> The function first searches for a specific occurrence of a pivot
11 C> mnemonic, counting from the beginning of the subset. From there,
12 C> it then searches in either a forward or backward direction for a
13 C> specific occurrence of a nearby mnemonic, and if found
14 C> returns the data value from the corresponding location
15 C> within the subset.
16 C>
17 C> @param[in] LUNIT -- integer: Fortran logical unit number for
18 C> BUFR file
19 C> @param[in] TAGPV -- character*(*): Pivot mnemonic; the subroutine
20 C> will first search for the (NTAGPV)th occurrence
21 C> of this mnemonic, counting from the beginning
22 C> of the overall subset definition
23 C> @param[in] NTAGPV -- integer: Ordinal occurrence of TAGPV to search for,
24 C> counting from the beginning of the overall
25 C> subset definition
26 C> @param[in] TAGNB -- character*(*): Nearby mnemonic; assuming TAGPV is
27 C> successfully found, the subroutine will then search
28 C> nearby for the (NTAGNB)th occurrence of TAGNB and
29 C> return the corresponding value
30 C> @param[in] NTAGNB -- integer: Ordinal occurrence of TAGNB to search for,
31 C> counting from the location of TAGPV within the
32 C> overall subset definition. If NTAGNB is positive,
33 C> the subroutine will search in a forward direction
34 C> from the location of TAGPV; otherwise, if NTAGNB is
35 C> negative, it will instead search in a backwards
36 C> direction from the location of TAGPV.
37 C> @returns getvalnb -- real*8: Value corresponding to (NTAGNB)th occurrence
38 C> of TAGNB. If for any reason this value cannot be
39 C> located, then the current placeholder value for
40 C> "missing" data will be returned instead.
41 C>
42 C> The current placeholder value for "missing" data can be determined
43 C> via a separate call to function getbmiss().
44 C>
45 C> Before calling this function, a BUFR data subset should already be
46 C> open for reading via a previous call to one of the BUFRLIB
47 C> [subset-reading subroutines](@ref hierarchy).
48 C>
49 C> @author J. Ator @date 2012-09-12
50  RECURSIVE FUNCTION getvalnb
51  . ( lunit, tagpv, ntagpv, tagnb, ntagnb )
52  . result( r8val )
53 
54  USE modv_bmiss
55  USE modv_im8b
56 
57  USE moda_usrint
58  USE moda_msgcwd
59  USE moda_tables
60 
61  CHARACTER*(*) tagpv, tagnb
62 
63  real*8 r8val
64 
65 C----------------------------------------------------------------------
66 C----------------------------------------------------------------------
67 
68 C Check for I8 integers.
69 
70  IF(im8b) THEN
71  im8b=.false.
72 
73  CALL x84(lunit,my_lunit,1)
74  CALL x84(ntagpv,my_ntagpv,1)
75  CALL x84(ntagnb,my_ntagnb,1)
76  r8val=getvalnb(my_lunit,tagpv,my_ntagpv,tagnb,my_ntagnb)
77 
78  im8b=.true.
79  RETURN
80  ENDIF
81 
82  r8val = bmiss
83 
84 C Get LUN from LUNIT.
85 
86  CALL status (lunit, lun, il, im )
87  IF ( il .GE. 0 ) RETURN
88  IF ( inode(lun) .NE. inv(1,lun) ) RETURN
89 
90 C Starting from the beginning of the subset, locate the (NTAGPV)th
91 C occurrence of TAGPV.
92 
93  CALL fstag( lun, tagpv, ntagpv, 1, npv, iret )
94  IF ( iret .NE. 0 ) RETURN
95 
96 C Now, starting from the (NTAGPV)th occurrence of TAGPV, search
97 C forward or backward for the (NTAGNB)th occurrence of TAGNB.
98 
99  CALL fstag( lun, tagnb, ntagnb, npv, nnb, iret )
100  IF ( iret .NE. 0 ) RETURN
101 
102  r8val = val(nnb,lun)
103 
104  RETURN
105  END
subroutine fstag(LUN, UTAG, NUTAG, NIN, NOUT, IRET)
This subroutine finds the (NUTAG)th occurrence of mnemonic UTAG within the current overall subset def...
Definition: fstag.f:26
recursive real *8 function getvalnb(LUNIT, TAGPV, NTAGPV, TAGNB, NTAGNB)
This function can be used to read a data value corresponding to a specific occurrence of a mnemonic w...
Definition: getvalnb.f:53
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
This module contains array and variable declarations used to store the internal jump/link table.
This module contains declarations for arrays used to store data values and associated metadata for th...
real *8, dimension(:,:), allocatable, target val
Data values.
integer, dimension(:,:), allocatable, target inv
Inventory pointer which links each data value to its corresponding node in the internal jump/link tab...
This module declares and initializes the BMISS variable.
Definition: modules_vars.F90:9
real *8, public bmiss
Current placeholder value to represent "missing" data when reading from or writing to BUFR files; thi...
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 ...
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
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19