1 SUBROUTINE READMT
( IMT
, IMTV
, IOGCE
, IMTVL
)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: ATOR ORG: NP12 DATE: 2009-03-23
8 C ABSTRACT: THIS SUBROUTINE OPENS AND READS BUFR MASTER TABLES AS
9 C SPECIFIED BY THE INPUT ARGUMENTS AND USING ADDITIONAL INFORMATION
10 C AS WAS DEFINED IN THE MOST RECENT CALL TO BUFR ARCHIVE LIBRARY
11 C SUBROUTINE MTINFO (OR AS WAS DEFINED WITHIN BUFR ARCHIVE LIBRARY
12 C SUBROUTINE BFRINI, IF SUBROUTINE MTINFO WAS NEVER CALLED).
14 C PROGRAM HISTORY LOG:
15 C 2009-03-23 J. ATOR -- ORIGINAL AUTHOR
17 C USAGE: CALL READMT ( IMT, IMTV, IOGCE, IMTVL )
18 C INPUT ARGUMENT LIST:
19 C IMT - INTEGER: MASTER TABLE NUMBER
20 C IMTV - INTEGER: MASTER TABLE VERSION NUMBER
21 C IOGCE - INTEGER: ORIGINATING CENTER
22 C IMTVL - INTEGER: LOCAL TABLE VERSION NUMBER
25 C UNITS 98,99 - IF SUBROUTINE MTINFO WAS NEVER CALLED, THEN THESE
26 C LOGICAL UNIT NUMBERS ARE USED BY THIS ROUTINE FOR
27 C OPENING AND READING THE BUFR MASTER TABLES.
28 C ALTERNATIVELY, IF SUBROUTINE MTINFO WAS CALLED,
29 C THEN THE LOGICAL UNIT NUMBERS SPECIFIED IN THE
30 C MOST RECENT CALL TO MTINFO (ARGUMENTS LUNMT1 AND
31 C LUNMT2) ARE USED INSTEAD.
33 C THIS ROUTINE CALLS: BORT2 ERRWRT ICVIDX IGETTDI
35 C THIS ROUTINE IS CALLED BY: READS3
36 C Not normally called by any application
37 C programs but it could be.
40 C LANGUAGE: FORTRAN 77
41 C MACHINE: PORTABLE TO ALL PLATFORMS
48 COMMON /MSTINF
/ LUN1
, LUN2
, LMTD
, MTDIR
49 COMMON /MSTABS
/ NMTB
, IBFXYN
(MXMTBB
), CBSCL
(MXMTBB
),
50 . CBSREF
(MXMTBB
), CBBW
(MXMTBB
),
51 . CBUNIT
(MXMTBB
), CBMNEM
(MXMTBB
),
53 . NMTD
, IDFXYN
(MXMTBD
), CDSEQ
(MXMTBD
),
54 . CDMNEM
(MXMTBD
), NDELEM
(MXMTBD
),
55 . IDEFXY
(MXMTBD*MAXCD
),
56 . CDELEM
(MXMTBD*MAXCD
)
58 DIMENSION IMFXYB
(MXMTBB
), IMFXYD
(MXMTBD
),
59 . NMELEM
(MXMTBD
), IEFXYN
(MXMTBD
,MAXCD
)
60 CHARACTER*4 CMDSCB
(MXMTBB
), CMDSCD
(MXMTBD
),
61 . CBSCL
, CMSCL
(MXMTBB
),
63 CHARACTER*8 CBMNEM
, CMMNMB
(MXMTBB
),
64 . CDMNEM
, CMMNMD
(MXMTBD
)
65 CHARACTER*12 CBSREF
, CMSREF
(MXMTBB
)
66 CHARACTER*14 CBUNIT
, CMUNIT
(MXMTBB
)
69 CHARACTER*120 CBELEM
, CMELEM
(MXMTBB
),
70 . CDSEQ
, CMSEQ
(MXMTBD
),
71 . CDELEM
, CEELEM
(MXMTBD
,MAXCD
)
72 CHARACTER*128 BORT_STR
73 CHARACTER*132 TBLFIL
,STDFIL
,LOCFIL1
,LOCFIL2
76 C-----------------------------------------------------------------------
77 C-----------------------------------------------------------------------
79 C* Reset the scratch table D index for this master table.
83 IF ( IPRT
.GE
. 2 ) THEN
85 CALL ERRWRT
('+++++++++++++++++++++++++++++++++++++++++++++++++')
86 CALL ERRWRT
('BUFRLIB: READMT - OPENING/READING MASTER TABLES')
89 C* Locate and open the master Table B files. There should be one
90 C* file of standard descriptors and one file of local descriptors.
92 C* First locate and open the file of standard Table B descriptors.
94 IF ( ( IMT
.EQ
. 0 ) .AND
. ( IMTV
.LE
. 13 ) ) THEN
96 C* For master table 0, version 13 is a superset of all earlier
99 STDFIL
= MTDIR
(1:LMTD
) // '/' // 'bufrtab.TableB_STD_0_13'
101 WRITE ( FMTF
, '(A,I1,A,I1,A)' )
102 . '(2A,I', ISIZE
(IMT
), ',A,I', ISIZE
(IMTV
), ')'
103 WRITE ( STDFIL
, FMTF
) MTDIR
(1:LMTD
), '/bufrtab.TableB_STD_',
107 IF ( IPRT
.GE
. 2 ) THEN
108 CALL ERRWRT
('Standard Table B:')
111 INQUIRE
( FILE
= TBLFIL
, EXIST
= FOUND
)
112 IF ( .NOT
. FOUND
) GOTO 900
113 OPEN
( UNIT
= LUN1
, FILE
= TBLFIL
, IOSTAT
= IER
)
114 IF ( IER
.NE
. 0 ) GOTO 901
116 C* Now locate and open the file of local Table B descriptors.
118 C* Use the local table corresponding to the originating center
119 C* and local table version number of the current message, if such
120 C* a table exists. Otherwise use the NCEP local table B.
122 LOCFIL2
= MTDIR
(1:LMTD
) // '/' // 'bufrtab.TableB_LOC_0_7_1'
123 WRITE ( FMTF
, '(A,I1,A,I1,A,I1,A)' )
124 . '(2A,I', ISIZE
(IMT
), ',A,I', ISIZE
(IOGCE
),
125 . ',A,I', ISIZE
(IMTVL
), ')'
126 WRITE ( LOCFIL1
, FMTF
) MTDIR
(1:LMTD
), '/bufrtab.TableB_LOC_',
127 . IMT
, '_', IOGCE
, '_', IMTVL
129 IF ( IPRT
.GE
. 2 ) THEN
130 CALL ERRWRT
('Local Table B:')
133 INQUIRE
( FILE
= TBLFIL
, EXIST
= FOUND
)
134 IF ( .NOT
. FOUND
) THEN
136 C* Use the NCEP local table B.
139 IF ( IPRT
.GE
. 2 ) THEN
140 CALL ERRWRT
('Local Table B not found, so using:')
143 INQUIRE
( FILE
= TBLFIL
, EXIST
= FOUND
)
144 IF ( .NOT
. FOUND
) GOTO 900
146 OPEN
( UNIT
= LUN2
, FILE
= TBLFIL
, IOSTAT
= IER
)
147 IF ( IER
.NE
. 0 ) GOTO 901
149 C* Read the master Table B files.
151 CALL RDMTBB
( LUN1
, LUN2
, MXMTBB
,
152 . IBMT
, IBMTV
, IBOGCE
, IBLTV
,
153 . NMTBB
, IMFXYB
, CMSCL
, CMSREF
, CMBW
,
154 . CMUNIT
, CMMNMB
, CMDSCB
, CMELEM
)
156 C* Save the output into COMMON /MSTABS/.
160 IBFXYN
(I
) = IMFXYB
(I
)
162 CBSREF
(I
) = CMSREF
(I
)
164 CBUNIT
(I
) = CMUNIT
(I
)
165 CBMNEM
(I
) = CMMNMB
(I
)
166 CBELEM
(I
) = CMELEM
(I
)
169 C* Close the master Table B files.
171 CLOSE
( UNIT
= LUN1
)
172 CLOSE
( UNIT
= LUN2
)
174 C* Locate and open the master Table D files. There should be one
175 C* file of standard descriptors and one file of local descriptors.
177 C* First locate and open the file of standard Table D descriptors.
180 TBLFIL
(LMTD
+15:LMTD
+15) = 'D'
181 IF ( IPRT
.GE
. 2 ) THEN
182 CALL ERRWRT
('Standard Table D:')
185 INQUIRE
( FILE
= TBLFIL
, EXIST
= FOUND
)
186 IF ( .NOT
. FOUND
) GOTO 900
187 OPEN
( UNIT
= LUN1
, FILE
= TBLFIL
, IOSTAT
= IER
)
188 IF ( IER
.NE
. 0 ) GOTO 901
190 C* Now locate and open the file of local Table D descriptors.
192 C* Use the local table corresponding to the originating center
193 C* and local table version number of the current message, if such
194 C* a table exists. Otherwise use the NCEP local table D.
197 TBLFIL
(LMTD
+15:LMTD
+15) = 'D'
198 IF ( IPRT
.GE
. 2 ) THEN
199 CALL ERRWRT
('Local Table D:')
202 INQUIRE
( FILE
= TBLFIL
, EXIST
= FOUND
)
203 IF ( .NOT
. FOUND
) THEN
205 C* Use the NCEP local table D.
208 TBLFIL
(LMTD
+15:LMTD
+15) = 'D'
209 IF ( IPRT
.GE
. 2 ) THEN
210 CALL ERRWRT
('Local Table D not found, so using:')
213 INQUIRE
( FILE
= TBLFIL
, EXIST
= FOUND
)
214 IF ( .NOT
. FOUND
) GOTO 900
216 OPEN
( UNIT
= LUN2
, FILE
= TBLFIL
, IOSTAT
= IER
)
217 IF ( IER
.NE
. 0 ) GOTO 901
219 C* Read the master Table D files.
221 CALL RDMTBD
( LUN1
, LUN2
, MXMTBD
, MAXCD
,
222 . IDMT
, IDMTV
, IDOGCE
, IDLTV
,
223 . NMTBD
, IMFXYD
, CMMNMD
, CMDSCD
, CMSEQ
,
224 . NMELEM
, IEFXYN
, CEELEM
)
226 C* Save the output into COMMON /MSTABS/.
230 IDFXYN
(I
) = IMFXYD
(I
)
231 CDMNEM
(I
) = CMMNMD
(I
)
233 NDELEM
(I
) = NMELEM
(I
)
235 IDX
= ICVIDX
( I
-1, J
-1, MAXCD
) + 1
236 IDEFXY
(IDX
) = IEFXYN
(I
,J
)
237 CDELEM
(IDX
) = CEELEM
(I
,J
)
241 C* Close the master Table D files.
243 CLOSE
( UNIT
= LUN1
)
244 CLOSE
( UNIT
= LUN2
)
246 IF ( IPRT
.GE
. 2 ) THEN
247 CALL ERRWRT
('+++++++++++++++++++++++++++++++++++++++++++++++++')
252 900 BORT_STR
= 'BUFRLIB: READMT - COULD NOT FIND FILE:'
253 CALL BORT2
(BORT_STR
,TBLFIL
)
254 901 BORT_STR
= 'BUFRLIB: READMT - COULD NOT OPEN FILE:'
255 CALL BORT2
(BORT_STR
,TBLFIL
)