NCEPLIBS-bufr  11.7.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> | Date | Programmer | Comments |
30 C> | -----|------------|----------|
31 C> | 1994-01-06 | J. Woollen | Original author |
32 C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine "ABORT" with call to new internal routine bort() |
33 C> | 1998-10-27 | J. Woollen | Modified to correct problems caused by in-lining code with fpp directives |
34 C> | 1999-11-18 | J. Woollen | The number of BUFR files which can be opened at one time increased from 10 to 32 |
35 C> | 2000-09-19 | J. Woollen | Maximum message length increased from 10,000 to 20,000 bytes |
36 C> | 2001-08-15 | D. Keyser | Increased MAXMEM from 8 Mb to 16 Mb |
37 C> | 2004-08-09 | J. Ator | Maximum message length increased from 20,000 to 50,000 bytes |
38 C> | 2004-11-15 | D. Keyser | Increased MAXMEM from 16 Mb to 50 Mb |
39 C> | 2009-04-21 | J. Ator | Use errwrt() |
40 C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
41 C>
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 
53 C-----------------------------------------------------------------------
54 C-----------------------------------------------------------------------
55 
56 C CHECK THE MESSAGE REQUEST AND FILE STATUS
57 C -----------------------------------------
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 
83 C POSITION TO SUBSET NUMBER ISUB IN MEMORY MESSAGE
84 C ------------------------------------------------
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
92 c .... 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
97 c .... compressed message
98  nsub(lun) = isub-1
99  ENDIF
100 
101 C NOW READ SUBSET NUMBER ISUB FROM MEMORY MESSAGE
102 C -----------------------------------------------
103 
104  CALL readsb(munit,iret)
105 c .... This should have already been accounted for with stmt. 902 or
106 c IRET = -1 above
107  IF(iret.NE.0) goto 904
108 
109 C RESET SUBSET POINTER BACK TO ZERO (BEGINNING OF MESSAGE) AND RETURN
110 C -------------------------------------------------------------------
111 
112  mbyt(lun) = mbym
113  nsub(lun) = 0
114 
115 C EXITS
116 C -----
117 
118 100 RETURN
119 900 CALL bort('BUFRLIB: RDMEMS - INPUT BUFR FILE IS CLOSED, IT '//
120  . 'MUST BE OPEN FOR INPUT')
121 901 CALL bort('BUFRLIB: RDMEMS - INPUT BUFR FILE IS OPEN FOR '//
122  . 'OUTPUT, IT MUST BE OPEN FOR INPUT')
123 902 CALL bort('BUFRLIB: RDMEMS - A MEMORY MESSAGE MUST BE OPEN IN '//
124  . 'INPUT BUFR FILE, NONE ARE')
125 903 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)
129 904 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
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:42
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:55
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:41
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22
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:47