NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
readmg.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read the next message from a BUFR file that was previously
3 C> opened for reading.
4 
5 C> This subroutine reads the next BUFR message from logical unit
6 C> ABS(LUNXX) into internal arrays.
7 C>
8 C> <p>Logical unit ABS(LUNXX) should have already been opened for
9 C> input operations via a previous call to subroutine openbf().
10 C>
11 C> @authors J. Woollen
12 C> @authors J. Ator
13 C> @date 1994-01-06
14 C>
15 C> @param[in] LUNXX - integer: Absolute value is Fortran logical unit
16 C> number for BUFR file
17 C> @param[out] SUBSET - character*8: Table A mnemonic for type of BUFR
18 C> message that was read
19 C> (see [DX BUFR Tables](@ref dfbftab)
20 C> for further information about Table A mnemonics)
21 C> @param[out] JDATE - integer: Date-time stored within Section 1 of
22 C> BUFR message that was read, in format of either
23 C> YYMMDDHH or YYYYMMDDHH, depending on the most
24 C> recent call to subroutine datelen()
25 C> @param[out] IRET - integer: return code
26 C> - 0 = new BUFR message was successfully
27 C> read into internal arrays
28 C> - -1 = there are no more BUFR messages in
29 C> the file connected to logical unit
30 C> ABS(LUNXX)
31 C>
32 C> <p>Whenever this subroutine returns with IRET = 0, this indicates
33 C> that a new BUFR message of type SUBSET and date-time JDATE was
34 C> successfully read into internal arrays within the BUFRLIB
35 C> software, and from where it can then be easily manipulated or further
36 C> parsed via a call to one of the
37 C> [subset-reading subroutines](@ref hierarchy). Otherwise,
38 C> if the subroutine returns with IRET = -1, then this indicates that
39 C> there are no more BUFR messages (i.e. end-of-file) within the file
40 C> connected to logical unit ABS(LUNXX).
41 C>
42 C> @remarks
43 C> - Any DX BUFR table messages encountered within ABS(LUNXX) will be
44 C> automatically processed and stored internally, so a successful return
45 C> from this subroutine will always result in a BUFR message containing
46 C> actual data values within the internal arrays.
47 C> - In prior versions of the BUFRLIB software, an input value of
48 C> LUNXX < 0 was an indicator to the subroutine to treat any read error
49 C> from ABS(LUNXX) the same as an end-of-file condition. This option is
50 C> no longer supported, but the capability to call this subroutine with
51 C> LUNXX < 0 is itself still supported for backwards-compatibility with
52 C> certain legacy application programs.
53 C>
54 C> <b>Program history log:</b>
55 C> - 1994-01-06 J. Woollen -- Original author
56 C> - 1996-11-25 J. Woollen -- Modified to exit gracefully when the BUFR
57 C> file is positioned after an "end-of-file"
58 C> - 1998-07-08 J. Woollen -- Replaced call to Cray library routine
59 C> "ABORT" with call to new internal BUFRLIB
60 C> routine "BORT"; modified to make Y2K
61 C> compliant
62 C> - 1999-11-18 J. Woollen -- The number of BUFR files which can be
63 C> opened at one time increased from 10 to 32
64 C> (necessary in order to process multiple
65 C> BUFR files under the MPI); modified with
66 C> semantic adjustments to ameliorate compiler
67 C> complaints from Linux boxes (increases
68 C> portability)
69 C> - 2000-09-19 J. Woollen -- Removed message decoding logic that had
70 C> been replicated in this and other read
71 C> routines and consolidated it into a new
72 C> routine cktaba(); maximum message
73 C> length increased from 10,000 to 20,000
74 C> bytes
75 C> - 2002-05-14 J. Woollen -- Removed entry point datelen() (it became a
76 C> separate routine in the BUFRLIB to increase
77 C> portability to other platforms)
78 C> - 2003-11-04 J. Ator -- Added documentation
79 C> - 2003-11-04 S. Bender -- Added remarks and routine interdependencies
80 C> - 2003-11-04 D. Keyser -- Unified/portable for WRF; added history
81 C> documentation; outputs more complete
82 C> diagnostic info when routine terminates
83 C> abnormally
84 C> - 2004-08-09 J. Ator -- Maximum message length increased from
85 C> 20,000 to 50,000 bytes
86 C> - 2005-11-29 J. Ator -- Added rdmsgw() and rdmsgb calls to simulate
87 C> readibm; added LUNXX < 0 option to simulate
88 C> readft
89 C> - 2009-03-23 J. Ator -- Add logic to allow Section 3 decoding;
90 C> add logic to process internal dictionary
91 C> messages
92 C> - 2012-06-07 J. Ator -- Don't respond to internal dictionary
93 C> messages if Section 3 decoding is being used
94 C> - 2012-09-15 J. Woollen -- Convert to C language I/O interface;
95 C> remove code to reread message as bytes;
96 C> replace Fortran BACKSPACE with C backbufr()
97 C> - 2014-12-10 J. Ator -- Use modules instead of COMMON blocks
98 C>
99  SUBROUTINE readmg(LUNXX,SUBSET,JDATE,IRET)
100 
101  USE moda_msgcwd
102  USE moda_sc3bfr
103  USE moda_bitbuf
104 
105  COMMON /quiet / iprt
106 
107  CHARACTER*128 errstr
108  CHARACTER*8 subset
109 
110 C-----------------------------------------------------------------------
111 C-----------------------------------------------------------------------
112 
113  iret = 0
114  lunit = abs(lunxx)
115 
116 C CHECK THE FILE STATUS
117 C ---------------------
118 
119  CALL status(lunit,lun,il,im)
120  IF(il.EQ.0) goto 900
121  IF(il.GT.0) goto 901
122  CALL wtstat(lunit,lun,il,1)
123 
124 C READ A MESSAGE INTO THE INTERNAL MESSAGE BUFFER
125 C -----------------------------------------------
126 
127 1 CALL rdmsgw(lunit,mbay(1,lun),ier)
128  IF(ier.EQ.-1) goto 200
129 
130 C PARSE THE MESSAGE SECTION CONTENTS
131 C ----------------------------------
132 
133  IF(isc3(lun).NE.0) CALL reads3(lun)
134  CALL cktaba(lun,subset,jdate,iret)
135 
136 C LOOK FOR A DICTIONARY MESSAGE
137 C -----------------------------
138 
139  IF(idxmsg(mbay(1,lun)).NE.1) RETURN
140 
141 C This is an internal dictionary message that was
142 C generated by the BUFRLIB archive library software.
143 
144  IF(isc3(lun).NE.0) RETURN
145 
146 C Section 3 decoding isn't being used, so backspace the
147 C file pointer and then use subroutine RDBFDX to read in
148 C all such dictionary messages (they should be stored
149 C consecutively!) and reset the internal tables.
150 
151  CALL backbufr(lun)
152  CALL rdbfdx(lunit,lun)
153 
154  IF(iprt.GE.1) THEN
155  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
156  errstr = 'BUFRLIB: READMG - INTERNAL DICTIONARY MESSAGE READ;'//
157  .' ACCOUNT FOR IT THEN READ IN NEXT MESSAGE WITHOUT RETURNING'
158  CALL errwrt(errstr)
159  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
160  CALL errwrt(' ')
161  ENDIF
162 
163 C Now go read another message.
164 
165  goto 1
166 
167 C EOF ON ATTEMPTED READ
168 C ---------------------
169 
170 200 CALL wtstat(lunit,lun,il,0)
171  inode(lun) = 0
172  idate(lun) = 0
173  subset = ' '
174  jdate = 0
175  iret = -1
176  RETURN
177 
178 C EXITS
179 C -----
180 
181 900 CALL bort('BUFRLIB: READMG - INPUT BUFR FILE IS CLOSED, IT MUST'//
182  . ' BE OPEN FOR INPUT')
183 901 CALL bort('BUFRLIB: READMG - INPUT BUFR FILE IS OPEN FOR OUTPUT'//
184  . ', IT MUST BE OPEN FOR INPUT')
185  END
subroutine cktaba(LUN, SUBSET, JDATE, IRET)
THIS SUBROUTINE PARSES THE TABLE A MNEMONIC AND THE DATE OUT OF SECTION 1 OF A BUFR MESSAGE PREVIOUSL...
Definition: cktaba.f:75
void backbufr(f77int *nfile)
This subroutine backspaces a BUFR file by one BUFR message.
Definition: cread.c:76
subroutine reads3(LUN)
THIS SUBROUTINE READS THE SECTION 3 DESCRIPTORS FROM THE BUFR MESSAGE IN MBAY(1,LUN).
Definition: reads3.f:30
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
function idxmsg(MESG)
THIS FUNCTION DETERMINES WHETHER THE GIVEN BUFR MESSAGE IS A DX DICTIONARY MESSAGE THAT WAS CREATED B...
Definition: idxmsg.f:29
subroutine wtstat(LUNIT, LUN, IL, IM)
This subroutine can be used to connect or disconnect a specified Fortran logical unit number to/from ...
Definition: wtstat.f:58
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:61
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 rdbfdx(LUNIT, LUN)
BEGINNING AT THE CURRENT FILE POINTER LOCATION WITHIN LUNIT, THIS SUBROUTINE READS A COMPLETE DICTION...
Definition: rdbfdx.f:70
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
This subroutine reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays...
Definition: readmg.f:99