NCEPLIBS-bufr 11.7.1
getcfmng.f
Go to the documentation of this file.
1C> @file
2C> @brief Decode the meaning of a numerical value from a code or flag table
3
4C> This subroutine searches for a specified Table B mnemonic and associated
5C> value (code figure or bit number) within the master Code/Flag tables,
6C> and if found returns the associated meaning as a character string.
7C>
8C> @author J. Ator
9C> @date 2018-01-11
10C>
11C> @param[in] LUNIT -- integer: Fortran logical unit number for
12C> BUFR file
13C> @param[in] NEMOI -- character*(*): Mnemonic to search for
14C> @param[in] IVALI -- integer: Value (code figure or bit number)
15C> associated with NEMOI
16C> @param[in] NEMOD -- character*(*): Optional second mnemonic upon
17C> which the values NEMOI and IVALI depend; set to
18C> all blank characters if the meanings of NEMOI and
19C> IVALI do not depend on the value of any other
20C> mnemonic
21C> @param[in] IVALD -- integer: Value (code figure or bit number)
22C> associated with NEMOD; set to (-1) whenever
23C> NEMOD is set to all blank characters
24C> @param[out] CMEANG -- character*(*): If the initial search of the
25C> master Code/Flag tables was successful, then this
26C> string contains the meaning corresponding to NEMOI
27C> and IVALI (and to NEMOD and IVALD, if specified).
28C> However, if the initial search was unsuccessful,
29C> <b>and</b> if no optional second mnemonic and
30C> associated value were specified on input,
31C> <b>and</b> if a second search of the table
32C> determines that the meaning of NEMOI and IVALI
33C> indeed depends on one or more other possible
34C> second mnemonics, then those possible second
35C. mnemonics are returned within this string, as a
36C> series of IRET successive 8-byte substrings.
37C> An example of this scenario is included below
38C> within the Remarks.
39C> @param[out] LNMNG -- integer: Length (in bytes) of string returned in
40C> CMEANG
41C> @param[out] IRET -- integer: return code
42C> - 0 = meaning found and stored in CMEANG string
43C> - -1 = meaning not found
44C> - >0 = meaning not found, <b>and</b> NEMOD and
45C> IVALD were not specified on input,
46C> <b>and</b> the meaning of NEMOI and IVALI
47C> depends on the value of one of the
48C> mnemonics stored in the first IRET 8-byte
49C> substrings of CMEANG
50C>
51C> <p>As noted above, this subroutine first does an initial search of
52C> the master Code/Flag tables based on the mnemonics and values provided.
53C> The input parameters NEMOI and IVALI specify the mnemonic and
54C> corresponding numerical code or flag table value for which the meaning
55C> is sought, and the optional secondary parameters NEMOD and IVALD are
56C> specified when needed to differentiate between multiple possible
57C> results. An example of this particular scenario is included below
58C> within the Remarks. Otherwise, if the meaning of NEMOD and IVALD
59C> does not depend on the value associated with any other mnemonic, then
60C> NEMOD should be set to a field of all blank characters, and IVALD
61C> should be set to a value of (-1).
62C>
63C> <p>Subroutine codflg() must be called with a CF value of 'Y' prior to
64C> calling this subroutine, in order to ensure that master Code/Flag
65C> tables have been read into internal memory.
66C>
67C> <p>This subroutine can be called at any time after a BUFR message
68C> has been read into internal arrays by one of the BUFRLIB
69C> [message-reading subroutines](@ref hierarchy), and it
70C> can be called for any code or flag table mnemonic defined within that
71C> particular message. In most cases, this means that the mnemonic must
72C> be contained within the subset definition (Section 3) of that message.
73C> The only exceptions to this rule are for originating centers,
74C> originating subcenters, data types and data subtypes, since those can
75C> also be contained within the identification section (Section 1) of a
76C> BUFR message.
77C>
78C> <p>It is the user's responsibility to provide sufficient allocated
79C> space in CMEANG for the returned meaning string; otherwise, the
80C> returned string will be truncated.
81C>
82C> @remarks
83C> - An example of when secondary mnemonics NEMOD and IVALD would be
84C> required is when a user is searching for the meaning of a numerical
85C> code table value for an originating sub-center (i.e. mnemonic GSES).
86C> The meaning of any originating sub-center value depends on the identity
87C> of the originating center for which the sub-center in question is a
88C> member, so in order for the subroutine to locate and return the proper
89C> one, information about the originating center must also be provided. So
90C> in this case the user would input GSES and the associated numerical
91C> value as NEMOI and IVALI, respectively, but the user would also need to
92C> specify an appropriate originating center mnemonic (e.g. GCLONG, OGCE
93C> or ORIGC) and associated value from the same BUFR message as input
94C> parameters NEMOD and IVALD, respectively, and then the subroutine will
95C> be able to locate and return the appropriate meaning string. Otherwise,
96C> if this information was not provided, the subroutine would return with
97C> an IRET value of 3, and with each of the mnemonics GCLONG, OGCE and
98C> ORIGC contained in successive 8-byte substrings of CMEANG (and with a
99C> corresponding value of 24 returned for LNMNG), as a hint to the user
100C> that more information needs to be input to the subroutine in order to
101C> achieve the desired result.
102C>
103C> <b>Program history log:</b>
104C> | Date | Programmer | Comments |
105C> | -----|------------|----------|
106C> | 2018-01-11 | J. Ator | Original author |
107C> | 2018-02-08 | J. Ator | Add special handling for data types and subtypes in Section 1 |
108C>
109 SUBROUTINE getcfmng ( LUNIT, NEMOI, IVALI, NEMOD, IVALD,
110 . CMEANG, LNMNG, IRET )
111
112 USE moda_tababd
113
114 COMMON /tablef/ cdmf
115
116 character*(*) nemoi, nemod, cmeang
117
118 character*128 bort_str
119 character*8 nemo
120 character*1 cdmf, tab
121
122 dimension ifxyd(10)
123
124C-----------------------------------------------------------------------
125C-----------------------------------------------------------------------
126
127 CALL status ( lunit, lun, il, im )
128 IF ( il .EQ. 0 ) GOTO 900
129 IF ( il .GT. 0 ) GOTO 901
130 IF ( im .EQ. 0 ) GOTO 902
131
132C* Make sure the appropriate code/flag information has already been
133C* read into internal memory.
134
135 IF ( cdmf .NE. 'Y' ) GOTO 903
136
137 itmp = ireadmt( lun )
138
139C* Check the validity of the input mnemonic(s). Include special
140C* handling for originating centers, originating subcenters, data
141C* types and data subtypes, since those can be reported in
142C* Section 1 of a BUFR message as well as in Section 3, so if a
143C* user requests those mnemonics we can't necessarily assume they
144C* came from within Section 3.
145
146 lcmg = len( cmeang )
147
148 IF ( nemoi(1:4) .EQ. 'GSES' ) THEN
149 IF ( ( nemod(1:6) .EQ. 'GCLONG' ) .OR.
150 . ( nemod(1:4) .EQ. 'OGCE' ) .OR.
151 . ( nemod(1:5) .EQ. 'ORIGC' ) ) THEN
152 ifxyi = ifxy( '001034' )
153 ifxyd(1) = ifxy( '001035' )
154 ELSE
155 lnmng = min( 24, lcmg )
156 IF ( lnmng .EQ. 24 ) THEN
157 iret = 3
158 cmeang(1:24) = 'GCLONG OGCE ORIGC '
159 ELSE
160 iret = -1
161 END IF
162 RETURN
163 END IF
164 ELSE IF ( nemoi(1:6) .EQ. 'GCLONG' ) THEN
165 ifxyi = ifxy( '001031' )
166 ifxyd(1) = (-1)
167 ELSE IF ( nemoi(1:4) .EQ. 'OGCE' ) THEN
168 ifxyi = ifxy( '001033' )
169 ifxyd(1) = (-1)
170 ELSE IF ( nemoi(1:5) .EQ. 'ORIGC' ) THEN
171 ifxyi = ifxy( '001035' )
172 ifxyd(1) = (-1)
173 ELSE IF ( ( nemoi(1:7) .EQ. 'TABLASS' ) .OR.
174 + ( nemoi(1:7) .EQ. 'TABLASL' ) ) THEN
175 IF ( ( nemod(1:6) .EQ. 'TABLAT' ) ) THEN
176 IF ( nemoi(1:7) .EQ. 'TABLASS' ) THEN
177 ifxyi = ifxy( '055021' )
178 ELSE
179 ifxyi = ifxy( '055022' )
180 ENDIF
181 ifxyd(1) = ifxy( '055020' )
182 ELSE
183 lnmng = min( 8, lcmg )
184 IF ( lnmng .EQ. 8 ) THEN
185 iret = 1
186 cmeang(1:8) = 'TABLAT '
187 ELSE
188 iret = -1
189 END IF
190 RETURN
191 END IF
192 ELSE IF ( nemoi(1:6) .EQ. 'TABLAT' ) THEN
193 ifxyi = ifxy( '055020' )
194 ifxyd(1) = (-1)
195 ELSE
196 CALL parstr ( nemoi, nemo, 1, ntg, ' ', .true. )
197 CALL nemtab ( lun, nemo, ifxyi, tab, n )
198 IF ( ( n .EQ. 0 ) .OR. ( tab .NE. 'B' ) ) GOTO 904
199 IF ( ( tabb( n, lun )(71:74) .NE. 'CODE' ) .AND.
200 . ( tabb( n, lun )(71:74) .NE. 'FLAG' ) ) GOTO 905
201 IF ( nemod(1:1) .NE. ' ' ) THEN
202 CALL parstr ( nemod, nemo, 1, ntg, ' ', .true. )
203 CALL nemtab ( lun, nemo, ifxyd(1), tab, n )
204 IF ( ( n .EQ. 0 ) .OR. ( tab .NE. 'B' ) ) GOTO 904
205 IF ( ( tabb( n, lun )(71:74) .NE. 'CODE' ) .AND.
206 . ( tabb( n, lun )(71:74) .NE. 'FLAG' ) ) GOTO 905
207 ELSE
208 ifxyd(1) = (-1)
209 END IF
210 END IF
211
212C* Search the internal table for the requested meaning.
213
214 CALL srchtbf ( ifxyi, ivali, ifxyd, 10, ivald,
215 . cmeang, lcmg, lnmng, iret )
216 IF ( iret .LE. 0 ) RETURN
217
218C* The meaning of this value is dependent on the value of another
219C* mnemonic in the report.
220
221 iret2 = iret
222 lnmng = 0
223 iret = 0
224 DO ii = 1, iret2
225 CALL numtbd ( lun, ifxyd(ii), nemo, tab, ierbd )
226 IF ( ( ierbd .GT. 0 ) .AND. ( tab .EQ. 'B' ) .AND.
227 . ( lcmg .GE. ( lnmng + 8 ) ) ) THEN
228 iret = iret + 1
229 cmeang(lnmng+1:lnmng+8) = nemo
230 lnmng = lnmng + 8
231 END IF
232 END DO
233 IF ( iret .EQ. 0 ) iret = -1
234
235 RETURN
236900 CALL bort('BUFRLIB: GETCFMNG - INPUT BUFR FILE IS CLOSED, IT '//
237 . 'MUST BE OPEN FOR INPUT')
238901 CALL bort('BUFRLIB: GETCFMNG - INPUT BUFR FILE IS OPEN FOR '//
239 . 'OUTPUT, IT MUST BE OPEN FOR INPUT')
240902 CALL bort('BUFRLIB: GETCFMNG - A MESSAGE MUST BE OPEN IN '//
241 . 'INPUT BUFR FILE, NONE ARE')
242903 CALL bort('BUFRLIB: GETCFMNG - TO USE THIS SUBROUTINE, MUST '//
243 . 'FIRST CALL SUBROUTINE CODFLG WITH INPUT ARGUMENT SET TO Y')
244904 WRITE(bort_str,'("BUFRLIB: GETCFMNG - MNEMONIC ",A,'//
245 . '" NOT FOUND IN TABLE B")') nemo
246 CALL bort(bort_str)
247905 WRITE(bort_str,'("BUFRLIB: GETCFMNG - MNEMONIC ",A,'//
248 . '" IS NOT A CODE OR FLAG TABLE")') nemo
249 CALL bort(bort_str)
250 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
void srchtbf(f77int *, f77int *, f77int *, f77int *, f77int *, char *, f77int *, f77int *, f77int *)
This subroutine searches for a specified FXY number and associated value (code figure or bit number) ...
Definition: srchtbf.c:74
subroutine getcfmng(LUNIT, NEMOI, IVALI, NEMOD, IVALD, CMEANG, LNMNG, IRET)
This subroutine searches for a specified Table B mnemonic and associated value (code figure or bit nu...
Definition: getcfmng.f:111
function ifxy(ADSC)
This function converts an FXY value from its 6 character representation to its bit-wise (integer) rep...
Definition: ifxy.f:43
integer function ireadmt(LUN)
This function checks the most recent BUFR message that was read via a call to one of the message-read...
Definition: ireadmt.f:43
This module contains array and variable declarations used to store DX BUFR tables internally for mult...
Definition: moda_tababd.F:10
character *128, dimension(:,:), allocatable tabb
Table B entries for each internal I/O stream.
Definition: moda_tababd.F:59
subroutine nemtab(LUN, NEMO, IDN, TAB, IRET)
This subroutine returns information about a descriptor from the internal DX BUFR tables,...
Definition: nemtab.f:45
subroutine numtbd(LUN, IDN, NEMO, TAB, IRET)
This subroutine searches for a descriptor within Table B and Table D of the internal DX BUFR tables.
Definition: numtbd.f:36
subroutine parstr(STR, TAGS, MTAG, NTAG, SEP, LIMIT80)
THIS SUBROUTINE PARSES A STRING CONTAINING ONE OR MORE SUBSTRINGS INTO AN ARRAY OF SUBSTRINGS.
Definition: parstr.f:38
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:56