NCEPLIBS-bufr  12.0.1
rdmgsb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read a specified data subset from a BUFR file.
3 C>
4 C> @author J. Woollen @date 2003-11-04
5 
6 C> Read a specified data subset from a BUFR file.
7 C>
8 C> This subroutine combines the functionality of openbf(),
9 C> readmg(), and readsb().
10 C>
11 C> Logical unit LUNIT should not have already been opened via a
12 C> previous call to subroutine openbf(). This subroutine will
13 C> open the file for input.
14 C>
15 C> Whenever this subroutine returns successfully, this indicates
16 C> that a new data subset was successfully read into internal arrays
17 C> within the NCEPLIBS-bufr software, and that subsequent calls can
18 C> immediately be made to any of the various
19 C> [values-reading subroutines](@ref hierarchy).
20 C>
21 C> Note that the value specified for IMSG should not include any
22 C> DX BUFR table messages which may be present in the file.
23 C> In other words, a value of 12 for IMSG means to read the 12th
24 C> message which contains actual report data.
25 C>
26 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
27 C> @param[in] IMSG - integer: Number of BUFR message to be read from the
28 C> BUFR file, counting from the beginning of the file, but <b>not</b>
29 C> counting any DX BUFR table messages which may be present in the file
30 C> @param[in] ISUB - integer: Number of data subset to be read from the
31 C> (IMSG)th BUFR message, counting from the beginning of the message
32 C>
33 C> @author J. Woollen @date 2003-11-04
34  RECURSIVE SUBROUTINE rdmgsb(LUNIT,IMSG,ISUB)
35 
36  USE moda_msgcwd
37  USE moda_bitbuf
38  USE modv_im8b
39 
40  CHARACTER*128 bort_str
41  CHARACTER*8 subset
42 
43 C-----------------------------------------------------------------------
44 C-----------------------------------------------------------------------
45 
46 C CHECK FOR I8 INTEGERS
47 C ---------------------
48  IF(im8b) THEN
49  im8b=.false.
50 
51  CALL x84(lunit,my_lunit,1)
52  CALL x84(imsg,my_imsg,1)
53  CALL x84(isub,my_isub,1)
54  CALL rdmgsb(my_lunit,my_imsg,my_isub)
55 
56  im8b=.true.
57  RETURN
58  ENDIF
59 
60 C OPEN THE FILE AND SKIP TO MESSAGE # IMSG
61 C ----------------------------------------
62 
63  CALL openbf(lunit,'IN',lunit)
64  CALL status(lunit,lun,il,im)
65 
66 C Note that we need to use subroutine READMG to actually read in all
67 C of the messages (including the first (IMSG-1) messages!), just in
68 C case there are any embedded dictionary messages in the file.
69 
70  DO i=1,imsg
71  CALL readmg(lunit,subset,jdate,iret)
72  IF(iret.LT.0) GOTO 901
73  ENDDO
74 
75 C POSITION AT SUBSET # ISUB
76 C -------------------------
77 
78  DO i=1,isub
79  CALL readsb(lunit,iret)
80  IF(iret.LT.0) GOTO 902
81  ENDDO
82 
83 C EXITS
84 C -----
85 
86  RETURN
87 901 WRITE(bort_str,'("BUFRLIB: RDMGSB - HIT END OF FILE BEFORE '//
88  . 'READING REQUESTED MESSAGE NO.",I5," IN BUFR FILE CONNECTED TO'//
89  . ' UNIT",I4)') imsg,lunit
90  CALL bort(bort_str)
91 902 WRITE(bort_str,'("BUFRLIB: RDMGSB - ALL SUBSETS READ BEFORE '//
92  . 'READING REQ. SUBSET NO.",I3," IN REQ. MSG NO.",I5," IN BUFR '//
93  . 'FILE CONNECTED TO UNIT",I4)') isub,imsg,lunit
94  CALL bort(bort_str)
95  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...
This module contains declarations for arrays used to store information about the current 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
recursive subroutine rdmgsb(LUNIT, IMSG, ISUB)
Read a specified data subset from a BUFR file.
Definition: rdmgsb.f:35
recursive subroutine readmg(LUNXX, SUBSET, JDATE, IRET)
Reads the next BUFR message from logical unit ABS(LUNXX) into internal arrays.
Definition: readmg.f:52
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 x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19