NCEPLIBS-bufr 11.7.1
strsuc.f
Go to the documentation of this file.
1C> @file
2C> @brief Remove leading and trailing blanks from a character string
3
4C> This subroutine removes leading and trailing blanks from a
5C> character string. The string may not contain any embedded blanks.
6C>
7C> @author J. Woollen
8C> @date 1994-01-06
9C>
10C> @param[in] STR1 -- character*(*): String
11C> @param[out] STR2 -- character*(*): Copy of STR1 with leading and
12C> trailing blanks removed
13C> @param[out] LENS -- integer: Length of STR2
14C> - -1 = STR1 contained embedded blanks
15C>
16C> <b>Program History Log:</b>
17C> | Date | Programmer | Comments |
18C> | -----|------------|----------|
19C> | 1994-01-06 | J. Woollen | Original author
20C> | 2003-11-04 | J. Ator | Added documentation
21C> | 2009-04-21 | J. Ator | Use errwrt()
22C>
23 SUBROUTINE strsuc(STR1,STR2,LENS)
24
25 CHARACTER*(*) STR1,STR2
26
27 COMMON /quiet / iprt
28
29C-----------------------------------------------------------------------
30C-----------------------------------------------------------------------
31
32 lens = 0
33 lstr = len(str1)
34
35C FIND THE FIRST NON-BLANK IN THE INPUT STRING
36C --------------------------------------------
37
38 DO i=1,lstr
39 IF(str1(i:i).NE.' ') GOTO 2
40 ENDDO
41 GOTO 100
42
43C Now, starting with the first non-blank in the input string,
44C copy characters from the input string into the output string
45C until reaching the next blank in the input string.
46
472 DO j=i,lstr
48 IF(str1(j:j).EQ.' ') GOTO 3
49 lens = lens+1
50 str2(lens:lens) = str1(j:j)
51 ENDDO
52 GOTO 100
53
54C Now, continuing on within the input string, make sure that
55C there are no more non-blank characters. If there are, then
56C the blank at which we stopped copying from the input string
57C into the output string was an embedded blank.
58
593 DO i=j,lstr
60 IF(str1(i:i).NE.' ') lens = -1
61 ENDDO
62
63 IF(lens.EQ.-1 .AND. iprt.GE.0) THEN
64 CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
65 CALL errwrt('BUFRLIB: STRSUC - INPUT STRING:')
66 CALL errwrt(str1)
67 CALL errwrt('CONTAINS ONE OR MORE EMBEDDED BLANKS')
68 CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
69 CALL errwrt(' ')
70 ENDIF
71
72C EXIT
73C ----
74
75100 RETURN
76 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 strsuc(STR1, STR2, LENS)
This subroutine removes leading and trailing blanks from a character string.
Definition: strsuc.f:24