Screamer Project  V3.3.1
Screamer Structure
 All Files Functions Variables
cnv2int.f
Go to the documentation of this file.
1  subroutine conv_to_int (text, intmag, intsign, flag)
2 c
3 c Define passed variables
4 c
5  character text*(*)
6  integer intmag, intsign, flag
7 c
8 c Internal variables
9 c
10  parameter(limit = 80)
11  dimension int_text(limit)
12  integer start, end, char_value
13 c
14  integer error
15  parameter(error = 1, no_error = 0)
16  integer plus, minus
17  parameter(plus = -5, minus = -3)
18  integer ascii_factor
19  parameter(ascii_factor = 48)
20  parameter(max_digits = 9)
21 c
22 c Convert TEXT (up to 80 characters) to its integer equivalent,
23 c labeled INTMAG.
24 c INTMAG is always >= 0, INTSIGN is its sign (+1 or -1).
25 c Routine only recognizes integers in the form
26 c '(sign)xxxxxx' with no blanks.
27 c x is a decimal digit and sign is
28 c '+' (optional) or '-'. Anything else causes INTMAG=0.
29 c If TEXT was a legal form, FLAG=0; otherwise, FLAG=1.
30 c TEXT has from 1 to 80 characters.
31 c Integers must be in the range -10**9 < I < 10**9 , otherwise an
32 c error is flagged.
33 c
34  flag = no_error
35  start = 1
36  end = len(text)
37  if (end .gt. limit) then
38  go to 999
39  end if
40 c
41 c Fill ITEXT with ASCII decimal values - 48 of TEXT's characters.
42 c 'X'=X for a digit X. Return if not in above form.
43 c
44 c Check first character for sign or digit or something else.
45 c
46  char_value = ichar(text(start:start)) - ascii_factor
47  int_text(start) = char_value
48  if (char_value .eq. plus) then
49  if (start .ge. end) then
50  go to 999
51  else
52  intsign = +1
53  start = start + 1
54  end if
55  else if (char_value .eq. minus) then
56  if (start .ge. end) then
57  go to 999
58  else
59  intsign = -1
60  start = start + 1
61  end if
62  else if ((char_value .ge. 0) .and. (char_value .le. 9)) then
63  intsign = +1
64  else
65  go to 999
66  end if
67 c
68 c Check characters to see if they are digits
69 c
70  do i = start, end
71  char_value = ichar(text(i:i)) - ascii_factor
72  if ((char_value .lt. 0) .or. (char_value .gt. 9)) then
73  go to 999
74  else
75  int_text(i) = char_value
76  end if
77  end do
78 c
79 c Add the digits, multiplied by the appropriate power of 10,
80 c using nested multiplication.
81 c
82 c First digit.
83 c
84  intmag = int_text(start)
85  num_digits = end - start + 1
86  if ((num_digits .gt. max_digits) .and.
87  & (intmag .gt. 0)) then
88  go to 999
89  end if
90 c
91 c Rest of the digits.
92 c
93  do i = start + 1, end
94  num_digits = num_digits - 1
95  if ((num_digits .gt. max_digits) .and.
96  & (int_text(i) .gt. 0)) then
97  go to 999
98  else
99  intmag = 10*intmag + int_text(i)
100  end if
101  end do
102 c
103  return
104 c
105 c Error.
106 c
107  999 continue
108  intmag = 0
109  flag = error
110 c
111  return
112  end
subroutine conv_to_int(text, intmag, intsign, flag)
Definition: cnv2int.f:1