NCEPLIBS-bufr  11.7.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> | Date | Programmer | Comments |
27 C> | -----|------------|----------|
28 C> | 1994-01-06 | J. Woollen | Original author |
29 C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine "ABORT" with call to new internal routine bort(); modified to make Y2K compliant |
30 C> | 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) |
31 C> | 2000-09-19 | J. Woollen | Maximum message length increased from 10,000 to 20,000 bytes |
32 C> | 2003-05-19 | J. Woollen | Corrected a bug which prevented the dump center and initiation time messages from being written out |
33 C> | 2003-11-04 | J. Ator | Added documentation |
34 C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
35 C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added history documentation; outputs more complete diagnostic info when routine terminates abnormally |
36 C> | 2004-08-09 | J. Ator | Maximum message length increased from 20,000 to 50,000 bytes |
37 C> | 2005-05-26 | D. Keyser | Add LUNIN < 0 option to suppress writing of all future zero-subset messsages to ABS(LUNIN) |
38 C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
39 C>
40  SUBROUTINE closmg(LUNIN)
41 
42  USE moda_msgcwd
43  USE moda_msglim
44  USE moda_bitbuf
45 
46 C-----------------------------------------------------------------------
47 C-----------------------------------------------------------------------
48 
49 C CHECK THE FILE STATUS
50 C ---------------------
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 
68 C EXITS
69 C -----
70 
71  RETURN
72 900 CALL bort('BUFRLIB: CLOSMG - OUTPUT BUFR FILE IS CLOSED, IT '//
73  . 'MUST BE OPEN FOR OUTPUT')
74 901 CALL bort('BUFRLIB: CLOSMG - OUTPUT BUFR FILE IS OPEN FOR '//
75  . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
76  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 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:52
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:55
subroutine closmg(LUNIN)
This subroutine closes the BUFR message that is currently open for writing within internal arrays ass...
Definition: closmg.f:40
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22
This module contains array and variable declarations used to store BUFR messages internally for multi...
Definition: moda_bitbuf.F:10