NCEPLIBS-bufr 11.7.1
mesgbc.f
Go to the documentation of this file.
1C> @file
2C> @author KEYSER @date 2003-11-04
3
4C> THIS SUBROUTINE EXAMINES A BUFR MESSAGE AND RETURNS BOTH
5C> THE MESSAGE TYPE FROM SECTION 1 AND A MESSAGE COMPRESSION INDICATOR
6C> UNPACKED FROM SECTION 3. IT OBTAINS THE BUFR MESSAGE VIA TWO
7C> DIFFERENT METHODS, BASED UPON THE SIGN OF LUNIN.
8C> IF LUNIN IS GREATER THAN ZERO, THIS SUBROUTINE READS AND EXAMINES
9C> SECTION 1 OF MESSAGES IN A BUFR FILE IN SEQUENCE UNTIL IT FINDS THE
10C> FIRST MESSAGE THAT ACTUALLY CONTAINS REPORT DATA {I.E., BEYOND THE
11C> BUFR TABLE (DICTIONARY) MESSAGES AT THE TOP AND, FOR DUMP FILES,
12C> BEYOND THE TWO DUMMY MESSAGES CONTAINING THE CENTER TIME AND THE
13C> DUMP TIME}. IT THEN RETURNS THE MESSAGE TYPE AND COMPRESSION
14C> INDICATOR FOR THIS FIRST DATA MESSAGE. IN THIS CASE, THE BUFR FILE
15C> SHOULD NOT BE OPENED VIA BUFR ARCHIVE LIBRARY SUBROUTINE OPENBF
16C> PRIOR TO CALLING THIS SUBROUTINE. HOWEVER, THE BUFR FILE MUST BE
17C> CONNECTED TO UNIT ABS(LUNIN). WHEN USED THIS WAY, THIS SUBROUTINE
18C> IS IDENTICAL TO BUFR ARCHIVE LIBRARY SUBROUTINE MESGBF EXCEPT MESGBF
19C> DOES NOT RETURN ANY INFORMATION ABOUT COMPRESSION AND MESGBF READS
20C> UNTIL IT FINDS THE FIRST NON-DICTIONARY MESSAGE REGARDLESS OF
21C> WHETHER OR NOT IT CONTAINS ANY REPORTS (I.E., IT WOULD STOP AT THE
22C> DUMMY MESSAGE CONTAINING THE CENTER TIME FOR DUMP FILES).
23C> THE SECOND METHOD IN WHICH THIS SUBROUTINE CAN BE USED OCCURS
24C> WHEN LUNIN IS PASSED IN WITH A VALUE LESS THAN ZERO. IN THIS CASE,
25C> IT SIMPLY RETURNS THE MESSAGE TYPE AND COMPRESSION INDICATOR FOR THE
26C> BUFR MESSAGE CURRENTLY STORED IN THE INTERNAL MESSAGE BUFFER (ARRAY
27C> MBAY IN MODULE BITBUF). IN THIS CASE, THE BUFR FILE
28C> CONNECTED TO ABS(LUNIN) MUST HAVE BEEN PREVIOUSLY OPENED FOR INPUT
29C> OPERATIONS BY BUFR ARCHIVE LIBRARY SUBROUTINE OPENBF, AND THE BUFR
30C> MESSAGE MUST HAVE BEEN READ INTO MEMORY BY BUFR ARCHIVE LIBRARY
31C> ROUTINE READMG OR EQUIVALENT.
32C>
33C> PROGRAM HISTORY LOG:
34C> 2003-11-04 D. KEYSER -- ORIGINAL AUTHOR
35C> 2004-06-29 D. KEYSER -- ADDED NEW OPTION TO RETURN MESSAGE TYPE AND
36C> COMPRESSION INDICATOR FOR BUFR MESSAGE
37C> CURRENTLY STORED IN MEMORY (TRIGGERED BY
38C> INPUT ARGUMENT LUNIN LESS THAN ZERO)
39C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
40C> 20,000 TO 50,000 BYTES
41C> 2005-11-29 J. ATOR -- USE IUPBS01, GETLENS AND RDMSGW
42C> 2009-03-23 J. ATOR -- USE IUPBS3 AND IDXMSG
43C> 2012-09-15 J. WOOLLEN -- CONVERT TO C LANGUAGE I/O INTERFACE
44C> ADD OPENBF AND CLOSBF FOR THE CASE
45C> WHEN LUNIN GT 0
46C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
47C>
48C> USAGE: CALL MESGBC (LUNIN, MESGTYP, ICOMP)
49C> INPUT ARGUMENT LIST:
50C> LUNIN - INTEGER: ABSOLUTE VALUE IS FORTRAN LOGICAL UNIT NUMBER
51C> FOR BUFR FILE
52C> - IF LUNIN IS GREATER THAN ZERO, THIS SUBROUTINE
53C> READS THROUGH ALL BUFR MESSAGES FROM BEGINNING OF
54C> FILE UNTIL IT FINDS THE FIRST MESSAGE CONTAINING
55C> REPORT DATA
56C> - IF LUNIN IS LESS THAN ZERO, THIS SUBROUTINE
57C> OPERATES ON THE BUFR MESSAGE CURRENTLY STORED IN
58C> MEMORY
59C>
60C> OUTPUT ARGUMENT LIST:
61C> MESGTYP - INTEGER: BUFR MESSAGE TYPE FOR EITHER THE FIRST
62C> MESSAGE IN FILE CONTAINING REPORT DATA (IF LUNIN > 0),
63C> OR FOR THE MESSAGE CURRENTLY IN MEMORY (IF LUNIN < 0)
64C> -256 = for LUNIN > 0 case only: no messages read
65C> or error reading file
66C> < 0 = for LUNIN > 0 case only: none of the
67C> messages read contain reports; this is the
68C> negative of the message type the last
69C> message read (i.e., -11 indicates the BUFR
70C> file contains only BUFR table messages)
71C> ICOMP - INTEGER: BUFR MESSAGE COMPRESSION SWITCH:
72C> -3 = for LUNIN > 0 case only: BUFR file does not
73C> exist
74C> -2 = for LUNIN > 0 case only: BUFR file does not
75C> contain any report messages
76C> -1 = for LUNIN > 0 case only: cannot determine
77C> if first BUFR message containing report
78C> data is compressed due to error reading
79C> file
80C> 0 = BUFR message (either first containing
81C> report data if LUNIN > 0, or that currently
82C> in memory if LUNIN < 0) is NOT compressed
83C> 1 = BUFR message (either first containing
84C> report data if LUNIN > 0, or that currently
85C> in memory if LUNIN < 0) IS compressed
86C>
87C> INPUT FILES:
88C> UNIT ABS(LUNIN) - BUFR FILE
89C>
90C> REMARKS:
91C> THIS ROUTINE CALLS: CLOSBF IDXMSG IUPBS01 IUPBS3
92C> OPENBF RDMSGW STATUS
93C> THIS ROUTINE IS CALLED BY: COPYSB UFBTAB
94C> Also called by application programs.
95C>
96 SUBROUTINE mesgbc(LUNIN,MESGTYP,ICOMP)
97
98 USE moda_bitbuf
99 USE moda_mgwa
100
101C-----------------------------------------------------------------------
102C-----------------------------------------------------------------------
103
104 lunit = abs(lunin)
105
106C DETERMINE METHOD OF OPERATION BASED ON SIGN OF LUNIN
107C LUNIN > 0 - REWIND AND LOOK FOR FIRST DATA MESSAGE (ITYPE = 0)
108C LUNIN < 0 - LOOK AT MESSAGE CURRENLY IN MEMORY (ITYPE = 1)
109C ---------------------------------------------------------------
110
111 itype = 0
112 IF(lunit.NE.lunin) itype = 1
113
114 icomp = -1
115 mesgtyp = -256
116
117 IF(itype.EQ.0) THEN
118
119 irec = 0
120
121C CALL OPENBF SINCE FILE IS NOT OPEN TO THE C INTERFACE YET
122C ---------------------------------------------------------
123
124 CALL openbf(lunit,'INX',lunit)
125
126C READ PAST ANY BUFR TABLES AND RETURN THE FIRST MESSAGE TYPE FOUND
127C -----------------------------------------------------------------
128
1291 CALL rdmsgw(lunit,mgwa,ier)
130 IF(ier.EQ.-1) GOTO 900
131 IF(ier.EQ.-2) GOTO 901
132
133 irec = irec + 1
134
135 mesgtyp = iupbs01(mgwa,'MTYP')
136
137 IF((idxmsg(mgwa).EQ.1).OR.(iupbs3(mgwa,'NSUB').EQ.0)) GOTO 1
138
139 ELSE
140
141C RETURN MESSAGE TYPE FOR MESSAGE CURRENTLY STORED IN MEMORY
142C ----------------------------------------------------------
143
144 CALL status(lunit,lun,il,im)
145
146 DO i=1,12
147 mgwa(i) = mbay(i,lun)
148 ENDDO
149
150 mesgtyp = iupbs01(mgwa,'MTYP')
151
152 END IF
153
154C SET THE COMPRESSION SWITCH
155C --------------------------
156
157 icomp = iupbs3(mgwa,'ICMP')
158
159 GOTO 100
160
161C CAN ONLY GET TO STATEMENTS 900 OR 901 WHEN ITYPE = 0
162C ----------------------------------------------------
163
164900 IF(irec.EQ.0) THEN
165 mesgtyp = -256
166 icomp = -3
167 ELSE
168 IF(mesgtyp.GE.0) mesgtyp = -mesgtyp
169 icomp = -2
170 ENDIF
171 GOTO 100
172
173901 mesgtyp = -256
174 icomp = -1
175
176C EXIT
177C ----
178
179100 IF(itype.EQ.0) CALL closbf(lunit)
180 RETURN
181 END
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.f:35
function idxmsg(MESG)
This function determines whether a given BUFR message contains DX BUFR tables information that was ge...
Definition: idxmsg.f:24
function iupbs01(MBAY, S01MNEM)
This function returns a specified value from within Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:74
function iupbs3(MBAY, S3MNEM)
This function returns a specified value from within Section 3 of a BUFR message.
Definition: iupbs3.f:35
subroutine mesgbc(LUNIN, MESGTYP, ICOMP)
THIS SUBROUTINE EXAMINES A BUFR MESSAGE AND RETURNS BOTH THE MESSAGE TYPE FROM SECTION 1 AND A MESSAG...
Definition: mesgbc.f:97
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 openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.f:139
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 status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:56