NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
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 
5 C> This subroutine opens and initializes a new BUFR message within
6 C> internal arrays, for eventual output to logical unit LUNIT.
7 C>
8 C> @author J. Woollen
9 C> @date 1994-01-06
10 C>
11 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR
12 C> file
13 C> @param[in] SUBSET - character*(*): Table A mnemonic for type of
14 C> BUFR message to be opened
15 C> (see [DX BUFR Tables](@ref dfbftab) for
16 C> further information about Table A mnemonics)
17 C> @param[in] JDATE - integer: Date-time to be stored within Section 1
18 C> of BUFR message being opened, in format of either
19 C> YYMMDDHH or YYYYMMDDHH
20 C>
21 C> <p>Logical unit LUNIT should have already been opened for output
22 C> operations via a previous call to subroutine openbf().
23 C>
24 C> <p>This subroutine is similar to subroutine openmg(), except that it
25 C> will only open a new message if either SUBSET or JDATE has changed
26 C> since the previous call to this subroutine. Otherwise, it will
27 C> leave the existing internal message unchanged so that the next data
28 C> subset can be written into the same internal message, thereby
29 C> improving overall storage efficiency by allowing the maximum number
30 C> of data subsets to be stored within each output BUFR message. For
31 C> this reason, openmb() is much more widely used than openmg().
32 C>
33 C> <p>If this subroutine does need to open and initialize a new BUFR
34 C> message for output (e.g. if the value of SUBSET or JDATE has changed
35 C> since the previous call to this subroutine), then any existing
36 C> message within the internal arrays will be automatically flushed and
37 C> written to logical unit LUNIT via an internal call to subroutine
38 C> closmg(). In this case, the behavior of this subroutine then
39 C> becomes exactly like that of subroutine openmg().
40 C>
41 C> <b>Program history log:</b>
42 C> - 1994-01-06 J. Woollen -- Original author
43 C> - 1998-07-08 J. Woollen -- Replaced call to Cray library routine
44 C> "ABORT" with call to new internal BUFRLIB
45 C> routine "BORT"; modified to make Y2K
46 C> compliant
47 C> - 1999-11-18 J. Woollen -- The number of BUFR files which can be
48 C> opened at one time increased from 10 to 32
49 C> (necessary in order to process multiple
50 C> BUFR files under the MPI)
51 C> - 2003-11-04 J. Ator -- Added documentation
52 C> - 2003-11-04 S. Bender -- Added remarks and routine interdependencies
53 C> - 2003-11-04 D. Keyser -- Unified/portable for WRF; added history
54 C> documentation; outputs more complete
55 C> diagnostic info when routine terminates
56 C> abnormally
57 C> - 2014-12-10 J. Ator -- Use modules instead of COMMON blocks
58 C>
59  SUBROUTINE openmb(LUNIT,SUBSET,JDATE)
60 
61  USE moda_msgcwd
62 
63  CHARACTER*(*) subset
64  LOGICAL open
65 
66 C-----------------------------------------------------------------------
67 C-----------------------------------------------------------------------
68 
69 C CHECK THE FILE STATUS
70 C ---------------------
71 
72  CALL status(lunit,lun,il,im)
73  IF(il.EQ.0) goto 900
74  IF(il.LT.0) goto 901
75 
76 C GET SOME SUBSET PARTICULARS
77 C ---------------------------
78 
79 c .... Given SUBSET, returns MTYP,MSTB,INOD
80  CALL nemtba(lun,subset,mtyp,mstb,inod)
81  OPEN = im.EQ.0.OR.inod.NE.inode(lun).OR.i4dy(jdate).NE.idate(lun)
82 
83 C MAYBE(?) OPEN A NEW OR DIFFERENT TYPE OF MESSAGE
84 C ------------------------------------------------
85 
86  IF(open) THEN
87  CALL closmg(lunit)
88  CALL wtstat(lunit,lun,il, 1)
89 c .... Set pos. index for new Tbl A mnem.
90  inode(lun) = inod
91 c .... Set date for new message
92  idate(lun) = i4dy(jdate)
93 
94 C INITIALIZE THE OPEN MESSAGE
95 C ---------------------------
96 
97  CALL msgini(lun)
98  CALL usrtpl(lun,1,1)
99  ENDIF
100 
101 C EXITS
102 C -----
103 
104  RETURN
105 900 CALL bort('BUFRLIB: OPENMB - OUTPUT BUFR FILE IS CLOSED, IT '//
106  . 'MUST BE OPEN FOR OUTPUT')
107 901 CALL bort('BUFRLIB: OPENMB - OUTPUT BUFR FILE IS OPEN FOR '//
108  . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
109  END
function i4dy(IDATE)
THIS FUNCTION CONVERTS AN EIGHT DIGIT INTEGER DATE (YYMMDDHH) TO TEN DIGITS (YYYYMMDDHH) USING THE Y2...
Definition: i4dy.f:49
subroutine usrtpl(LUN, INVN, NBMP)
THIS SUBROUTINE STORES THE SUBSET TEMPLATE INTO INTERNAL SUBSET ARRAYS IN MODULE USRINT FOR CASES OF ...
Definition: usrtpl.f:51
subroutine openmb(LUNIT, SUBSET, JDATE)
This subroutine opens and initializes a new BUFR message within internal arrays, for eventual output ...
Definition: openmb.f:59
subroutine wtstat(LUNIT, LUN, IL, IM)
This subroutine can be used to connect or disconnect a specified Fortran logical unit number to/from ...
Definition: wtstat.f:58
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 msgini(LUN)
THIS SUBROUTINE INITIALIZES, WITHIN THE INTERNAL ARRAYS, A NEW BUFR MESSAGE FOR OUTPUT.
Definition: msgini.f:55
subroutine closmg(LUNIN)
This subroutine closes the BUFR message that is currently open for writing within internal arrays ass...
Definition: closmg.f:53
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23
subroutine nemtba(LUN, NEMO, MTYP, MSBT, INOD)
THIS SUBROUTINE SEARCHES FOR MNEMONIC NEMO WITHIN THE INTERNAL TABLE A ARRAYS HOLDING THE DICTIONARY ...
Definition: nemtba.f:50