1 SUBROUTINE CKTABA
(LUN
,SUBSET
,JDATE
,IRET
)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: WOOLLEN ORG: NP20 DATE: 2000-09-19
8 C ABSTRACT: THIS SUBROUTINE PARSES THE TABLE A MNEMONIC AND THE DATE
9 C OUT OF SECTION 1 OF A BUFR MESSAGE PREVIOUSLY READ FROM UNIT LUNIT
10 C USING BUFR ARCHIVE LIBRARY SUBROUTINE READMG OR EQUIVALENT (AND NOW
11 C STORED IN THE INTERNAL MESSAGE BUFFER, ARRAY MBAY IN COMMON BLOCK
12 C /BITBUF/). THE TABLE A MNEMONIC IS ASSOCIATED WITH THE BUFR
13 C MESSAGE TYPE/SUBTYPE IN SECTION 1. IT ALSO FILLS IN THE MESSAGE
14 C CONTROL WORD PARTITION ARRAYS IN COMMON BLOCK /MSGCWD/.
16 C PROGRAM HISTORY LOG:
17 C 2000-09-19 J. WOOLLEN -- ORIGINAL AUTHOR - CONSOLIDATED MESSAGE
18 C DECODING LOGIC THAT HAD BEEN REPLICATED IN
19 C READMG, READFT, READERME, RDMEMM AND READIBM
20 C (CKTABA IS NOW CALLED BY THESE CODES);
21 C LOGIC ENHANCED HERE TO ALLOW COMPRESSED AND
22 C STANDARD BUFR MESSAGES TO BE READ
23 C 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
25 C 2003-11-04 D. KEYSER -- MODIFIED TO NOT ABORT WHEN THE SECTION 1
26 C MESSAGE SUBTYPE DOES NOT AGREE WITH THE
27 C SECTION 1 MESSAGE SUBTYPE IN THE DICTIONARY
28 C IF THE MESSAGE TYPE MNEMONIC IS NOT OF THE
29 C FORM "NCtttsss", WHERE ttt IS THE BUFR TYPE
30 C AND sss IS THE BUFR SUBTYPE (E.G., IN
31 C "PREPBUFR" FILES); MODIFIED DATE
32 C CALCULATIONS TO NO LONGER USE FLOATING
33 C POINT ARITHMETIC SINCE THIS CAN LEAD TO
34 C ROUND OFF ERROR AND AN IMPROPER RESULTING
35 C DATE ON SOME MACHINES (E.G., NCEP IBM
36 C FROST/SNOW), INCREASES PORTABILITY;
37 C UNIFIED/PORTABLE FOR WRF; ADDED
38 C DOCUMENTATION (INCLUDING HISTORY); OUTPUTS
39 C MORE COMPLETE DIAGNOSTIC INFO WHEN ROUTINE
40 C TERMINATES ABNORMALLY OR UNUSUAL THINGS
41 C HAPPEN; SUBSET DEFINED AS " " IF
42 C IRET RETURNED AS 11 (BEFORE WAS UNDEFINED)
43 C 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
44 C 20,000 TO 50,000 BYTES
45 C 2005-11-29 J. ATOR -- USE IUPBS01, IGETDATE AND GETLENS
46 C 2006-04-14 J. ATOR -- ALLOW "FRtttsss" AND "FNtttsss" AS POSSIBLE
47 C TABLE A MNEMONICS, WHERE ttt IS THE BUFR
48 C TYPE AND sss IS THE BUFR SUBTYPE
49 C 2009-03-23 J. ATOR -- ADD LOGIC TO ALLOW SECTION 3 DECODING;
50 C USE IUPBS3 AND ERRWRT
52 C USAGE: CALL CKTABA (LUN, SUBSET, JDATE, IRET)
53 C INPUT ARGUMENT LIST:
54 C LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
56 C OUTPUT ARGUMENT LIST:
57 C SUBSET - CHARACTER*8: TABLE A MNEMONIC FOR TYPE OF BUFR MESSAGE
59 C " " = IRET equal to 11 (see IRET below)
60 C and not using Section 3 decoding
61 C JDATE - INTEGER: DATE-TIME STORED WITHIN SECTION 1 OF BUFR
62 C MESSAGE BEING CHECKED, IN FORMAT OF EITHER YYMMDDHH OR
63 C YYYYMMDDHH, DEPENDING ON DATELEN() VALUE
64 C IRET - INTEGER: RETURN CODE:
66 C -1 = unrecognized Table A (message type) value
67 C 11 = this is a BUFR table (dictionary) message
70 C THIS ROUTINE CALLS: BORT DIGIT ERRWRT GETLENS
71 C I4DY IGETDATE IUPB IUPBS01
72 C IUPBS3 NEMTBAX NUMTAB OPENBT
74 C THIS ROUTINE IS CALLED BY: RDMEMM READERME READMG
75 C Normally not called by any application
79 C LANGUAGE: FORTRAN 77
80 C MACHINE: PORTABLE TO ALL PLATFORMS
86 COMMON /SC3BFR
/ ISC3
(NFILES
),TAMNEM
(NFILES
)
87 COMMON /MSGCWD
/ NMSG
(NFILES
),NSUB
(NFILES
),MSUB
(NFILES
),
88 . INODE
(NFILES
),IDATE
(NFILES
)
89 COMMON /BITBUF
/ MAXBYT
,IBIT
,IBAY
(MXMSGLD4
),MBYT
(NFILES
),
90 . MBAY
(MXMSGLD4
,NFILES
)
91 COMMON /PADESC
/ IBCT
,IPD1
,IPD2
,IPD3
,IPD4
92 COMMON /UNPTYP
/ MSGUNP
(NFILES
)
95 CHARACTER*128 BORT_STR
,ERRSTR
96 CHARACTER*8 SUBSET
,TAMNEM
101 DATA CPFX
/ 'NC', 'FR', 'FN' /
104 C-----------------------------------------------------------------------
105 C-----------------------------------------------------------------------
111 JDATE
= IGETDATE
(MBAY
(1,LUN
),IYR
,IMO
,IDY
,IHR
)
114 MTYP
= IUPBS01
(MBAY
(1,LUN
),'MTYP')
115 c .... Message subtype
116 MSBT
= IUPBS01
(MBAY
(1,LUN
),'MSBT')
119 c .... This is a BUFR table (dictionary) message.
121 c .... There's no need to proceed any further unless Section 3 is being
122 c .... used for decoding.
123 IF(ISC3
(LUN
).EQ
.0) THEN
132 CALL GETLENS
(MBAY
(1,LUN
),3,LEN0
,LEN1
,LEN2
,LEN3
,L4
,L5
)
134 IAD3
= LEN0
+LEN1
+LEN2
136 c .... First descriptor (integer)
137 KSUB
= IUPB
(MBAY
(1,LUN
),IAD3
+8 ,16)
138 c .... Second descriptor (integer)
139 ISUB
= IUPB
(MBAY
(1,LUN
),IAD3
+10,16)
146 C NOW, TRY TO GET "SUBSET" (MNEMONIC ASSOCIATED WITH TABLE A) FROM MSG
147 C --------------------------------------------------------------------
149 C FIRST CHECK WHETHER SECTION 3 IS BEING USED FOR DECODING
150 C --------------------------------------------------------
152 IF(ISC3
(LUN
).NE
.0) THEN
154 c .... is SUBSET from Table A?
155 CALL NEMTBAX
(LUN
,SUBSET
,MTY1
,MSB1
,INOD
)
158 MBYT
(LUN
) = 8*(IAD4
+4)
164 C IF ISUB FROM SECTION 3 DEFINES TABLE A THEN MSGUNP=0
165 C ----------------------------------------------------
167 c .... get SUBSET from ISUB
168 5 CALL NUMTAB
(LUN
,ISUB
,SUBSET
,TAB
,ITAB
)
169 c .... is SUBSET from Table A?
170 CALL NEMTBAX
(LUN
,SUBSET
,MTY1
,MSB1
,INOD
)
178 C IF KSUB FROM SECTION 3 DEFINES TABLE A THEN MSGUNP=1 (standard)
179 C ---------------------------------------------------------------
181 c .... get SUBSET from KSUB
182 CALL NUMTAB
(LUN
,KSUB
,SUBSET
,TAB
,ITAB
)
183 c .... is SUBSET from Table A?
184 CALL NEMTBAX
(LUN
,SUBSET
,MTY1
,MSB1
,INOD
)
187 MBYT
(LUN
) = 8*(IAD4
+4)
192 C OKAY, STILL NO "SUBSET", LETS MAKE IT "NCtttsss" (where ttt=MTYP
193 C and sss=MSBT) AND SEE IF IT DEFINES TABLE A. IF NOT, THEN ALSO
194 C TRY "FRtttsss" AND "FNtttsss".
195 C ----------------------------------------------------------------
198 DO WHILE(II
.LE
.NCPFX
)
199 WRITE(SUBSET
,'(A2,2I3.3)') CPFX
(II
),MTYP
,MSBT
200 c .... is SUBSET from Table A?
201 CALL NEMTBAX
(LUN
,SUBSET
,MTY1
,MSB1
,INOD
)
204 IF(KSUB
.EQ
.IBCT
) THEN
208 MBYT
(LUN
) = 8*(IAD4
+4)
216 C NOW WE HAVE A GENERATED "SUBSET", BUT IT STILL DOES NOT DEFINE
217 C TABLE A - MAKE ONE LAST DESPERATE ATTEMPT - SEE IF AN EXTERNAL
218 C USER-SUPPLIED BUFR DICTIONARY TABLE IN CHARACTER FORMAT IS DEFINED
219 C IN OPENBT (ONLY POSSIBLE IF APPLICATION PROGRAM HAS AN IN-LINE
220 C OPENBT OVERRIDING THE ONE IN THE BUFR ARCHIVE LIBRARY)
221 C ------------------------------------------------------------------
226 CALL ERRWRT
('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
227 ERRSTR
= 'BUFRLIB: CKTABA - LAST RESORT, CHECK FOR EXTERNAL'//
228 . ' BUFR TABLE VIA CALL TO IN-LINE OPENBT'
230 CALL ERRWRT
('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
233 CALL OPENBT
(LUNDX
,MTYP
)
235 c .... Good news, there is a unit (LUNDX) connected to a table file,
236 c .... so store the table internally
237 CALL RDUSDX
(LUNDX
,LUN
)
242 C IF ALL ATTEMPTS TO DEFINE TABLE A FAIL SKIP GIVE UP
243 C ---------------------------------------------------
246 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
247 ERRSTR
= 'BUFRLIB: CKTABA - UNRECOGNIZED TABLE A MESSAGE TYPE ('//
248 . SUBSET
// ') - RETURN WITH IRET = -1'
250 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
256 C CHECK THE VALIDITY OF THE MTYP/MSBT AND FOR COMPRESSION (MSGUNP=2)
257 C ------------------------------------------------------------------
259 10 IF(ISC3
(LUN
).EQ
.0) THEN
260 IF(MTYP
.NE
.MTY1
) GOTO 900
261 IF(MSBT
.NE
.MSB1
.AND
.DIGIT
(SUBSET
(3:8))) GOTO 901
263 IF(IUPBS3
(MBAY
(1,LUN
),'ICMP').GT
.0) MSGUNP
(LUN
) = 2
265 C SET THE OTHER REQUIRED PARAMETERS IN MESSAGE CONTROL WORD PARTITION
266 C -------------------------------------------------------------------
268 c .... Date for this message
269 IDATE
(LUN
) = I4DY
(JDATE
)
270 c .... Positional index of Table A mnem.
272 c .... Number of subsets in this message
273 MSUB
(LUN
) = IUPBS3
(MBAY
(1,LUN
),'NSUB')
274 c .... Number of subsets read so far from this message
278 c .... Number of non-dictionary messages read so far from this file
279 NMSG
(LUN
) = NMSG
(LUN
)+1
286 900 WRITE(BORT_STR
,'("BUFRLIB: CKTABA - MESSAGE TYPE MISMATCH '//
287 . '(SUBSET=",A8,", MTYP=",I3,", MTY1=",I3)') SUBSET
,MTYP
,MTY1
289 901 WRITE(BORT_STR
,'("BUFRLIB: CKTABA - MESSAGE SUBTYPE MISMATCH '//
290 . '(SUBSET=",A8,", MSBT=",I3,", MSB1=",I3)') SUBSET
,MSBT
,MSB1