NCEPLIBS-bufr  12.0.0
datebf.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Read the Section 1 date-time from the first data message
3 C> of a BUFR file.
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> This subroutine reads and returns the Section 1 date-time from
7 C> the first data message of a BUFR file, bypassing any messages
8 C> at the beginning of the file which may contain embedded DX BUFR
9 C> table information.
10 C>
11 C> @param[in] LUNIT -- integer: Fortran logical unit number for BUFR
12 C> file
13 C> @param[out] MEAR -- integer: Year stored within Section 1 of
14 C> first data message, in format of either
15 C> YY or YYYY, depending on the most
16 C> recent call to subroutine datelen()
17 C> @param[out] MMON -- integer: Month stored within Section 1 of
18 C> first data message
19 C> @param[out] MDAY -- integer: Day stored within Section 1 of
20 C> first data message
21 C> @param[out] MOUR -- integer: Hour stored within Section 1 of
22 C> first data message
23 C> @param[out] IDATE -- integer: Date-time stored within Section 1 of
24 C> first data message, in format of either
25 C> YYMMDDHH or YYYYMMDDHH, depending on the most
26 C> recent call to subroutine datelen()
27 C>
28 C> Logical unit LUNIT must already be associated with a filename
29 C> on the local system, typically via a Fortran "OPEN" statement.
30 C>
31 C>
32 C> @author J. Woollen @date 1994-01-06
33  RECURSIVE SUBROUTINE datebf(LUNIT,MEAR,MMON,MDAY,MOUR,IDATE)
34 
35  USE moda_mgwa
36  USE modv_im8b
37 
38  COMMON /quiet / iprt
39 
40  CHARACTER*128 errstr
41 
42 C-----------------------------------------------------------------------
43 C-----------------------------------------------------------------------
44 
45 C CHECK FOR I8 INTEGERS
46 C ---------------------
47 
48  IF(im8b) THEN
49  im8b=.false.
50 
51  CALL x84(lunit,my_lunit,1)
52  CALL datebf(my_lunit,mear,mmon,mday,mour,idate)
53  CALL x48(mear,mear,1)
54  CALL x48(mmon,mmon,1)
55  CALL x48(mday,mday,1)
56  CALL x48(mour,mour,1)
57  CALL x48(idate,idate,1)
58 
59  im8b=.true.
60  RETURN
61  ENDIF
62 
63 C Initialization, in case OPENBF hasn't been called yet.
64 C ------------------------------------------------------
65 
66  IF ( .NOT. ALLOCATED(mgwa) ) THEN
67  CALL openbf(lunit,'FIRST',lunit)
68  ENDIF
69 
70  idate = -1
71 
72 C SEE IF THE FILE IS ALREADY OPEN TO BUFR INTERFACE (A NO-NO)
73 C -----------------------------------------------------------
74 
75  CALL status(lunit,lun,jl,jm)
76  IF(jl.NE.0) GOTO 900
77  CALL openbf(lunit,'INX',lunit)
78 
79 C READ TO A DATA MESSAGE AND PICK OUT THE DATE
80 C --------------------------------------------
81 
82 1 CALL rdmsgw(lunit,mgwa,ier)
83  IF(ier.LT.0) GOTO 100
84  IF(idxmsg(mgwa).EQ.1) GOTO 1
85 
86  idate = igetdate(mgwa,mear,mmon,mday,mour)
87 
88 100 IF(iprt.GE.1 .AND. idate.EQ.-1) THEN
89  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
90  errstr = 'BUFRLIB: DATEBF - SECTION 1 DATE COULD NOT BE '//
91  . 'LOCATED - RETURN WITH IDATE = -1'
92  CALL errwrt(errstr)
93  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
94  CALL errwrt(' ')
95  ENDIF
96 
97 C EXITS
98 C -----
99 
100  CALL closbf(lunit)
101  RETURN
102 900 CALL bort
103  . ('BUFRLIB: DATEBF - INPUT BUFR FILE IS OPEN, IT MUST BE CLOSED')
104  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive subroutine closbf(LUNIT)
Close the connection between logical unit LUNIT and the NCEPLIBS-bufr software.
Definition: closbf.f:24
recursive subroutine datebf(LUNIT, MEAR, MMON, MDAY, MOUR, IDATE)
This subroutine reads and returns the Section 1 date-time from the first data message of a BUFR file,...
Definition: datebf.f:34
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
recursive function idxmsg(MESG)
Check whether a BUFR message contains DX BUFR tables information.
Definition: idxmsg.f:23
recursive function igetdate(MBAY, IYR, IMO, IDY, IHR)
This function returns the date-time from within Section 1 of a BUFR message.
Definition: igetdate.f:30
This module contains a declaration for an array used by various subroutines and functions to hold a t...
integer, dimension(:), allocatable mgwa
Temporary working copy of BUFR message.
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 openbf(LUNIT, IO, LUNDX)
Connects a new file to the NCEPLIBS-bufr software for input or output operations, or initializes the ...
Definition: openbf.f:124
subroutine rdmsgw(lunit, mesg, iret)
Read the next BUFR message from logical unit lunit as an array of integer words.
Definition: rdmsgw.F90:16
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