NCEPLIBS-bufr  11.5.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> - 1994-01-06 J. Woollen -- Original author
35 C> - 1998-07-08 J. Woollen -- Replaced call to Cray library routine ABORT
36 C> with call to new internal routine bort()
37 C> - 1998-08-31 J. Woollen -- Modified to correct an error which led to
38 C> MEAR being returned as 2-digit when it was
39 C> requested as 4-digit via a prior call to
40 C> datelen()
41 C> - 1998-10-27 J. Woollen -- Modified to correct problems caused by
42 C> in-lining code with fpp directives
43 C> - 2003-05-19 M. Shirey -- Replaced calls to Fortran insrinsic
44 C> function ICHAR with the NCEP W3LIB
45 C> function MOVA2I
46 C> - 2003-11-04 D. Keyser -- Modified date calculations to no longer
47 C> use floating point arithmetic
48 C> - 2004-08-18 J. Ator -- Modified 'BUFR' string test for portability
49 C> to EBCDIC machines
50 C> - 2004-12-20 D. Keyser -- Calls wrdlen() to initialize local machine
51 C> information, in case it has not yet been
52 C> called
53 C> - 2005-11-29 J. Ator -- Use igetdate(), iupbs01() and rdmsgw()
54 C> - 2009-03-23 J. Ator -- Use idxmsg() and errwrt()
55 C> - 2012-09-15 J. Woollen -- Modified for C/I/O/BUFR interface;
56 C> use new openbf type 'INX' to open and close
57 C> the C file without closing the Fortran file
58 C> - 2014-12-10 J. Ator -- Use modules instead of COMMON blocks
59 C>
60  SUBROUTINE datebf(LUNIT,MEAR,MMON,MDAY,MOUR,IDATE)
61 
62  USE moda_mgwa
63 
64  COMMON /quiet / iprt
65 
66  CHARACTER*128 errstr
67 
68 C-----------------------------------------------------------------------
69 C-----------------------------------------------------------------------
70 
71 C Initialization, in case OPENBF or WRDLEN haven't been called yet.
72 
73 #ifdef DYNAMIC_ALLOCATION
74  IF ( .NOT. ALLOCATED(mgwa) ) THEN
75  CALL openbf(lunit,'FIRST',lunit)
76  ENDIF
77 #else
78  CALL wrdlen
79 #endif
80 
81  idate = -1
82 
83 C SEE IF THE FILE IS ALREADY OPEN TO BUFR INTERFACE (A NO-NO)
84 C -----------------------------------------------------------
85 
86  CALL status(lunit,lun,jl,jm)
87  IF(jl.NE.0) goto 900
88  CALL openbf(lunit,'INX',lunit)
89 
90 C READ TO A DATA MESSAGE AND PICK OUT THE DATE
91 C --------------------------------------------
92 
93 1 CALL rdmsgw(lunit,mgwa,ier)
94  IF(ier.LT.0) goto 100
95  IF(idxmsg(mgwa).EQ.1) goto 1
96 
97  idate = igetdate(mgwa,mear,mmon,mday,mour)
98 
99 100 IF(iprt.GE.1 .AND. idate.EQ.-1) THEN
100  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
101  errstr = 'BUFRLIB: DATEBF - SECTION 1 DATE COULD NOT BE '//
102  . 'LOCATED - RETURN WITH IDATE = -1'
103  CALL errwrt(errstr)
104  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
105  CALL errwrt(' ')
106  ENDIF
107 
108 C EXITS
109 C -----
110 
111  CALL closbf(lunit)
112  RETURN
113 900 CALL bort
114  . ('BUFRLIB: DATEBF - INPUT BUFR FILE IS OPEN, IT MUST BE CLOSED')
115  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:29
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
Definition: closbf.F:36
subroutine openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
Definition: openbf.F:157
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
function idxmsg(MESG)
THIS FUNCTION DETERMINES WHETHER THE GIVEN BUFR MESSAGE IS A DX DICTIONARY MESSAGE THAT WAS CREATED B...
Definition: idxmsg.f:29
subroutine status(LUNIT, LUN, IL, IM)
This subroutine checks whether a specified Fortran logical unit number is currently connected to the ...
Definition: status.f:61
subroutine wrdlen
This subroutine figures out some important information about the local machine on which the BUFRLIB s...
Definition: wrdlen.F:43
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:39
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
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:60