NCEPLIBS-bufr 11.7.1
closmg.f
Go to the documentation of this file.
1C> @file
2C> @brief Close and write the current message to a BUFR file that was
3C> previously opened for writing.
4
5C> This subroutine closes the BUFR message that is currently open for
6C> writing within internal arrays associated with logical unit
7C> ABS(LUNIN), and it then writes the message to that logical unit.
8C>
9C> @authors J. Woollen
10C> @authors D. Keyser
11C> @date 1994-01-06
12C>
13C> @param[in] LUNIN -- integer: Absolute value is Fortran logical unit
14C> number for BUFR file
15C>
16C> <p>Logical unit ABS(LUNIN) should have already been opened for output
17C> operations via a previous call to subroutine openbf().
18C>
19C> <p>If LUNIN < 0, then any message containing zero data subsets will
20C> not be written to logical unit ABS(LUNIN) for the remainder of the
21C> life of the application program. This includes suppressing the
22C> writing of any dummy messages containing dump center and initiation
23C> times that normally appear in the first 2 messages of NCEP dump files.
24C>
25C> <b>Program history log:</b>
26C> | Date | Programmer | Comments |
27C> | -----|------------|----------|
28C> | 1994-01-06 | J. Woollen | Original author |
29C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine "ABORT" with call to new internal routine bort(); modified to make Y2K compliant |
30C> | 1999-11-18 | J. Woollen | The number of BUFR files which can be opened at one time increased from 10 to 32 (necessary in order to process multiple BUFR files under the MPI) |
31C> | 2000-09-19 | J. Woollen | Maximum message length increased from 10,000 to 20,000 bytes |
32C> | 2003-05-19 | J. Woollen | Corrected a bug which prevented the dump center and initiation time messages from being written out |
33C> | 2003-11-04 | J. Ator | Added documentation |
34C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
35C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added history documentation; outputs more complete diagnostic info when routine terminates abnormally |
36C> | 2004-08-09 | J. Ator | Maximum message length increased from 20,000 to 50,000 bytes |
37C> | 2005-05-26 | D. Keyser | Add LUNIN < 0 option to suppress writing of all future zero-subset messsages to ABS(LUNIN) |
38C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
39C>
40 SUBROUTINE closmg(LUNIN)
41
42 USE moda_msgcwd
43 USE moda_msglim
44 USE moda_bitbuf
45
46C-----------------------------------------------------------------------
47C-----------------------------------------------------------------------
48
49C CHECK THE FILE STATUS
50C ---------------------
51
52 lunit = abs(lunin)
53 CALL status(lunit,lun,il,im)
54 IF(lunit.NE.lunin) msglim(lun) = 0
55 IF(il.EQ.0) GOTO 900
56 IF(il.LT.0) GOTO 901
57 IF(im.NE.0) THEN
58 IF(nsub(lun).GT.0) THEN
59 CALL msgwrt(lunit,mbay(1,lun),mbyt(lun))
60 ELSE IF(nsub(lun).EQ.0.AND.nmsg(lun).LT.msglim(lun)) THEN
61 CALL msgwrt(lunit,mbay(1,lun),mbyt(lun))
62 ELSE IF(nsub(lun).LT.0) THEN
63 CALL wrcmps(-lunit)
64 ENDIF
65 ENDIF
66 CALL wtstat(lunit,lun,il,0)
67
68C EXITS
69C -----
70
71 RETURN
72900 CALL bort('BUFRLIB: CLOSMG - OUTPUT BUFR FILE IS CLOSED, IT '//
73 . 'MUST BE OPEN FOR OUTPUT')
74901 CALL bort('BUFRLIB: CLOSMG - OUTPUT BUFR FILE IS OPEN FOR '//
75 . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
76 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine closmg(LUNIN)
This subroutine closes the BUFR message that is currently open for writing within internal arrays ass...
Definition: closmg.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 BUFR messages internally for multi...
Definition: moda_bitbuf.F:10
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 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 wrcmps(LUNIX)
THIS SUBROUTINE PACKS UP THE CURRENT SUBSET WITHIN MEMORY (ARRAY IBAY IN MODULE BITBUF),...
Definition: wrcmps.f:81
subroutine wtstat(LUNIT, LUN, IL, IM)
This subroutine can be used to connect or disconnect a specified Fortran logical unit number to/from ...
Definition: wtstat.f:53