NCEPLIBS-bufr  12.0.1
closmg.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Close and write the current message to a BUFR file that was
3 C> previously opened for writing.
4 C>
5 C> @author J. Woollen, D. Keyser @date 1994-01-06
6 
7 C> This subroutine closes the BUFR message that is currently open for
8 C> writing within internal arrays associated with logical unit
9 C> ABS(LUNIN), and it then writes the message to that logical unit.
10 C>
11 C> Logical unit ABS(LUNIN) should have already been opened for output
12 C> operations via a previous call to subroutine openbf().
13 C>
14 C> If LUNIN < 0, then any message containing zero data subsets will
15 C> not be written to logical unit ABS(LUNIN) for the remainder of the
16 C> life of the application program. This includes suppressing the
17 C> writing of any "dummy" messages containing dump center and initiation
18 C> times that normally appear in the first 2 messages of NCEP dump files.
19 C>
20 C> @param[in] LUNIN - integer: Absolute value is Fortran logical unit
21 C> number for BUFR file
22 C>
23 C> @author J. Woollen, D. Keyser @date 1994-01-06
24 
25  RECURSIVE SUBROUTINE closmg(LUNIN)
26 
27  USE moda_msgcwd
28  USE moda_msglim
29  USE moda_bitbuf
30  USE modv_im8b
31 
32 C-----------------------------------------------------------------------
33 C-----------------------------------------------------------------------
34 
35 C CHECK FOR I8 INTEGERS
36 C ---------------------
37 
38  IF(im8b) THEN
39  im8b=.false.
40 
41  CALL x84(lunin,my_lunin,1)
42  CALL closmg(my_lunin)
43 
44  im8b=.true.
45  RETURN
46  ENDIF
47 
48 C CHECK THE FILE STATUS
49 C ---------------------
50 
51  lunit = abs(lunin)
52  CALL status(lunit,lun,il,im)
53  IF(lunit.NE.lunin) msglim(lun) = 0
54  IF(il.EQ.0) GOTO 900
55  IF(il.LT.0) GOTO 901
56  IF(im.NE.0) THEN
57  IF(nsub(lun).GT.0) THEN
58  CALL msgwrt(lunit,mbay(1,lun),mbyt(lun))
59  ELSE IF(nsub(lun).EQ.0.AND.nmsg(lun).LT.msglim(lun)) THEN
60  CALL msgwrt(lunit,mbay(1,lun),mbyt(lun))
61  ELSE IF(nsub(lun).LT.0) THEN
62  CALL wrcmps(-lunit)
63  ENDIF
64  ENDIF
65  CALL wtstat(lunit,lun,il,0)
66 
67 C EXITS
68 C -----
69 
70  RETURN
71 900 CALL bort('BUFRLIB: CLOSMG - OUTPUT BUFR FILE IS CLOSED, IT '//
72  . 'MUST BE OPEN FOR OUTPUT')
73 901 CALL bort('BUFRLIB: CLOSMG - OUTPUT BUFR FILE IS OPEN FOR '//
74  . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
75  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive subroutine closmg(LUNIN)
This subroutine closes the BUFR message that is currently open for writing within internal arrays ass...
Definition: closmg.f:26
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 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.
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each internal I/O stream.
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.
integer, dimension(:), allocatable nsub
Current subset pointer within message.
This module contains a declaration for an array used to keep track of which logical units should not ...
integer, dimension(:), allocatable msglim
Tracking index for each I/O stream index.
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 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 wrcmps(LUNIX)
This subroutine packs up the current subset within memory (array ibay in module moda_bitbuf),...
Definition: wrcmps.f:23
subroutine wtstat(LUNIT, LUN, IL, IM)
Update file status in library internals.
Definition: wtstat.f:37
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19