NCEPLIBS-bufr  12.0.1
status.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Check whether a file is connected to the NCEPLIBS-bufr software.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> Check whether a specified Fortran logical unit
7 C> number is currently connected to the NCEPLIBS-bufr software.
8 C>
9 C> If the unit number is already connected, then the subroutine
10 C> returns information about the associated file. Otherwise, it
11 C> returns the next available file ID that could
12 C> be used to connect the associated file to the software via a
13 C> subsequent call to subroutine wtstat().
14 C>
15 C> @param[in] LUNIT - integer: Fortran logical unit number for
16 C> BUFR file.
17 C> @param[out] LUN - integer: File ID associated with LUNIT.
18 C> - 0 = LUNIT is not already connected to the software, <b>and</b>
19 C> there is no remaining internal space available that could be used
20 C> to connect it.
21 C> @param[out] IL - integer: File status:
22 C> - 0 = LUNIT is not already connected to the software, but LUN
23 C> contains a file ID that could be used to connect it via a subsequent
24 C> call to subroutine wtstat().
25 C> - 1 = LUNIT is already connected to the software for output
26 C> operations (i.e. writing/encoding BUFR).
27 C> - -1 = LUNIT is already connected to the software for input
28 C> operations (i.e. reading/decoding BUFR).
29 C> @param[out] IM - integer: Message status, indicating whether
30 C> there is already a message open within internal arrays for LUNIT.
31 C> - 0 = No
32 C> - 1 = Yes
33 C>
34 C> @author J. Woollen @date 1994-01-06
35  RECURSIVE SUBROUTINE status(LUNIT,LUN,IL,IM)
36 
37  USE modv_nfiles
38  USE modv_im8b
39 
40  USE moda_stbfr
41 
42  CHARACTER*128 bort_str, errstr
43 
44 C-----------------------------------------------------------------------
45 C-----------------------------------------------------------------------
46 
47 C CHECK FOR I8 INTEGERS
48 C ---------------------
49 
50  IF(im8b) THEN
51  im8b=.false.
52 
53  CALL x84(lunit,my_lunit,1)
54  CALL status(my_lunit,lun,il,im)
55  CALL x48(lun,lun,1)
56  CALL x48(il,il,1)
57  CALL x48(im,im,1)
58 
59  im8b=.true.
60  RETURN
61  ENDIF
62 
63  IF(lunit.LE.0 .OR. lunit.GT.99) GOTO 900
64 
65 C CLEAR THE STATUS INDICATORS
66 C ---------------------------
67 
68  lun = 0
69  il = 0
70  im = 0
71 
72 C SEE IF UNIT IS ALREADY CONNECTED TO BUFR ARCHIVE LIBRARY SOFTWARE
73 C -----------------------------------------------------------------
74 
75  IF ( .NOT. ALLOCATED(iolun) ) THEN
76  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
77  errstr = 'BUFRLIB: STATUS WAS CALLED WITHOUT HAVING ' //
78  . 'PREVIOUSLY CALLED OPENBF'
79  CALL errwrt(errstr)
80  CALL errwrt('++++++++++++++++++++WARNING++++++++++++++++++++++')
81  RETURN
82  ENDIF
83 
84  DO i=1,nfiles
85  IF(abs(iolun(i)).EQ.lunit) lun = i
86  ENDDO
87 
88 C IF NOT, TRY TO DEFINE IT SO AS TO CONNECT IT TO BUFR ARCHIVE LIBRARY
89 C SOFTWARE
90 C --------------------------------------------------------------------
91 
92  IF(lun.EQ.0) THEN
93  DO i=1,nfiles
94  IF(iolun(i).EQ.0) THEN
95 
96 C File space is available, return with LUN > 0, IL and IM remain 0
97 C ----------------------------------------------------------------
98 
99  lun = i
100  GOTO 100
101  ENDIF
102  ENDDO
103 
104 C File space is NOT available, return with LUN, IL and IM all 0
105 C -------------------------------------------------------------
106 
107  GOTO 100
108  ENDIF
109 
110 C IF THE UNIT WAS ALREADY CONNECTED TO THE BUFR ARCHIVE LIBRARY
111 C SOFTWARE PRIOR TO THIS CALL, RETURN STATUSES
112 C -------------------------------------------------------------
113 
114  il = sign(1,iolun(lun))
115  im = iomsg(lun)
116 
117 C EXITS
118 C ----
119 
120 100 RETURN
121 900 WRITE(bort_str,'("BUFRLIB: STATUS - INPUT UNIT NUMBER (",I3,") '//
122  . 'OUTSIDE LEGAL RANGE OF 1-99")') lunit
123  CALL bort(bort_str)
124  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
This module contains array declarations used to store file and message status indicators for all logi...
integer, dimension(:), allocatable iolun
File status indicators.
integer, dimension(:), allocatable iomsg
Message status indicator corresponding to iolun, denoting whether a BUFR message is currently open wi...
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 ...
This module declares and initializes the NFILES variable.
integer, public nfiles
Maximum number of BUFR files that can be connected to the BUFRLIB software (for reading or writing) a...
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 x48(IIN4, IOUT8, NVAL)
Encode one or more 4-byte integer values as 8-byte integer values.
Definition: x48.F:19
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19