NCEPLIBS-bufr  11.6.0
 All Data Structures Files Functions Variables Pages
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 
5 C> This subroutine reads and returns the Section 1 date-time from
6 C> the first data message of a BUFR file, bypassing any messages
7 C> at the beginning of the file which may contain embedded DX BUFR
8 C> table information.
9 C>
10 C> @author J. Woollen
11 C> @date 1994-01-06
12 C>
13 C> @param[in] LUNIT -- integer: Fortran logical unit number for BUFR
14 C> file
15 C> @param[out] MEAR -- integer: Year stored within Section 1 of
16 C> first data message, in format of either
17 C> YY or YYYY, depending on the most
18 C> recent call to subroutine datelen()
19 C> @param[out] MMON -- integer: Month stored within Section 1 of
20 C> first data message
21 C> @param[out] MDAY -- integer: Day stored within Section 1 of
22 C> first data message
23 C> @param[out] MOUR -- integer: Hour stored within Section 1 of
24 C> first data message
25 C> @param[out] IDATE -- integer: Date-time stored within Section 1 of
26 C> first data message, in format of either
27 C> YYMMDDHH or YYYYMMDDHH, depending on the most
28 C> recent call to subroutine datelen()
29 C>
30 C> <p>Logical unit LUNIT must already be associated with a filename
31 C> on the local system, typically via a Fortran "OPEN" statement.
32 C>
33 C> <b>Program history log:</b>
34 C> | Date | Programmer | Comments |
35 C> | -----|------------|----------|
36 C> | 1994-01-06 | J. Woollen | Original author |
37 C> | 1998-07-08 | J. Woollen | Replaced call to Cray library routine ABORT with call to new internal routine bort() |
38 C> | 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() |
39 C> | 1998-10-27 | J. Woollen | Modified to correct problems caused by in-lining code with fpp directives |
40 C> | 2003-05-19 | M. Shirey | Replaced calls to Fortran insrinsic function ICHAR with the NCEP W3LIB function MOVA2I |
41 C> | 2003-11-04 | D. Keyser | Modified date calculations to no longer use floating point arithmetic |
42 C> | 2004-08-18 | J. Ator | Modified 'BUFR' string test for portability to EBCDIC machines |
43 C> | 2004-12-20 | D. Keyser | Calls wrdlen() to initialize local machine information, in case it has not yet been called |
44 C> | 2005-11-29 | J. Ator | Use igetdate(), iupbs01() and rdmsgw() |
45 C> | 2009-03-23 | J. Ator | Use idxmsg() and errwrt() |
46 C> | 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 |
47 C> | 2014-12-10 | J. Ator | Use modules instead of COMMON blocks |
48 C>
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 
57 C-----------------------------------------------------------------------
58 C-----------------------------------------------------------------------
59 
60 C 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 
68 C SEE IF THE FILE IS ALREADY OPEN TO BUFR INTERFACE (A NO-NO)
69 C -----------------------------------------------------------
70 
71  CALL status(lunit,lun,jl,jm)
72  IF(jl.NE.0) goto 900
73  CALL openbf(lunit,'INX',lunit)
74 
75 C READ TO A DATA MESSAGE AND PICK OUT THE DATE
76 C --------------------------------------------
77 
78 1 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 
84 100 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 
93 C EXITS
94 C -----
95 
96  CALL closbf(lunit)
97  RETURN
98 900 CALL bort
99  . ('BUFRLIB: DATEBF - INPUT BUFR FILE IS OPEN, IT MUST BE CLOSED')
100  END
function igetdate(MBAY, IYR, IMO, IDY, IHR)
This function returns the date-time from within Section 1 of a BUFR message.
Definition: igetdate.f:34
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:37
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.f:34
function idxmsg(MESG)
This function determines whether a given BUFR message contains DX BUFR tables information that was ge...
Definition: idxmsg.f:23
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:55
subroutine openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.f:138
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:49
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:41
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22