NCEPLIBS-bufr  12.0.1
writsb.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Write a data subset into a BUFR message.
3 C>
4 C> @author J. Woollen @date 1994-01-06
5 
6 C> Write a data subset into a BUFR message.
7 C>
8 C> This subroutine writes a complete data subset into a BUFR message,
9 C> for eventual output to logical unit LUNIT.
10 C>
11 C> This subroutine is called when all necessary values for a data subset
12 C> (i.e. report) have been written, and the subset is ready to be encoded
13 C> and packed into the current message for the BUFR file associated with
14 C> logical unit LUNIT. Logical unit LUNIT should have already been
15 C> opened for output operations via a previous call to subroutine
16 C> openbf(), and a BUFR message should already be open for output within
17 C> internal arrays via a previous call to one of the BUFRLIB
18 C> [message-writing subroutines](@ref hierarchy). All of the values for
19 C> the data subset should have already been written into internal arrays
20 C> via calls to any of the BUFRLIB [values-writing subroutines](@ref
21 C> hierarchy).
22 C>
23 C> There is a maximum size for any BUFR message that can be written
24 C> by the BUFRLIB software. This maximum message size is initially set
25 C> to an internal default value within subroutine bfrini(), but it can
26 C> be changed to a different value via a separate prior call to
27 C> subroutine maxout().
28 C>
29 C> This subroutine will always check to ensure that the data subset,
30 C> when encoded and packed, will fit into the current BUFR message that
31 C> is already open within the internal arrays associated with logical
32 C> unit LUNIT. If adding the data subset to the current message would
33 C> cause the maximum message size to be exceeded, then the subroutine will
34 C> automatically flush the current message to logical unit LUNIT, then
35 C> open and initialize a new internal message using the same SUBSET and
36 C> JDATE values that were specified in the most recent call to one of
37 C> the [message-writing subroutines](@ref hierarchy) for LUNIT, then
38 C> encode and pack the data subset into that new message.
39 C>
40 C> @param[in] LUNIT - integer: Fortran logical unit number for BUFR file.
41 C>
42 C> @author J. Woollen @date 1994-01-06
43 
44  RECURSIVE SUBROUTINE writsb(LUNIT)
45 
46  USE modv_im8b
47 
48  COMMON /msgcmp/ ccmf
49 
50  CHARACTER*1 ccmf
51 
52 C-----------------------------------------------------------------------
53 C-----------------------------------------------------------------------
54 
55 C CHECK FOR I8 INTEGERS
56 C ---------------------
57 
58  IF(im8b) THEN
59  im8b=.false.
60 
61  CALL x84 ( lunit, my_lunit, 1 )
62  CALL writsb ( my_lunit )
63 
64  im8b=.true.
65  RETURN
66  ENDIF
67 
68 C CHECK THE FILE STATUS
69 C ---------------------
70 
71  CALL status(lunit,lun,il,im)
72  IF(il.EQ.0) GOTO 900
73  IF(il.LT.0) GOTO 901
74  IF(im.EQ.0) GOTO 902
75 
76 C PACK UP THE SUBSET AND PUT IT INTO THE MESSAGE
77 C ----------------------------------------------
78 
79  CALL wrtree(lun)
80  IF( ccmf.EQ.'Y' ) THEN
81  CALL wrcmps(lunit)
82  ELSE
83  CALL msgupd(lunit,lun)
84  ENDIF
85 
86 C EXITS
87 C -----
88 
89  RETURN
90 900 CALL bort('BUFRLIB: WRITSB - OUTPUT BUFR FILE IS CLOSED, IT '//
91  . 'MUST BE OPEN FOR OUTPUT')
92 901 CALL bort('BUFRLIB: WRITSB - OUTPUT BUFR FILE IS OPEN FOR '//
93  . 'INPUT, IT MUST BE OPEN FOR OUTPUT')
94 902 CALL bort('BUFRLIB: WRITSB - A MESSAGE MUST BE OPEN IN OUTPUT '//
95  . 'BUFR FILE, NONE ARE')
96  END
subroutine bort(STR)
Log one error message and abort application program.
Definition: bort.f:18
subroutine msgupd(LUNIT, LUN)
This subroutine packs up the current subset within memory (array ibay in module moda_bitbuf) and then...
Definition: msgupd.f:24
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 ...
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 wrcmps(LUNIX)
This subroutine packs up the current subset within memory (array ibay in module moda_bitbuf),...
Definition: wrcmps.f:23
recursive subroutine writsb(LUNIT)
Write a data subset into a BUFR message.
Definition: writsb.f:45
subroutine wrtree(LUN)
Pack a BUFR data subset.
Definition: wrtree.f:16
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19