Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jato!ripple.jpl.nasa.gov!mparisi From: mparisi@ripple.jpl.nasa.gov (Mark Parisi) Newsgroups: comp.lang.fortran Subject: Re: Checking a string for an integer Message-ID: <1991Apr1.222449.12621@jato.jpl.nasa.gov> Date: 1 Apr 91 22:24:49 GMT References: <1991Apr1.104227.243@biivax.dp.beckman.com> <009467BE.E4367B40@vmsd.csd.mu.edu> Sender: news@jato.jpl.nasa.gov Reply-To: mparisi@ripple.jpl.nasa.gov (Mark Parisi) Organization: Jet Propulsion Laboratory Lines: 36 Nntp-Posting-Host: ripple.jpl.nasa.gov In article <009467BE.E4367B40@vmsd.csd.mu.edu>, 8099pierzina@vmsd.csd.mu.edu (Todd Pierzina) writes: |> read (String, '(I3)', err=1000, iostat=iostat) i This doesn't work quite as well as you might think. In VMS Fortran, this will pass anything which resembles a valid real or integer format, including: "1E2" "D " "Q " If you are really worried about checking for valid input, you are best off checking that each character in the string is between "0" and "9". (You will probably want to allow blanks in some places, this will complicate things.) The intrinsic function INDEX is useful for performing this check: CHARACTER*(*) DIGITS PARAMETER (DIGITS = '0123456789') INTEGER I LOGICAL VALID ... VALID = .TRUE. DO 10 I = 1, LEN(STR) IF INDEX(DIGITS, STR(I:I) .EQ. 0) VALID = .FALSE. 10 CONTINUE ... you get the idea. -- Mark Parisi (mparisi@ripple.jpl.nasa.gov)