NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
ireadmt.F
Go to the documentation of this file.
1 C> @file
2 C> @author ATOR @date 2009-03-23
3 
4 C> THIS FUNCTION CHECKS THE MOST RECENT BUFR MESSAGE THAT
5 C> WAS READ AS INPUT VIA SUBROUTINE READMG, READERME OR EQUIVALENT
6 C> TO DETERMINE IF THE APPROPRIATE CORRESPONDING BUFR MASTER TABLES
7 C> HAVE ALREADY BEEN READ INTO INTERNAL MEMORY. IF NOT, THEN IT
8 C> OPENS THE APPROPRIATE BUFR MASTER TABLE FILES AND READS THEM INTO
9 C> INTERNAL MEMORY, CLEARING ANY PREVIOUS MASTER TABLE INFORMATION
10 C> ALREADY STORED THERE. INFORMATION ABOUT THE BUFR MASTER TABLE
11 C> FILES IS OBTAINED FROM THE MOST RECENT CALL TO SUBROUTINE MTINFO,
12 C> OR ELSE AS DEFINED WITHIN SUBROUTINE BFRINI IF SUBROUTINE MTINFO
13 C> WAS NEVER CALLED.
14 C>
15 C> PROGRAM HISTORY LOG:
16 C> 2009-03-23 J. ATOR -- ORIGINAL AUTHOR
17 C> 2014-11-25 J. ATOR -- ADD CALL TO CPMSTABS FOR ACCESS TO MASTER
18 C> TABLE INFORMATION WITHIN C WHEN USING
19 C> DYNAMICALLY ALLOCATED ARRAYS
20 C> 2017-10-13 J. ATOR -- ADD FUNCTIONALITY TO CHECK WHETHER NEW
21 C> MASTER TABLES NEED TO BE READ (THIS
22 C> FUNCTIONALITY WAS PREVIOUSLY PART OF
23 C> SUBROUTINE READS3)
24 C> 2018-04-09 J. ATOR -- ONLY READ MASTER B AND D TABLES WHEN
25 C> SECTION 3 IS BEING USED FOR DECODING
26 C>
27 C> USAGE: IREADMT ( LUN )
28 C> INPUT ARGUMENT LIST:
29 C> LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
30 C>
31 C> OUTPUT ARGUMENT LIST:
32 C> IREADMT - INTEGER: RETURN CODE INDICATING WHETHER NEW BUFR
33 C> MASTER TABLE FILES NEEDED TO BE OPENED AND READ
34 C> DURING THIS CALL TO THE FUNCTION
35 C> 0 = NO
36 C> 1 = YES
37 C>
38 C> INPUT FILES:
39 C> UNITS 98,99 - IF SUBROUTINE MTINFO WAS NEVER CALLED, THEN THESE
40 C> LOGICAL UNIT NUMBERS ARE USED BY THIS ROUTINE FOR
41 C> OPENING AND READING THE BUFR MASTER TABLES.
42 C> ALTERNATIVELY, IF SUBROUTINE MTINFO WAS CALLED,
43 C> THEN THE LOGICAL UNIT NUMBERS SPECIFIED IN THE
44 C> MOST RECENT CALL TO MTINFO (ARGUMENTS LUNMT1 AND
45 C> LUNMT2) ARE USED INSTEAD.
46 C> REMARKS:
47 C> THIS ROUTINE CALLS: BORT2 CPMSTABS ERRWRT ICVIDX
48 C> IFXY ISTDESC IUPBS01 MTFNAM
49 C> RDMTBB RDMTBD RDMTBF UPDS3
50 C> THIS ROUTINE IS CALLED BY: GETCFMNG READS3 UFDUMP
51 C> Normally not called by any application
52 C> programs.
53 C>
54  INTEGER FUNCTION ireadmt ( LUN )
55 
56  USE modv_maxnc
57 
58  USE moda_mstabs
59  USE moda_bitbuf
60  USE moda_rdmtb
61  USE moda_sc3bfr
62 
63  COMMON /quiet/ iprt
64  COMMON /mstinf/ lun1, lun2, lmtd, mtdir
65  COMMON /tablef/ cdmf
66 
67  character*1 cdmf
68  character*6 cds3(maxnc)
69  character*100 mtdir
70  character*128 bort_str
71  character*132 stdfil,locfil
72  logical allstd
73 
74 C* Initializing the following value ensures that new master tables
75 C* are read during the first call to this subroutine.
76 
77  DATA lmt /-99/
78 
79  SAVE lmt, lmtv, logce, lmtvl
80 
81 C-----------------------------------------------------------------------
82 C-----------------------------------------------------------------------
83 
84  ireadmt = 0
85 
86 C* Unpack some Section 1 information from the message that was
87 C* most recently read.
88 
89  imt = iupbs01( mbay(1,lun), 'BMT' )
90  imtv = iupbs01( mbay(1,lun), 'MTV' )
91  iogce = iupbs01( mbay(1,lun), 'OGCE' )
92  imtvl = iupbs01( mbay(1,lun), 'MTVL' )
93 
94 C* Compare the master table and master table version numbers from
95 C* this message to those from the message that was processed during
96 C* the previous call to this subroutine.
97 
98  IF ( ( imt .NE. lmt )
99  . .OR.
100  . ( ( imt .NE. 0 ) .AND. ( imtv .NE. lmtv ) )
101  . .OR.
102  . ( ( imt .EQ. 0 ) .AND. ( imtv .NE. lmtv ) .AND.
103  . ( ( imtv .GT. 13 ) .OR. ( lmtv .GT. 13 ) ) ) )
104  . THEN
105 
106 C* Either the master table number has changed
107 C* .OR.
108 C* The master table number hasn't changed, but it isn't 0, and
109 C* the table version number has changed
110 C* .OR.
111 C* The master table number hasn't changed and is 0, but the table
112 C* version number has changed, and at least one of the table
113 C* version numbers (i.e. the current or the previous) is greater
114 C* than 13 (which is the last version that was a superset of all
115 C* earlier versions of master table 0!)
116 
117 C* In any of these cases, we need to read in new tables!
118 
119  ireadmt = 1
120  ELSE
121 
122 C* Unpack the list of Section 3 descriptors from the message and
123 C* determine if any of them are local descriptors.
124 
125  CALL upds3( mbay(1,lun), maxnc, cds3, ncds3 )
126  ii = 1
127  allstd = .true.
128  DO WHILE ( (allstd) .AND. (ii.LE.ncds3) )
129  IF ( istdesc(ifxy(cds3(ii))) .EQ. 0 ) THEN
130  allstd = .false.
131  ELSE
132  ii = ii + 1
133  ENDIF
134  ENDDO
135 
136 C* If there was at least one local (i.e. non-standard) descriptor,
137 C* and if either the originating center or local table version
138 C* number are different than those from the message that was
139 C* processed during the previous call to this subroutine, then
140 C* we need to read in new tables.
141 
142  IF ( ( .NOT. allstd ) .AND.
143  + ( ( iogce .NE. logce ) .OR. ( imtvl .NE. lmtvl ) ) )
144  + ireadmt = 1
145 
146  ENDIF
147 
148  IF ( ireadmt .EQ. 0 ) RETURN
149 
150  lmt = imt
151  lmtv = imtv
152  logce = iogce
153  lmtvl = imtvl
154 
155  IF ( iprt .GE. 2 ) THEN
156  CALL errwrt(' ')
157  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
158  CALL errwrt('BUFRLIB: IREADMT - OPENING/READING MASTER TABLES')
159  ENDIF
160 
161  IF ( isc3(lun) .NE. 0 ) THEN
162 
163 C* Locate and open the master Table B files. There should be one
164 C* file of standard descriptors and one file of local descriptors.
165 
166  CALL mtfnam( imt, imtv, iogce, imtvl, 'TableB',
167  . stdfil, locfil )
168  OPEN ( unit = lun1, file = stdfil, iostat = ier )
169  IF ( ier .NE. 0 ) goto 900
170  OPEN ( unit = lun2, file = locfil, iostat = ier )
171  IF ( ier .NE. 0 ) goto 901
172 
173 C* Read the master Table B files.
174 
175  CALL rdmtbb( lun1, lun2, mxmtbb,
176  . ibmt, ibmtv, ibogce, ibltv,
177  . nmtb, ibfxyn, cbscl, cbsref, cbbw,
178  . cbunit, cbmnem, cmdscb, cbelem )
179 
180 C* Close the master Table B files.
181 
182  CLOSE ( unit = lun1 )
183  CLOSE ( unit = lun2 )
184 
185 C* Locate and open the master Table D files. There should be one
186 C* file of standard descriptors and one file of local descriptors.
187 
188  CALL mtfnam( imt, imtv, iogce, imtvl, 'TableD',
189  . stdfil, locfil )
190  OPEN ( unit = lun1, file = stdfil, iostat = ier )
191  IF ( ier .NE. 0 ) goto 900
192  OPEN ( unit = lun2, file = locfil, iostat = ier )
193  IF ( ier .NE. 0 ) goto 901
194 
195 C* Read the master Table D files.
196 
197  CALL rdmtbd( lun1, lun2, mxmtbd, maxcd,
198  . idmt, idmtv, idogce, idltv,
199  . nmtd, idfxyn, cdmnem, cmdscd, cdseq,
200  . ndelem, iefxyn, ceelem )
201  DO i = 1, nmtd
202  DO j = 1, ndelem(i)
203  idx = icvidx( i-1, j-1, maxcd ) + 1
204  idefxy(idx) = iefxyn(i,j)
205  ENDDO
206  ENDDO
207 
208 C* Close the master Table D files.
209 
210  CLOSE ( unit = lun1 )
211  CLOSE ( unit = lun2 )
212 
213 #ifdef DYNAMIC_ALLOCATION
214 C* Copy master table B and D information into internal C arrays.
215 
216  CALL cpmstabs( nmtb, ibfxyn, cbscl, cbsref, cbbw, cbunit,
217  . cbmnem, cbelem, nmtd, idfxyn, cdseq, cdmnem,
218  . ndelem, idefxy, maxcd )
219 #endif
220  ENDIF
221 
222  IF ( cdmf .EQ. 'Y' ) THEN
223 
224 C* Locate and open the master code and flag table files. There
225 C* should be one file corresponding to the standard Table B
226 C* descriptors, and one file corresponding to the local Table B
227 C* descriptors.
228 
229  CALL mtfnam( imt, imtv, iogce, imtvl, 'CodeFlag',
230  . stdfil, locfil )
231  OPEN ( unit = lun1, file = stdfil, iostat = ier )
232  IF ( ier .NE. 0 ) goto 900
233  OPEN ( unit = lun2, file = locfil, iostat = ier )
234  IF ( ier .NE. 0 ) goto 901
235 
236 C* Read the master code and flag table files.
237 
238  CALL rdmtbf( lun1, lun2 )
239 
240 C* Close the master code and flag table files.
241 
242  CLOSE ( unit = lun1 )
243  CLOSE ( unit = lun2 )
244 
245  ENDIF
246 
247  IF ( iprt .GE. 2 ) THEN
248  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
249  CALL errwrt(' ')
250  ENDIF
251 
252  RETURN
253 900 bort_str = 'BUFRLIB: IREADMT - COULD NOT OPEN STANDARD FILE:'
254  CALL bort2(bort_str,stdfil)
255 901 bort_str = 'BUFRLIB: IREADMT - COULD NOT OPEN LOCAL FILE:'
256  CALL bort2(bort_str,locfil)
257  END
void cpmstabs(f77int *pnmtb, f77int *pibfxyn, char(*pcbscl)[4], char(*pcbsref)[12], char(*pcbbw)[4], char(*pcbunit)[14], 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:44
subroutine bort2(STR1, STR2)
This subroutine calls subroutine errwrt() to log two error messages, then calls subroutine bort_exit(...
Definition: bort2.f:20
function istdesc(IDN)
GIVEN THE BIT-WISE REPRESENTATION OF THE FXY VALUE FOR A DESCRIPTOR, THIS FUNCTION DETERMINES WHETHER...
Definition: istdesc.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:33
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 (I.E.
Definition: rdmtbf.f:28
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 (I.E.
Definition: rdmtbb.f:56
This module declares and initializes the MAXNC variable.
Definition: modv_MAXNC.f90:9
function ifxy(ADSC)
THIS FUNCTION RETURNS THE INTEGER CORRESPONDING TO THE BIT-WISE REPRESENTATION OF AN INPUT CHARACTER ...
Definition: ifxy.f:49
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:39
INTEGER function ireadmt(LUN)
THIS FUNCTION CHECKS THE MOST RECENT BUFR MESSAGE THAT WAS READ AS INPUT VIA SUBROUTINE READMG...
Definition: ireadmt.F:54
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 (I.E.
Definition: rdmtbd.f:65
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
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:72