NCEPLIBS-bufr 11.7.1
cpyupd.f
Go to the documentation of this file.
1C> @file
2C> @author WOOLLEN @date 1994-01-06
3
4C> THIS SUBROUTINE COPIES A SUBSET FROM ONE MESSAGE BUFFER
5C> (ARRAY MBAY IN MODULE BITBUF) TO ANOTHER AND/OR RESETS THE
6C> POINTERS. IF THE SUBSET WILL NOT FIT INTO THE OUTPUT MESSAGE, OR
7C> IF THE SUBSET BYTE COUNT EXCEEDS 65530 (SUFFICIENTLY CLOSE TO THE
8C> 16-BIT BYTE COUNTER UPPER LIMIT OF 65535), THEN THAT MESSAGE IS
9C> FLUSHED TO LUNIT AND A NEW ONE IS CREATED IN ORDER TO HOLD THE
10C> COPIED SUBSET. ANY SUBSET WITH BYTE COUNT > 65530 WILL BE WRITTEN
11C> INTO ITS OWN ONE-SUBSET MESSAGE. IF THE SUBSET TO BE COPIED IS
12C> LARGER THAN THE MAXIMUM MESSAGE LENGTH, THEN A CALL IS ISSUED TO
13C> BUFR ARCHIVE LIBRARY SUBROUTINE BORT.
14C>
15C> PROGRAM HISTORY LOG:
16C> 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
17C> 1998-07-08 J. WOOLLEN -- REPLACED CALL TO CRAY LIBRARY ROUTINE
18C> "ABORT" WITH CALL TO NEW INTERNAL BUFRLIB
19C> ROUTINE "BORT"
20C> 1999-11-18 J. WOOLLEN -- THE NUMBER OF BUFR FILES WHICH CAN BE
21C> OPENED AT ONE TIME INCREASED FROM 10 TO 32
22C> (NECESSARY IN ORDER TO PROCESS MULTIPLE
23C> BUFR FILES UNDER THE MPI)
24C> 2000-09-19 J. WOOLLEN -- MAXIMUM MESSAGE LENGTH INCREASED FROM
25C> 10,000 TO 20,000 BYTES
26C> 2002-05-14 J. WOOLLEN -- REMOVED OLD CRAY COMPILER DIRECTIVES
27C> 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
28C> INTERDEPENDENCIES
29C> 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED
30C> DOCUMENTATION (INCLUDING HISTORY); OUTPUTS
31C> MORE COMPLETE DIAGNOSTIC INFO WHEN ROUTINE
32C> TERMINATES ABNORMALLY
33C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
34C> 20,000 TO 50,000 BYTES
35C> 2009-03-23 J. ATOR -- USE MSGFULL
36C> 2014-10-27 J. WOOLLEN -- ACCOUNT FOR SUBSETS WITH BYTE COUNT > 65530
37C> (THESE MUST BE WRITTEN INTO THEIR OWN
38C> ONE-SUBSET MESSAGE)
39C> 2014-10-27 D. KEYSER -- FOR CASE ABOVE, DO NOT WRITE "CURRENT"
40C> MESSAGE IF IT CONTAINS ZERO SUBSETS
41C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
42C> 2015-09-24 D. STOKES -- FIX MISSING DECLARATION OF COMMON /QUIET/
43C>
44C> USAGE: CALL CPYUPD (LUNIT, LIN, LUN, IBYT)
45C> INPUT ARGUMENT LIST:
46C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
47C> LIN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
48C> FOR INPUT MESSAGE LOCATION
49C> LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
50C> FOR OUTPUT MESSAGE LOCATION
51C> IBYT - INTEGER: NUMBER OF BYTES OCCUPIED BY THIS SUBSET
52C>
53C> REMARKS:
54C> THIS ROUTINE CALLS: BORT ERRWRT IUPB MSGFULL
55C> MSGINI MSGWRT MVB PKB
56C> THIS ROUTINE IS CALLED BY: COPYSB
57C> Normally not called by any application
58C> programs.
59C>
60 SUBROUTINE cpyupd(LUNIT,LIN,LUN,IBYT)
61
62 USE moda_msgcwd
63 USE moda_bitbuf
64
65 COMMON /msgptr/ nby0,nby1,nby2,nby3,nby4,nby5
66
67 COMMON /quiet / iprt
68
69 CHARACTER*128 BORT_STR, ERRSTR
70
71 LOGICAL MSGFULL
72
73C-----------------------------------------------------------------------
74C-----------------------------------------------------------------------
75
76C CHECK WHETHER THE NEW SUBSET SHOULD BE WRITTEN INTO THE CURRENTLY
77C OPEN MESSAGE
78C -----------------------------------------------------------------
79
80 IF(msgfull(mbyt(lun),ibyt,maxbyt)
81 . .OR.
82 . ((ibyt.GT.65530).AND.(nsub(lun).GT.0))) THEN
83c NO it should not, either because:
84c 1) it doesn't fit,
85c -- OR --
86c 2) it has byte count > 65530 (sufficiently close to the
87c upper limit for the 16 bit byte counter placed at the
88c beginning of each subset), AND the current message has
89c at least one subset in it,
90c SO write the current message out and create a new one to
91c hold the current subset
92 CALL msgwrt(lunit,mbay(1,lun),mbyt(lun))
93 CALL msgini(lun)
94 ENDIF
95
96 IF(msgfull(mbyt(lun),ibyt,maxbyt)) GOTO 900
97
98C TRANSFER SUBSET FROM ONE MESSAGE TO THE OTHER
99C ---------------------------------------------
100
101C Note that we want to append the data for this subset to the end
102C of Section 4, but the value in MBYT(LUN) already includes the
103C length of Section 5 (i.e. 4 bytes). Therefore, we need to begin
104C writing at the point 3 bytes prior to the byte currently pointed
105C to by MBYT(LUN).
106
107 CALL mvb(mbay(1,lin),mbyt(lin)+1,mbay(1,lun),mbyt(lun)-3,ibyt)
108
109C UPDATE THE SUBSET AND BYTE COUNTERS
110C --------------------------------------
111
112 mbyt(lun) = mbyt(lun) + ibyt
113 nsub(lun) = nsub(lun) + 1
114
115 lbit = (nby0+nby1+nby2+4)*8
116 CALL pkb(nsub(lun),16,mbay(1,lun),lbit)
117
118 lbyt = nby0+nby1+nby2+nby3
119 nbyt = iupb(mbay(1,lun),lbyt+1,24)
120 lbit = lbyt*8
121 CALL pkb(nbyt+ibyt,24,mbay(1,lun),lbit)
122
123C IF THE SUBSET BYTE COUNT IS > 65530, THEN GIVE IT ITS OWN ONE-SUBSET
124C MESSAGE (CANNOT HAVE ANY OTHER SUBSETS IN THIS MESSAGE BECAUSE THEIR
125C BEGINNING WOULD BE BEYOND THE UPPER LIMIT OF 65535 IN THE 16-BIT
126C BYTE COUNTER, MEANING THEY COULD NOT BE LOCATED!)
127C --------------------------------------------------------------------
128
129 IF(ibyt.GT.65530) THEN
130 IF(iprt.GE.1) THEN
131 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
132 WRITE ( unit=errstr, fmt='(A,I7,A,A)')
133 . 'BUFRLIB: CPYUPD - SUBSET HAS BYTE COUNT = ',ibyt,' > UPPER ',
134 . 'LIMIT OF 65535'
135 CALL errwrt(errstr)
136 CALL errwrt('>>>>>>>WILL BE COPIED INTO ITS OWN MESSAGE<<<<<<<<')
137 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
138 CALL errwrt(' ')
139 ENDIF
140 CALL msgwrt(lunit,mbay(1,lun),mbyt(lun))
141 CALL msgini(lun)
142 ENDIF
143
144C EXITS
145C -----
146
147 RETURN
148900 WRITE(bort_str,'("BUFRLIB: CPYUPD - THE LENGTH OF THIS SUBSET '//
149 . 'EXCEEDS THE MAXIMUM MESSAGE LENGTH (",I6,")")') maxbyt
150 CALL bort(bort_str)
151 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine cpyupd(LUNIT, LIN, LUN, IBYT)
THIS SUBROUTINE COPIES A SUBSET FROM ONE MESSAGE BUFFER (ARRAY MBAY IN MODULE BITBUF) TO ANOTHER AND/...
Definition: cpyupd.f:61
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:42
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
subroutine msgini(LUN)
THIS SUBROUTINE INITIALIZES, WITHIN THE INTERNAL ARRAYS, A NEW BUFR MESSAGE FOR OUTPUT.
Definition: msgini.f:58
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
subroutine mvb(IB1, NB1, IB2, NB2, NBM)
THIS SUBROUTINE COPIES A SPECIFIED NUMBER OF BYTES FROM ONE PACKED BINARY ARRAY TO ANOTHER.
Definition: mvb.f:44
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
integer maxbyt
Maximum length of an output BUFR message.
Definition: moda_bitbuf.F:22
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:25
integer, dimension(:,:), allocatable mbay
Current BUFR message for each internal I/O stream.
Definition: moda_bitbuf.F:26
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