NCEPLIBS-bufr  11.6.0
 All Data Structures Files Functions Variables Pages
closbf.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Close a previously opened system file and disconnect it from
3 C> the BUFRLIB software.
4 
5 C> This subroutine closes the connection between logical unit
6 C> LUNIT and the BUFRLIB software.
7 C>
8 C> @authors J. Woollen
9 C> @authors J. Ator
10 C> @date 1994-01-06
11 C>
12 C> @param[in] LUNIT -- integer: Fortran logical unit number for BUFR file
13 C>
14 C> @remarks
15 C> - This subroutine will execute a Fortran "CLOSE" on logical unit LUNIT,
16 C> even though subroutine openbf() didn't previously handle the corresponding
17 C> Fortran "OPEN" of the same file.
18 C> - It's a good idea to call this subroutine for every LUNIT that was
19 C> opened to the software via openbf(); however, it's especially
20 C> important to do so when writing/encoding a BUFR file, in order to
21 C> ensure that all output is properly flushed to LUNIT.
22 C>
23 C> <b>Program history log:</b>
24 C> | Date | Programmer | Comments |
25 C> | -----|------------|----------|
26 C> | 1994-01-06 | J. Woollen | Original author |
27 C> | 2003-11-04 | J. Ator | Don't close lunit if opened as a NULL file by openbf() |
28 C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
29 C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added history documentation |
30 C> | 2012-09-15 | J. Woollen | Modified for C/I/O/BUFR interface; added call to closfb() to close C files |
31 C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
32 C> | 2020-07-16 | J. Ator | Add sanity check to ensure that openbf() was previously called (needed for GSI) |
33 C>
34  SUBROUTINE closbf(LUNIT)
35 
36  USE moda_nulbfr
37 
38  CHARACTER*128 errstr
39 
40 C-----------------------------------------------------------------------
41 C-----------------------------------------------------------------------
42 
43  IF ( .NOT. ALLOCATED(null) ) THEN
44  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
45  errstr = 'BUFRLIB: CLOSBF WAS CALLED WITHOUT HAVING ' //
46  . 'PREVIOUSLY CALLED OPENBF'
47  CALL errwrt(errstr)
48  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
49  RETURN
50  ENDIF
51 
52  CALL status(lunit,lun,il,im)
53  IF(il.GT.0 .AND. im.NE.0) CALL closmg(lunit)
54  IF(il.NE.0 .AND. null(lun).EQ.0) CALL closfb(lun)
55  CALL wtstat(lunit,lun,0,0)
56 
57 C CLOSE fortran UNIT IF NULL(LUN) = 0
58 C -----------------------------------
59 
60  IF(null(lun).EQ.0) CLOSE(lunit)
61 
62  RETURN
63  END
void closfb(f77int *nfile)
This subroutine closes a previously opened BUFR file.
Definition: cread.c:116
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.f:34
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 errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:41