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