GCC version 4.6
The Problem: To find a way to feed in parameters to the executable, say a.out
, from the command line - more specifically feed in an array of double precision numbers.
Attempt: Using the READ(*,*)
command, which is older in the standard:
Program test.f
-
PROGRAM MAIN
REAL(8) :: A,B
READ(*,*) A,B
PRINT*, A+B, COMMAND_ARGUMENT_COUNT()
END PROGRAM MAIN
The execution -
$ gfortran test.f
$ ./a.out 3.D0 1.D0
This did not work. On a bit of soul-searching, found that
$./a.out
3.d0,1.d0
4.0000000000000000 0
does work, but the second line is an input prompt, and the objective of getting this done in one-line is not achieved. Also the COMMAND_ARGUMENT_COUNT()
shows that the numbers fed into the input prompt don't really count as 'command line arguments', unlike PERL.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…