将变量从Shell脚本传递到Fortran 90程序 [英] Passing Variables from a Shell-Script to a Fortran 90 Program
问题描述
我陷入了这个小问题.我想知道是否有可能将bash-shell脚本的变量传递给f90代码?
I'm stuck on this little problem. I was wondering if it is possible to pass a variable of a bash-shell script to a f90 code?
推荐答案
我很确定之前已经在这里进行了讨论,但是我找不到确切的重复项.
I am pretty sure it was discussed here before, but I cannot find an exact duplicate.
您可以将参数直接作为参数传递给程序
You can pass arguments directly as arguments to the program
./program arg1 arg2
您可以使用子例程 GET_COMMAND ARGUMENT
和 COMMAND_ARGUMENT_COUNT
.单击链接以获取有用的示例.
you can retrieve the values in the program as character strings in Fortran 2003 using subroutines GET_COMMAND ARGUMENT
and COMMAND_ARGUMENT_COUNT
. Click on the links to get useful examples.
在较早的Fortran中,您必须使用非标准扩展名,例如子例程 GETARG
和 IARGC 代码>
.
In older Fortran you have to use non-standard extensions, such as the subroutines GETARG
and IARGC
.
您还可以读取脚本中设置的环境变量
You can also read an environment variable which was set in the script
VAR1 = ...
VAR2 = ...
./program
使用Fortran 2003子例程 GET_ENVIRONMENT_VARIABLE
.在较早的Fortran中,您必须使用一些非标准扩展名,例如子例程 GETENV
.
using Fortran 2003 subroutine GET_ENVIRONMENT_VARIABLE
. In older Fortran you have to use some non-standard extension, such as the subroutine GETENV
.
您还可以将文件重定向到程序的标准输入,并使用 READ
语句读取数据.
You can also redirect a file to the standard input of the program and read the data using the READ
statement.
这篇关于将变量从Shell脚本传递到Fortran 90程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!