NCEPLIBS-bufr  12.0.1
rdmemm.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read a specified BUFR message from internal arrays.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> This subroutine reads a specified BUFR message from internal
7 C> arrays in memory, so that it is now in scope for processing
8 C> via a subsequent call to subroutine rdmems().
9 C>
10 C> BUFR messages should already be stored within internal
11 C> arrays in memory via one or more previous calls to
12 C> subroutine ufbmem().
13 C>
14 C> This subroutine is similar to subroutine readmm(), except that
15 C> readmm() also increments the value of IMSG prior to returning to
16 C> the calling program, which in turn allows it to be easily called
17 C> within an iterative program loop.
18 C>
19 C> @param[in] IMSG -- integer: Number of BUFR message to be
20 C> read into scope for further processing,
21 C> counting from the beginning of the
22 C> internal arrays in memory
23 C> @param[out] SUBSET -- character*8: Table A mnemonic for type of BUFR
24 C> message that was read into scope
25 C> (see [DX BUFR Tables](@ref dfbftab) for
26 C> further information about Table A mnemonics)
27 C> @param[out] JDATE -- integer: Date-time stored within Section 1 of
28 C> BUFR message that was read into scope,
29 C> in format of either YYMMDDHH or YYYYMMDDHH,
30 C> depending on the most
31 C> recent call to subroutine datelen()
32 C> @param[out] IRET -- integer: return code
33 C> - 0 = requested message was
34 C> successfully read into scope
35 C> - -1 = requested message number could not
36 C> be found in internal arrays
37 C>
38 C> @author J. Woollen @date 1994-01-06
39  RECURSIVE SUBROUTINE rdmemm(IMSG,SUBSET,JDATE,IRET)
40 
41  USE moda_msgcwd
42  USE moda_bitbuf
43  USE moda_mgwa
44  USE moda_msgmem
45  USE modv_im8b
46 
47  COMMON /quiet / iprt
48 
49  CHARACTER*128 bort_str,errstr
50  CHARACTER*8 subset
51 
52  LOGICAL known
53 
54 C-----------------------------------------------------------------------
55 C-----------------------------------------------------------------------
56 
57 C CHECK FOR I8 INTEGERS
58 C ---------------------
59 
60  IF(im8b) THEN
61  im8b=.false.
62 
63  CALL x84(imsg,my_imsg,1)
64  CALL rdmemm(my_imsg,subset,jdate,iret)
65  CALL x48(jdate,jdate,1)
66  CALL x48(iret,iret,1)
67 
68  im8b=.true.
69  RETURN
70  ENDIF
71 
72 C CHECK THE MESSAGE REQUEST AND FILE STATUS
73 C -----------------------------------------
74 
75  CALL status(munit,lun,il,im)
76  CALL wtstat(munit,lun,il, 1)
77  IF(il.EQ.0) GOTO 900
78  IF(il.GT.0) GOTO 901
79  iret = 0
80 
81  IF(imsg.EQ.0 .OR.imsg.GT.msgp(0)) THEN
82  CALL wtstat(munit,lun,il,0)
83  IF(iprt.GE.1) THEN
84  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
85  IF(imsg.EQ.0) THEN
86  errstr = 'BUFRLIB: RDMEMM - REQUESTED MEMORY MESSAGE '//
87  . 'NUMBER {FIRST (INPUT) ARGUMENT} IS 0, RETURN WITH '//
88  . 'IRET = -1'
89  ELSE
90  WRITE ( unit=errstr, fmt='(A,I6,A,I6,A)' )
91  . 'BUFRLIB: RDMEMM - REQ. MEMORY MESSAGE #', imsg,
92  . ' {= 1ST (INPUT) ARG.} > # OF MESSAGES IN MEMORY (',
93  . msgp(0), '), RETURN WITH IRET = -1'
94  ENDIF
95  CALL errwrt(errstr)
96  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
97  CALL errwrt(' ')
98  ENDIF
99  iret = -1
100  GOTO 100
101  ENDIF
102 
103 C ENSURE THAT THE PROPER DICTIONARY TABLE IS IN SCOPE
104 C ---------------------------------------------------
105 
106 C Determine which table applies to this message.
107 
108  known = .false.
109  jj = ndxts
110  DO WHILE ((.NOT.known).AND.(jj.GE.1))
111  IF (ipmsgs(jj).LE.imsg) THEN
112  known = .true.
113  ELSE
114  jj = jj - 1
115  ENDIF
116  ENDDO
117  IF (.NOT.known) GOTO 902
118 
119 C Is this table the one that is currently in scope?
120 
121  IF (jj.NE.ldxts) THEN
122 
123 C No, so reset the software to use the proper table.
124 
125  IF(iprt.GE.2) THEN
126  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++')
127  WRITE ( unit=errstr, fmt='(A,I3,A,I3,A,I6)' )
128  . 'BUFRLIB: RDMEMM - RESETTING TO USE DX TABLE #', jj,
129  . ' INSTEAD OF DX TABLE #', ldxts,
130  . ' FOR REQUESTED MESSAGE #', imsg
131  CALL errwrt(errstr)
132  CALL errwrt('+++++++++++++++++++++++++++++++++++++++++++++')
133  CALL errwrt(' ')
134  ENDIF
135  CALL dxinit(lun,0)
136 
137 C Store each of the DX dictionary messages which constitute
138 C this table.
139 
140  DO ii = ifdxts(jj), (ifdxts(jj)+icdxts(jj)-1)
141  IF (ii.EQ.ndxm) THEN
142  nwrd = ldxm - ipdxm(ii) + 1
143  ELSE
144  nwrd = ipdxm(ii+1) - ipdxm(ii)
145  ENDIF
146  DO kk = 1, nwrd
147  mgwa(kk) = mdx(ipdxm(ii)+kk-1)
148  ENDDO
149  CALL stbfdx(lun,mgwa)
150  ENDDO
151 
152 C Rebuild the internal jump/link table.
153 
154  CALL makestab
155  ldxts = jj
156  ENDIF
157 
158 C READ MEMORY MESSAGE NUMBER IMSG INTO A MESSAGE BUFFER
159 C -----------------------------------------------------
160 
161  iptr = msgp(imsg)
162  IF(imsg.LT.msgp(0)) lptr = msgp(imsg+1)-iptr
163  IF(imsg.EQ.msgp(0)) lptr = mlast-iptr+1
164  iptr = iptr-1
165 
166  DO i=1,lptr
167  mbay(i,lun) = msgs(iptr+i)
168  ENDDO
169 
170 C PARSE THE MESSAGE SECTION CONTENTS
171 C ----------------------------------
172 
173  CALL cktaba(lun,subset,jdate,jret)
174  nmsg(lun) = imsg
175 
176 C EXITS
177 C -----
178 
179 100 RETURN
180 900 CALL bort('BUFRLIB: RDMEMM - INPUT BUFR FILE IS CLOSED, IT '//
181  . 'MUST BE OPEN FOR INPUT')
182 901 CALL bort('BUFRLIB: RDMEMM - INPUT BUFR FILE IS OPEN FOR '//
183  . 'OUTPUT, IT MUST BE OPEN FOR INPUT')
184 902 WRITE(bort_str,'("BUFRLIB: RDMEMM - UNKNOWN DX TABLE FOR '//
185  . 'REQUESTED MESSAGE #",I5)') imsg
186  CALL bort(bort_str)
187  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine cktaba(LUN, SUBSET, JDATE, IRET)
This subroutine parses the Table A mnemonic and date out of Section 1 of a BUFR message that was prev...
Definition: cktaba.f:27
subroutine dxinit(LUN, IOI)
This subroutine initializes the internal arrays (in module moda_tababd) holding the DX BUFR table.
Definition: dxinit.f:18
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
subroutine makestab
This subroutine constructs the internal jump/link table within module tables, using all of the intern...
Definition: makestab.f:24
This module contains array and variable declarations used to store BUFR messages internally for multi...
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
This module contains a declaration for an array used by various subroutines and functions to hold a t...
integer, dimension(:), allocatable mgwa
Temporary working copy of BUFR message.
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable nmsg
Current message pointer within logical unit.
This module contains array and variable declarations used to store the contents of one or more BUFR f...
integer, dimension(:), allocatable msgp
Pointers to the beginning of each message within msgs (up to a maximum of MAXMSG, and where array ele...
integer, dimension(:), allocatable ipmsgs
Pointers to first message within msgs for which each DX BUFR table applies.
integer, dimension(:), allocatable msgs
BUFR messages read from one or more BUFR files.
integer, dimension(:), allocatable icdxts
Number of consecutive messages within mdx which constitute each DX BUFR table, beginning with the cor...
integer, dimension(:), allocatable ifdxts
Pointers to the beginning of each DX BUFR table within mdx.
integer munit
Fortran logical unit number for use in accessing contents of BUFR files within internal memory.
integer ndxm
Number of DX BUFR table messages stored within mdx (up to a maximum of MXDXM).
integer ldxm
Number of array elements filled within mdx (up to a maximum of MXDXW).
integer mlast
Number of array elements filled within msgs (up to a maximum of MAXMEM).
integer ldxts
Number of DX BUFR table that is currently in scope, depending on which BUFR message within msgs is cu...
integer ndxts
Number of DX BUFR tables represented by the messages within mdx (up to a maximum of MXDXTS).
integer, dimension(:), allocatable mdx
DX BUFR table messages read from one or more BUFR files, for use in decoding the messages in msgs.
integer, dimension(:), allocatable ipdxm
Pointers to the beginning of each message within mdx.
This module declares and initializes the IM8B variable.
logical, public im8b
Status indicator to keep track of whether all future calls to BUFRLIB subroutines and functions from ...
recursive 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:40
recursive subroutine status(LUNIT, LUN, IL, IM)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
Definition: status.f:36
subroutine stbfdx(LUN, MESG)
This subroutine copies a DX BUFR tables message from the input array mesg into the internal memory ar...
Definition: stbfdx.f:15
subroutine wtstat(LUNIT, LUN, IL, IM)
Update file status in library internals.
Definition: wtstat.f:37
subroutine x48(IIN4, IOUT8, NVAL)
Encode one or more 4-byte integer values as 8-byte integer values.
Definition: x48.F:19
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19