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