NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
strnum.f
Go to the documentation of this file.
1 C> @file
2 C> @author WOOLLEN @date 1994-01-06
3 
4 C> THIS SUBROUTINE DECODES AN INTEGER FROM A CHARACTER STRING.
5 C> THE INPUT STRING SHOULD CONTAIN ONLY DIGITS AND (OPTIONAL) TRAILING
6 C> BLANKS AND SHOULD NOT CONTAIN ANY SIGN CHARACTERS (E.G. '+', '-')
7 C> NOR LEADING BLANKS NOR EMBEDDED BLANKS.
8 C>
9 C> PROGRAM HISTORY LOG:
10 C> 1994-01-06 J. WOOLLEN -- ORIGINAL AUTHOR
11 C> 2003-11-04 J. ATOR -- ADDED DOCUMENTATION
12 C> 2003-11-04 S. BENDER -- ADDED REMARKS/BUFRLIB ROUTINE
13 C> INTERDEPENDENCIES
14 C> 2003-11-04 D. KEYSER -- UNIFIED/PORTABLE FOR WRF; ADDED HISTORY
15 C> DOCUMENTATION
16 C> 2009-04-21 J. ATOR -- USE ERRWRT
17 C>
18 C> USAGE: CALL STRNUM (STR, NUM)
19 C> INPUT ARGUMENT LIST:
20 C> STR - CHARACTER*(*): STRING CONTAINING ENCODED INTEGER VALUE
21 C>
22 C> OUTPUT ARGUMENT LIST:
23 C> NUM - INTEGER: DECODED VALUE
24 C> -1 = decode was unsuccessful
25 C>
26 C> REMARKS:
27 C> THIS ROUTINE CALLS: ERRWRT STRSUC
28 C> THIS ROUTINE IS CALLED BY: JSTNUM PARUTG SEQSDX SNTBFE
29 C> STSEQ
30 C> Normally not called by any application
31 C> programs but it could be.
32 C>
33  SUBROUTINE strnum(STR,NUM)
34 
35 
36 
37  CHARACTER*(*) str
38  CHARACTER*20 str2
39 
40  COMMON /quiet / iprt
41 
42 C-----------------------------------------------------------------------
43 C-----------------------------------------------------------------------
44 
45  num = 0
46  k = 0
47 
48 C Note that, in the following call to subroutine STRSUC, the output
49 C string STR2 is not used anywhere else in this routine. In fact,
50 C the only reason that subroutine STRSUC is being called here is to
51 C determine NUM, which, owing to the fact that the input string STR
52 C cannot contain any leading blanks, is equal to the number of
53 C digits to be decoded from the beginning of STR.
54 
55  CALL strsuc(str,str2,num)
56  IF(num.EQ.-1) goto 100
57 
58  DO i=1,num
59  READ(str(i:i),'(I1)',err=99) j
60  IF(j.EQ.0 .AND. str(i:i).NE.'0') goto 99
61  k = k*10+j
62  ENDDO
63 
64  num = k
65  goto 100
66 
67 C Note that NUM = -1 unambiguously indicates a bad decode since
68 C the input string cannot contain sign characters; thus, NUM is
69 C always positive if the decode is successful.
70 
71 99 num = -1
72  IF(iprt.GE.0) THEN
73  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
74  CALL errwrt('BUFRLIB: STRNUM - BAD DECODE; RETURN WITH NUM = -1')
75  CALL errwrt('++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
76  CALL errwrt(' ')
77  ENDIF
78 
79 C EXIT
80 C ----
81 
82 100 RETURN
83  END
subroutine strsuc(STR1, STR2, LENS)
THIS SUBROUTINE REMOVES LEADING AND TRAILING BLANKS FROM A STRING.
Definition: strsuc.f:34
subroutine strnum(STR, NUM)
THIS SUBROUTINE DECODES AN INTEGER FROM A CHARACTER STRING.
Definition: strnum.f:33
subroutine errwrt(STR)
This subroutine allows the user to specify a custom location for the logging of error and diagnostic ...
Definition: errwrt.f:39