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