规范部分中的 Fortran 命令行输入
Fortran Command Line Input In Specification Part
我是 Fortran 的新手,我在尝试通过命令行传递参数时遇到问题。例如我的工作代码有以下几行:
!experimental parameters
real (kind=8), parameter :: rhot =1.2456
!density of top fluid
real (kind=8), parameter :: rhob = 1.3432
!density of bottom fluid
real (kind=8), parameter :: rhof = (rhot-rhob)
!generic function of rhot rhob
我想通过以下方式提交:
./fulltime_2009_05_15_Fortran9 [Value rhot] [Value rhob]
使用类似的东西:
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
问题是,我声明了依赖于输入值的参数,例如 rhof。所以我想立即应用用户输入的值,以便所有相关参数都可以使用这些值。但是,如果将我的代码修改为:
real (kind=8) :: rhot, rhoB
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
real (kind=8), parameter :: rhof = (rhot-rhob)
我收到错误:规范语句不能出现在可执行部分。
关于如何解决这个问题有什么想法或建议吗?
编译时间常量 (parameter
) 不能通过命令行参数更改。它在编译时固定。
此代码:
real (kind=8) :: rhot, rhoB
real (kind=8) :: rhof
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
rhof = (rhot-rhob)
可以编译。但是你不能在普通语句之后有变量声明。
你可以
real (kind=8) :: rhot, rhoB
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
block
real (kind=8) :: rhof = (rhot-rhob)
在 Fortran 2008 中,但您不能使用非常量表达式定义编译时常量。
一些编程语言确实允许在 运行 配置期间设置并在之后固定的常量类型。 Fortran 不是其中之一。
我是 Fortran 的新手,我在尝试通过命令行传递参数时遇到问题。例如我的工作代码有以下几行:
!experimental parameters
real (kind=8), parameter :: rhot =1.2456
!density of top fluid
real (kind=8), parameter :: rhob = 1.3432
!density of bottom fluid
real (kind=8), parameter :: rhof = (rhot-rhob)
!generic function of rhot rhob
我想通过以下方式提交:
./fulltime_2009_05_15_Fortran9 [Value rhot] [Value rhob]
使用类似的东西:
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
问题是,我声明了依赖于输入值的参数,例如 rhof。所以我想立即应用用户输入的值,以便所有相关参数都可以使用这些值。但是,如果将我的代码修改为:
real (kind=8) :: rhot, rhoB
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
real (kind=8), parameter :: rhof = (rhot-rhob)
我收到错误:规范语句不能出现在可执行部分。
关于如何解决这个问题有什么想法或建议吗?
编译时间常量 (parameter
) 不能通过命令行参数更改。它在编译时固定。
此代码:
real (kind=8) :: rhot, rhoB
real (kind=8) :: rhof
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
rhof = (rhot-rhob)
可以编译。但是你不能在普通语句之后有变量声明。
你可以
real (kind=8) :: rhot, rhoB
call get_command_argument(1,input1)
call get_command_argument(2,input2)
read(input1,*) rhot
read(input2,*) rhob
block
real (kind=8) :: rhof = (rhot-rhob)
在 Fortran 2008 中,但您不能使用非常量表达式定义编译时常量。
一些编程语言确实允许在 运行 配置期间设置并在之后固定的常量类型。 Fortran 不是其中之一。