NCEPLIBS-bufr 11.7.1
ufbmex.f
Go to the documentation of this file.
1C> @file
2C> @brief Connect a new system file to the BUFRLIB software, and read
3C> the entire file contents into internal arrays.
4
5C> This subroutine connects a new system file to the BUFRLIB software
6C> for input operations, then reads the entire file contents into
7C> internal arrays so that any of the individual BUFR messages can
8C> later be accessed from memory, instead of having to read them one
9C> at a time sequentially from the system file.
10C>
11C> <p>This subroutine is similar to subroutine ufbmem(), except that
12C> instead of a file status it returns an array of message types that
13C> were read in. Furthermore, this subroutine doesn't process any
14C> embedded DX BUFR tables contained within the system file; instead,
15C> it provides an additional call argument LUNDX to allow
16C> for specification of the necessary DX BUFR table information
17C> associated with the messages in the file.
18C>
19C> @author J. Woollen
20C> @date 2012-01-26
21C>
22C> @param[in] LUNIT -- integer: Fortran logical unit number for BUFR
23C> file
24C> @param[in] LUNDX -- integer: Fortran logical unit number
25C> containing DX BUFR table information
26C> associated with BUFR messages in LUNIT
27C> @param[in] INEW -- integer: Processing option
28C> - 0 = Initialize the internal arrays, then
29C> read all BUFR messages from LUNIT into
30C> internal arrays
31C> - Otherwise, read all BUFR messages from LUNIT
32C> and append them to the existing messages
33C> within the internal arrays
34C> @param[out] IRET -- integer: Number of BUFR messages that were
35C> read from LUNIT and stored into internal arrays
36C> @param[out] MESG -- integer(*): Types of BUFR messages that were
37C> read from LUNIT and stored into internal arrays
38C>
39C> <p>Logical unit numbers LUNIT and LUNDX must already be associated
40C> with actual filenames on the local system, typically via a Fortran
41C> "OPEN" statement.
42C>
43C> <b>Program history log:</b>
44C> | Date | Programmer | Comments |
45C> | -----|------------|----------|
46C> | 2012-01-26 | J. Woollen | Original author |
47C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
48C> | 2015-09-24 | D. Stokes | Fix missing declaration of COMMON /QUIET/ |
49C>
50 SUBROUTINE ufbmex(LUNIT,LUNDX,INEW,IRET,MESG)
51
52 USE modv_maxmem
53 USE modv_maxmsg
54
55 USE moda_mgwa
56 USE moda_msgmem
57
58 COMMON /quiet / iprt
59
60 CHARACTER*128 BORT_STR,ERRSTR
61
62 INTEGER MESG(*)
63
64C-----------------------------------------------------------------------
65C-----------------------------------------------------------------------
66
67C TRY TO OPEN BUFR FILE AND SET TO INITIALIZE OR CONCATENATE
68C ----------------------------------------------------------
69
70 CALL openbf(lunit,'IN',lundx)
71
72 IF(inew.EQ.0) THEN
73 msgp(0) = 0
74 munit = 0
75 mlast = 0
76 ndxts = 0
77 ldxts = 0
78 ndxm = 0
79 ldxm = 0
80 ENDIF
81
82 nmsg = msgp(0)
83 iret = 0
84 iflg = 0
85 itim = 0
86
87C SET SOME FLAGS SO THAT SUBSEQUENT CALLS TO THE MESSAGE READING
88C ROUTINES WILL KNOW THERE IS A BUFR TABLE IN SCOPE.
89
90 ndxts = 1
91 ldxts = 1
92 ipmsgs(1) = 1
93
94C TRANSFER MESSAGES FROM FILE TO MEMORY - SET MESSAGE POINTERS
95C ------------------------------------------------------------
96
971 CALL rdmsgw(lunit,mgwa,ier)
98 IF(ier.EQ.-1) GOTO 100
99 IF(ier.EQ.-2) GOTO 900
100
101 nmsg = nmsg+1
102 mesg(nmsg) = iupbs01(mgwa,'MTYP')
103 IF(nmsg .GT.maxmsg) iflg = 1
104 lmem = nmwrd(mgwa)
105 IF(lmem+mlast.GT.maxmem) iflg = 2
106
107 IF(iflg.EQ.0) THEN
108 iret = iret+1
109 DO i=1,lmem
110 msgs(mlast+i) = mgwa(i)
111 ENDDO
112 msgp(0) = nmsg
113 msgp(nmsg) = mlast+1
114 ELSE
115 IF(itim.EQ.0) THEN
116 mlast0 = mlast
117 itim=1
118 ENDIF
119 ENDIF
120 mlast = mlast+lmem
121 GOTO 1
122
123C EXITS
124C -----
125
126100 IF(iflg.EQ.1) THEN
127
128C EMERGENCY ROOM TREATMENT FOR MAXMSG ARRAY OVERFLOW
129C --------------------------------------------------
130
131 IF(iprt.GE.0) THEN
132 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
133 WRITE ( unit=errstr, fmt='(A,A,I8,A)' )
134 . 'BUFRLIB: UFBMEX - THE NO. OF MESSAGES REQUIRED TO STORE ',
135 . 'ALL MESSAGES INTERNALLY EXCEEDS MAXIMUM (', maxmsg,
136 . ') - INCOMPLETE READ'
137 CALL errwrt(errstr)
138 WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
139 . '>>>UFBMEX STORED ', msgp(0), ' MESSAGES OUT OF ', nmsg, '<<<'
140 CALL errwrt(errstr)
141 WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
142 . '>>>UFBMEX STORED ', mlast0, ' BYTES OUT OF ', mlast, '<<<'
143 CALL errwrt(errstr)
144 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
145 CALL errwrt(' ')
146 ENDIF
147 mlast=mlast0
148 ENDIF
149
150 IF(iflg.EQ.2) THEN
151
152C EMERGENCY ROOM TREATMENT FOR MAXMEM ARRAY OVERFLOW
153C --------------------------------------------------
154
155 IF(iprt.GE.0) THEN
156 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
157 WRITE ( unit=errstr, fmt='(A,A,I8,A)' )
158 . 'BUFRLIB: UFBMEX - THE NO. OF BYTES REQUIRED TO STORE ',
159 . 'ALL MESSAGES INTERNALLY EXCEEDS MAXIMUM (', maxmem,
160 . ') - INCOMPLETE READ'
161 CALL errwrt(errstr)
162 WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
163 . '>>>UFBMEX STORED ', mlast0, ' BYTES OUT OF ', mlast, '<<<'
164 CALL errwrt(errstr)
165 WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
166 . '>>>UFBMEX STORED ', msgp(0), ' MESSAGES OUT OF ', nmsg, '<<<'
167 CALL errwrt(errstr)
168 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
169 CALL errwrt(' ')
170 ENDIF
171 mlast=mlast0
172 ENDIF
173
174 IF(iret.EQ.0) THEN
175 CALL closbf(lunit)
176 ELSE
177 IF(munit.NE.0) CALL closbf(lunit)
178 IF(munit.EQ.0) munit = lunit
179 ENDIF
180
181C EXITS
182C -----
183
184 RETURN
185900 WRITE(bort_str,'("BUFRLIB: UFBMEX - ERROR READING MESSAGE '//
186 . 'NUMBER",I5," INTO MEMORY FROM UNIT",I3)') nmsg+1,lunit
187 CALL bort(bort_str)
188 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.f:35
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:42
function iupbs01(MBAY, S01MNEM)
This function returns a specified value from within Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:74
This module contains array and variable declarations used to store the contents of one or more BUFR f...
Definition: moda_msgmem.F:14
integer, dimension(:), allocatable msgs
BUFR messages read from one or more BUFR files.
Definition: moda_msgmem.F:80
integer ldxm
Number of array elements filled within mdx (up to a maximum of MXDXW).
Definition: moda_msgmem.F:73
integer mlast
Number of array elements filled within msgs (up to a maximum of MAXMEM).
Definition: moda_msgmem.F:72
integer ndxm
Number of DX BUFR table messages stored within mdx (up to a maximum of MXDXM).
Definition: moda_msgmem.F:74
integer munit
Fortran logical unit number for use in accessing contents of BUFR files within internal memory.
Definition: moda_msgmem.F:71
integer ldxts
Number of DX BUFR table that is currently in scope, depending on which BUFR message within msgs is cu...
Definition: moda_msgmem.F:75
integer, dimension(:), allocatable ipmsgs
Pointers to first message within msgs for which each DX BUFR table applies.
Definition: moda_msgmem.F:85
integer, dimension(:), allocatable msgp
Pointers to the beginning of each message within msgs (up to a maximum of MAXMSG, and where array ele...
Definition: moda_msgmem.F:79
integer ndxts
Number of DX BUFR tables represented by the messages within mdx (up to a maximum of MXDXTS).
Definition: moda_msgmem.F:76
This module declares and initializes the MAXMEM variable.
Definition: modv_MAXMEM.f:13
integer maxmem
Maximum number of bytes that can be used to store BUFR messages within internal memory.
Definition: modv_MAXMEM.f:19
This module declares and initializes the MAXMSG variable.
Definition: modv_MAXMSG.f:13
integer maxmsg
Maximum number of BUFR messages that can be stored within internal memory.
Definition: modv_MAXMSG.f:19
function nmwrd(MBAY)
GIVEN AN INTEGER ARRAY CONTAINING SECTION ZERO FROM A BUFR MESSAGE, THIS FUNCTION DETERMINES A COUNT ...
Definition: nmwrd.f:28
subroutine openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.f:139
subroutine rdmsgw(LUNIT, MESG, IRET)
THIS SUBROUTINE READS THE NEXT BUFR MESSAGE FROM LOGICAL UNIT LUNIT AS AN ARRAY OF INTEGER WORDS.
Definition: rdmsgw.f:38
subroutine ufbmex(LUNIT, LUNDX, INEW, IRET, MESG)
This subroutine connects a new system file to the BUFRLIB software for input operations,...
Definition: ufbmex.f:51