NCEPLIBS-bufr  12.0.1
wrdxtb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Write DX BUFR tables messages to a BUFR file.
3 C>
4 C> @author J. Ator @date 2009-03-23
5 
6 C> This subroutine generates one or more BUFR messages from the DX
7 C> BUFR tables information associated with a given BUFR file, and
8 C> it then writes the messages out to the same or possibly a
9 C> different BUFR file.
10 C>
11 C> Logical units LUNDX and LUNOT should have already been
12 C> opened via previous calls to subroutine openbf(), and in
13 C> particular logical unit LUNOT must have been opened for
14 C> output operations. LUNDX and LUNOT may be the same if it is
15 C> desired to append to LUNOT with DX BUFR messages generated
16 C> from its own internal tables.
17 C>
18 C> @param[in] LUNDX - integer: Fortran logical unit number associated with
19 C> DX BUFR table information to be written out.
20 C> @param[in] LUNOT - integer: Fortran logical unit number of BUFR file to
21 C> which messages are to be written.
22 C>
23 C> @author J. Ator @date 2009-03-23
24 
25  RECURSIVE SUBROUTINE wrdxtb(LUNDX,LUNOT)
26 
27  USE modv_im8b
28  USE moda_tababd
29  USE moda_mgwa
30 
31  COMMON /dxtab / maxdx,idxv,nxstr(10),ldxa(10),ldxb(10),ldxd(10),
32  . ld30(10),dxstr(10)
33 
34  CHARACTER*56 dxstr
35  CHARACTER*6 adn30
36 
37  LOGICAL msgfull
38 
39 C-----------------------------------------------------------------------
40 C-----------------------------------------------------------------------
41 
42 C CHECK FOR I8 INTEGERS
43 C ---------------------
44 
45  IF(im8b) THEN
46  im8b=.false.
47 
48  CALL x84(lundx,my_lundx,1)
49  CALL x84(lunot,my_lunot,1)
50  CALL wrdxtb(my_lundx,my_lunot)
51 
52  im8b=.true.
53  RETURN
54  ENDIF
55 
56 C CHECK FILE STATUSES
57 C -------------------
58 
59  CALL status(lunot,lot,il,im)
60  IF(il.EQ.0) GOTO 900
61  IF(il.LT.0) GOTO 901
62 
63  CALL status(lundx,ldx,il,im)
64  IF(il.EQ.0) GOTO 902
65 
66 C IF FILES ARE DIFFERENT, COPY INTERNAL TABLE
67 C INFORMATION FROM LUNDX TO LUNOT
68 C -------------------------------------------
69 
70  IF(lundx.NE.lunot) CALL cpbfdx(ldx,lot)
71 
72 C GENERATE AND WRITE OUT BUFR DICTIONARY MESSAGES TO LUNOT
73 C --------------------------------------------------------
74 
75  CALL dxmini(mgwa,mbyt,mby4,mbya,mbyb,mbyd)
76 
77  lda = ldxa(idxv+1)
78  ldb = ldxb(idxv+1)
79  ldd = ldxd(idxv+1)
80  l30 = ld30(idxv+1)
81 
82 C Table A information
83 
84  DO i=1,ntba(lot)
85  IF(msgfull(mbyt,lda,maxdx).OR.
86  + (iupb(mgwa,mbya,8).EQ.255)) THEN
87  CALL msgwrt(lunot,mgwa,mbyt)
88  CALL dxmini(mgwa,mbyt,mby4,mbya,mbyb,mbyd)
89  ENDIF
90  mbit = 8*(mby4-1)
91  CALL pkb(iupb(mgwa,mby4,24)+lda,24,mgwa,mbit)
92  mbit = 8*(mbya-1)
93  CALL pkb(iupb(mgwa,mbya, 8)+ 1, 8,mgwa,mbit)
94  mbit = 8*(mbyb-1)
95  CALL pkc(taba(i,lot),lda,mgwa,mbit)
96  CALL pkb( 0, 8,mgwa,mbit)
97  CALL pkb( 0, 8,mgwa,mbit)
98  mbyt = mbyt+lda
99  mbyb = mbyb+lda
100  mbyd = mbyd+lda
101  ENDDO
102 
103 C Table B information
104 
105  DO i=1,ntbb(lot)
106  IF(msgfull(mbyt,ldb,maxdx).OR.
107  + (iupb(mgwa,mbyb,8).EQ.255)) THEN
108  CALL msgwrt(lunot,mgwa,mbyt)
109  CALL dxmini(mgwa,mbyt,mby4,mbya,mbyb,mbyd)
110  ENDIF
111  mbit = 8*(mby4-1)
112  CALL pkb(iupb(mgwa,mby4,24)+ldb,24,mgwa,mbit)
113  mbit = 8*(mbyb-1)
114  CALL pkb(iupb(mgwa,mbyb, 8)+ 1, 8,mgwa,mbit)
115  mbit = 8*(mbyd-1)
116  CALL pkc(tabb(i,lot),ldb,mgwa,mbit)
117  CALL pkb( 0, 8,mgwa,mbit)
118  mbyt = mbyt+ldb
119  mbyd = mbyd+ldb
120  ENDDO
121 
122 C Table D information
123 
124  DO i=1,ntbd(lot)
125  nseq = iupm(tabd(i,lot)(ldd+1:ldd+1),8)
126  lend = ldd+1 + l30*nseq
127  IF(msgfull(mbyt,lend,maxdx).OR.
128  + (iupb(mgwa,mbyd,8).EQ.255)) THEN
129  CALL msgwrt(lunot,mgwa,mbyt)
130  CALL dxmini(mgwa,mbyt,mby4,mbya,mbyb,mbyd)
131  ENDIF
132  mbit = 8*(mby4-1)
133  CALL pkb(iupb(mgwa,mby4,24)+lend,24,mgwa,mbit)
134  mbit = 8*(mbyd-1)
135  CALL pkb(iupb(mgwa,mbyd, 8)+ 1, 8,mgwa,mbit)
136  mbit = 8*(mbyt-4)
137  CALL pkc(tabd(i,lot),ldd,mgwa,mbit)
138  CALL pkb( nseq, 8,mgwa,mbit)
139  DO j=1,nseq
140  jj = ldd+2 + (j-1)*2
141  idn = iupm(tabd(i,lot)(jj:jj),16)
142  CALL pkc(adn30(idn,l30),l30,mgwa,mbit)
143  ENDDO
144  mbyt = mbyt+lend
145  ENDDO
146 
147 C Write the unwritten (leftover) message.
148 
149  CALL msgwrt(lunot,mgwa,mbyt)
150 
151 C Write out one additional (dummy) DX message containing zero
152 C subsets. This will serve as a delimiter for this set of
153 C table messages within output unit LUNOT, just in case the
154 C next thing written to LUNOT ends up being another set of
155 C table messages.
156 
157  CALL dxmini(mgwa,mbyt,mby4,mbya,mbyb,mbyd)
158  CALL getlens(mgwa,2,len0,len1,len2,l3,l4,l5)
159  mbit = (len0+len1+len2+4)*8
160  CALL pkb(0,16,mgwa,mbit)
161  CALL msgwrt(lunot,mgwa,mbyt)
162 
163 C EXITS
164 C -----
165 
166  RETURN
167 900 CALL bort('BUFRLIB: WRDXTB - OUTPUT BUFR FILE IS CLOSED, IT '//
168  . 'MUST BE OPEN FOR OUTPUT')
169 901 CALL bort('BUFRLIB: WRDXTB - OUTPUT BUFR FILE IS OPEN FOR '//
170  . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
171 902 CALL bort('BUFRLIB: WRDXTB - DX TABLE FILE IS CLOSED, IT '//
172  . 'MUST BE OPEN')
173  END
character *(*) function adn30(IDN, L30)
Convert a WMO bit-wise representation of an FXY value to a character string of length 5 or 6.
Definition: adn30.f:23
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine cpbfdx(LUD, LUN)
This subroutine copies all of the DX BUFR table information from one unit to another within internal ...
Definition: cpbfdx.f:17
subroutine dxmini(MBAY, MBYT, MB4, MBA, MBB, MBD)
This subroutine initializes a DX BUFR tables (dictionary) message, writing all the preliminary inform...
Definition: dxmini.f:19
recursive subroutine getlens(MBAY, LL, LEN0, LEN1, LEN2, LEN3, LEN4, LEN5)
This subroutine reads the lengths of all of the individual sections of a given BUFR message,...
Definition: getlens.f:36
recursive function iupb(MBAY, NBYT, NBIT)
Decode an integer value from an integer array.
Definition: iupb.f:21
recursive function iupm(CBAY, NBITS)
Decode an integer value from a character string.
Definition: iupm.f:20
logical function msgfull(MSIZ, ITOADD, MXSIZ)
This function determines whether the current data subset in the internal arrays will fit within the c...
Definition: msgfull.f:21
subroutine msgwrt(LUNIT, MESG, MGBYT)
Perform final checks and updates on a BUFR message before writing it to a specified Fortran logical u...
Definition: msgwrt.f:38
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 array and variable declarations used to store DX BUFR tables internally for mult...
integer, dimension(:), allocatable ntba
Number of Table A entries for each internal I/O stream (up to a maximum of MAXTBA,...
character *600, dimension(:,:), allocatable tabd
Table D entries for each internal I/O stream.
character *128, dimension(:,:), allocatable taba
Table A entries for each internal I/O stream.
integer, dimension(:), allocatable ntbd
Number of Table D entries for each internal I/O stream (up to a maximum of MAXTBD,...
integer, dimension(:), allocatable ntbb
Number of Table B entries for each internal I/O stream (up to a maximum of MAXTBB,...
character *128, dimension(:,:), allocatable tabb
Table B entries for each internal I/O stream.
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 ...
subroutine pkb(NVAL, NBITS, IBAY, IBIT)
This subroutine encodes an integer value within a specified number of bits of an integer array,...
Definition: pkb.f:28
subroutine pkc(CHR, NCHR, IBAY, IBIT)
Encode a character string within an integer array.
Definition: pkc.f:31
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
recursive subroutine wrdxtb(LUNDX, LUNOT)
This subroutine generates one or more BUFR messages from the DX BUFR tables information associated wi...
Definition: wrdxtb.f:26
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19