1 SUBROUTINE READS3
( LUN
)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: ATOR ORG: NP12 DATE: 2009-03-23
8 C ABSTRACT: THIS SUBROUTINE READS THE SECTION 3 DESCRIPTORS FROM THE
9 C BUFR MESSAGE IN MBAY(1,LUN). IT THEN USES THE BUFR MASTER TABLES
10 C TO GENERATE THE NECESSARY INFORMATION FOR THESE DESCRIPTORS WITHIN
11 C THE INTERNAL BUFR TABLE ARRAYS.
13 C PROGRAM HISTORY LOG:
14 C 2009-03-23 J. ATOR -- ORIGINAL AUTHOR
16 C USAGE: CALL READS3 (LUN)
17 C INPUT ARGUMENT LIST:
18 C LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
21 C THIS ROUTINE CALLS: ADN30 BORT DXINIT ERRWRT
22 C IGETNTBI IGETTDI ISTDESC IUPBS01
23 C MAKESTAB READMT STNTBIA STSEQ
25 C THIS ROUTINE IS CALLED BY: READERME READMG
26 C Normally not called by any application
30 C LANGUAGE: FORTRAN 77
31 C MACHINE: PORTABLE TO ALL PLATFORMS
38 COMMON /SC3BFR
/ ISC3
(NFILES
),TAMNEM
(NFILES
),IRDMT
39 COMMON /BITBUF
/ MAXBYT
,IBIT
,IBAY
(MXMSGLD4
),MBYT
(NFILES
),
40 . MBAY
(MXMSGLD4
,NFILES
)
41 COMMON /DSCACH
/ NCNEM
,CNEM
(MXCNEM
),NDC
(MXCNEM
),
42 . IDCACH
(MXCNEM
,MAXNC
)
45 CHARACTER*6 CDS3
(MAXNC
),NUMB
,ADN30
47 CHARACTER*8 CNEM
,TAMNEM
52 LOGICAL INCACH
, ALLSTD
54 C* Initializing the following value ensures that new master tables
55 C* are read during the first call to this subroutine.
59 SAVE LMT
, LMTV
, LOGCE
, LMTVL
, IREPCT
61 C-----------------------------------------------------------------------
62 C-----------------------------------------------------------------------
64 C* Unpack some Section 1 information from the message.
66 IMT
= IUPBS01
( MBAY
(1,LUN
), 'BMT' )
67 IMTV
= IUPBS01
( MBAY
(1,LUN
), 'MTV' )
68 IOGCE
= IUPBS01
( MBAY
(1,LUN
), 'OGCE' )
69 IMTVL
= IUPBS01
( MBAY
(1,LUN
), 'MTVL' )
71 C* Unpack the list of Section 3 descriptors from the message.
73 CALL UPDS3
( MBAY
(1,LUN
), MAXNC
, CDS3
, NCDS3
)
75 IDS3
(II
) = IFXY
( CDS3
(II
) )
78 C* Compare the master table and master table version numbers from
79 C* this message to those from the message that was processed during
80 C* the previous call to this subroutine.
84 . ( ( IMT
.NE
. 0 ) .AND
. ( IMTV
.NE
. LMTV
) )
86 . ( ( IMT
.EQ
. 0 ) .AND
. ( IMTV
.NE
. LMTV
) .AND
.
87 . ( ( IMTV
.GT
. 13 ) .OR
. ( LMTV
.GT
. 13 ) ) ) )
90 C* Either the master table number has changed
92 C* The master table number hasn't changed, but it isn't 0, and
93 C* the table version number has changed
95 C* The master table number hasn't changed and is 0, but the table
96 C* version number has changed, and at least one of the table
97 C* version numbers (i.e. the current or the previous) is greater
98 C* than 13 (which is the last version that was a superset of all
99 C* earlier versions of master table 0!)
101 C* In any of these cases, we need to read in new tables and reset
102 C* the internal tables and local descriptor cache, since the
103 C* meanings of one or more Section 3 descriptors may have changed.
105 CALL READMT
( IMT
, IMTV
, IOGCE
, IMTVL
)
110 CALL DXINIT
( LUN
, 0 )
115 C* Check whether all of the Section 3 descriptors are standard.
116 C* If so, then the originating center and local table version
117 C* numbers are irrelevant as far as Section 3 is concerned.
121 DO WHILE ( (ALLSTD
) .AND
. (II
.LE
.NCDS3
) )
122 IF ( ISTDESC
(IDS3
(II
)) .EQ
. 0 ) THEN
128 IF ( .NOT
. ALLSTD
) THEN
130 C* There was at least one local (i.e. non-standard) descriptor,
131 C* so check whether the originating center and/or local table
132 C* version number are different than those from the message
133 C* that was processed during the previous call to this
134 C* subroutine. If so, then read in new tables and reset the
135 C* internal tables and local descriptor cache, since the
136 C* meanings of one or more local descriptors in Section 3 may
139 IF ( ( IOGCE
.NE
. LOGCE
) .OR
. ( IMTVL
.NE
. LMTVL
) ) THEN
140 CALL READMT
( IMT
, IMTV
, IOGCE
, IMTVL
)
145 CALL DXINIT
( LUN
, 0 )
152 C* Is the list of Section 3 descriptors already in the cache?
154 C* The cache is a performance-enhancing device which saves
155 C* time when the same descriptor sequences are encountered
156 C* over and over within the calling program. Time is saved
157 C* because the below calls to subroutines STSEQ and MAKESTAB
158 C* are bypassed whenever a list is already in the cache.
161 IF ( NCNEM
.GT
. 0 ) THEN
163 DO WHILE ( (.NOT
.INCACH
) .AND
. (II
.LE
.NCNEM
) )
164 IF ( NCDS3
.EQ
. NDC
(II
) ) THEN
167 DO WHILE ( (INCACH
) .AND
. (JJ
.LE
.NCDS3
) )
168 IF ( IDS3
(JJ
) .EQ
. IDCACH
(II
,JJ
) ) THEN
176 C* The list is already in the cache, so store the
177 C* corresponding Table A mnemonic into COMMON /SC3BFR/
180 IF ( IPRT
.GE
. 2 ) THEN
181 CALL ERRWRT
('+++++++++++++++++++++++++++++++++++++++++++++++++')
182 ERRSTR
= 'BUFRLIB: READS3 - RE-USED CACHE LIST FOR ' // CNEM
(II
)
184 CALL ERRWRT
('+++++++++++++++++++++++++++++++++++++++++++++++++')
187 TAMNEM
(LUN
) = CNEM
(II
)
195 C* Get the next available index within the internal Table A.
197 N
= IGETNTBI
( LUN
, 'A' )
199 C* Generate a Table A mnemonic and sequence description.
201 WRITE ( TAMNEM
(LUN
), '(A5,I3.3)') 'MSTTB', N
202 CSEQ
= 'TABLE A MNEMONIC ' // TAMNEM
(LUN
)
204 C* Store the Table A mnemonic and sequence into the cache.
207 IF ( NCNEM
.GT
. MXCNEM
) GOTO 900
208 CNEM
(NCNEM
) = TAMNEM
(LUN
)
211 IDCACH
(NCNEM
,JJ
) = IDS3
(JJ
)
213 IF ( IPRT
.GE
. 2 ) THEN
214 CALL ERRWRT
('+++++++++++++++++++++++++++++++++++++++++++++++++')
215 ERRSTR
= 'BUFRLIB: READS3 - STORED CACHE LIST FOR ' //
218 CALL ERRWRT
('+++++++++++++++++++++++++++++++++++++++++++++++++')
222 C* Get an FXY value to use with this Table A mnemonic.
224 IDN
= IGETTDI
( LUN
)
225 NUMB
= ADN30
( IDN
, 6 )
227 C* Store all of the information for this mnemonic within the
230 CALL STNTBIA
( N
, LUN
, NUMB
, TAMNEM
(LUN
), CSEQ
)
232 C* Store all of the information for this sequence within the
233 C* internal Tables B and D.
235 CALL STSEQ
( LUN
, IREPCT
, IDN
, TAMNEM
(LUN
), CSEQ
, IDS3
, NCDS3
)
237 C* Update the jump/link table.
242 900 CALL BORT
('BUFRLIB: READS3 - MXCNEM OVERFLOW')