NCEPLIBS-bufr  12.0.1
openmb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Open a new message for output in a BUFR file that was
3 C> previously opened for writing.
4 C>
5 C> @author J. Woollen @date 1994-01-06
6 
7 C> Open a new message for output in a BUFR file that was
8 C> previously opened for writing.
9 C>
10 C> This subroutine opens and initializes a new BUFR message within
11 C> internal arrays, for eventual output to logical unit LUNIT.
12 C>
13 C> Logical unit LUNIT should have already been opened for output
14 C> operations via a previous call to subroutine openbf().
15 C>
16 C> This subroutine is similar to subroutine openmg(), except that it
17 C> will only open a new message if either SUBSET or JDATE has changed
18 C> since the previous call to this subroutine. Otherwise, it will
19 C> leave the existing internal message unchanged so that the next data
20 C> subset can be written into the same internal message, thereby
21 C> improving overall storage efficiency by allowing the maximum number
22 C> of data subsets to be stored within each output BUFR message. For
23 C> this reason, openmb() is much more widely used than openmg().
24 C>
25 C> If this subroutine does need to open and initialize a new BUFR
26 C> message for output (e.g. if the value of SUBSET or JDATE has changed
27 C> since the previous call to this subroutine), then any existing
28 C> message within the internal arrays will be automatically flushed and
29 C> written to logical unit LUNIT via an internal call to subroutine
30 C> closmg(). In this case, the behavior of this subroutine then
31 C> becomes exactly like that of subroutine openmg().
32 C>
33 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
34 C> @param[in] SUBSET - character*(*): Table A mnemonic for type of BUFR
35 C> BUFR message to be opened (see [DX BUFR Tables](@ref dfbftab) for
36 C> further information about Table A mnemonics)
37 C> @param[in] JDATE - integer: Date-time to be stored within Section 1 of
38 C> BUFR message being opened, in format of either YYMMDDHH or YYYYMMDDHH.
39 C>
40 C> @author J. Woollen @date 1994-01-06
41  RECURSIVE SUBROUTINE openmb(LUNIT,SUBSET,JDATE)
42 
43  USE moda_msgcwd
44  USE modv_im8b
45 
46  CHARACTER*(*) subset
47  LOGICAL open
48 
49 C-----------------------------------------------------------------------
50 C-----------------------------------------------------------------------
51 
52 C CHECK FOR I8 INTEGERS
53 C ---------------------
54 
55  IF(im8b) THEN
56  im8b=.false.
57 
58  CALL x84(lunit,my_lunit,1)
59  CALL x84(jdate,my_jdate,1)
60  CALL openmb(my_lunit,subset,my_jdate)
61 
62  im8b=.true.
63  RETURN
64  ENDIF
65 
66 C CHECK THE FILE STATUS
67 C ---------------------
68 
69  CALL status(lunit,lun,il,im)
70  IF(il.EQ.0) GOTO 900
71  IF(il.LT.0) GOTO 901
72 
73 C GET SOME SUBSET PARTICULARS
74 C ---------------------------
75 
76 c .... Given SUBSET, returns MTYP,MSTB,INOD
77  CALL nemtba(lun,subset,mtyp,mstb,inod)
78  OPEN = im.EQ.0.OR.inod.NE.inode(lun).OR.i4dy(jdate).NE.idate(lun)
79 
80 C MAYBE(?) OPEN A NEW OR DIFFERENT TYPE OF MESSAGE
81 C ------------------------------------------------
82 
83  IF(open) THEN
84  CALL closmg(lunit)
85  CALL wtstat(lunit,lun,il, 1)
86 c .... Set pos. index for new Tbl A mnem.
87  inode(lun) = inod
88 c .... Set date for new message
89  idate(lun) = i4dy(jdate)
90 
91 C INITIALIZE THE OPEN MESSAGE
92 C ---------------------------
93 
94  CALL msgini(lun)
95  CALL usrtpl(lun,1,1)
96  ENDIF
97 
98 C EXITS
99 C -----
100 
101  RETURN
102 900 CALL bort('BUFRLIB: OPENMB - OUTPUT BUFR FILE IS CLOSED, IT '//
103  . 'MUST BE OPEN FOR OUTPUT')
104 901 CALL bort('BUFRLIB: OPENMB - OUTPUT BUFR FILE IS OPEN FOR '//
105  . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
106  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
recursive subroutine closmg(LUNIN)
This subroutine closes the BUFR message that is currently open for writing within internal arrays ass...
Definition: closmg.f:26
recursive function i4dy(IDATE)
This function converts a date-time with a 2-digit year (YYMMDDHH) to a date-time with a 4-digit year ...
Definition: i4dy.f:24
subroutine msgini(LUN)
This subroutine initializes, within the internal arrays, a new uncompressed BUFR message for output.
Definition: msgini.f:14
This module contains declarations for arrays used to store information about the current BUFR message...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
integer, dimension(:), allocatable idate
Section 1 date-time of 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 ...
subroutine nemtba(LUN, NEMO, MTYP, MSBT, INOD)
This subroutine searches for a descriptor within Table A of the internal DX BUFR tables.
Definition: nemtba.f:25
recursive subroutine openmb(LUNIT, SUBSET, JDATE)
Open a new message for output in a BUFR file that was previously opened for writing.
Definition: openmb.f:42
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 usrtpl(LUN, INVN, NBMP)
Store the subset template into internal arrays.
Definition: usrtpl.f:22
subroutine wtstat(LUNIT, LUN, IL, IM)
Update file status in library internals.
Definition: wtstat.f:37
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19