Xref: utzoo comp.lang.fortran:5084 comp.os.vms:37483 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!slacvm!kencb From: KENCB@SLACVM.SLAC.STANFORD.EDU Newsgroups: comp.lang.fortran,comp.os.vms Subject: Re: Checking a string for an integer Message-ID: <91091.134117KENCB@SLACVM.SLAC.STANFORD.EDU> Date: 1 Apr 91 21:41:17 GMT References: <1991Apr1.104227.243@biivax.dp.beckman.com> Organization: Stanford Linear Accelerator Center Lines: 43 In article <1991Apr1.104227.243@biivax.dp.beckman.com>, dsroberts@biivax.dp.beckman.com says: > >I would like to take a 3 byte string and find out if it contains only ascii >digits for number or if letters were entered. On VMS, the DCL command would >be > >result = f$integer (string) > >which would put the numeric equivalent in result, or return an error. I don't >find an obvious way to do this in FORTRAN. Any suggestions? I am not averse >to a VMS system service, btw. > How about using the OTS$CVT_TI_L system service. OTS will return a FALSE status if it can't convert the text string. Sample code: INTEGER*4 IVAL, OTS$CVT_TI_L CHARACTER*3 CVAL . . READ (5,*) CVAL IF (OTS$CVT_TI_L (CVAL, IVAL, %VAL(4), %VAL('11'X))) THEN IF (IVAL.GE.1 .AND. IVAL.LE.254) THEN . . ELSE . ENDIF ELSE . ENDIF Do a $HELP RTL OTS$ OTS$CVT_TI_L for details on the 3rd and 4th arguments. Ken Dr. Kenneth H. Fairfield Internet: Fairfield@Tpc.Slac.Stanford.Edu SLAC, P.O.Box 4349, Bin 98 DECnet: 45047::FAIRFIELD (TPC::) Stanford, CA 94309 BITNET Fairfield@SlacTpc "These opinions are worth what you paid for 'em... ...and they are mine, not SLAC's, Stanford's, nor the DOE's..."