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