NCEPLIBS-bufr  12.0.0
parstr.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Parse a string containing one or more substrings into an array of substrings.
3 C> @author J. Ator @date 2007-01-19
4 
5 C> Parse a string containing one or more substrings into an array of substrings.
6 C>
7 C> This subroutine parses a string containing one or more
8 C> substrings into an array of substrings. The separator for the
9 C> substrings is specified during input, and multiple adjacent
10 C> occurrences of this character will be treated as a single
11 C> occurrence when the string is actually parsed.
12 C>
13 C> @param[in] STR - character*(*): string.
14 C> @param[out] TAGS - character*(*): array of substrings
15 C> @param[in] MTAG - integer: dimensioned size of TAGS within calling program;
16 C> used by the subroutine to make sure it doesn't overflow the TAGS array.
17 C> @param[out] NTAG - integer: number of substrings returned in TAGS
18 C> @param[in] SEP - character*1: separator character for substrings.
19 C> @param[in] LIMIT80 - logical: .true. if an abort should occur when STR is
20 C> longer than 80 characters; included for historical consistency with old subroutine parseq.
21 C>
22 C> @author J. Ator @date 2007-01-19
23  SUBROUTINE parstr(STR,TAGS,MTAG,NTAG,SEP,LIMIT80)
24 
25  CHARACTER*(*) STR,TAGS(MTAG)
26  CHARACTER*128 BORT_STR1,BORT_STR2
27  CHARACTER*1 SEP
28  LOGICAL SUBSTR,LIMIT80
29 
30 C-----------------------------------------------------------------------
31 C-----------------------------------------------------------------------
32 
33  lstr = len(str)
34  ltag = len(tags(1))
35  IF( limit80 .AND. (lstr.GT.80) ) GOTO 900
36  ntag = 0
37  nchr = 0
38  substr = .false.
39 
40  DO i=1,lstr
41 
42  IF( .NOT.substr .AND. (str(i:i).NE.sep) ) THEN
43  ntag = ntag+1
44  IF(ntag.GT.mtag) GOTO 901
45  tags(ntag) = ' '
46  ENDIF
47 
48  IF( substr .AND. (str(i:i).EQ.sep) ) nchr = 0
49  substr = str(i:i).NE.sep
50 
51  IF(substr) THEN
52  nchr = nchr+1
53  IF(nchr.GT.ltag) GOTO 902
54  tags(ntag)(nchr:nchr) = str(i:i)
55  ENDIF
56 
57  ENDDO
58 
59 C EXITS
60 C -----
61 
62  RETURN
63 900 WRITE(bort_str1,'("BUFRLIB: PARSTR - INPUT STRING (",A,") HAS ")')
64  . str
65  WRITE(bort_str2,'(18X,"LENGTH (",I4,"), > LIMIT OF 80 CHAR.")')
66  . lstr
67  CALL bort2(bort_str1,bort_str2)
68 901 WRITE(bort_str1,'("BUFRLIB: PARSTR - INPUT STRING (",A,") '//
69  . 'CONTAINS",I4)') str,ntag
70  WRITE(bort_str2,'(18X,"SUBSTRINGS, EXCEEDING THE LIMIT {",I4,'//
71  . '" - THIRD (INPUT) ARGUMENT}")') mtag
72  CALL bort2(bort_str1,bort_str2)
73 902 WRITE(bort_str1,'("BUFRLIB: PARSTR - INPUT STRING (",A,") ")') str
74  WRITE(bort_str2,'(18X,"CONTAINS A PARSED SUBSTRING WITH LENGTH '//
75  . 'EXCEEDING THE MAXIMUM OF",I4," CHARACTERS")') ltag
76  CALL bort2(bort_str1,bort_str2)
77  END
subroutine bort2(STR1, STR2)
Log two error messages and abort application program.
Definition: bort2.f:18
subroutine parstr(STR, TAGS, MTAG, NTAG, SEP, LIMIT80)
Parse a string containing one or more substrings into an array of substrings.
Definition: parstr.f:24