NCEPLIBS-bufr 11.7.1
status.f
Go to the documentation of this file.
1C> @file
2C> @brief Check whether a system file is connected to the BUFRLIB
3C> software.
4
5C> This subroutine checks whether a specified Fortran logical unit
6C> number is currently connected to the BUFRLIB software.
7C>
8C> <p>If the unit number is already connected, then the subroutine
9C> returns information about the associated file. Otherwise, it
10C> returns the next available internal I/O stream index that could
11C> be used to connect the associated file to the software via a
12C> subsequent call to subroutine wtstat().
13C>
14C> @author J. Woollen
15C> @date 1994-01-06
16C>
17C> @param[in] LUNIT -- integer: Fortran logical unit number for
18C> BUFR file
19C> @param[out] LUN -- integer: Internal I/O stream index associated
20C> with LUNIT
21C> - 0 = LUNIT is not already connected to the
22C> software, <b>and</b> there is no
23C> remaining internal space available
24C> that could be used to connect it
25C> @param[out] IL -- integer: File status
26C> - 0 = LUNIT is not already connected to the
27C> software, but LUN contains a new
28C> internal I/O stream index that could
29C> be used to connect it via a subsequent
30C> call to subroutine wtstat()
31C> - 1 = LUNIT is already connected to the
32C> software for output operations
33C> (i.e. writing/encoding BUFR)
34C> - -1 = LUNIT is already connected to the
35C> software for input operations
36C> (i.e. reading/decoding BUFR)
37C> @param[out] IM -- integer: Message status, indicating whether
38C> there is already a message open within
39C> internal arrays for LUNIT
40C> - 0 = No
41C> - 1 = Yes
42C>
43C> <b>Program history log:</b>
44C> | Date | Programmer | Comments |
45C> | -----|------------|----------|
46C> | 1994-01-06 | J. Woollen | Original author |
47C> | 1996-12-11 | J. Woollen | Fixed a long standing bug which occurs in unusual situations, very low impact |
48C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine ABORT with call to new internal routine bort() |
49C> | 1999-11-18 | J. Woollen | The number of BUFR files which can be opened at one time increased from 10 to 32 |
50C> | 2003-11-04 | J. Ator | Added documentation |
51C> | 2003-11-04 | S. Bender | Added remarks and routine interdependencies |
52C> | 2003-11-04 | D. Keyser | Unified/portable for WRF; added documentation; outputs more complete diagnostic info when routine terminates abnormally |
53C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
54C>
55 SUBROUTINE status(LUNIT,LUN,IL,IM)
56
57 USE modv_nfiles
58
59 USE moda_stbfr
60
61 CHARACTER*128 BORT_STR
62
63C-----------------------------------------------------------------------
64C-----------------------------------------------------------------------
65
66 IF(lunit.LE.0 .OR. lunit.GT.99) GOTO 900
67
68C CLEAR THE STATUS INDICATORS
69C ---------------------------
70
71 lun = 0
72 il = 0
73 im = 0
74
75C SEE IF UNIT IS ALREADY CONNECTED TO BUFR ARCHIVE LIBRARY SOFTWARE
76C -----------------------------------------------------------------
77
78 DO i=1,nfiles
79 IF(abs(iolun(i)).EQ.lunit) lun = i
80 ENDDO
81
82C IF NOT, TRY TO DEFINE IT SO AS TO CONNECT IT TO BUFR ARCHIVE LIBRARY
83C SOFTWARE
84C --------------------------------------------------------------------
85
86 IF(lun.EQ.0) THEN
87 DO i=1,nfiles
88 IF(iolun(i).EQ.0) THEN
89
90C File space is available, return with LUN > 0, IL and IM remain 0
91C ----------------------------------------------------------------
92
93 lun = i
94 GOTO 100
95 ENDIF
96 ENDDO
97
98C File space is NOT available, return with LUN, IL and IM all 0
99C -------------------------------------------------------------
100
101 GOTO 100
102 ENDIF
103
104C IF THE UNIT WAS ALREADY CONNECTED TO THE BUFR ARCHIVE LIBRARY
105C SOFTWARE PRIOR TO THIS CALL, RETURN STATUSES
106C -------------------------------------------------------------
107
108 il = sign(1,iolun(lun))
109 im = iomsg(lun)
110
111C EXITS
112C ----
113
114100 RETURN
115900 WRITE(bort_str,'("BUFRLIB: STATUS - INPUT UNIT NUMBER (",I3,") '//
116 . 'OUTSIDE LEGAL RANGE OF 1-99")') lunit
117 CALL bort(bort_str)
118 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
This module declares and initializes the NFILES variable.
Definition: modv_NFILES.f90:12
integer, public nfiles
Maximum number of BUFR files that can be connected to the BUFRLIB software (for reading or writing) a...
Definition: modv_NFILES.f90:17
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:56