NCEPLIBS-bufr  12.0.1
cktaba.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Parse the Table A mnemonic and date out of Section 1 of a
3 C> BUFR message.
4 C>
5 C> @author Woollen @date 2000-09-19
6 
7 C> This subroutine parses the Table A mnemonic and date
8 C> out of Section 1 of a BUFR message that was previously read from lun
9 C> using one of the [message-reading subroutines](@ref hierarchy).
10 C>
11 C> @param[in] LUN - integer: I/O stream index into internal memory arrays.
12 C> @param[out] SUBSET - character*8: Table A mnemonic
13 C> - returned as a string of all blank characters
14 C> if IRET is equal to 11 (see below) and if Section 3
15 C> isn't being used for decoding
16 C> @param[out] JDATE - integer: date-time stored within Section 1 of BUFR
17 C> in format of either YYMMDDHH or
18 C> YYYYMMDDHH, depending on datelen() value.
19 C> @param[out] IRET - integer: return code:
20 C> - 0 normal return
21 C> - -1 unrecognized Table A (message type) value
22 C> - 11 this is a BUFR table (dictionary) message
23 C>
24 C> @author Woollen @date 2000-09-19
25 
26  SUBROUTINE cktaba(LUN,SUBSET,JDATE,IRET)
27 
28  USE moda_msgcwd
29  USE moda_sc3bfr
30  USE moda_unptyp
31  USE moda_bitbuf
32 
33  COMMON /padesc/ ibct,ipd1,ipd2,ipd3,ipd4
34  COMMON /quiet / iprt
35 
36  CHARACTER*128 BORT_STR,ERRSTR
37  CHARACTER*8 SUBSET
38  CHARACTER*2 CPFX(3)
39  CHARACTER*1 TAB
40  LOGICAL TRYBT, DIGIT
41 
42  DATA cpfx / 'NC', 'FR', 'FN' /
43  DATA ncpfx / 3 /
44 
45 C-----------------------------------------------------------------------
46 C-----------------------------------------------------------------------
47 
48  iret = 0
49 
50  trybt = .true.
51 
52  jdate = igetdate(mbay(1,lun),iyr,imo,idy,ihr)
53 
54 c .... Message type
55  mtyp = iupbs01(mbay(1,lun),'MTYP')
56 c .... Message subtype
57  msbt = iupbs01(mbay(1,lun),'MSBT')
58 
59  IF(mtyp.EQ.11) THEN
60 c .... This is a BUFR table (dictionary) message.
61  iret = 11
62 c .... There's no need to proceed any further unless Section 3 is being
63 c .... used for decoding.
64  IF(isc3(lun).EQ.0) THEN
65  subset = " "
66  GOTO 100
67  ENDIF
68  ENDIF
69 
70 C PARSE SECTION 3
71 C ---------------
72 
73  CALL getlens(mbay(1,lun),3,len0,len1,len2,len3,l4,l5)
74 
75  iad3 = len0+len1+len2
76 
77 c .... First descriptor (integer)
78  ksub = iupb(mbay(1,lun),iad3+8 ,16)
79 c .... Second descriptor (integer)
80  isub = iupb(mbay(1,lun),iad3+10,16)
81 
82 C LOCATE SECTION 4
83 C ----------------
84 
85  iad4 = iad3+len3
86 
87 C NOW, TRY TO GET "SUBSET" (MNEMONIC ASSOCIATED WITH TABLE A) FROM MSG
88 C --------------------------------------------------------------------
89 
90 C FIRST CHECK WHETHER SECTION 3 IS BEING USED FOR DECODING
91 C --------------------------------------------------------
92 
93  IF(isc3(lun).NE.0) THEN
94  subset = tamnem(lun)
95 c .... is SUBSET from Table A?
96  CALL nemtbax(lun,subset,mty1,msb1,inod)
97  IF(inod.GT.0) THEN
98 c .... yes it is
99  mbyt(lun) = 8*(iad4+4)
100  msgunp(lun) = 1
101  GOTO 10
102  ENDIF
103  ENDIF
104 
105 C IF ISUB FROM SECTION 3 DEFINES TABLE A THEN MSGUNP=0
106 C ----------------------------------------------------
107 
108 c .... get SUBSET from ISUB
109 5 CALL numtab(lun,isub,subset,tab,itab)
110 c .... is SUBSET from Table A?
111  CALL nemtbax(lun,subset,mty1,msb1,inod)
112  IF(inod.GT.0) THEN
113 c .... yes it is
114  mbyt(lun) = (iad4+4)
115  msgunp(lun) = 0
116  GOTO 10
117  ENDIF
118 
119 C IF KSUB FROM SECTION 3 DEFINES TABLE A THEN MSGUNP=1 (standard)
120 C ---------------------------------------------------------------
121 
122 c .... get SUBSET from KSUB
123  CALL numtab(lun,ksub,subset,tab,itab)
124 c .... is SUBSET from Table A?
125  CALL nemtbax(lun,subset,mty1,msb1,inod)
126  IF(inod.GT.0) THEN
127 c .... yes it is
128  mbyt(lun) = 8*(iad4+4)
129  msgunp(lun) = 1
130  GOTO 10
131  ENDIF
132 
133 C OKAY, STILL NO "SUBSET", LETS MAKE IT "NCtttsss" (where ttt=MTYP
134 C and sss=MSBT) AND SEE IF IT DEFINES TABLE A. IF NOT, THEN ALSO
135 C TRY "FRtttsss" AND "FNtttsss".
136 C ----------------------------------------------------------------
137 
138  ii=1
139  DO WHILE(ii.LE.ncpfx)
140  WRITE(subset,'(A2,2I3.3)') cpfx(ii),mtyp,msbt
141 c .... is SUBSET from Table A?
142  CALL nemtbax(lun,subset,mty1,msb1,inod)
143  IF(inod.GT.0) THEN
144 c .... yes it is
145  IF(ksub.EQ.ibct) THEN
146  mbyt(lun) = (iad4+4)
147  msgunp(lun) = 0
148  ELSE
149  mbyt(lun) = 8*(iad4+4)
150  msgunp(lun) = 1
151  ENDIF
152  GOTO 10
153  ENDIF
154  ii=ii+1
155  ENDDO
156 
157 C NOW WE HAVE A GENERATED "SUBSET", BUT IT STILL DOES NOT DEFINE
158 C TABLE A - MAKE ONE LAST DESPERATE ATTEMPT - SEE IF AN EXTERNAL
159 C USER-SUPPLIED BUFR DICTIONARY TABLE IN CHARACTER FORMAT IS DEFINED
160 C IN OPENBT (ONLY POSSIBLE IF APPLICATION PROGRAM HAS AN IN-LINE
161 C OPENBT OVERRIDING THE ONE IN THE BUFR ARCHIVE LIBRARY)
162 C ------------------------------------------------------------------
163 
164  IF(trybt) THEN
165  trybt = .false.
166  IF(iprt.GE.1) THEN
167  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
168  errstr = 'BUFRLIB: CKTABA - LAST RESORT, CHECK FOR EXTERNAL'//
169  . ' BUFR TABLE VIA CALL TO IN-LINE OPENBT'
170  CALL errwrt(errstr)
171  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
172  CALL errwrt(' ')
173  ENDIF
174  CALL openbt(lundx,mtyp)
175  IF(lundx.GT.0) THEN
176 c .... Good news, there is a unit (LUNDX) connected to a table file,
177 c .... so store the table internally
178  CALL rdusdx(lundx,lun)
179  GOTO 5
180  ENDIF
181  ENDIF
182 
183 C IF ALL ATTEMPTS TO DEFINE TABLE A FAIL SKIP GIVE UP
184 C ---------------------------------------------------
185 
186  IF(iprt.GE.0) THEN
187  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
188  errstr = 'BUFRLIB: CKTABA - UNRECOGNIZED TABLE A MESSAGE TYPE ('//
189  . subset // ') - RETURN WITH IRET = -1'
190  CALL errwrt(errstr)
191  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
192  CALL errwrt(' ')
193  ENDIF
194  iret = -1
195  GOTO 100
196 
197 C CHECK THE VALIDITY OF THE MTYP/MSBT AND FOR COMPRESSION (MSGUNP=2)
198 C ------------------------------------------------------------------
199 
200 10 IF(isc3(lun).EQ.0) THEN
201  IF(mtyp.NE.mty1) GOTO 900
202  IF(msbt.NE.msb1.AND.digit(subset(3:8))) GOTO 901
203  ENDIF
204  IF(iupbs3(mbay(1,lun),'ICMP').GT.0) msgunp(lun) = 2
205 
206 C SET THE OTHER REQUIRED PARAMETERS IN MESSAGE CONTROL WORD PARTITION
207 C -------------------------------------------------------------------
208 
209 c .... Date for this message
210  idate(lun) = i4dy(jdate)
211 c .... Positional index of Table A mnem.
212  inode(lun) = inod
213 c .... Number of subsets in this message
214  msub(lun) = iupbs3(mbay(1,lun),'NSUB')
215 c .... Number of subsets read so far from this message
216  nsub(lun) = 0
217 
218  IF(iret.NE.11) THEN
219 c .... Number of non-dictionary messages read so far from this file
220  nmsg(lun) = nmsg(lun)+1
221  ENDIF
222 
223 C EXITS
224 C -----
225 
226 100 RETURN
227 900 WRITE(bort_str,'("BUFRLIB: CKTABA - MESSAGE TYPE MISMATCH '//
228  . '(SUBSET=",A8,", MTYP=",I3,", MTY1=",I3)') subset,mtyp,mty1
229  CALL bort(bort_str)
230 901 WRITE(bort_str,'("BUFRLIB: CKTABA - MESSAGE SUBTYPE MISMATCH '//
231  . '(SUBSET=",A8,", MSBT=",I3,", MSB1=",I3)') subset,msbt,msb1
232  CALL bort(bort_str)
233  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine cktaba(LUN, SUBSET, JDATE, IRET)
This subroutine parses the Table A mnemonic and date out of Section 1 of a BUFR message that was prev...
Definition: cktaba.f:27
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
recursive subroutine getlens(MBAY, LL, LEN0, LEN1, LEN2, LEN3, LEN4, LEN5)
This subroutine reads the lengths of all of the individual sections of a given BUFR message,...
Definition: getlens.f:36
recursive function i4dy(IDATE)
This function converts a date-time with a 2-digit year (YYMMDDHH) to a date-time with a 4-digit year ...
Definition: i4dy.f:24
recursive function igetdate(MBAY, IYR, IMO, IDY, IHR)
This function returns the date-time from within Section 1 of a BUFR message.
Definition: igetdate.f:30
recursive function iupb(MBAY, NBYT, NBIT)
Decode an integer value from an integer array.
Definition: iupb.f:21
recursive function iupbs01(MBAY, S01MNEM)
Read a data value from Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:69
recursive function iupbs3(MBAY, S3MNEM)
This function returns a specified value from within Section 3 of a BUFR message.
Definition: iupbs3.f:30
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.
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
integer, dimension(:), allocatable idate
Section 1 date-time of message.
integer, dimension(:), allocatable nmsg
Current message pointer within logical unit.
integer, dimension(:), allocatable msub
Total number of data subsets in message.
integer, dimension(:), allocatable nsub
Current subset pointer within message.
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.
integer, dimension(:), allocatable isc3
Section 3 switch for each internal I/O stream index:
This module contains an array declaration used to store, for each I/O stream index from which a BUFR ...
integer, dimension(:), allocatable msgunp
Flag indicating how to unpack data subsets from BUFR message:
subroutine nemtbax(LUN, NEMO, MTYP, MSBT, INOD)
This subroutine searches for a descriptor within Table A of the internal DX BUFR tables.
Definition: nemtbax.f:26
subroutine numtab(LUN, IDN, NEMO, TAB, IRET)
Get information about a descriptor, based on the WMO bit-wise representation of an FXY value.
Definition: numtab.f:42
recursive subroutine openbt(LUNDX, MTYP)
This subroutine is called as a last resort from within subroutine cktaba(), in the event the latter s...
Definition: openbt.f:36
subroutine rdusdx(LUNDX, LUN)
Read a complete DX BUFR table.
Definition: rdusdx.f:22