NCEPLIBS-bufr  11.5.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> - 1994-01-06 J. Woollen -- Original author
25 C> - 2003-11-04 J. Ator -- Don't close lunit if opened as a NULL file
26 C> by openbf()
27 C> - 2003-11-04 S. Bender -- Added remarks and routine interdependencies
28 C> - 2003-11-04 D. Keyser -- Unified/portable for WRF; added history
29 C> documentation
30 C> - 2012-09-15 J. Woollen -- Modified for C/I/O/BUFR interface;
31 C> added call to closfb() to close C files
32 C> - 2014-12-10 J. Ator -- Use modules instead of COMMON blocks
33 C> - 2020-07-16 J. Ator -- Add sanity check to ensure that openbf()
34 C> was previously called (needed for GSI)
35 C>
36  SUBROUTINE closbf(LUNIT)
37 
38  USE moda_nulbfr
39 
40  CHARACTER*128 errstr
41 
42 C-----------------------------------------------------------------------
43 C-----------------------------------------------------------------------
44 
45 #ifdef DYNAMIC_ALLOCATION
46  IF ( .NOT. ALLOCATED(null) ) THEN
47  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
48  errstr = 'BUFRLIB: CLOSBF WAS CALLED WITHOUT HAVING ' //
49  . 'PREVIOUSLY CALLED OPENBF'
50  CALL errwrt(errstr)
51  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
52  RETURN
53  ENDIF
54 #endif
55 
56  CALL status(lunit,lun,il,im)
57  IF(il.GT.0 .AND. im.NE.0) CALL closmg(lunit)
58  IF(il.NE.0 .AND. null(lun).EQ.0) CALL closfb(lun)
59  CALL wtstat(lunit,lun,0,0)
60 
61 C CLOSE fortran UNIT IF NULL(LUN) = 0
62 C -----------------------------------
63 
64  IF(null(lun).EQ.0) CLOSE(lunit)
65 
66  RETURN
67  END
void closfb(f77int *nfile)
This subroutine closes a previously opened BUFR file.
Definition: cread.c:104
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.F:36
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 errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:39