我正在编写一个文件读取库,需要检查文件是否已打开,以便我可以跳过open语句并直接进入读取状态.
如何在fortran中实现这一目标?
我创建了一个可分配的数组.我分配元素然后打印数组的大小.我发现奇怪的是,在解除分配后大小保持不变.
Integer, Allocatable :: fred(:)
Allocate (fred(3))
Write (*,*) "fred: ", Size (fred)
Deallocate (fred)
Write (*,*) "fred: ", Size (fred)
Run Code Online (Sandbox Code Playgroud) 我正在使用^实现两个向量的交叉乘积,但是我收到一个错误.不知道如何解决问题.
这是代码
Interface Operator (^)
Module Procedure vector_cross_product
End Interface Operator (^)
Contains
Function vector_cross_product (u, v) Result (w)
!!$ Input
Type (Vector), Intent(in) :: u, v
!!$ Output
Type (Vector) :: w
w% x = (u% y * v% z) - (u% z * v% y)
w% y = (u% z * v% x) - (u% x * v% z)
w% z = (u% x * v% y) - (u% y * v% x)
End Function vector_cross_product
Run Code Online (Sandbox Code Playgroud)
这是我使用gfortran的相应错误
Interface …Run Code Online (Sandbox Code Playgroud) 我想创建一个运算符.f.检查文件是否存在以便我可以写
if (.f. filename) Then ...
Run Code Online (Sandbox Code Playgroud)
我已经写了一个函数来做这个,现在必须创建接口.具有上述功能的e函数参数的约束是什么?
在g ++中我getopt_long用来处理命令行选项.Gfortran是否存在同样的事情?
我希望能够将aguments传递给一些Fortran单元测试.
目前我有以下内容.正如人们可以注意到的那样,我正在照顾自己的关键和价值.使用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 …Run Code Online (Sandbox Code Playgroud) 我正在打开一个必须在最后删除的文件.以下命令抱怨使用dispose.
f = "espy.tmp"; h = "formatted"; r = "read"
Open (newunit=u, file=f, form=h, action=r, &
status="old", dispose="delete")
lib/core.f:177:21:
status="old", dispose="delete")
1
Error: Syntax error in OPEN statement at (1)
Run Code Online (Sandbox Code Playgroud) 我正在写一个函数来返回一个字符串
function doc () Result s
character (Len=65) :: s
...
end function
Run Code Online (Sandbox Code Playgroud)
是否可以使用可变长度字符串,我可以在其中分配返回的字符串的长度.我知道我可以使用子程序来完成它,但不能用于函数.
Function discl (nm) Result (s)
Character (Len=:), Allocatable :: s
Character (Len=*), Intent (In) :: nm
Integer :: n
Character (Len=65) :: stamp
stamp = "Thu May 7 15:13:48 BST 2015"
n = Len_trim (stamp)
Allocate (Character (n) :: s)
s = Trim (fstamp)
End Subroutine discl
Run Code Online (Sandbox Code Playgroud) 我有以下命令来设置我的数组
Use, Intrinsic :: iso_fortran_env
Integer (Int8), Allocatable :: iu(:)
Allocate (iu(4))
iu = [4,3,2,1]
Run Code Online (Sandbox Code Playgroud)
我怎么能阻止编译器给我
Allocate (iu(4)); iu = [4,3,2,1]
1
Warning: Possible change of value in conversion
from INTEGER(4) to INTEGER(1) at (1) [-Wconversion]
Run Code Online (Sandbox Code Playgroud)