现在的位置: 首页 > 综合 > 正文

fortran如何获取命令行中输入的参数

2014年01月22日 ⁄ 综合 ⁄ 共 970字 ⁄ 字号 评论关闭

program main
implicit none

integer ::narg
CHARACTER(len=32) ::arg

narg=IARGC()

if(narg >0)then
call getarg(1,arg)
endif
write(*,*)narg
write(*,*)arg

end

IARGC — Get the number of command line arguments

Return value:

The number of command line arguments, type INTEGER(4)

GETARG — Get command line arguments

Description:
Retrieve the POS-th argument that was passed on the command line when the containing program was invoked.
Syntax:
CALL GETARG(POS, VALUE) 
Arguments:
POS Shall be of type INTEGER and not wider than the default integer kind; POS \geq 0 
VALUE Shall be of type CHARACTER and of default kind. 
VALUE Shall be of type CHARACTER

Return value:
After GETARG returns, the VALUE argument holds the POSth command line argument. If VALUE can not hold the argument, it is truncated to fit the length of VALUE.
If there are less than POS arguments specified at the command line, VALUEwill be filled with blanks. If POS = 0, VALUE is set to the name of the program (on systems that support this 
比如用gfortran编译之后
gfortran 1.F90 -o test 编译成目标文件test,执行的时候在程序名后跟上需要输入的参数即可
比如./test fgh 3 5,这样就相当于输入的时候键入了3个命令行参数

抱歉!评论已关闭.