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