NCEPLIBS-bufr 11.7.1
readsb.f
Go to the documentation of this file.
1C> @file
2C> @brief Read the next data subset from a BUFR message.
3
4C> This subroutine reads the next data subset from a BUFR
5C> message into internal arrays.
6C>
7C> @author J. Woollen
8C> @date 1994-01-06
9C>
10C> @param[in] LUNIT -- integer: Fortran logical unit number for BUFR file
11C> @param[out] IRET -- integer: return code
12C> - 0 = new BUFR data subset was successfully
13C> read into internal arrays
14C> - -1 = there are no more BUFR data subsets in
15C> the BUFR message
16C>
17C> <p>Logical unit LUNIT should have already been opened for
18C> input operations via a previous call to subroutine openbf(), and a
19C> BUFR message should have already been read into internal arrays via
20C> a previous call to one of the
21C> [message-reading subroutines](@ref hierarchy).
22C>
23C> <p>Whenever this subroutine returns with IRET = 0, this indicates
24C> that a new BUFR data subset (i.e. report) was successfully read into
25C> internal arrays within the BUFRLIB software, and from where it can
26C> then be easily manipulated or further parsed via calls to any of the
27C> [values-reading subroutines](@ref hierarchy).
28C> Otherwise, if the subroutine returns with IRET = -1, then this
29C> indicates that there are no more data subsets available within the
30C> current message, and therefore that a new call needs to be made to
31C> one of the [message-reading subroutines](@ref hierarchy) in order
32C> to read in the next message from logical unit LUNIT.
33C>
34C> <b>Program history log:</b>
35C> | Date | Programmer | Comments |
36C> | -----|------------|----------|
37C> | 1994-01-06 | J. Woollen | Original author |
38C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine "ABORT" with call to new internal routine bort() |
39C> | 1999-11-18 | J. Woollen | The number of BUFR files which can be opened at one time increased from 10 to 32 |
40C> | 2000-09-19 | J. Woollen | Added call to new routine rdcmps() allowing subsets to also be decoded from compressed BUFR messages; maximum length increased from 10,000 to 20,000 bytes |
41C> | 2002-05-14 | J. Woollen | Corrected error relating to certain foreign file types; removed old Cray compiler directives |
42C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
43C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added documentation; outputs more complete diagnostic info when routine terminates abnormally |
44C> | 2004-08-09 | J. Ator | Maximum message length increased from 20,000 to 50,000 bytes |
45C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
46C>
47 SUBROUTINE readsb(LUNIT,IRET)
48
49 USE moda_msgcwd
50 USE moda_unptyp
51 USE moda_bitbuf
52 USE moda_bitmaps
53
54 CHARACTER*128 BORT_STR
55
56C-----------------------------------------------------------------------
57C-----------------------------------------------------------------------
58
59 iret = 0
60
61C CHECK THE FILE STATUS
62C ---------------------
63
64 CALL status(lunit,lun,il,im)
65 IF(il.EQ.0) GOTO 900
66 IF(il.GT.0) GOTO 901
67 IF(im.EQ.0) THEN
68 iret = -1
69 GOTO 100
70 ENDIF
71
72C SEE IF THERE IS ANOTHER SUBSET IN THE MESSAGE
73C ---------------------------------------------
74
75 IF(nsub(lun).EQ.msub(lun)) THEN
76 iret = -1
77 GOTO 100
78 ELSE
79 nsub(lun) = nsub(lun) + 1
80 ENDIF
81
82C READ THE NEXT SUBSET AND RESET THE POINTERS
83C -------------------------------------------
84
85 nbtm = 0
86 lstnod = 0
87 lstnodct = 0
88 linbtm = .false.
89
90 IF(msgunp(lun).EQ.0) THEN
91 ibit = mbyt(lun)*8
92 CALL upb(nbyt,16,mbay(1,lun),ibit)
93 CALL rdtree(lun,ier)
94 IF(ier.NE.0) THEN
95 iret = -1
96 GOTO 100
97 ENDIF
98 mbyt(lun) = mbyt(lun) + nbyt
99 ELSEIF(msgunp(lun).EQ.1) THEN
100c .... message with "standard" Section 3
101 ibit = mbyt(lun)
102 CALL rdtree(lun,ier)
103 IF(ier.NE.0) THEN
104 iret = -1
105 GOTO 100
106 ENDIF
107 mbyt(lun) = ibit
108 ELSEIF(msgunp(lun).EQ.2) THEN
109c .... compressed message
110 CALL rdcmps(lun)
111 ELSE
112 GOTO 902
113 ENDIF
114
115C EXITS
116C -----
117
118100 RETURN
119900 CALL bort('BUFRLIB: READSB - INPUT BUFR FILE IS CLOSED, IT MUST'//
120 . ' BE OPEN FOR INPUT')
121901 CALL bort('BUFRLIB: READSB - INPUT BUFR FILE IS OPEN FOR OUTPUT'//
122 . ', IT MUST BE OPEN FOR INPUT')
123902 WRITE(bort_str,'("BUFRLIB: READSB - MESSAGE UNPACK TYPE",I3,"IS'//
124 . ' NOT RECOGNIZED")') msgunp
125 CALL bort(bort_str)
126 END
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
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:25
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:26
This module contains array and variable declarations used to store bitmaps internally within a data s...
Definition: moda_bitmaps.F:13
integer lstnod
Most recent jump/link table entry that was processed by function igetrfel() and whose corresponding v...
Definition: moda_bitmaps.F:75
integer nbtm
Number of stored bitmaps for the current data subset (up to a maximum of MXBTM).
Definition: moda_bitmaps.F:73
logical linbtm
TRUE if a bitmap is in the process of being read for the current data subset.
Definition: moda_bitmaps.F:77
integer lstnodct
Current count of consecutive occurrences of lstnod.
Definition: moda_bitmaps.F:76
subroutine rdcmps(LUN)
THIS SUBROUTINE UNCOMPRESSES AND UNPACKS THE NEXT SUBSET FROM THE INTERNAL COMPRESSED MESSAGE BUFFER ...
Definition: rdcmps.f:47
subroutine rdtree(LUN, IRET)
THIS SUBROUTINE UNPACKS THE NEXT SUBSET FROM THE INTERNAL UNCOMPRESSED MESSAGE BUFFER (ARRAY MBAY IN ...
Definition: rdtree.f:59
subroutine readsb(LUNIT, IRET)
This subroutine reads the next data subset from a BUFR message into internal arrays.
Definition: readsb.f:48
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 upb(NVAL, NBITS, IBAY, IBIT)
THIS SUBROUTINE UNPACKS AND RETURNS A BINARY INTEGER CONTAINED WITHIN NBITS BITS OF IBAY,...
Definition: upb.f:50