NCEPLIBS-bufr  12.0.1
mesgbc.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Get information about a BUFR message
3 
4 C> This subroutine examines a BUFR message and returns both the
5 C> message type (from Section 1) and message compression indicator
6 C> (from Section 3).
7 C>
8 C> @author D. Keyser @date 2003-11-04
9 C>
10 C> The message to be examined is obtained in one of two different
11 C> ways, depending on the sign of LUNIN:
12 C> - If LUNIN > 0, the subroutine reads and examines Section 1 of each
13 C> message in a BUFR file starting from the beginning of the file, and
14 C> continuing until it reaches the first message which actually contains
15 C> report data. This means it will skip any messages containing DX BUFR
16 C> table information, as well as any "dummy" messages containing the
17 C> dump center time or dump initiation time within NCEP dump files.
18 C> It then returns the message type and compression indicator from the
19 C> first message containing report data. When used this way, the
20 C> BUFR file in question should not have already been opened via a call
21 C> to subroutine openbf(), though it should already be associated with
22 C> Fortran logical unit number LUNIN. In this situation, the
23 C> subroutine is similar to subroutine mesgbf(), except that mesgbf()
24 C> doesn't skip past any "dummy" messages within NCEP dump files, nor
25 C> does it return a compression indicator.
26 C> - If LUNIN < 0, the subroutine simply returns the message type and
27 C> compression indicator for the BUFR message currently stored in the
28 C> internal arrays via the most recent call to one of the
29 C> [message-reading subroutines](@ref hierarchy) for Fortran logical
30 C> unit number ABS(LUNIN).
31 C>
32 C> @param[in] LUNIN -- integer: Absolute value is Fortran logical unit
33 C> number for BUFR file
34 C> @param[out] MESGTYP -- integer: Message type
35 C> - When LUNIN > 0, a MESGTYP value of -256
36 C> means that there was an error reading the
37 C> BUFR file, or that no messages were read from
38 C> the file. Otherwise, any other MESGTYP
39 C> value < 0 means that none of the messages
40 C> in the BUFR file contained any report data.
41 C> @param[out] ICOMP -- integer: Message compression indicator
42 C> - -3 = BUFR file does not exist
43 C> - -2 = none of the messages in the BUFR file
44 C> contained any report data
45 C> - -1 = error reading the BUFR file
46 C> - 0 = message is not compressed
47 C> - 1 = message is compressed
48 C>
49 C> @author D. Keyser @date 2003-11-04
50  RECURSIVE SUBROUTINE mesgbc(LUNIN,MESGTYP,ICOMP)
51 
52  USE moda_bitbuf
53  USE moda_mgwa
54  USE modv_im8b
55 
56 C-----------------------------------------------------------------------
57 C-----------------------------------------------------------------------
58 
59 C CHECK FOR I8 INTEGERS
60 C ---------------------
61 
62  IF(im8b) THEN
63  im8b=.false.
64 
65  CALL x84(lunin,my_lunin,1)
66  CALL mesgbc(my_lunin,mesgtyp,icomp)
67  CALL x48(mesgtyp,mesgtyp,1)
68  CALL x48(icomp,icomp,1)
69 
70  im8b=.true.
71  RETURN
72  ENDIF
73 
74  lunit = abs(lunin)
75 
76 C DETERMINE METHOD OF OPERATION BASED ON SIGN OF LUNIN
77 C LUNIN > 0 - REWIND AND LOOK FOR FIRST DATA MESSAGE (ITYPE = 0)
78 C LUNIN < 0 - LOOK AT MESSAGE CURRENLY IN MEMORY (ITYPE = 1)
79 C ---------------------------------------------------------------
80 
81  itype = 0
82  IF(lunit.NE.lunin) itype = 1
83 
84  icomp = -1
85  mesgtyp = -256
86 
87  IF(itype.EQ.0) THEN
88 
89  irec = 0
90 
91 C CALL OPENBF SINCE FILE IS NOT OPEN TO THE C INTERFACE YET
92 C ---------------------------------------------------------
93 
94  CALL openbf(lunit,'INX',lunit)
95 
96 C READ PAST ANY BUFR TABLES AND RETURN THE FIRST MESSAGE TYPE FOUND
97 C -----------------------------------------------------------------
98 
99 1 CALL rdmsgw(lunit,mgwa,ier)
100  IF(ier.EQ.-1) GOTO 900
101 
102  irec = irec + 1
103 
104  mesgtyp = iupbs01(mgwa,'MTYP')
105 
106  IF((idxmsg(mgwa).EQ.1).OR.(iupbs3(mgwa,'NSUB').EQ.0)) GOTO 1
107 
108  ELSE
109 
110 C RETURN MESSAGE TYPE FOR MESSAGE CURRENTLY STORED IN MEMORY
111 C ----------------------------------------------------------
112 
113  CALL status(lunit,lun,il,im)
114 
115  DO i=1,12
116  mgwa(i) = mbay(i,lun)
117  ENDDO
118 
119  mesgtyp = iupbs01(mgwa,'MTYP')
120 
121  END IF
122 
123 C SET THE COMPRESSION SWITCH
124 C --------------------------
125 
126  icomp = iupbs3(mgwa,'ICMP')
127 
128  GOTO 100
129 
130 C CAN ONLY GET TO STATEMENT 900 WHEN ITYPE = 0
131 C --------------------------------------------
132 
133 900 IF(irec.EQ.0) THEN
134  mesgtyp = -256
135  icomp = -3
136  ELSE
137  IF(mesgtyp.GE.0) mesgtyp = -mesgtyp
138  icomp = -2
139  ENDIF
140 
141 C EXIT
142 C ----
143 
144 100 IF(itype.EQ.0) CALL closbf(lunit)
145  RETURN
146  END
recursive subroutine closbf(LUNIT)
Close the connection between logical unit LUNIT and the NCEPLIBS-bufr software.
Definition: closbf.f:24
recursive function idxmsg(MESG)
Check whether a BUFR message contains DX BUFR tables information.
Definition: idxmsg.f:23
recursive function iupbs01(MBAY, S01MNEM)
Read a data value from Section 0 or Section 1 of a BUFR message.
Definition: iupbs01.f:69
recursive function iupbs3(MBAY, S3MNEM)
This function returns a specified value from within Section 3 of a BUFR message.
Definition: iupbs3.f:30
recursive subroutine mesgbc(LUNIN, MESGTYP, ICOMP)
This subroutine examines a BUFR message and returns both the message type (from Section 1) and messag...
Definition: mesgbc.f:51
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 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 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 ...
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 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 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