NCEPLIBS-bufr  12.0.1
ireadmt.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Check whether master BUFR tables need to be read from the
3 C> local file system.
4 C>
5 C> @author J. Ator @date 2009-03-23
6 
7 C> Check whether master BUFR tables need to be read from the local
8 C> file system.
9 C>
10 C> This function checks the most recent BUFR message that was read
11 C> via a call to one of the
12 C> [message-reading subroutines](@ref hierarchy) and determines
13 C> whether the appropriate corresponding BUFR master tables have
14 C> already been read into internal memory.
15 C>
16 C> If not, then it opens the appropriate master BUFR tables on the
17 C> local file system and reads the contents into internal
18 C> memory, clearing any previous master BUFR table information that
19 C> may have previously been stored there.
20 C>
21 C> @param[in] LUN - integer: File ID.
22 C> @returns ireadmt - integer: Flag indicating whether new master
23 C> BUFR tables needed to be read into internal memory:
24 C> - 0 = No
25 C> - 1 = Yes
26 C>
27 C> Information about the location of master BUFR tables on the
28 C> local file system is obtained from the most recent call to
29 C> subroutine mtinfo(), or else from subroutine bfrini() if
30 C> subroutine mtinfo() was never called, and in which case Fortran
31 C> logical unit numbers 98 and 99 will be used by this function
32 C> for opening and reading master BUFR table files.
33 C>
34 C> @author J. Ator @date 2009-03-23
35  INTEGER FUNCTION ireadmt ( LUN )
36 
37  use bufrlib
38 
39  USE modv_maxnc
40  USE modv_maxcd
41  USE modv_mxmtbb
42  USE modv_mxmtbd
43 
44  USE moda_mstabs
45  USE moda_bitbuf
46  USE moda_rdmtb
47  USE moda_sc3bfr
48 
49  COMMON /quiet/ iprt
50  COMMON /mstinf/ lun1, lun2, lmtd, mtdir
51  COMMON /tablef/ cdmf
52 
53  CHARACTER*1 cdmf
54  CHARACTER*6 cds3(maxnc)
55  CHARACTER*100 mtdir
56  CHARACTER*128 bort_str
57  CHARACTER*132 stdfil,locfil
58  LOGICAL allstd
59 
60 C* Initializing the following value ensures that new master tables
61 C* are read during the first call to this subroutine.
62 
63  DATA lmt /-99/
64 
65  SAVE lmt, lmtv, logce, lmtvl
66 
67 C-----------------------------------------------------------------------
68 C-----------------------------------------------------------------------
69 
70  ireadmt = 0
71 
72 C* Unpack some Section 1 information from the message that was
73 C* most recently read.
74 
75  imt = iupbs01( mbay(1,lun), 'BMT' )
76  imtv = iupbs01( mbay(1,lun), 'MTV' )
77  iogce = iupbs01( mbay(1,lun), 'OGCE' )
78  imtvl = iupbs01( mbay(1,lun), 'MTVL' )
79 
80 C* Compare the master table and master table version numbers from
81 C* this message to those from the message that was processed during
82 C* the previous call to this subroutine.
83 
84  IF ( ( imt .NE. lmt )
85  + .OR.
86  + ( ( imt .NE. 0 ) .AND. ( imtv .NE. lmtv ) )
87  + .OR.
88  + ( ( imt .EQ. 0 ) .AND. ( imtv .NE. lmtv ) .AND.
89  + ( ( imtv .GT. 13 ) .OR. ( lmtv .GT. 13 ) ) ) )
90  + THEN
91 
92 C* Either the master table number has changed
93 C* .OR.
94 C* The master table number hasn't changed, but it isn't 0, and
95 C* the table version number has changed
96 C* .OR.
97 C* The master table number hasn't changed and is 0, but the table
98 C* version number has changed, and at least one of the table
99 C* version numbers (i.e. the current or the previous) is greater
100 C* than 13 (which is the last version that was a superset of all
101 C* earlier versions of master table 0!)
102 
103 C* In any of these cases, we need to read in new tables!
104 
105  ireadmt = 1
106  ELSE
107 
108 C* Unpack the list of Section 3 descriptors from the message and
109 C* determine if any of them are local descriptors.
110 
111  CALL upds3 ( mbay(1,lun), maxnc, cds3, ncds3 )
112  ii = 1
113  allstd = .true.
114  DO WHILE ( (allstd) .AND. (ii.LE.ncds3) )
115  IF ( istdesc(ifxy(cds3(ii))) .EQ. 0 ) THEN
116  allstd = .false.
117  ELSE
118  ii = ii + 1
119  ENDIF
120  ENDDO
121 
122 C* If there was at least one local (i.e. non-standard) descriptor,
123 C* and if either the originating center or local table version
124 C* number are different than those from the message that was
125 C* processed during the previous call to this subroutine, then
126 C* we need to read in new tables.
127 
128  IF ( ( .NOT. allstd ) .AND.
129  + ( ( iogce .NE. logce ) .OR. ( imtvl .NE. lmtvl ) ) )
130  + ireadmt = 1
131 
132  ENDIF
133 
134  IF ( ireadmt .EQ. 0 ) RETURN
135 
136  lmt = imt
137  lmtv = imtv
138  logce = iogce
139  lmtvl = imtvl
140 
141  IF ( iprt .GE. 2 ) THEN
142  CALL errwrt(' ')
143  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
144  CALL errwrt('BUFRLIB: IREADMT - OPENING/READING MASTER TABLES')
145  ENDIF
146 
147  IF ( isc3(lun) .NE. 0 ) THEN
148 
149 C* Locate and open the master Table B files. There should be one
150 C* file of standard descriptors and one file of local descriptors.
151 
152  CALL mtfnam ( imt, imtv, iogce, imtvl, 'TableB',
153  + stdfil, locfil )
154  OPEN ( unit = lun1, file = stdfil, iostat = ier )
155  IF ( ier .NE. 0 ) GOTO 900
156  OPEN ( unit = lun2, file = locfil, iostat = ier )
157  IF ( ier .NE. 0 ) GOTO 901
158 
159 C* Read the master Table B files.
160 
161  CALL rdmtbb ( lun1, lun2, mxmtbb,
162  + ibmt, ibmtv, ibogce, ibltv,
163  + nmtb, ibfxyn, cbscl, cbsref, cbbw,
164  + cbunit, cbmnem, cmdscb, cbelem )
165 
166 C* Close the master Table B files.
167 
168  CLOSE ( unit = lun1 )
169  CLOSE ( unit = lun2 )
170 
171 C* Locate and open the master Table D files. There should be one
172 C* file of standard descriptors and one file of local descriptors.
173 
174  CALL mtfnam ( imt, imtv, iogce, imtvl, 'TableD',
175  + stdfil, locfil )
176  OPEN ( unit = lun1, file = stdfil, iostat = ier )
177  IF ( ier .NE. 0 ) GOTO 900
178  OPEN ( unit = lun2, file = locfil, iostat = ier )
179  IF ( ier .NE. 0 ) GOTO 901
180 
181 C* Read the master Table D files.
182 
183  CALL rdmtbd ( lun1, lun2, mxmtbd, maxcd,
184  + idmt, idmtv, idogce, idltv,
185  + nmtd, idfxyn, cdmnem, cmdscd, cdseq,
186  + ndelem, iefxyn, ceelem )
187  DO i = 1, nmtd
188  DO j = 1, ndelem(i)
189  idx = icvidx_c( i-1, j-1, maxcd ) + 1
190  idefxy(idx) = iefxyn(i,j)
191  ENDDO
192  ENDDO
193 
194 C* Close the master Table D files.
195 
196  CLOSE ( unit = lun1 )
197  CLOSE ( unit = lun2 )
198 
199 C* Copy master table B and D information into internal C arrays.
200 
203  + ndelem, idefxy, maxcd )
204  ENDIF
205 
206  IF ( cdmf .EQ. 'Y' ) THEN
207 
208 C* Locate and open the master code and flag table files. There
209 C* should be one file corresponding to the standard Table B
210 C* descriptors, and one file corresponding to the local Table B
211 C* descriptors.
212 
213  CALL mtfnam ( imt, imtv, iogce, imtvl, 'CodeFlag',
214  + stdfil, locfil )
215  OPEN ( unit = lun1, file = stdfil, iostat = ier )
216  IF ( ier .NE. 0 ) GOTO 900
217  OPEN ( unit = lun2, file = locfil, iostat = ier )
218  IF ( ier .NE. 0 ) GOTO 901
219 
220 C* Read the master code and flag table files.
221 
222  CALL rdmtbf ( lun1, lun2 )
223 
224 C* Close the master code and flag table files.
225 
226  CLOSE ( unit = lun1 )
227  CLOSE ( unit = lun2 )
228 
229  ENDIF
230 
231  IF ( iprt .GE. 2 ) THEN
232  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
233  CALL errwrt(' ')
234  ENDIF
235 
236  RETURN
237 900 bort_str = 'BUFRLIB: IREADMT - COULD NOT OPEN STANDARD FILE:'
238  CALL bort2(bort_str,stdfil)
239 901 bort_str = 'BUFRLIB: IREADMT - COULD NOT OPEN LOCAL FILE:'
240  CALL bort2(bort_str,locfil)
241  END
subroutine bort2(STR1, STR2)
Log two error messages and abort application program.
Definition: bort2.f:18
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
function ifxy(ADSC)
Convert an FXY value from its 6 character representation to its WMO bit-wise representation.
Definition: ifxy.f:34
integer function ireadmt(LUN)
Check whether master BUFR tables need to be read from the local file system.
Definition: ireadmt.f:36
function istdesc(IDN)
Check whether a descriptor is WMO-standard.
Definition: istdesc.f:23
recursive function iupbs01(MBAY, S01MNEM)
Read a data value from Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:69
subroutine mtfnam(IMT, IMTV, IOGCE, IMTVL, TBLTYP, STDFIL, LOCFIL)
Based on the input arguments, this subroutine determines the names of the corresponding standard and ...
Definition: mtfnam.f:28
Wrap C NCEPLIBS-bufr functions so they can be called from within the Fortran part of the library.
Definition: bufrlib.F90:11
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
This module contains array and variable declarations used to store master Table B and Table D entries...
integer, dimension(:), allocatable idfxyn
Bit-wise representations of FXY numbers for master Table D.
character, dimension(:,:), allocatable cbunit
Units corresponding to ibfxyn.
integer nmtb
Number of master Table B entries (up to a maximum of MXMTBB).
character, dimension(:,:), allocatable cbbw
Bit widths corresponding to ibfxyn.
character, dimension(:,:), allocatable cdseq
Sequence names corresponding to idfxyn.
character, dimension(:,:), allocatable cbmnem
Mnemonics corresponding to ibfxyn.
integer, dimension(:), allocatable ndelem
Numbers of child descriptors corresponding to idfxyn.
character, dimension(:,:), allocatable cbelem
Element names corresponding to ibfxyn.
character, dimension(:,:), allocatable cbscl
Scale factors corresponding to ibfxyn.
character, dimension(:,:), allocatable cdmnem
Mnemonics corresponding to idfxyn.
character, dimension(:,:), allocatable cbsref
Reference values corresponding to ibfxyn.
integer nmtd
Number of master Table D entries (up to a maximum of MXMTBD).
integer, dimension(:), allocatable idefxy
Bit-wise representations of child descriptors corresponding to idfxyn.
integer, dimension(:), allocatable ibfxyn
Bit-wise representations of FXY numbers for master Table B.
This module contains array and variable declarations used to store master Table B and Table D entries...
character *120, dimension(:,:), allocatable ceelem
Element names corresponding to iefxyn.
character *4, dimension(:), allocatable cmdscb
Descriptor codes for Table B elements.
integer, dimension(:,:), allocatable iefxyn
Bit-wise representations of child descriptors of Table D sequences.
character *4, dimension(:), allocatable cmdscd
Descriptor codes for Table D sequences.
This module contains an array declaration used to store a switch for each internal I/O stream index,...
integer, dimension(:), allocatable isc3
Section 3 switch for each internal I/O stream index:
This module declares and initializes the MAXCD variable.
integer, public maxcd
Maximum number of child descriptors that can be included within the sequence definition of a Table D ...
This module declares and initializes the MAXNC variable.
integer, parameter, public maxnc
Maximum number of descriptors within Section 3 of a BUFR message.
This module declares and initializes the MXMTBB variable.
integer mxmtbb
Maximum number of entries in a master BUFR Table B.
This module declares and initializes the MXMTBD variable.
integer mxmtbd
Maximum number of entries in a master BUFR Table D.
subroutine rdmtbb(LUNSTB, LUNLTB, MXMTBB, IMT, IMTV, IOGCE, ILTV, NMTBB, IMFXYN, CMSCL, CMSREF, CMBW, CMUNIT, CMMNEM, CMDSC, CMELEM)
This subroutine reads master Table B information from two separate ASCII files (one standard and one ...
Definition: rdmtbb.f:58
subroutine rdmtbd(LUNSTD, LUNLTD, MXMTBD, MXELEM, IMT, IMTV, IOGCE, ILTV, NMTBD, IMFXYN, CMMNEM, CMDSC, CMSEQ, NMELEM, IEFXYN, CEELEM)
This subroutine reads master Table D information from two separate ASCII files (one standard and one ...
Definition: rdmtbd.f:61
subroutine rdmtbf(LUNSTF, LUNLTF)
This subroutine reads master Code/Flag table information from two separate ASCII files (one standard ...
Definition: rdmtbf.f:22
recursive subroutine upds3(MBAY, LCDS3, CDS3, NDS3)
This subroutine returns the sequence of data descriptors contained within Section 3 of a BUFR message...
Definition: upds3.f:26