NCEPLIBS-bufr  12.0.1
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 C>
5 C> @authors J. Woollen, J. Ator @date 1994-01-06
6 
7 C> Reads the next BUFR message from logical unit
8 C> ABS(LUNXX) into internal arrays.
9 C>
10 C> Logical unit ABS(LUNXX) should have already been opened for
11 C> input operations via a previous call to subroutine openbf().
12 C>
13 C> Whenever this subroutine returns with IRET = 0, this indicates
14 C> that a new BUFR message of type SUBSET and date-time JDATE was
15 C> successfully read into internal arrays within the NCEPLIBS-bufr
16 C> software, and from where it can then be easily manipulated or further
17 C> parsed via a call to one of the
18 C> [subset-reading subroutines](@ref hierarchy). Otherwise,
19 C> if the subroutine returns with IRET = -1, then this indicates that
20 C> there are no more BUFR messages (i.e. end-of-file) within the file
21 C> connected to logical unit ABS(LUNXX).
22 C>
23 C> @remarks
24 C> - Any DX BUFR table messages encountered within ABS(LUNXX) will be
25 C> automatically processed and stored internally, so a successful return
26 C> from this subroutine will always result in a BUFR message containing
27 C> actual data values within the internal arrays.
28 C> - In prior versions of the NCEPLIBS-bufr software, an input value of
29 C> LUNXX < 0 was an indicator to the subroutine to treat any read error
30 C> from ABS(LUNXX) the same as an end-of-file condition. This option is
31 C> no longer supported, but the capability to call this subroutine with
32 C> LUNXX < 0 is itself still supported for backwards-compatibility with
33 C> certain legacy application programs.
34 C>
35 C> @param[in] LUNXX -- integer: Absolute value is Fortran logical unit
36 C> number for BUFR file
37 C> @param[out] SUBSET -- character*8: Table A mnemonic for type of BUFR
38 C> message that was read
39 C> (see [DX BUFR Tables](@ref dfbftab)
40 C> for further information about Table A mnemonics)
41 C> @param[out] JDATE -- integer: Date-time stored within Section 1 of
42 C> BUFR message that was read, in format of either
43 C> YYMMDDHH or YYYYMMDDHH, depending on the most
44 C> recent call to subroutine datelen()
45 C> @param[out] IRET -- integer: return code
46 C> - 0 = new BUFR message was successfully read into internal arrays.
47 C> - -1 = there are no more BUFR messages in the file connected to logical unit
48 C> ABS(LUNXX).
49 C>
50 C> @authors J. Woollen, J. Ator @date 1994-01-06
51  RECURSIVE SUBROUTINE readmg(LUNXX,SUBSET,JDATE,IRET)
52 
53  use bufrlib
54 
55  USE moda_msgcwd
56  USE moda_sc3bfr
57  USE moda_bitbuf
58  USE modv_im8b
59 
60  COMMON /quiet / iprt
61 
62  CHARACTER*128 errstr
63  CHARACTER*8 subset
64 
65 C-----------------------------------------------------------------------
66 C-----------------------------------------------------------------------
67 
68 C CHECK FOR I8 INTEGERS
69 C ---------------------
70 
71  IF(im8b) THEN
72  im8b=.false.
73 
74  CALL x84(lunxx,my_lunxx,1)
75  CALL readmg(my_lunxx,subset,jdate,iret)
76  CALL x48(jdate,jdate,1)
77  CALL x48(iret,iret,1)
78 
79  im8b=.true.
80  RETURN
81  ENDIF
82 
83  iret = 0
84  lunit = abs(lunxx)
85 
86 C CHECK THE FILE STATUS
87 C ---------------------
88 
89  CALL status(lunit,lun,il,im)
90  IF(il.EQ.0) GOTO 900
91  IF(il.GT.0) GOTO 901
92  CALL wtstat(lunit,lun,il,1)
93 
94 C READ A MESSAGE INTO THE INTERNAL MESSAGE BUFFER
95 C -----------------------------------------------
96 
97 1 CALL rdmsgw(lunit,mbay(1,lun),ier)
98  IF(ier.EQ.-1) GOTO 200
99 
100 C PARSE THE MESSAGE SECTION CONTENTS
101 C ----------------------------------
102 
103  IF(isc3(lun).NE.0) CALL reads3(lun)
104  CALL cktaba(lun,subset,jdate,iret)
105 
106 C LOOK FOR A DICTIONARY MESSAGE
107 C -----------------------------
108 
109  IF(idxmsg(mbay(1,lun)).NE.1) RETURN
110 
111 C This is an internal dictionary message that was
112 C generated by the NCEPLIBS-bufr software.
113 
114  IF(isc3(lun).NE.0) RETURN
115 
116 C Section 3 decoding isn't being used, so backspace the
117 C file pointer and then use subroutine RDBFDX to read in
118 C all such dictionary messages (they should be stored
119 C consecutively!) and reset the internal tables.
120 
121  CALL backbufr_c(lun)
122  CALL rdbfdx(lunit,lun)
123 
124  IF(iprt.GE.1) THEN
125  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
126  errstr = 'BUFRLIB: READMG - INTERNAL DICTIONARY MESSAGE READ;'//
127  .' ACCOUNT FOR IT THEN READ IN NEXT MESSAGE WITHOUT RETURNING'
128  CALL errwrt(errstr)
129  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
130  CALL errwrt(' ')
131  ENDIF
132 
133 C Now go read another message.
134 
135  GOTO 1
136 
137 C EOF ON ATTEMPTED READ
138 C ---------------------
139 
140 200 CALL wtstat(lunit,lun,il,0)
141  inode(lun) = 0
142  idate(lun) = 0
143  subset = ' '
144  jdate = 0
145  iret = -1
146  RETURN
147 
148 C EXITS
149 C -----
150 
151 900 CALL bort('BUFRLIB: READMG - INPUT BUFR FILE IS CLOSED, IT MUST'//
152  . ' BE OPEN FOR INPUT')
153 901 CALL bort('BUFRLIB: READMG - INPUT BUFR FILE IS OPEN FOR OUTPUT'//
154  . ', IT MUST BE OPEN FOR INPUT')
155  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine cktaba(LUN, SUBSET, JDATE, IRET)
This subroutine parses the Table A mnemonic and date out of Section 1 of a BUFR message that was prev...
Definition: cktaba.f:27
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 idxmsg(MESG)
Check whether a BUFR message contains DX BUFR tables information.
Definition: idxmsg.f:23
Wrap C NCEPLIBS-bufr functions so they can be called from within the Fortran part of the library.
Definition: bufrlib.F90:11
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
integer, dimension(:), allocatable idate
Section 1 date-time of message.
This module contains an array declaration used to store a switch for each internal I/O stream index,...
integer, dimension(:), allocatable isc3
Section 3 switch for each internal I/O stream index:
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 ...
subroutine rdbfdx(LUNIT, LUN)
Beginning at the current file pointer location within LUNIT, this subroutine reads a complete DX BUFR...
Definition: rdbfdx.f:28
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 readmg(LUNXX, SUBSET, JDATE, IRET)
Reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays.
Definition: readmg.f:52
subroutine reads3(LUN)
This subroutine reads the Section 3 descriptors from the BUFR message in mbay(1,lun).
Definition: reads3.f:15
recursive subroutine status(LUNIT, LUN, IL, IM)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
Definition: status.f:36
subroutine wtstat(LUNIT, LUN, IL, IM)
Update file status in library internals.
Definition: wtstat.f:37
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