NCEPLIBS-bufr 11.7.1
rdmemm.f
Go to the documentation of this file.
1C> @file
2C> @brief Read a specified BUFR message from internal arrays.
3
4C> This subroutine reads a specified BUFR message from internal
5C> arrays in memory, so that it is now in scope for processing
6C> via a subsequent call to subroutine rdmems().
7C>
8C> <p>BUFR messages should already be stored within internal
9C> arrays in memory via one or more previous calls to
10C> subroutine ufbmem().
11C>
12C> @author J. Woollen
13C> @date 1994-01-06
14C>
15C> @param[in] IMSG -- integer: Number of BUFR message to be
16C> read into scope for further processing,
17C> counting from the beginning of the
18C> internal arrays in memory
19C> @param[out] SUBSET -- character*8: Table A mnemonic for type of BUFR
20C> message that was read into scope
21C> (see [DX BUFR Tables](@ref dfbftab) for
22C> further information about Table A mnemonics)
23C> @param[out] JDATE -- integer: Date-time stored within Section 1 of
24C> BUFR message that was read into scope,
25C> in format of either YYMMDDHH or YYYYMMDDHH,
26C> depending on the most
27C> recent call to subroutine datelen()
28C> @param[out] IRET -- integer: return code
29C> - 0 = requested message was
30C> successfully read into scope
31C> - -1 = requested message number could not
32C> be found in internal arrays
33C>
34C> <b>Program history log:</b>
35C> | Date | Programmer | Comments |
36C> | -----|------------|----------|
37C> | 1994-01-06 | J. Woollen | Original author |
38C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine "ABORT" with call to new internal routine bort(); modified to make Y2K compliant |
39C> | 1999-11-18 | J. Woollen | The number of BUFR files which can be opened at one time increased from 10 to 32; increased MAXMEM from 4 Mb to 8 Mb |
40C> | 2000-09-19 | J. Woollen | Removed logic that had been replicated in this and other read routines and consolidated it into a new routine cktaba(); maximum message length increased from 10,000 to 20,000 bytes |
41C> | 2001-08-15 | D. Keyser | Increased MAXMEM from 8 Mb to 16 Mb |
42C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
43C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added documentation |
44C> | 2004-08-09 | J. Ator | Maximum message length increased from 20,000 to 50,000 bytes |
45C> | 2004-11-15 | D. Keyser | Increased MAXMEM from 16 Mb to 50 Mb |
46C> | 2009-03-23 | J. Ator | Modified to handle embedded BUFR table (dictionary) messages; use errwrt() |
47C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
48C>
49 SUBROUTINE rdmemm(IMSG,SUBSET,JDATE,IRET)
50
51 USE moda_msgcwd
52 USE moda_bitbuf
53 USE moda_mgwa
54 USE moda_msgmem
55
56 COMMON /quiet / iprt
57
58 CHARACTER*128 BORT_STR,ERRSTR
59 CHARACTER*8 SUBSET
60
61 LOGICAL KNOWN
62
63C-----------------------------------------------------------------------
64C-----------------------------------------------------------------------
65
66C CHECK THE MESSAGE REQUEST AND FILE STATUS
67C -----------------------------------------
68
69 CALL status(munit,lun,il,im)
70 CALL wtstat(munit,lun,il, 1)
71 IF(il.EQ.0) GOTO 900
72 IF(il.GT.0) GOTO 901
73 iret = 0
74
75 IF(imsg.EQ.0 .OR.imsg.GT.msgp(0)) THEN
76 CALL wtstat(munit,lun,il,0)
77 IF(iprt.GE.1) THEN
78 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
79 IF(imsg.EQ.0) THEN
80 errstr = 'BUFRLIB: RDMEMM - REQUESTED MEMORY MESSAGE '//
81 . 'NUMBER {FIRST (INPUT) ARGUMENT} IS 0, RETURN WITH '//
82 . 'IRET = -1'
83 ELSE
84 WRITE ( unit=errstr, fmt='(A,I6,A,I6,A)' )
85 . 'BUFRLIB: RDMEMM - REQ. MEMORY MESSAGE #', imsg,
86 . ' {= 1ST (INPUT) ARG.} > # OF MESSAGES IN MEMORY (',
87 . msgp(0), '), RETURN WITH IRET = -1'
88 ENDIF
89 CALL errwrt(errstr)
90 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
91 CALL errwrt(' ')
92 ENDIF
93 iret = -1
94 GOTO 100
95 ENDIF
96
97C ENSURE THAT THE PROPER DICTIONARY TABLE IS IN SCOPE
98C ---------------------------------------------------
99
100C Determine which table applies to this message.
101
102 known = .false.
103 jj = ndxts
104 DO WHILE ((.NOT.known).AND.(jj.GE.1))
105 IF (ipmsgs(jj).LE.imsg) THEN
106 known = .true.
107 ELSE
108 jj = jj - 1
109 ENDIF
110 ENDDO
111 IF (.NOT.known) GOTO 902
112
113C Is this table the one that is currently in scope?
114
115 IF (jj.NE.ldxts) THEN
116
117C No, so reset the software to use the proper table.
118
119 IF(iprt.GE.2) THEN
120 CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++')
121 WRITE ( unit=errstr, fmt='(A,I3,A,I3,A,I6)' )
122 . 'BUFRLIB: RDMEMM - RESETTING TO USE DX TABLE #', jj,
123 . ' INSTEAD OF DX TABLE #', ldxts,
124 . ' FOR REQUESTED MESSAGE #', imsg
125 CALL errwrt(errstr)
126 CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++')
127 CALL errwrt(' ')
128 ENDIF
129 CALL dxinit(lun,0)
130
131C Store each of the DX dictionary messages which constitute
132C this table.
133
134 DO ii = ifdxts(jj), (ifdxts(jj)+icdxts(jj)-1)
135 IF (ii.EQ.ndxm) THEN
136 nwrd = ldxm - ipdxm(ii) + 1
137 ELSE
138 nwrd = ipdxm(ii+1) - ipdxm(ii)
139 ENDIF
140 DO kk = 1, nwrd
141 mgwa(kk) = mdx(ipdxm(ii)+kk-1)
142 ENDDO
143 CALL stbfdx(lun,mgwa)
144 ENDDO
145
146C Rebuild the internal jump/link table.
147
148 CALL makestab
149 ldxts = jj
150 ENDIF
151
152C READ MEMORY MESSAGE NUMBER IMSG INTO A MESSAGE BUFFER
153C -----------------------------------------------------
154
155 iptr = msgp(imsg)
156 IF(imsg.LT.msgp(0)) lptr = msgp(imsg+1)-iptr
157 IF(imsg.EQ.msgp(0)) lptr = mlast-iptr+1
158 iptr = iptr-1
159
160 DO i=1,lptr
161 mbay(i,lun) = msgs(iptr+i)
162 ENDDO
163
164C PARSE THE MESSAGE SECTION CONTENTS
165C ----------------------------------
166
167 CALL cktaba(lun,subset,jdate,jret)
168 nmsg(lun) = imsg
169
170C EXITS
171C -----
172
173100 RETURN
174900 CALL bort('BUFRLIB: RDMEMM - INPUT BUFR FILE IS CLOSED, IT '//
175 . 'MUST BE OPEN FOR INPUT')
176901 CALL bort('BUFRLIB: RDMEMM - INPUT BUFR FILE IS OPEN FOR '//
177 . 'OUTPUT, IT MUST BE OPEN FOR INPUT')
178902 WRITE(bort_str,'("BUFRLIB: RDMEMM - UNKNOWN DX TABLE FOR '//
179 . 'REQUESTED MESSAGE #",I5)') imsg
180 CALL bort(bort_str)
181 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine cktaba(LUN, SUBSET, JDATE, IRET)
THIS SUBROUTINE PARSES THE TABLE A MNEMONIC AND THE DATE OUT OF SECTION 1 OF A BUFR MESSAGE PREVIOUSL...
Definition: cktaba.f:76
subroutine dxinit(LUN, IOI)
THIS SUBROUTINE INITIALIZES THE INTERNAL ARRAYS (IN MODULE TABABD) HOLDING THE DICTIONARY TABLE.
Definition: dxinit.f:41
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:42
subroutine makestab
THIS SUBROUTINE CONSTRUCTS AN INTERNAL JUMP/LINK TABLE WITHIN MODULE TABLES, USING THE INFORMATION WI...
Definition: makestab.f:75
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
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, dimension(:), allocatable msgs
BUFR messages read from one or more BUFR files.
Definition: moda_msgmem.F:80
integer ldxm
Number of array elements filled within mdx (up to a maximum of MXDXW).
Definition: moda_msgmem.F:73
integer, dimension(:), allocatable ifdxts
Pointers to the beginning of each DX BUFR table within mdx.
Definition: moda_msgmem.F:83
integer mlast
Number of array elements filled within msgs (up to a maximum of MAXMEM).
Definition: moda_msgmem.F:72
integer, dimension(:), allocatable icdxts
Number of consecutive messages within mdx which constitute each DX BUFR table, beginning with the cor...
Definition: moda_msgmem.F:84
integer, dimension(:), allocatable ipdxm
Pointers to the beginning of each message within mdx.
Definition: moda_msgmem.F:82
integer ndxm
Number of DX BUFR table messages stored within mdx (up to a maximum of MXDXM).
Definition: moda_msgmem.F:74
integer, dimension(:), allocatable mdx
DX BUFR table messages read from one or more BUFR files, for use in decoding the messages in msgs.
Definition: moda_msgmem.F:81
integer munit
Fortran logical unit number for use in accessing contents of BUFR files within internal memory.
Definition: moda_msgmem.F:71
integer ldxts
Number of DX BUFR table that is currently in scope, depending on which BUFR message within msgs is cu...
Definition: moda_msgmem.F:75
integer, dimension(:), allocatable ipmsgs
Pointers to first message within msgs for which each DX BUFR table applies.
Definition: moda_msgmem.F:85
integer, dimension(:), allocatable msgp
Pointers to the beginning of each message within msgs (up to a maximum of MAXMSG, and where array ele...
Definition: moda_msgmem.F:79
integer ndxts
Number of DX BUFR tables represented by the messages within mdx (up to a maximum of MXDXTS).
Definition: moda_msgmem.F:76
subroutine rdmemm(IMSG, SUBSET, JDATE, IRET)
This subroutine reads a specified BUFR message from internal arrays in memory, so that it is now in s...
Definition: rdmemm.f:50
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
subroutine stbfdx(LUN, MESG)
THIS SUBROUTINE COPIES A BUFR TABLE (DICTIONARY) MESSAGE FROM THE INPUT ARRAY MESG INTO THE INTERNAL ...
Definition: stbfdx.f:29
subroutine wtstat(LUNIT, LUN, IL, IM)
This subroutine can be used to connect or disconnect a specified Fortran logical unit number to/from ...
Definition: wtstat.f:53