1c 2c 3c ################################################### 4c ## COPYRIGHT (C) 1993 by Jay William Ponder ## 5c ## All Rights Reserved ## 6c ################################################### 7c 8c ################################################################ 9c ## ## 10c ## subroutine getnumb -- extract an integer from a string ## 11c ## ## 12c ################################################################ 13c 14c 15c "getnumb" searches an input string from left to right for an 16c integer and puts the numeric value in "number"; returns zero 17c with "next" unchanged if no integer value is found 18c 19c variables and parameters: 20c 21c string input character string to be searched 22c number output with the first integer in the string 23c next input with first position of search string; 24c output with the position following the number 25c 26c 27 subroutine getnumb (string,number,next) 28 use ascii 29 implicit none 30 integer i,j,length 31 integer number,digit 32 integer next,trimtext 33 integer first,last,code 34 integer initial,final 35 integer place(10) 36 logical positive 37 logical negative 38 logical numeral 39 character*1 letter 40 character*(*) string 41 data place / 1, 10, 100, 1000, 10000, 100000, 1000000, 42 & 10000000, 100000000, 1000000000 / 43c 44c 45c initialize number and get the input text string length 46c 47 number = 0 48 positive = .false. 49 negative = .false. 50 numeral = .false. 51 length = trimtext(string(next:)) 52c 53c search the string for the first run of numeric characters 54c 55 first = next 56 last = 0 57 initial = next 58 final = next + length - 1 59 do i = initial, final 60 letter = string(i:i) 61 code = ichar(letter) 62 if (letter.ge.'0' .and. letter.le.'9') then 63 if (.not. numeral) then 64 numeral = .true. 65 first = i 66 end if 67 if (i .eq. final) then 68 last = final 69 next = i + 1 70 end if 71 else if (code.eq.plus .and. .not.positive) then 72 positive = .true. 73 else if (code.eq.minus .and. .not.negative) then 74 negative = .true. 75 else if (numeral) then 76 if (code.eq.space .or. code.eq.tab .or. 77 & code.eq.comma .or. code.eq.semicolon .or. 78 & code.eq.colon .or. code.eq.underbar) then 79 last = i - 1 80 next = i 81 else 82 numeral = .false. 83 end if 84 goto 10 85 else if (positive .or. negative) then 86 numeral = .false. 87 goto 10 88 else if (code.ne.space .and. code.ne.tab) then 89 numeral = .false. 90 goto 10 91 end if 92 end do 93 10 continue 94c 95c trim the actual number if it is too big to return 96c 97 if (.not. numeral) next = initial 98 last = min(last,first+9) 99c 100c convert the text numeral into an integer number 101c 102 j = 0 103 do i = last, first, -1 104 j = j + 1 105 if (string(i:i) .eq. '0') then 106 digit = 0 107 else if (string(i:i) .eq. '1') then 108 digit = 1 109 else if (string(i:i) .eq. '2') then 110 digit = 2 111 else if (string(i:i) .eq. '3') then 112 digit = 3 113 else if (string(i:i) .eq. '4') then 114 digit = 4 115 else if (string(i:i) .eq. '5') then 116 digit = 5 117 else if (string(i:i) .eq. '6') then 118 digit = 6 119 else if (string(i:i) .eq. '7') then 120 digit = 7 121 else if (string(i:i) .eq. '8') then 122 digit = 8 123 else if (string(i:i) .eq. '9') then 124 digit = 9 125 end if 126 number = number + digit * place(j) 127 end do 128 if (negative) number = -number 129 return 130 end 131