NCEPLIBS-bufr  12.0.0
hold4wlc.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Write a long character string (greater than 8 bytes) to
3 C> a data subset
4 C>
5 C> @author J. Ator @date 2014-02-05
6 
7 C> This subroutine writes a long character string (greater than 8 bytes)
8 C> to a data subset.
9 C>
10 C> Normally, subroutine writlc() is used to write a long character
11 C> string to a data subset. However, subroutine writlc() can only be
12 C> called <b>after</b> a call to one of the
13 C> [subset-writing subroutines](@ref hierarchy), so it will not work
14 C> for cases when one of those subroutines flushes the message
15 C> containing the data subset in question to logical unit LUNIT during
16 C> the same call to that subroutine, such as when the data subset
17 C> contains more than 65530 bytes. When this happens, there is no
18 C> longer any way for a subsequent writlc() call to write a long
19 C> character string into that data subset, because the data subset has
20 C> already been flushed from internal memory. This subroutine solves
21 C> that problem, by allowing a long character string to be specified
22 C> <b>before</b> calling one of the
23 C> [subset-writing subroutines](@ref hierarchy), and the string value
24 C> will be held and stored automatically (via an internal call to
25 C> subroutine writlc()) at the proper time during the subsequent call
26 C> to the [subset-writing subroutines](@ref hierarchy).
27 C>
28 C> @param[in] LUNIT -- integer: Fortran logical unit number for BUFR file
29 C> @param[in] CHR -- character*(*): Value corresponding to STR
30 C> @param[in] STR -- character*(*): Table B mnemonic of long character
31 C> string to be written, possibly supplemented
32 C> with an ordinal occurrence notation
33 C>
34 C> If there is more than one occurrence of STR within the data subset
35 C> definition, then each occurrence can be written via a separate call
36 C> to this subroutine, and by appending the ordinal number of the
37 C> occurrence to STR in each case. For example, if there are 5
38 C> occurrences of mnemonic LSTID within a given data subset definition,
39 C> then 5 separate calls should be made to this subroutine, once each
40 C> with STR set to 'LSTID#1', 'LSTID#2', 'LSTID#3', 'LSTID#4' and
41 C> 'LSTID#5'. However, the first notation is superfluous, because
42 C> omitting the ordinal number always defaults to the first occurrence
43 C> of a particular string, so a user could just specify 'LSTID'
44 C> instead of 'LSTID#1'.
45 C>
46 C> @remarks
47 C> - Character strings which are 8 bytes or less in length can be
48 C> written by converting the string into a real*8 value within the
49 C> application program, and then using the real*8 USR array within a
50 C> call to one of the BUFRLIB
51 C> [values-writing subroutines](@ref hierarchy)
52 C> prior to calling one of the
53 C> [subset-writing subroutines](@ref hierarchy)
54 C> for the data subset.
55 C>
56 C> @author J. Ator @date 2014-02-05
57  RECURSIVE SUBROUTINE hold4wlc(LUNIT,CHR,STR)
58 
59  USE moda_h4wlc
60  USE modv_im8b
61 
62  COMMON /quiet/ iprt
63 
64  CHARACTER*(*) chr,str
65 
66  CHARACTER*128 errstr
67  CHARACTER*14 mystr
68 
69 C-----------------------------------------------------------------------
70 C-----------------------------------------------------------------------
71 
72 C CHECK FOR I8 INTEGERS
73 
74  IF(im8b) THEN
75  im8b=.false.
76 
77  CALL x84(lunit,my_lunit,1)
78  CALL hold4wlc(my_lunit,chr,str)
79 
80  im8b=.true.
81  RETURN
82  ENDIF
83 
84  CALL strsuc( str, mystr, lens )
85  IF ( lens .EQ. -1 ) RETURN
86 
87  lenc = min( len( chr ), 120 )
88 
89 C IF THIS SUBROUTINE HAS ALREADY BEEN CALLED WITH THIS MNEMONIC FOR
90 C THIS PARTICULAR SUBSET, THEN OVERWRITE THE CORRESPONDING ENTRY IN
91 C THE INTERNAL HOLDING AREA.
92 
93  IF ( nh4wlc .GT. 0 ) THEN
94  DO i = 1, nh4wlc
95  IF ( ( lunit .EQ. luh4wlc(i) ) .AND.
96  . ( mystr(1:lens) .EQ. sth4wlc(i)(1:lens) ) ) THEN
97  chh4wlc(i) = ''
98  chh4wlc(i)(1:lenc) = chr(1:lenc)
99  RETURN
100  ENDIF
101  ENDDO
102  ENDIF
103 
104 C OTHERWISE, USE THE NEXT AVAILABLE UNUSED ENTRY IN THE HOLDING AREA.
105 
106  IF ( nh4wlc .GE. mxh4wlc ) THEN
107  IF(iprt.GE.0) THEN
108  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
109  WRITE ( unit=errstr, fmt='(A,A,I3)' )
110  . 'BUFRLIB: HOLD4WLC - THE MAXIMUM NUMBER OF LONG CHARACTER ',
111  . 'STRINGS THAT CAN BE HELD INTERNALLY IS ', mxh4wlc
112  CALL errwrt(errstr)
113  CALL errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
114  ENDIF
115  ELSE
116  nh4wlc = nh4wlc + 1
117  luh4wlc(nh4wlc) = lunit
118  sth4wlc(nh4wlc) = ''
119  sth4wlc(nh4wlc)(1:lens) = mystr(1:lens)
120  chh4wlc(nh4wlc) = ''
121  chh4wlc(nh4wlc)(1:lenc) = chr(1:lenc)
122  ENDIF
123 
124  RETURN
125  END
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:36
recursive subroutine hold4wlc(LUNIT, CHR, STR)
This subroutine writes a long character string (greater than 8 bytes) to a data subset.
Definition: hold4wlc.f:58
This module contains array and variable declarations needed to store long character strings (greater ...
integer nh4wlc
Number of long character strings being stored.
character *14, dimension(:), allocatable sth4wlc
Table B mnemonics associated with long character strings.
integer, dimension(:), allocatable luh4wlc
I/O stream index into internal arrays for associated output file.
character *120, dimension(:), allocatable chh4wlc
Long character strings.
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 strsuc(str1, str2, lens)
This subroutine removes leading and trailing blanks from a character string.
Definition: strsuc.F90:16
subroutine x84(IIN8, IOUT4, NVAL)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x84.F:19