1 SUBROUTINE UFBMEM
(LUNIT
,INEW
,IRET
,IUNIT
)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: WOOLLEN ORG: NP20 DATE: 1994-01-06
8 C ABSTRACT: THIS SUBROUTINE OPENS A BUFR FILE FOR INPUT, READS EACH
9 C MESSAGE AND TRANSFERS THEM ONE-BY-ONE TO INTERNAL MEMORY (ARRAY
10 C MSGS IN COMMON BLOCK /MSGMEM/). IF MESSAGES ARE APPENDED TO
11 C EXISTING MESSAGES IN INTERNAL MEMORY, THE BUFR FILE READ HERE IS
12 C CLOSED PRIOR TO RETURNING TO THE CALLING PROGRAM.
14 C PROGRAM HISTORY LOG:
15 C 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
16 C 1998-07-08 J. WOOLLEN -- REPLACED CALL TO CRAY LIBRARY ROUTINE
17 C "ABORT" WITH CALL TO NEW INTERNAL BUFRLIB
19 C 1999-11-18 J. WOOLLEN -- THE MAXIMUM NUMBER OF BYTES REQUIRED TO
20 C STORE ALL MESSAGES INTERNALLY WAS INCREASED
21 C FROM 4 MBYTES TO 8 MBYTES
22 C 2000-09-19 J. WOOLLEN -- MAXIMUM MESSAGE LENGTH INCREASED FROM
23 C 10,000 TO 20,000 BYTES
24 C 2001-08-15 D. KEYSER -- PARAMETER MAXMEM (THE MAXIMUM NUMBER OF
25 C BYTES REQUIRED TO STORE ALL MESSAGES
26 C INTERNALLY) WAS INCREASED FROM 8 MBYTES TO
28 C 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
30 C 2003-11-04 D. KEYSER -- PARAMETER MAXMSG (THE MAXIMUM NUMBER OF
31 C BUFR MESSAGES WHICH CAN BE STORED
32 C INTERNALLY) INCREASED FROM 50000 TO 200000;
33 C UNIFIED/PORTABLE FOR WRF; ADDED
34 C DOCUMENTATION (INCLUDING HISTORY); OUTPUTS
35 C MORE COMPLETE DIAGNOSTIC INFO WHEN ROUTINE
36 C TERMINATES ABNORMALLY
37 C 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
38 C 20,000 TO 50,000 BYTES
39 C 2004-11-15 D. KEYSER -- MODIFIED TO NOT ABORT WHEN THERE ARE EITHER
40 C TOO MANY MESSAGES READ IN (I.E., .GT.
41 C MAXMSG) OR TOO MANY BYTES READ IN (I.E.,
42 C .GT. MAXMEM), BUT RATHER JUST STORE MAXMSG
43 C MESSAGES OR MAXMEM BYTES AND PRINT A
44 C DIAGNOSTIC; PARAMETER MAXMEM (THE MAXIMUM
45 C NUMBER OF BYTES REQUIRED TO STORE ALL
46 C MESSAGES INTERNALLY) WAS INCREASED FROM 16
48 C 2005-11-29 J. ATOR -- USE RDMSGW AND NMWRD
49 C 2009-03-23 J. ATOR -- MODIFIED TO HANDLE EMBEDDED BUFR TABLE
50 C (DICTIONARY) MESSAGES
51 C 2012-09-15 J. WOOLLEN -- MODIFIED FOR C/I/O/BUFR INTERFACE;
52 C CALL STATUS TO GET LUN; REPLACE FORTRAN
53 C REWIND AND BACKSPACE WITH C ROUTINES CEWIND
56 C USAGE: CALL UFBMEM (LUNIT, INEW, IRET, IUNIT)
57 C INPUT ARGUMENT LIST:
58 C LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
59 C INEW - INTEGER: SWITCH:
60 C 0 = initialize internal arrays prior to
61 C transferring messages here
62 C else = append the messages transferred here to
63 C internal memory arrays
65 C OUTPUT ARGUMENT LIST:
66 C IRET - INTEGER: NUMBER OF MESSAGES TRANSFERRED
67 C IUNIT - INTEGER: RETURN CODE:
68 C 0 = no messages were read from LUNIT, file is
70 C LUNIT = INEW input as 0
71 C else = FORTRAN logical unit for BUFR file
72 C associated with initial message transferred
76 C UNIT "LUNIT" - BUFR FILE
79 C NOTE THAT IREADMM, RDMEMM, READMM, UFBMMS, UFBMNS, UFBRMS, UFBTAB
80 C OR UFBTAM CAN BE CALLED AFTER THIS TO READ SPECIFIC BUFR MESSAGES
81 C FROM INTERNAL MEMORY.
83 C THIS ROUTINE CALLS: BORT CLOSBF CPDXMM ERRWRT
84 C IDXMSG NMWRD OPENBF RDMSGW
85 C STATUS CEWIND BACKBUFR
86 C THIS ROUTINE IS CALLED BY: None
87 C Normally called only by application
91 C LANGUAGE: FORTRAN 77
92 C MACHINE: PORTABLE TO ALL PLATFORMS
98 COMMON /MSGMEM
/ MUNIT
,MLAST
,MSGP
(0:MAXMSG
),MSGS
(MAXMEM
),
99 . MDX
(MXDXW
),IPDXM
(MXDXM
),LDXM
,NDXM
,LDXTS
,NDXTS
,
100 . IFDXTS
(MXDXTS
),ICDXTS
(MXDXTS
),IPMSGS
(MXDXTS
)
102 CHARACTER*128 BORT_STR
,ERRSTR
103 DIMENSION MBAY
(MXMSGLD4
)
105 C-----------------------------------------------------------------------
106 C-----------------------------------------------------------------------
108 C TRY TO OPEN BUFR FILE AND SET TO INITIALIZE OR CONCATENATE
109 C ----------------------------------------------------------
111 CALL OPENBF
(LUNIT
,'IN',LUNIT
)
128 C Copy any BUFR dictionary table messages from the beginning of
129 C LUNIT into COMMON /MSGMEM/ for possible later use. Note that
130 C such a table (if one exists) is already now in scope due to the
131 C prior call to subroutine OPENBF, which in turn would have
132 C automatically called subroutines READDX, RDBFDX and MAKESTAB
136 CALL STATUS
(LUNIT
,LUN
,IL
,IM
)
140 C If a table was indeed present at the beginning of the file,
141 C then set the flag to indicate that this table is now in scope.
143 IF ((ITEMP
+1).EQ
.NDXTS
) LDXTS
= NDXTS
145 C TRANSFER MESSAGES FROM FILE TO MEMORY - SET MESSAGE POINTERS
146 C ------------------------------------------------------------
148 1 CALL RDMSGW
(LUNIT
,MBAY
,IER
)
149 IF(IER
.EQ
.-1) GOTO 100
150 IF(IER
.EQ
.-2) GOTO 900
152 IF(IDXMSG
(MBAY
).EQ
.1) THEN
154 C New "embedded" BUFR dictionary table messages have been found in
155 C this file. Copy them into COMMON /MSGMEM/ for later use.
157 call backbufr
(lun
) !BACKSPACE LUNIT
163 IF(NMSG
.GT
.MAXMSG
) IFLG
= 1
165 IF(LMEM
+MLAST
.GT
.MAXMEM
) IFLG
= 2
170 MSGS
(MLAST
+I
) = MBAY
(I
)
186 100 IF(IFLG
.EQ
.1) THEN
188 C EMERGENCY ROOM TREATMENT FOR MAXMSG ARRAY OVERFLOW
189 C --------------------------------------------------
192 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
193 WRITE ( UNIT
=ERRSTR
, FMT
='(A,A,I8,A)' )
194 . 'BUFRLIB: UFBMEM - THE NO. OF MESSAGES REQUIRED TO STORE ',
195 . 'ALL MESSAGES INTERNALLY EXCEEDS MAXIMUM (', MAXMSG
,
196 . ') - INCOMPLETE READ'
198 WRITE ( UNIT
=ERRSTR
, FMT
='(A,I8,A,I8,A)' )
199 . '>>>UFBMEM STORED ', MSGP
(0), ' MESSAGES OUT OF ', NMSG
, '<<<'
201 WRITE ( UNIT
=ERRSTR
, FMT
='(A,I8,A,I8,A)' )
202 . '>>>UFBMEM STORED ', MLAST0
, ' BYTES OUT OF ', MLAST
, '<<<'
204 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
212 C EMERGENCY ROOM TREATMENT FOR MAXMEM ARRAY OVERFLOW
213 C --------------------------------------------------
216 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
217 WRITE ( UNIT
=ERRSTR
, FMT
='(A,A,I8,A)' )
218 . 'BUFRLIB: UFBMEM - THE NO. OF BYTES REQUIRED TO STORE ',
219 . 'ALL MESSAGES INTERNALLY EXCEEDS MAXIMUM (', MAXMEM
,
220 . ') - INCOMPLETE READ'
222 WRITE ( UNIT
=ERRSTR
, FMT
='(A,I8,A,I8,A)' )
223 . '>>>UFBMEM STORED ', MLAST0
, ' BYTES OUT OF ', MLAST
, '<<<'
225 WRITE ( UNIT
=ERRSTR
, FMT
='(A,I8,A,I8,A)' )
226 . '>>>UFBMEM STORED ', MSGP
(0), ' MESSAGES OUT OF ', NMSG
, '<<<'
228 CALL ERRWRT
('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
237 IF(MUNIT
.NE
.0) CALL CLOSBF
(LUNIT
)
238 IF(MUNIT
.EQ
.0) MUNIT
= LUNIT
246 900 WRITE(BORT_STR
,'("BUFRLIB: UFBMEM - ERROR READING MESSAGE '//
247 . 'NUMBER",I5," INTO MEMORY FROM UNIT",I3)') NMSG
+1,LUNIT