parsing command line args (or converting characters into real)

3 views
Skip to first unread message

nt moore

unread,
Oct 9, 2006, 1:41:49 PM10/9/06
to gg95
My guess is that this is a simple question.

I'd like to write a fortran prgram that reads in command line arguments
and then parses them as number, character, etc, and in that direction,
have been working with the following program, (which fails to compile
with the error, "Error: Can't convert CHARACTER(1) to REAL(8) ")

Is there an obvious solution to this (a conversion function perhaps?)

- - -

integer*4 num,j,length,stat
character(LEN=15) :: value
real*8 foo

num = command_argument_count()
print *,"There are ",num," command line args"

do j=1,num,1
call get_command_argument(j,value,length,stat)
print *, "j = ",j
print *, "value = ",value
foo = value
print *, "foo = ",foo
print *, "length = ",length
print *, "stat = ",stat
print *,"\n"
end do

stop
end

Doug

unread,
Oct 9, 2006, 2:54:29 PM10/9/06
to gg95

On Oct 9, 1:41 pm, "nt moore" <ntmo...@gmail.com> wrote:
> My guess is that this is a simple question.
>
> I'd like to write a fortran prgram that reads in command line arguments
> and then parses them as number, character, etc, and in that direction,
> have been working with the following program, (which fails to compile
> with the error, "Error: Can't convert CHARACTER(1) to REAL(8) ")
>
> Is there an obvious solution to this (a conversion function perhaps?)
>

Change the line:
foo = value
to something like:
READ (value, fmt='(f12.3)') foo
This produces:
$ ./a.out 13.2 14.867
There are 2 command line args
j = 1
value = 13.2
foo = 13.2
length = 4
stat = 0


j = 2
value = 14.867
foo = 14.867
length = 6
stat = 0

Doug

nt moore

unread,
Oct 10, 2006, 10:13:44 PM10/10/06
to gg95
perfect! thanks!

Reply all
Reply to author
Forward
0 new messages