NCEPLIBS-bufr  12.0.1
closbf.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Close a previously opened file and disconnect it from
3 C> the NCEPLIBS-bufr software.
4 C>
5 C> @author J. Woollen, J. Ator @date 1994-01-06
6 
7 C> Close the connection between logical unit
8 C> LUNIT and the NCEPLIBS-bufr software.
9 C>
10 C> @remarks
11 C> - This subroutine will execute a Fortran "CLOSE" on logical unit LUNIT,
12 C> even though subroutine openbf() didn't previously handle the corresponding
13 C> Fortran "OPEN" of the same file.
14 C> - It's a good idea to call this subroutine for every LUNIT that was
15 C> opened to the software via openbf(); however, it's especially
16 C> important to do so when writing/encoding a BUFR file, in order to
17 C> ensure that all output is properly flushed to LUNIT.
18 C>
19 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
20 C>
21 C> @author J. Woollen, J. Ator @date 1994-01-06
22 
23  RECURSIVE SUBROUTINE closbf(LUNIT)
24 
25  use bufrlib
26 
27  USE moda_nulbfr
28  USE modv_im8b
29 
30  CHARACTER*128 errstr
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(lunit,my_lunit,1)
42  CALL closbf(my_lunit)
43 
44  im8b=.true.
45  RETURN
46  ENDIF
47 
48  IF ( .NOT. ALLOCATED(null) ) THEN
49  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
50  errstr = 'BUFRLIB: CLOSBF WAS CALLED WITHOUT HAVING ' //
51  . 'PREVIOUSLY CALLED OPENBF'
52  CALL errwrt(errstr)
53  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
54  RETURN
55  ENDIF
56 
57  CALL status(lunit,lun,il,im)
58  IF(il.GT.0 .AND. im.NE.0) CALL closmg(lunit)
59  IF(il.NE.0 .AND. null(lun).EQ.0) CALL closfb_c(lun)
60  CALL wtstat(lunit,lun,0,0)
61 
62 C CLOSE fortran UNIT IF NULL(LUN) = 0
63 C -----------------------------------
64 
65  IF(null(lun).EQ.0) CLOSE(lunit)
66 
67  RETURN
68  END
recursive subroutine closbf(LUNIT)
Close the connection between logical unit LUNIT and the NCEPLIBS-bufr software.
Definition: closbf.f:24
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 errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
Wrap C NCEPLIBS-bufr functions so they can be called from within the Fortran part of the library.
Definition: bufrlib.F90:11
This module contains an array declaration used to store a switch for each internal I/O stream index,...
integer, dimension(:), allocatable null
Output switch for each internal 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 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