NCEPLIBS-bufr 11.7.1
datebf.f
Go to the documentation of this file.
1C> @file
2C> @brief Read the Section 1 date-time from the first data message
3C> of a BUFR file.
4
5C> This subroutine reads and returns the Section 1 date-time from
6C> the first data message of a BUFR file, bypassing any messages
7C> at the beginning of the file which may contain embedded DX BUFR
8C> table information.
9C>
10C> @author J. Woollen
11C> @date 1994-01-06
12C>
13C> @param[in] LUNIT -- integer: Fortran logical unit number for BUFR
14C> file
15C> @param[out] MEAR -- integer: Year stored within Section 1 of
16C> first data message, in format of either
17C> YY or YYYY, depending on the most
18C> recent call to subroutine datelen()
19C> @param[out] MMON -- integer: Month stored within Section 1 of
20C> first data message
21C> @param[out] MDAY -- integer: Day stored within Section 1 of
22C> first data message
23C> @param[out] MOUR -- integer: Hour stored within Section 1 of
24C> first data message
25C> @param[out] IDATE -- integer: Date-time stored within Section 1 of
26C> first data message, in format of either
27C> YYMMDDHH or YYYYMMDDHH, depending on the most
28C> recent call to subroutine datelen()
29C>
30C> <p>Logical unit LUNIT must already be associated with a filename
31C> on the local system, typically via a Fortran "OPEN" statement.
32C>
33C> <b>Program history log:</b>
34C> | Date | Programmer | Comments |
35C> | -----|------------|----------|
36C> | 1994-01-06 | J. Woollen | Original author |
37C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine ABORT with call to new internal routine bort() |
38C> | 1998-08-31 | J. Woollen | Modified to correct an error which led to MEAR being returned as 2-digit when it was requested as 4-digit via a prior call to datelen() |
39C> | 1998-10-27 | J. Woollen | Modified to correct problems caused by in-lining code with fpp directives |
40C> | 2003-05-19 | M. Shirey | Replaced calls to Fortran insrinsic function ICHAR with the NCEP W3LIB function MOVA2I |
41C> | 2003-11-04 | D. Keyser | Modified date calculations to no longer use floating point arithmetic |
42C> | 2004-08-18 | J. Ator | Modified 'BUFR' string test for portability to EBCDIC machines |
43C> | 2004-12-20 | D. Keyser | Calls wrdlen() to initialize local machine information, in case it has not yet been called |
44C> | 2005-11-29 | J. Ator | Use igetdate(), iupbs01() and rdmsgw() |
45C> | 2009-03-23 | J. Ator | Use idxmsg() and errwrt() |
46C> | 2012-09-15 | J. Woollen | Modified for C/I/O/BUFR interface; use new openbf type 'INX' to open and close the C file without closing the Fortran file |
47C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
48C>
49 SUBROUTINE datebf(LUNIT,MEAR,MMON,MDAY,MOUR,IDATE)
50
51 USE moda_mgwa
52
53 COMMON /quiet / iprt
54
55 CHARACTER*128 ERRSTR
56
57C-----------------------------------------------------------------------
58C-----------------------------------------------------------------------
59
60C Initialization, in case OPENBF hasn't been called yet.
61
62 IF ( .NOT. ALLOCATED(mgwa) ) THEN
63 CALL openbf(lunit,'FIRST',lunit)
64 ENDIF
65
66 idate = -1
67
68C SEE IF THE FILE IS ALREADY OPEN TO BUFR INTERFACE (A NO-NO)
69C -----------------------------------------------------------
70
71 CALL status(lunit,lun,jl,jm)
72 IF(jl.NE.0) GOTO 900
73 CALL openbf(lunit,'INX',lunit)
74
75C READ TO A DATA MESSAGE AND PICK OUT THE DATE
76C --------------------------------------------
77
781 CALL rdmsgw(lunit,mgwa,ier)
79 IF(ier.LT.0) GOTO 100
80 IF(idxmsg(mgwa).EQ.1) GOTO 1
81
82 idate = igetdate(mgwa,mear,mmon,mday,mour)
83
84100 IF(iprt.GE.1 .AND. idate.EQ.-1) THEN
85 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
86 errstr = 'BUFRLIB: DATEBF - SECTION 1 DATE COULD NOT BE '//
87 . 'LOCATED - RETURN WITH IDATE = -1'
88 CALL errwrt(errstr)
89 CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
90 CALL errwrt(' ')
91 ENDIF
92
93C EXITS
94C -----
95
96 CALL closbf(lunit)
97 RETURN
98900 CALL bort
99 . ('BUFRLIB: DATEBF - INPUT BUFR FILE IS OPEN, IT MUST BE CLOSED')
100 END
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.f:35
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:50
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:42
function idxmsg(MESG)
This function determines whether a given BUFR message contains DX BUFR tables information that was ge...
Definition: idxmsg.f:24
function igetdate(MBAY, IYR, IMO, IDY, IHR)
This function returns the date-time from within Section 1 of a BUFR message.
Definition: igetdate.f:35
subroutine openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.f:139
subroutine rdmsgw(LUNIT, MESG, IRET)
THIS SUBROUTINE READS THE NEXT BUFR MESSAGE FROM LOGICAL UNIT LUNIT AS AN ARRAY OF INTEGER WORDS.
Definition: rdmsgw.f:38
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