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