gpt4 book ai didi

command-line - Fortran 命令行参数

转载 作者:行者123 更新时间:2023-12-04 01:00:11 27 4
gpt4 key购买 nike

在 g++ 中,我使用 getopt_long 来处理命令行选项。有没有Gfortran 存在同样的事情?

我希望能够将参数传递给某些 Fortran 单元测试。

目前我有以下内容。人们可以注意到我正在照顾获得 key 并重视自己。使用 C++ getopt_long 时正在为我做这件事。

i = 1

Do

Call Get_command_argument (i, arg)
If (Len_trim (arg) == 0) Exit

pos = Index (arg, "=")

!!$ Long option argument.
If (arg(1:2) == "--") Then
If (pos == 0) Then
c = arg
val = ""
Else
c = arg(:pos-1)
val = arg(pos+1:)
End If

!!$ Short option argument.
Elseif (arg(1:1) == "-") Then
c = arg
val = arg(pos+1:)

!!$ Non option argument.
Else
c = arg
val = arg

End If

!!$------------------------------------------------------------

Select Case (c)

Case ("-b","--brief")
arg_brief = .True.

Case ("-h","--help")
arg_help = .True.

Case ("-v","-V","--version")
arg_version = .True.

! Output model geographical definition
Case ("-cunit")
arg_cunit = val

Case default
arg_nonopt = Trim (Adjustl (arg))
Write (*,*) "Warning: Non option argument"

End Select

i = i + 1

End Do

!!$-------------------------------------------------------------

!!$ [TODO] Get numbers from arg_cunit

If (arg_cunit .contains. "-") Then

If (arg_cunit .contains. ",") Then
!!$ "-" and "," are present.

Else
!!$ "-" only are present.

End If

Else If (arg_cunit .contains. ",") Then
!!$ "," only are present

End If

最佳答案

查看 COMMAND_ARGUMENT_COUNTGET_COMMAND_ARGUMENT。例如,在 gfortran 手册中。它们是标准的 Fortran 内在函数。

关于command-line - Fortran 命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27285209/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com