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