NCEPLIBS-bufr 11.7.1
rdmems.f
Go to the documentation of this file.
1C> @file
2C> @brief Read a specified data subset from a BUFR message.
3
4C> This subroutine reads a specified data subset from the BUFR message
5C> that was most recently read via a call to subroutine rdmemm() or
6C> readmm().
7C>
8C> @author J. Woollen
9C> @date 1994-01-06
10C>
11C> @param[in] ISUB -- integer: Number of data subset to be
12C> read from BUFR message, counting from the
13C> beginning of the message
14C> @param[out] IRET -- integer: return code
15C> - 0 = requested data subset was
16C> successfully read
17C> - -1 = requested subset number could not
18C> be found in the message
19C>
20C> <p>Whenever this subroutine returns with IRET = 0, this indicates
21C> that a new BUFR data subset (i.e. report) was successfully read into
22C> internal arrays within the BUFRLIB software, and from where it can
23C> now be easily manipulated or further parsed via calls to any of the
24C> [values-reading subroutines](@ref hierarchy) using the Fortran
25C> logical unit number IUNIT that was returned from the most recent
26C> call to subroutine ufbmem().
27C>
28C> <b>Program history log:</b>
29C> | Date | Programmer | Comments |
30C> | -----|------------|----------|
31C> | 1994-01-06 | J. Woollen | Original author |
32C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine "ABORT" with call to new internal routine bort() |
33C> | 1998-10-27 | J. Woollen | Modified to correct problems caused by in-lining code with fpp directives |
34C> | 1999-11-18 | J. Woollen | The number of BUFR files which can be opened at one time increased from 10 to 32 |
35C> | 2000-09-19 | J. Woollen | Maximum message length increased from 10,000 to 20,000 bytes |
36C> | 2001-08-15 | D. Keyser | Increased MAXMEM from 8 Mb to 16 Mb |
37C> | 2004-08-09 | J. Ator | Maximum message length increased from 20,000 to 50,000 bytes |
38C> | 2004-11-15 | D. Keyser | Increased MAXMEM from 16 Mb to 50 Mb |
39C> | 2009-04-21 | J. Ator | Use errwrt() |
40C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
41C>
42 SUBROUTINE rdmems(ISUB,IRET)
43
44 USE moda_msgcwd
45 USE moda_unptyp
46 USE moda_bitbuf
47 USE moda_msgmem
48
49 CHARACTER*128 BORT_STR,ERRSTR
50
51 COMMON /quiet / iprt
52
53C-----------------------------------------------------------------------
54C-----------------------------------------------------------------------
55
56C CHECK THE MESSAGE REQUEST AND FILE STATUS
57C -----------------------------------------
58
59 CALL status(munit,lun,il,im)
60 IF(il.EQ.0) GOTO 900
61 IF(il.GT.0) GOTO 901
62 IF(im.EQ.0) GOTO 902
63 IF(nsub(lun).NE.0) GOTO 903
64
65 IF(isub.GT.msub(lun)) THEN
66 IF(iprt.GE.0) THEN
67 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
68 WRITE ( unit=errstr, fmt='(A,I5,A,A,I5,A)' )
69 . 'BUFRLIB: RDMEMS - REQ. SUBSET #', isub, ' (= 1st INPUT ',
70 . 'ARG.) > # OF SUBSETS IN MEMORY MESSAGE (', msub(lun), ')'
71 CALL errwrt(errstr)
72 CALL errwrt('RETURN WITH IRET = -1')
73 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
74 CALL errwrt(' ')
75 ENDIF
76 iret = -1
77 GOTO 100
78 ENDIF
79
80 mbym = mbyt(lun)
81 nbyt = 0
82
83C POSITION TO SUBSET NUMBER ISUB IN MEMORY MESSAGE
84C ------------------------------------------------
85
86 IF(msgunp(lun).EQ.0) THEN
87 nsub(lun) = isub-1
88 DO i=1,isub-1
89 mbyt(lun) = mbyt(lun) + iupb(mbay(1,lun),mbyt(lun)+1,16)
90 ENDDO
91 ELSEIF(msgunp(lun).EQ.1) THEN
92c .... message with "standard" Section 3
93 DO i=1,isub-1
94 CALL readsb(munit,iret)
95 ENDDO
96 ELSEIF(msgunp(lun).EQ.2) THEN
97c .... compressed message
98 nsub(lun) = isub-1
99 ENDIF
100
101C NOW READ SUBSET NUMBER ISUB FROM MEMORY MESSAGE
102C -----------------------------------------------
103
104 CALL readsb(munit,iret)
105c .... This should have already been accounted for with stmt. 902 or
106c IRET = -1 above
107 IF(iret.NE.0) GOTO 904
108
109C RESET SUBSET POINTER BACK TO ZERO (BEGINNING OF MESSAGE) AND RETURN
110C -------------------------------------------------------------------
111
112 mbyt(lun) = mbym
113 nsub(lun) = 0
114
115C EXITS
116C -----
117
118100 RETURN
119900 CALL bort('BUFRLIB: RDMEMS - INPUT BUFR FILE IS CLOSED, IT '//
120 . 'MUST BE OPEN FOR INPUT')
121901 CALL bort('BUFRLIB: RDMEMS - INPUT BUFR FILE IS OPEN FOR '//
122 . 'OUTPUT, IT MUST BE OPEN FOR INPUT')
123902 CALL bort('BUFRLIB: RDMEMS - A MEMORY MESSAGE MUST BE OPEN IN '//
124 . 'INPUT BUFR FILE, NONE ARE')
125903 WRITE(bort_str,'("BUFRLIB: RDMEMS - UPON ENTRY, SUBSET POINTER '//
126 . 'IN MEMORY MESSAGE IS NOT AT BEGINNING (",I3," SUBSETS HAVE '//
127 . 'BEEN READ, SHOULD BE 0)")') nsub(lun)
128 CALL bort(bort_str)
129904 CALL bort('BUFRLIB: RDMEMS - CALL TO ROUTINE READSB RETURNED '//
130 . 'WITH IRET = -1 (EITHER MEMORY MESSAGE NOT OPEN OR ALL '//
131 . 'SUBSETS IN MESSAGE READ')
132 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:42
function iupb(MBAY, NBYT, NBIT)
THIS FUNCTION UNPACKS AND RETURNS A BINARY INTEGER WORD CONTAINED WITHIN NBIT BITS OF A BUFR MESSAGE ...
Definition: iupb.f:37
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 the contents of one or more BUFR f...
Definition: moda_msgmem.F:14
integer munit
Fortran logical unit number for use in accessing contents of BUFR files within internal memory.
Definition: moda_msgmem.F:71
subroutine rdmems(ISUB, IRET)
This subroutine reads a specified data subset from the BUFR message that was most recently read via a...
Definition: rdmems.f:43
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