NCEPLIBS-bufr  12.0.1
readsb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read the next data subset from a BUFR message.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> Read the next data subset from a BUFR message.
7 C>
8 C> Logical unit LUNIT should have already been opened for
9 C> input operations via a previous call to subroutine openbf(), and a
10 C> BUFR message should have already been read into internal arrays via
11 C> a previous call to one of the
12 C> [message-reading subroutines](@ref hierarchy).
13 C>
14 C> Whenever this subroutine returns with IRET = 0, this indicates that a
15 C> new BUFR data subset (i.e. report) was successfully read into internal
16 C> arrays within the BUFRLIB software, and from where it can be
17 C> manipulated or further parsed via calls to any of the [values-reading
18 C> subroutines](@ref hierarchy).
19 C>
20 C> If the subroutine returns with IRET = -1 there are no more data
21 C> subsets available within the current message; a new call needs to
22 C> be made to one of the [message-reading subroutines](@ref
23 C> hierarchy) in order to read in the next message from logical unit
24 C> LUNIT.
25 C>
26 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
27 C> @param[out] IRET - integer: return code:
28 C> - 0 new BUFR data subset was successfully read into internal arrays.
29 C> - -1 there are no more BUFR data subsets in the BUFR message.
30 C>
31 C> @author J. Woollen @date 1994-01-06
32  RECURSIVE SUBROUTINE readsb(LUNIT,IRET)
33 
34  USE moda_msgcwd
35  USE moda_unptyp
36  USE moda_bitbuf
37  USE moda_bitmaps
38  use moda_stcode
39  USE modv_im8b
40 
41  CHARACTER*128 bort_str
42 
43 C-----------------------------------------------------------------------
44 C-----------------------------------------------------------------------
45 
46 C CHECK FOR I8 INTEGERS
47 C ---------------------
48 
49  IF(im8b) THEN
50  im8b=.false.
51 
52  CALL x84(lunit,my_lunit,1)
53  CALL readsb(my_lunit,iret)
54  CALL x48(iret,iret,1)
55 
56  im8b=.true.
57  RETURN
58  ENDIF
59 
60  iret = 0
61 
62 C CHECK THE FILE STATUS
63 C ---------------------
64 
65  CALL status(lunit,lun,il,im)
66  IF(il.EQ.0) GOTO 900
67  IF(il.GT.0) GOTO 901
68  IF(im.EQ.0) THEN
69  iret = -1
70  GOTO 100
71  ENDIF
72 
73 C SEE IF THERE IS ANOTHER SUBSET IN THE MESSAGE
74 C ---------------------------------------------
75 
76  IF(nsub(lun).EQ.msub(lun)) THEN
77  iret = -1
78  GOTO 100
79  ELSE
80  nsub(lun) = nsub(lun) + 1
81  ENDIF
82 
83 C READ THE NEXT SUBSET AND RESET THE POINTERS
84 C -------------------------------------------
85 
86  nbtm = 0
87  lstnod = 0
88  lstnodct = 0
89  iscodes(lun) = 0
90  linbtm = .false.
91 
92  IF(msgunp(lun).EQ.0) THEN
93  ibit = mbyt(lun)*8
94  CALL upb(nbyt,16,mbay(1,lun),ibit)
95  CALL rdtree(lun,ier)
96  IF(ier.NE.0) THEN
97  iret = -1
98  GOTO 100
99  ENDIF
100  mbyt(lun) = mbyt(lun) + nbyt
101  ELSEIF(msgunp(lun).EQ.1) THEN
102 c .... message with "standard" Section 3
103  ibit = mbyt(lun)
104  CALL rdtree(lun,ier)
105  IF(ier.NE.0) THEN
106  iret = -1
107  GOTO 100
108  ENDIF
109  mbyt(lun) = ibit
110  ELSEIF(msgunp(lun).EQ.2) THEN
111 c .... compressed message
112  CALL rdcmps(lun)
113  if (iscodes(lun) .ne. 0) iret = -1
114  ELSE
115  GOTO 902
116  ENDIF
117 
118 C EXITS
119 C -----
120 
121 100 RETURN
122 900 CALL bort('BUFRLIB: READSB - INPUT BUFR FILE IS CLOSED, IT MUST'//
123  . ' BE OPEN FOR INPUT')
124 901 CALL bort('BUFRLIB: READSB - INPUT BUFR FILE IS OPEN FOR OUTPUT'//
125  . ', IT MUST BE OPEN FOR INPUT')
126 902 WRITE(bort_str,'("BUFRLIB: READSB - MESSAGE UNPACK TYPE",I3,"IS'//
127  . ' NOT RECOGNIZED")') msgunp
128  CALL bort(bort_str)
129  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer ibit
Bit pointer within IBAY.
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
This module contains array and variable declarations used to store bitmaps internally within a data s...
integer lstnod
Most recent jump/link table entry that was processed by function igetrfel() and whose corresponding v...
integer nbtm
Number of stored bitmaps for the current data subset (up to a maximum of MXBTM).
integer lstnodct
Current count of consecutive occurrences of lstnod.
logical linbtm
true if a bitmap is in the process of being read for the current data subset; false otherwise.
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable msub
Total number of data subsets in message.
integer, dimension(:), allocatable nsub
Current subset pointer within message.
This module contains an array declaration used to store a status code for each internal I/O stream in...
integer, dimension(:), allocatable iscodes
Abnormal status codes.
This module contains an array declaration used to store, for each I/O stream index from which a BUFR ...
integer, dimension(:), allocatable msgunp
Flag indicating how to unpack data subsets from 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 ...
subroutine rdcmps(LUN)
Read the next compressed BUFR data subset into internal arrays.
Definition: rdcmps.f:17
subroutine rdtree(LUN, IRET)
This subroutine unpacks the next subset from the internal uncompressed message buffer (array mbay in ...
Definition: rdtree.f:18
recursive subroutine readsb(LUNIT, IRET)
Read the next data subset from a BUFR message.
Definition: readsb.f:33
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 upb(NVAL, NBITS, IBAY, IBIT)
This subroutine decodes an integer value from within a specified number of bits of an integer array,...
Definition: upb.f:28
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