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