C @(#)itch.f 1.7 03/25/98 C integer*4 function itch (string, ier) c Alternative to function ITEM using character string variable c Assumes a character variable in STRING is to be converted c to a binary integer. c Leading blanks are treated as zeros. c A blank character other than a leading blank terminates the c string. c Plus or minus signs, when used, must prefix the digits with c no embedded blanks. c IER returns 0 if no digits were found c +n location of last digit in number. Terminated c by space or end of string c -n error found at byte n character*(*) string logical more, digit c find location of first non-blank character length = len(string) more = .true. i = 0 do while (more) i = i + 1 more = string(i:i) .eq. ' ' .and. i .lt. length end do jsign = 1 if (string(i:i) .eq. '+') then else if (string(i:i) .eq. '-') then jsign = -1 else i = i - 1 end if itch = 0 ier = 0 if (i .lt. length) then ! only a sign digit = .false. more = .true. do while (more) if (i .lt. length) then i = i + 1 if (string(i:i) .ge. '0' .and. string(i:i) .le. '9') then itch = itch*10 + ichar(string(i:i)) - ichar('0') digit = .true. else if (string(i:i) .eq. ' ') then if (digit) ier = i - 1 more = .false. else ier = -i more = .false. end if else if (digit) ier = i more = .false. end if end do itch = jsign * itch end if return end