NCEPLIBS-bufr 11.7.1
wrdxtb.f
Go to the documentation of this file.
1C> @file
2C> @author J @date 2009-03-23
3
4C> THIS SUBROUTINE WRITES BUFR TABLE (DICTIONARY) MESSAGES
5C> ASSOCIATED WITH THE BUFR FILE IN LUNDX TO THE BUFR FILE IN LUNOT.
6C> BOTH UNITS MUST BE OPENED VIA PREVIOUS CALLS TO BUFR ARCHIVE
7C> LIBRARY SUBROUTINE OPENBF, AND IN PARTICULAR LUNOT MUST HAVE
8C> BEEN OPENED FOR OUTPUT. THE TABLE MESSAGES ARE GENERATED FROM
9C> ARRAYS IN INTERNAL MEMORY (MODULE TABABD). LUNDX CAN BE THE
10C> SAME AS LUNOT IF IT IS DESIRED TO APPEND TO LUNOT WITH BUFR
11C> MESSAGES GENERATED FROM ITS OWN INTERNAL TABLES.
12C>
13C> PROGRAM HISTORY LOG:
14C> 2009-03-23 J. ATOR -- ORIGINAL AUTHOR, USING LOGIC FROM WRITDX
15C> 2012-04-06 J. ATOR -- PREVENT STORING OF MORE THAN 255 TABLE A,
16C> TABLE B OR TABLE D DESCRIPTORS IN ANY
17C> SINGLE DX MESSAGE
18C> 2014-11-14 J. ATOR -- REPLACE IPKM CALLS WITH PKB CALLS
19C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
20C>
21C> USAGE: CALL WRDXTB (LUNDX,LUNOT)
22C> INPUT ARGUMENT LIST:
23C> LUNDX - INTEGER: FORTRAN LOGICAL UNIT NUMBER ASSOCIATED
24C> WITH DX (DICTIONARY) TABLES TO BE WRITTEN OUT;
25C> CAN BE SAME AS LUNOT
26C> LUNOT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
27C> TO BE APPENDED WITH TABLES ASSOCIATED WITH LUNDX
28C>
29C> REMARKS:
30C> THIS ROUTINE CALLS: ADN30 BORT CPBFDX DXMINI
31C> GETLENS IUPB IUPM MSGFULL
32C> MSGWRT PKB PKC STATUS
33C> THIS ROUTINE IS CALLED BY: MAKESTAB WRITDX
34C> Also called by application programs.
35C>
36 SUBROUTINE wrdxtb(LUNDX,LUNOT)
37
38 USE moda_tababd
39 USE moda_mgwa
40
41 COMMON /dxtab / maxdx,idxv,nxstr(10),ldxa(10),ldxb(10),ldxd(10),
42 . ld30(10),dxstr(10)
43
44 CHARACTER*128 BORT_STR
45 CHARACTER*56 DXSTR
46 CHARACTER*6 ADN30
47
48 LOGICAL MSGFULL
49
50C-----------------------------------------------------------------------
51C-----------------------------------------------------------------------
52
53C CHECK FILE STATUSES
54C -------------------
55
56 CALL status(lunot,lot,il,im)
57 IF(il.EQ.0) GOTO 900
58 IF(il.LT.0) GOTO 901
59
60 CALL status(lundx,ldx,il,im)
61 IF(il.EQ.0) GOTO 902
62
63C IF FILES ARE DIFFERENT, COPY INTERNAL TABLE
64C INFORMATION FROM LUNDX TO LUNOT
65C -------------------------------------------
66
67 IF(lundx.NE.lunot) CALL cpbfdx(ldx,lot)
68
69C GENERATE AND WRITE OUT BUFR DICTIONARY MESSAGES TO LUNOT
70C --------------------------------------------------------
71
72 CALL dxmini(lot,mgwa,mbyt,mby4,mbya,mbyb,mbyd)
73
74 lda = ldxa(idxv+1)
75 ldb = ldxb(idxv+1)
76 ldd = ldxd(idxv+1)
77 l30 = ld30(idxv+1)
78
79C Table A information
80
81 DO i=1,ntba(lot)
82 IF(msgfull(mbyt,lda,maxdx).OR.
83 + (iupb(mgwa,mbya,8).EQ.255)) THEN
84 CALL msgwrt(lunot,mgwa,mbyt)
85 CALL dxmini(lot,mgwa,mbyt,mby4,mbya,mbyb,mbyd)
86 ENDIF
87 mbit = 8*(mby4-1)
88 CALL pkb(iupb(mgwa,mby4,24)+lda,24,mgwa,mbit)
89 mbit = 8*(mbya-1)
90 CALL pkb(iupb(mgwa,mbya, 8)+ 1, 8,mgwa,mbit)
91 mbit = 8*(mbyb-1)
92 CALL pkc(taba(i,lot),lda,mgwa,mbit)
93 CALL pkb( 0, 8,mgwa,mbit)
94 CALL pkb( 0, 8,mgwa,mbit)
95 mbyt = mbyt+lda
96 mbyb = mbyb+lda
97 mbyd = mbyd+lda
98 ENDDO
99
100C Table B information
101
102 DO i=1,ntbb(lot)
103 IF(msgfull(mbyt,ldb,maxdx).OR.
104 + (iupb(mgwa,mbyb,8).EQ.255)) THEN
105 CALL msgwrt(lunot,mgwa,mbyt)
106 CALL dxmini(lot,mgwa,mbyt,mby4,mbya,mbyb,mbyd)
107 ENDIF
108 mbit = 8*(mby4-1)
109 CALL pkb(iupb(mgwa,mby4,24)+ldb,24,mgwa,mbit)
110 mbit = 8*(mbyb-1)
111 CALL pkb(iupb(mgwa,mbyb, 8)+ 1, 8,mgwa,mbit)
112 mbit = 8*(mbyd-1)
113 CALL pkc(tabb(i,lot),ldb,mgwa,mbit)
114 CALL pkb( 0, 8,mgwa,mbit)
115 mbyt = mbyt+ldb
116 mbyd = mbyd+ldb
117 ENDDO
118
119C Table D information
120
121 DO i=1,ntbd(lot)
122 nseq = iupm(tabd(i,lot)(ldd+1:ldd+1),8)
123 lend = ldd+1 + l30*nseq
124 IF(msgfull(mbyt,lend,maxdx).OR.
125 + (iupb(mgwa,mbyd,8).EQ.255)) THEN
126 CALL msgwrt(lunot,mgwa,mbyt)
127 CALL dxmini(lot,mgwa,mbyt,mby4,mbya,mbyb,mbyd)
128 ENDIF
129 mbit = 8*(mby4-1)
130 CALL pkb(iupb(mgwa,mby4,24)+lend,24,mgwa,mbit)
131 mbit = 8*(mbyd-1)
132 CALL pkb(iupb(mgwa,mbyd, 8)+ 1, 8,mgwa,mbit)
133 mbit = 8*(mbyt-4)
134 CALL pkc(tabd(i,lot),ldd,mgwa,mbit)
135 CALL pkb( nseq, 8,mgwa,mbit)
136 DO j=1,nseq
137 jj = ldd+2 + (j-1)*2
138 idn = iupm(tabd(i,lot)(jj:jj),16)
139 CALL pkc(adn30(idn,l30),l30,mgwa,mbit)
140 ENDDO
141 mbyt = mbyt+lend
142 ENDDO
143
144C Write the unwritten (leftover) message.
145
146 CALL msgwrt(lunot,mgwa,mbyt)
147
148C Write out one additional (dummy) DX message containing zero
149C subsets. This will serve as a delimiter for this set of
150C table messages within output unit LUNOT, just in case the
151C next thing written to LUNOT ends up being another set of
152C table messages.
153
154 CALL dxmini(lot,mgwa,mbyt,mby4,mbya,mbyb,mbyd)
155 CALL getlens(mgwa,2,len0,len1,len2,l3,l4,l5)
156 mbit = (len0+len1+len2+4)*8
157 CALL pkb(0,16,mgwa,mbit)
158 CALL msgwrt(lunot,mgwa,mbyt)
159
160C EXITS
161C -----
162
163 RETURN
164900 CALL bort('BUFRLIB: WRDXTB - OUTPUT BUFR FILE IS CLOSED, IT '//
165 . 'MUST BE OPEN FOR OUTPUT')
166901 CALL bort('BUFRLIB: WRDXTB - OUTPUT BUFR FILE IS OPEN FOR '//
167 . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
168902 CALL bort('BUFRLIB: WRDXTB - DX TABLE FILE IS CLOSED, IT '//
169 . 'MUST BE OPEN')
170 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine cpbfdx(LUD, LUN)
THIS SUBROUTINE COPIES BUFR TABLE (DICTIONARY) MESSAGES FROM ONE LOCATION TO ANOTHER WITHIN INTERNAL ...
Definition: cpbfdx.f:36
subroutine dxmini(LUN, MBAY, MBYT, MB4, MBA, MBB, MBD)
THIS SUBROUTINE INITIALIZES A BUFR TABLE (DICTIONARY) MESSAGE, WRITING ALL THE PRELIMINARY INFORMATIO...
Definition: dxmini.f:58
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:40
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:37
function iupm(CBAY, NBITS)
THIS FUNCTION UNPACKS AND RETURNS A BINARY INTEGER WORD CONTAINED WITHIN NBITS BITS OF A CHARACTER ST...
Definition: iupm.f:41
subroutine msgwrt(LUNIT, MESG, MGBYT)
This subroutine performs final checks and updates on a BUFR message before writing it to a specified ...
Definition: msgwrt.f:55
This module contains array and variable declarations used to store DX BUFR tables internally for mult...
Definition: moda_tababd.F:10
character *128, dimension(:,:), allocatable tabb
Table B entries for each internal I/O stream.
Definition: moda_tababd.F:59
character *128, dimension(:,:), allocatable taba
Table A entries for each internal I/O stream.
Definition: moda_tababd.F:58
integer, dimension(:), allocatable ntbd
Number of Table D entries for each internal I/O stream (up to a maximum of MAXTBD,...
Definition: moda_tababd.F:53
integer, dimension(:), allocatable ntbb
Number of Table B entries for each internal I/O stream (up to a maximum of MAXTBB,...
Definition: moda_tababd.F:52
integer, dimension(:), allocatable ntba
Number of Table A entries for each internal I/O stream (up to a maximum of MAXTBA,...
Definition: moda_tababd.F:51
character *600, dimension(:,:), allocatable tabd
Table D entries for each internal I/O stream.
Definition: moda_tababd.F:60
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:39
subroutine pkc(CHR, NCHR, IBAY, IBIT)
This subroutine encodes a character string within a specified number of bits of an integer array,...
Definition: pkc.f:41
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 wrdxtb(LUNDX, LUNOT)
THIS SUBROUTINE WRITES BUFR TABLE (DICTIONARY) MESSAGES ASSOCIATED WITH THE BUFR FILE IN LUNDX TO THE...
Definition: wrdxtb.f:37