NCEPLIBS-bufr  12.0.0
ufbmex.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Connect a new file to the BUFRLIB software, and read
3 C> the entire file contents into internal arrays.
4 C>
5 C> @author J. Woollen @date 2012-01-26
6 
7 C> Connect a new file to the BUFRLIB software
8 C> for input operations, then read the entire file contents into
9 C> internal arrays so that any of the individual BUFR messages can
10 C> later be accessed from memory, instead of having to read them one
11 C> at a time sequentially from the file.
12 C>
13 C> This subroutine is similar to subroutine ufbmem(), except that
14 C> instead of a file status it returns an array of message types that
15 C> were read in. Furthermore, this subroutine doesn't process any
16 C> embedded DX BUFR tables contained within the file; instead,
17 C> it provides an additional call argument LUNDX to allow
18 C> for specification of the necessary DX BUFR table information
19 C> associated with the messages in the file.
20 C>
21 C> Logical unit numbers LUNIT and LUNDX must already be associated
22 C> with actual filenames on the local system, typically via a Fortran
23 C> "OPEN" statement.
24 C>
25 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
26 C> @param[in] LUNDX - integer: Fortran logical unit number containing DX
27 C> BUFR table information associated with BUFR messages in LUNIT.
28 C> @param[in] INEW - integer: Processing option
29 C> - 0 = Initialize the internal arrays, then read all BUFR messages
30 C> from LUNIT into internal arrays
31 C> - Otherwise, read all BUFR messages from LUNIT and append them to the
32 C> existing messages within the internal arrays
33 C> @param[out] IRET - integer: Number of BUFR messages that were read
34 C> from LUNIT and stored into internal arrays.
35 C> @param[out] MESG - integer(*): Types of BUFR messages that were read
36 C> from LUNIT and stored into internal arrays.
37 C>
38 C> @author J. Woollen @date 2012-01-26
39  RECURSIVE SUBROUTINE ufbmex(LUNIT,LUNDX,INEW,IRET,MESG)
40 
41  USE modv_im8b
42  USE modv_maxmem
43  USE modv_maxmsg
44 
45  USE moda_mgwa
46  USE moda_msgmem
47 
48  COMMON /quiet / iprt
49 
50  CHARACTER*128 bort_str,errstr
51 
52  INTEGER mesg(*), iret(*), lunit(*), lundx(*), inew(*)
53  INTEGER my_lunit(1), my_lundx(1), my_inew(1)
54 
55 C-----------------------------------------------------------------------
56 C-----------------------------------------------------------------------
57 
58 C CHECK FOR I8 INTEGERS
59 C ---------------------
60 
61  IF(im8b) THEN
62  im8b=.false.
63 
64  CALL x84(lunit,my_lunit,1)
65  CALL x84(lundx,my_lundx,1)
66  CALL x84(inew,my_inew,1)
67  IF (my_inew(1).EQ.0) THEN
68  nmesg = 0
69  ELSE
70  nmesg = msgp(0)
71  CALL x84(mesg,mesg,nmesg)
72  ENDIF
73  CALL ufbmex(my_lunit,my_lundx,my_inew,iret,mesg)
74  CALL x48(mesg,mesg,nmesg+iret(1))
75  CALL x48(iret,iret,1)
76 
77  im8b=.true.
78  RETURN
79  ENDIF
80 
81 C TRY TO OPEN BUFR FILE AND SET TO INITIALIZE OR CONCATENATE
82 C ----------------------------------------------------------
83 
84  CALL openbf(lunit,'IN',lundx)
85 
86  IF(inew(1).EQ.0) THEN
87  msgp(0) = 0
88  munit = 0
89  mlast = 0
90  ndxts = 0
91  ldxts = 0
92  ndxm = 0
93  ldxm = 0
94  ENDIF
95 
96  nmsg = msgp(0)
97  iret(1) = 0
98  iflg = 0
99  itim = 0
100 
101 C SET SOME FLAGS SO THAT SUBSEQUENT CALLS TO THE MESSAGE READING
102 C ROUTINES WILL KNOW THERE IS A BUFR TABLE IN SCOPE.
103 
104  ndxts = 1
105  ldxts = 1
106  ipmsgs(1) = 1
107 
108 C TRANSFER MESSAGES FROM FILE TO MEMORY - SET MESSAGE POINTERS
109 C ------------------------------------------------------------
110 
111 1 CALL rdmsgw(lunit,mgwa,ier)
112  IF(ier.EQ.-1) GOTO 100
113  IF(ier.EQ.-2) GOTO 900
114 
115  nmsg = nmsg+1
116  mesg(nmsg) = iupbs01(mgwa,'MTYP')
117  IF(nmsg .GT.maxmsg) iflg = 1
118  lmem = nmwrd(mgwa)
119  IF(lmem+mlast.GT.maxmem) iflg = 2
120 
121  IF(iflg.EQ.0) THEN
122  iret(1) = iret(1)+1
123  DO i=1,lmem
124  msgs(mlast+i) = mgwa(i)
125  ENDDO
126  msgp(0) = nmsg
127  msgp(nmsg) = mlast+1
128  ELSE
129  IF(itim.EQ.0) THEN
130  mlast0 = mlast
131  itim=1
132  ENDIF
133  ENDIF
134  mlast = mlast+lmem
135  GOTO 1
136 
137 C EXITS
138 C -----
139 
140 100 IF(iflg.EQ.1) THEN
141 
142 C EMERGENCY ROOM TREATMENT FOR MAXMSG ARRAY OVERFLOW
143 C --------------------------------------------------
144 
145  IF(iprt.GE.0) THEN
146  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
147  WRITE ( unit=errstr, fmt='(A,A,I8,A)' )
148  . 'BUFRLIB: UFBMEX - THE NO. OF MESSAGES REQUIRED TO STORE ',
149  . 'ALL MESSAGES INTERNALLY EXCEEDS MAXIMUM (', maxmsg,
150  . ') - INCOMPLETE READ'
151  CALL errwrt(errstr)
152  WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
153  . '>>>UFBMEX STORED ', msgp(0), ' MESSAGES OUT OF ', nmsg, '<<<'
154  CALL errwrt(errstr)
155  WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
156  . '>>>UFBMEX STORED ', mlast0, ' BYTES OUT OF ', mlast, '<<<'
157  CALL errwrt(errstr)
158  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
159  CALL errwrt(' ')
160  ENDIF
161  mlast=mlast0
162  ENDIF
163 
164  IF(iflg.EQ.2) THEN
165 
166 C EMERGENCY ROOM TREATMENT FOR MAXMEM ARRAY OVERFLOW
167 C --------------------------------------------------
168 
169  IF(iprt.GE.0) THEN
170  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
171  WRITE ( unit=errstr, fmt='(A,A,I8,A)' )
172  . 'BUFRLIB: UFBMEX - THE NO. OF BYTES REQUIRED TO STORE ',
173  . 'ALL MESSAGES INTERNALLY EXCEEDS MAXIMUM (', maxmem,
174  . ') - INCOMPLETE READ'
175  CALL errwrt(errstr)
176  WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
177  . '>>>UFBMEX STORED ', mlast0, ' BYTES OUT OF ', mlast, '<<<'
178  CALL errwrt(errstr)
179  WRITE ( unit=errstr, fmt='(A,I8,A,I8,A)' )
180  . '>>>UFBMEX STORED ', msgp(0), ' MESSAGES OUT OF ', nmsg, '<<<'
181  CALL errwrt(errstr)
182  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
183  CALL errwrt(' ')
184  ENDIF
185  mlast=mlast0
186  ENDIF
187 
188  IF(iret(1).EQ.0) THEN
189  CALL closbf(lunit)
190  ELSE
191  IF(munit.NE.0) CALL closbf(lunit)
192  IF(munit.EQ.0) munit = lunit(1)
193  ENDIF
194 
195 C EXITS
196 C -----
197 
198  RETURN
199 900 WRITE(bort_str,'("BUFRLIB: UFBMEX - ERROR READING MESSAGE '//
200  . 'NUMBER",I5," INTO MEMORY FROM UNIT",I3)') nmsg+1,lunit(1)
201  CALL bort(bort_str)
202  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive subroutine closbf(LUNIT)
Close the connection between logical unit LUNIT and the NCEPLIBS-bufr software.
Definition: closbf.f:24
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 function iupbs01(MBAY, S01MNEM)
Read a data value from Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:69
This module contains a declaration for an array used by various subroutines and functions to hold a t...
integer, dimension(:), allocatable mgwa
Temporary working copy of BUFR message.
This module contains array and variable declarations used to store the contents of one or more BUFR f...
integer, dimension(:), allocatable msgp
Pointers to the beginning of each message within msgs (up to a maximum of MAXMSG, and where array ele...
integer, dimension(:), allocatable ipmsgs
Pointers to first message within msgs for which each DX BUFR table applies.
integer, dimension(:), allocatable msgs
BUFR messages read from one or more BUFR files.
integer munit
Fortran logical unit number for use in accessing contents of BUFR files within internal memory.
integer ndxm
Number of DX BUFR table messages stored within mdx (up to a maximum of MXDXM).
integer ldxm
Number of array elements filled within mdx (up to a maximum of MXDXW).
integer mlast
Number of array elements filled within msgs (up to a maximum of MAXMEM).
integer ldxts
Number of DX BUFR table that is currently in scope, depending on which BUFR message within msgs is cu...
integer ndxts
Number of DX BUFR tables represented by the messages within mdx (up to a maximum of MXDXTS).
This module declares and initializes the IM8B variable.
logical, public im8b
Status indicator to keep track of whether all future calls to BUFRLIB subroutines and functions from ...
This module declares and initializes the MAXMEM variable.
integer maxmem
Maximum number of bytes that can be used to store BUFR messages within internal memory.
This module declares and initializes the MAXMSG variable.
integer maxmsg
Maximum number of BUFR messages that can be stored within internal memory.
recursive function nmwrd(MBAY)
Given an integer array containing Section 0 from a BUFR message, this function determines the array s...
Definition: nmwrd.f:24
recursive subroutine openbf(LUNIT, IO, LUNDX)
Connects a new file to the NCEPLIBS-bufr software for input or output operations, or initializes the ...
Definition: openbf.f:124
subroutine rdmsgw(lunit, mesg, iret)
Read the next BUFR message from logical unit lunit as an array of integer words.
Definition: rdmsgw.F90:16
recursive subroutine ufbmex(LUNIT, LUNDX, INEW, IRET, MESG)
Connect a new file to the BUFRLIB software for input operations, then read the entire file contents i...
Definition: ufbmex.f:40
subroutine x48(IIN4, IOUT8, NVAL)
Encode one or more 4-byte integer values as 8-byte integer values.
Definition: x48.F:19
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19