This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: practical use of iargc() getarg()
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: RadSurfer <RadSurfer at yahoo dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Thu, 9 Aug 2007 20:53:26 -0700
- Subject: Re: practical use of iargc() getarg()
- References: <loom.20070810T051627-79@post.gmane.org>
On Fri, Aug 10, 2007 at 03:46:19AM +0000, RadSurfer wrote:
> Since getarg() returns strings, I was just wondering precisely how one
> converts a string to the proper numerical type desired?
>
> Strangely, the manual (gfortran.pdf) really does not show any practical
> example for using getarg() as regards converting to numerical types.
>
> I = IChar('123') ! Integer (How are the other types handled?)
>
> no matter how often I read through that manual, I see nothing about
> obtaining a REAL (single,double, let alone their attributes)
> from a String! Did I miss something?
>
> I was going to try to process some simple formula's with float values
> past from the command line, (a cinch for C/C++ naturally)!
>
> Sometimes Fortran just utterly amazes me.
>
You need to use an internal read.
PROGRAM test_getarg
INTEGER :: i
CHARACTER(len=32) :: arg
real x
DO i = 1, iargc()
CALL getarg(i, arg)
read(arg,*) x
END DO
END PROGRAM
The above is completely untested.
--
Steve