NCEPLIBS-bufr  11.6.0
 All Data Structures Files Functions Variables Pages
cpyupd.f
Go to the documentation of this file.
1 C> @file
2 C> @author WOOLLEN @date 1994-01-06
3 
4 C> THIS SUBROUTINE COPIES A SUBSET FROM ONE MESSAGE BUFFER
5 C> (ARRAY MBAY IN MODULE BITBUF) TO ANOTHER AND/OR RESETS THE
6 C> POINTERS. IF THE SUBSET WILL NOT FIT INTO THE OUTPUT MESSAGE, OR
7 C> IF THE SUBSET BYTE COUNT EXCEEDS 65530 (SUFFICIENTLY CLOSE TO THE
8 C> 16-BIT BYTE COUNTER UPPER LIMIT OF 65535), THEN THAT MESSAGE IS
9 C> FLUSHED TO LUNIT AND A NEW ONE IS CREATED IN ORDER TO HOLD THE
10 C> COPIED SUBSET. ANY SUBSET WITH BYTE COUNT > 65530 WILL BE WRITTEN
11 C> INTO ITS OWN ONE-SUBSET MESSAGE. IF THE SUBSET TO BE COPIED IS
12 C> LARGER THAN THE MAXIMUM MESSAGE LENGTH, THEN A CALL IS ISSUED TO
13 C> BUFR ARCHIVE LIBRARY SUBROUTINE BORT.
14 C>
15 C> PROGRAM HISTORY LOG:
16 C> 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
17 C> 1998-07-08 J. WOOLLEN -- REPLACED CALL TO CRAY LIBRARY ROUTINE
18 C> "ABORT" WITH CALL TO NEW INTERNAL BUFRLIB
19 C> ROUTINE "BORT"
20 C> 1999-11-18 J. WOOLLEN -- THE NUMBER OF BUFR FILES WHICH CAN BE
21 C> OPENED AT ONE TIME INCREASED FROM 10 TO 32
22 C> (NECESSARY IN ORDER TO PROCESS MULTIPLE
23 C> BUFR FILES UNDER THE MPI)
24 C> 2000-09-19 J. WOOLLEN -- MAXIMUM MESSAGE LENGTH INCREASED FROM
25 C> 10,000 TO 20,000 BYTES
26 C> 2002-05-14 J. WOOLLEN -- REMOVED OLD CRAY COMPILER DIRECTIVES
27 C> 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
28 C> INTERDEPENDENCIES
29 C> 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED
30 C> DOCUMENTATION (INCLUDING HISTORY); OUTPUTS
31 C> MORE COMPLETE DIAGNOSTIC INFO WHEN ROUTINE
32 C> TERMINATES ABNORMALLY
33 C> 2004-08-09 J. ATOR -- MAXIMUM MESSAGE LENGTH INCREASED FROM
34 C> 20,000 TO 50,000 BYTES
35 C> 2009-03-23 J. ATOR -- USE MSGFULL
36 C> 2014-10-27 J. WOOLLEN -- ACCOUNT FOR SUBSETS WITH BYTE COUNT > 65530
37 C> (THESE MUST BE WRITTEN INTO THEIR OWN
38 C> ONE-SUBSET MESSAGE)
39 C> 2014-10-27 D. KEYSER -- FOR CASE ABOVE, DO NOT WRITE "CURRENT"
40 C> MESSAGE IF IT CONTAINS ZERO SUBSETS
41 C> 2014-12-10 J. ATOR -- USE MODULES INSTEAD OF COMMON BLOCKS
42 C> 2015-09-24 D. STOKES -- FIX MISSING DECLARATION OF COMMON /QUIET/
43 C>
44 C> USAGE: CALL CPYUPD (LUNIT, LIN, LUN, IBYT)
45 C> INPUT ARGUMENT LIST:
46 C> LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
47 C> LIN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
48 C> FOR INPUT MESSAGE LOCATION
49 C> LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
50 C> FOR OUTPUT MESSAGE LOCATION
51 C> IBYT - INTEGER: NUMBER OF BYTES OCCUPIED BY THIS SUBSET
52 C>
53 C> REMARKS:
54 C> THIS ROUTINE CALLS: BORT ERRWRT IUPB MSGFULL
55 C> MSGINI MSGWRT MVB PKB
56 C> THIS ROUTINE IS CALLED BY: COPYSB
57 C> Normally not called by any application
58 C> programs.
59 C>
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 
73 C-----------------------------------------------------------------------
74 C-----------------------------------------------------------------------
75 
76 C CHECK WHETHER THE NEW SUBSET SHOULD BE WRITTEN INTO THE CURRENTLY
77 C OPEN MESSAGE
78 C -----------------------------------------------------------------
79 
80  IF(msgfull(mbyt(lun),ibyt,maxbyt)
81  . .OR.
82  . ((ibyt.GT.65530).AND.(nsub(lun).GT.0))) THEN
83 c NO it should not, either because:
84 c 1) it doesn't fit,
85 c -- OR --
86 c 2) it has byte count > 65530 (sufficiently close to the
87 c upper limit for the 16 bit byte counter placed at the
88 c beginning of each subset), AND the current message has
89 c at least one subset in it,
90 c SO write the current message out and create a new one to
91 c 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 
98 C TRANSFER SUBSET FROM ONE MESSAGE TO THE OTHER
99 C ---------------------------------------------
100 
101 C Note that we want to append the data for this subset to the end
102 C of Section 4, but the value in MBYT(LUN) already includes the
103 C length of Section 5 (i.e. 4 bytes). Therefore, we need to begin
104 C writing at the point 3 bytes prior to the byte currently pointed
105 C to by MBYT(LUN).
106 
107  CALL mvb(mbay(1,lin),mbyt(lin)+1,mbay(1,lun),mbyt(lun)-3,ibyt)
108 
109 C UPDATE THE SUBSET AND BYTE COUNTERS
110 C --------------------------------------
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 
123 C IF THE SUBSET BYTE COUNT IS > 65530, THEN GIVE IT ITS OWN ONE-SUBSET
124 C MESSAGE (CANNOT HAVE ANY OTHER SUBSETS IN THIS MESSAGE BECAUSE THEIR
125 C BEGINNING WOULD BE BEYOND THE UPPER LIMIT OF 65535 IN THE 16-BIT
126 C BYTE COUNTER, MEANING THEY COULD NOT BE LOCATED!)
127 C --------------------------------------------------------------------
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 
144 C EXITS
145 C -----
146 
147  RETURN
148 900 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 msgwrt(LUNIT, MESG, MGBYT)
This subroutine performs final checks and updates on a BUFR message before writing it to a specified ...
Definition: msgwrt.f:54
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:43
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:36
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:60
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:25
subroutine msgini(LUN)
THIS SUBROUTINE INITIALIZES, WITHIN THE INTERNAL ARRAYS, A NEW BUFR MESSAGE FOR OUTPUT.
Definition: msgini.f:57
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:41
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22
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:38
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10