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