Zeu*_*eus 3 fortran operator-keyword
我想创建一个运算符.f.检查文件是否存在以便我可以写
if (.f. filename) Then ...
Run Code Online (Sandbox Code Playgroud)
我已经写了一个函数来做这个,现在必须创建接口.具有上述功能的e函数参数的约束是什么?
你可以使用inquire内在的:
module fileIO
interface operator( .f. )
module procedure file_exists
end interface
contains
function file_exists(filename) result(res)
implicit none
character(len=*),intent(in) :: filename
logical :: res
! Check if the file exists
inquire( file=trim(filename), exist=res )
end function
end module
program test
use fileIO
print *, file_exists('/dev/null')
print *, .f. '/dev/null'
end program
Run Code Online (Sandbox Code Playgroud)