NCEPLIBS-bufr  12.0.0
reads3.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read the Section 3 descriptors from a BUFR message.
3 C>
4 C> @author J. Ator @date 2009-03-23
5 
6 C> This subroutine reads the Section 3 descriptors from the
7 C> BUFR message in mbay(1,lun). It then uses the BUFR master tables
8 C> to generate the necessary information for these descriptors within
9 C> the internal BUFR table arrays.
10 C>
11 C> @param[in] LUN - integer: I/O stream index into internal memory arrays.
12 C>
13 C> @author J. Ator @date 2009-03-23
14  SUBROUTINE reads3 ( LUN )
15 
16  use bufrlib
17  USE moda_sc3bfr
18  USE moda_bitbuf
19  USE moda_dscach
20 
21  COMMON /quiet/ iprt
22 
23  dimension ids3(maxnc)
24  CHARACTER*6 CDS3(MAXNC),NUMB,ADN30
25 
26  CHARACTER*55 CSEQ
27 
28  CHARACTER*128 ERRSTR
29 
30  LOGICAL INCACH
31 
32  SAVE irepct
33 
34 C-----------------------------------------------------------------------
35 C-----------------------------------------------------------------------
36 
37 C* Check whether the appropriate BUFR master table information has
38 C* already been read into internal memory for this message.
39 
40  IF ( ireadmt( lun ) .EQ. 1 ) THEN
41 
42 C* NO (i.e. we just had to read in new master table information
43 C* for this message), so reset some corresponding values in
44 C* other parts of the library.
45 
46  CALL dxinit ( lun, 0 )
47  itmp = igettdi( 0 )
48  irepct = 0
49  ncnem = 0
50  ENDIF
51 
52 C* Unpack the list of Section 3 descriptors from the message.
53 
54  CALL upds3 ( mbay(1,lun), maxnc, cds3, ncds3 )
55  DO ii = 1, ncds3
56  ids3(ii) = ifxy( cds3(ii) )
57  ENDDO
58 
59 C* Is the list of Section 3 descriptors already in the cache?
60 
61 C* The cache is a performance-enhancing device which saves
62 C* time when the same descriptor sequences are encountered
63 C* over and over within the calling program. Time is saved
64 C* because the below calls to subroutines STSEQ and MAKESTAB
65 C* are bypassed whenever a list is already in the cache.
66 
67  incach = .false.
68  IF ( ncnem .GT. 0 ) THEN
69  ii = 1
70  DO WHILE ( (.NOT.incach) .AND. (ii.LE.ncnem) )
71  IF ( ncds3 .EQ. ndc(ii) ) THEN
72  jj = 1
73  incach = .true.
74  DO WHILE ( (incach) .AND. (jj.LE.ncds3) )
75  IF ( ids3(jj) .EQ. idcach(ii,jj) ) THEN
76  jj = jj + 1
77  ELSE
78  incach = .false.
79  ENDIF
80  ENDDO
81  IF (incach) THEN
82 
83 C* The list is already in the cache, so store the
84 C* corresponding Table A mnemonic into MODULE SC3BFR
85 C* and return.
86 
87  IF ( iprt .GE. 2 ) THEN
88  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
89  errstr = 'BUFRLIB: READS3 - RE-USED CACHE LIST FOR ' // cnem(ii)
90  CALL errwrt(errstr)
91  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
92  CALL errwrt(' ')
93  ENDIF
94  tamnem(lun) = cnem(ii)
95  RETURN
96  ENDIF
97  ENDIF
98  ii = ii + 1
99  ENDDO
100  ENDIF
101 
102 C* Get the next available index within the internal Table A.
103 
104  n = igetntbi( lun, 'A' )
105 
106 C* Generate a Table A mnemonic and sequence description.
107 
108  WRITE ( tamnem(lun), '(A5,I3.3)') 'MSTTB', n
109  cseq = 'TABLE A MNEMONIC ' // tamnem(lun)
110 
111 C* Store the Table A mnemonic and sequence into the cache.
112 
113  ncnem = ncnem + 1
114  IF ( ncnem .GT. mxcnem ) GOTO 900
115  cnem(ncnem) = tamnem(lun)
116  ndc(ncnem) = ncds3
117  DO jj = 1, ncds3
118  idcach(ncnem,jj) = ids3(jj)
119  ENDDO
120  IF ( iprt .GE. 2 ) THEN
121  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
122  errstr = 'BUFRLIB: READS3 - STORED CACHE LIST FOR ' //
123  . cnem(ncnem)
124  CALL errwrt(errstr)
125  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++++++')
126  CALL errwrt(' ')
127  ENDIF
128 
129 C* Get an FXY value to use with this Table A mnemonic.
130 
131  idn = igettdi( lun )
132  numb = adn30( idn, 6 )
133 
134 C* Store all of the information for this mnemonic within the
135 C* internal Table A.
136 
137  CALL stntbia ( n, lun, numb, tamnem(lun), cseq )
138 
139 C* Store all of the information for this sequence within the
140 C* internal Tables B and D.
141 
142  CALL stseq_c ( lun, irepct, idn, tamnem(lun), cseq, ids3,
143  . ncds3 )
144 
145 C* Update the jump/link table.
146 
147  CALL makestab
148 
149  RETURN
150 900 CALL bort('BUFRLIB: READS3 - MXCNEM OVERFLOW')
151  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine dxinit(LUN, IOI)
This subroutine initializes the internal arrays (in module moda_tababd) holding the DX BUFR table.
Definition: dxinit.f:18
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
function ifxy(ADSC)
Convert an FXY value from its 6 character representation to its WMO bit-wise representation.
Definition: ifxy.f:34
function igetntbi(LUN, CTB)
This function returns the next available index for storing an entry within a specified internal DX BU...
Definition: igetntbi.f:22
function igettdi(IFLAG)
Get the next usable Table D index for the current master table, or reset the index.
Definition: igettdi.f:28
integer function ireadmt(LUN)
Check whether master BUFR tables need to be read from the local file system.
Definition: ireadmt.f:36
subroutine makestab
This subroutine constructs the internal jump/link table within module tables, using all of the intern...
Definition: makestab.f:24
Wrap C NCEPLIBS-bufr functions so they can be called from within the Fortran part of the library.
Definition: bufrlib.F90:11
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
This module contains array and variable declarations for the internal Table A mnemonic cache that is ...
character *8, dimension(mxcnem) cnem
Table A mnemonics.
integer, dimension(mxcnem, maxnc) idcach
Bit-wise representations of the child descriptors for the corresponding Table A mnemonic in cnem.
integer ncnem
Number of entries in the internal Table A mnemonic cache (up to a maximum of MXCNEM).
integer, dimension(mxcnem) ndc
Number of child descriptors for the corresponding Table A mnemonic in cnem.
This module contains an array declaration used to store a switch for each internal I/O stream index,...
character *8, dimension(:), allocatable tamnem
Table A mnemonic most recently read from each internal I/O stream index, if isc3 = 1 for that stream.
subroutine reads3(LUN)
This subroutine reads the Section 3 descriptors from the BUFR message in mbay(1,lun).
Definition: reads3.f:15
subroutine stntbia(N, LUN, NUMB, NEMO, CELSQ)
This subroutine stores a new entry within internal BUFR Table A.
Definition: stntbia.f:15
recursive 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:26