NCEPLIBS-bufr  12.0.0
setvalnb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Write one data value to a data subset.
3 C>
4 C> @author J. Ator @date 2016-07-29
5 
6 C> This subroutine can be used to write 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 subroutine 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> stores the specified data value in the corresponding location
15 C> within the subset.
16 C>
17 C> Before calling this subroutine, a BUFR message should already be
18 C> opened and initialized for output via a previous call to one of the
19 C> BUFRLIB [message-writing subroutines](@ref hierarchy).
20 C>
21 C> @param[in] LUNIT -- integer: Fortran logical unit number for
22 C> BUFR file
23 C> @param[in] TAGPV -- character*(*): Pivot mnemonic; the subroutine
24 C> will first search for the (NTAGPV)th occurrence
25 C> of this mnemonic, counting from the beginning
26 C> of the overall subset definition
27 C> @param[in] NTAGPV -- integer: Ordinal occurrence of TAGPV to search for,
28 C> counting from the beginning of the overall
29 C> subset definition
30 C> @param[in] TAGNB -- character*(*): Nearby mnemonic; assuming TAGPV is
31 C> successfully found, the subroutine will then search
32 C> nearby for the (NTAGNB)th occurrence of TAGNB and
33 C> store R8VAL as the corresponding value
34 C> @param[in] NTAGNB -- integer: Ordinal occurrence of TAGNB to search for,
35 C> counting from the location of TAGPV within the
36 C> overall subset definition. If NTAGNB is positive,
37 C> the subroutine will search in a forward direction
38 C> from the location of TAGPV; otherwise, if NTAGNB is
39 C> negative, it will instead search in a backwards
40 C> direction from the location of TAGPV.
41 C> @param[in] R8VAL -- real*8: Value to be stored corresponding to
42 C> (NTAGNB)th occurrence of TAGNB within the subset
43 C> @param[out] IRET -- integer: return code
44 C> - 0 = R8VAL was successfully stored
45 C> - -1 = the (NTAGNB)th occurence of mnemonic TAGNB
46 C> could not be found, or some other error
47 C> occurred
48 C>
49 C> @author J. Ator @date 2016-07-29
50  RECURSIVE SUBROUTINE setvalnb
51  . ( lunit, tagpv, ntagpv, tagnb, ntagnb, r8val, iret )
52 
53  USE moda_usrint
54  USE moda_msgcwd
55  USE moda_tables
56  USE modv_im8b
57 
58  CHARACTER*(*) tagpv, tagnb
59 
60  real*8 r8val
61 
62 C----------------------------------------------------------------------
63 C----------------------------------------------------------------------
64 
65 C Check for I8 integers.
66 
67  IF(im8b) THEN
68  im8b=.false.
69 
70  CALL x84 ( lunit, my_lunit, 1 )
71  CALL x84 ( ntagpv, my_ntagpv, 1 )
72  CALL x84 ( ntagnb, my_ntagnb, 1 )
73  CALL setvalnb ( my_lunit, tagpv, my_ntagpv, tagnb, my_ntagnb,
74  . r8val, iret )
75  CALL x48 ( iret, iret, 1 )
76 
77  im8b=.true.
78  RETURN
79  ENDIF
80 
81  iret = -1
82 
83 C Get LUN from LUNIT.
84 
85  CALL status (lunit, lun, il, im )
86  IF ( il .LE. 0 ) RETURN
87  IF ( inode(lun) .NE. inv(1,lun) ) RETURN
88 
89 C Starting from the beginning of the subset, locate the (NTAGPV)th
90 C occurrence of TAGPV.
91 
92  CALL fstag( lun, tagpv, ntagpv, 1, npv, ierft )
93  IF ( ierft .NE. 0 ) RETURN
94 
95 C Now, starting from the (NTAGPV)th occurrence of TAGPV, search
96 C forward or backward for the (NTAGNB)th occurrence of TAGNB.
97 
98  CALL fstag( lun, tagnb, ntagnb, npv, nnb, ierft )
99  IF ( ierft .NE. 0 ) RETURN
100 
101  iret = 0
102  val(nnb,lun) = r8val
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
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 IM8B variable.
logical, public im8b
Status indicator to keep track of whether all future calls to BUFRLIB subroutines and functions from ...
recursive subroutine setvalnb(LUNIT, TAGPV, NTAGPV, TAGNB, NTAGNB, R8VAL, IRET)
This subroutine can be used to write a data value corresponding to a specific occurrence of a mnemoni...
Definition: setvalnb.f:52
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 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