将子例程名称作为参数传递的语法是什么?示意图:
.
.
call action ( mySubX ( argA, argB ) )
.
.
subroutine action ( whichSub ( argA, argB ) )
...
call subroutine whichSub ( argA, argB )
...
end subroutine action
Run Code Online (Sandbox Code Playgroud)
目标是call subroutine whichSub ( argA, argB )
采取行动call subroutine mySubX ( argA, argB )
.我的偏好是避免传递switch参数然后使用SELECT CASE.
挑战在于创建一个包含模块列表的makefile,并且不需要我排除优先级.例如,模块是
mod allocations.f08 mod precision definitions.f08 mod unit values.f08
mod blocks.f08 mod shared.f08 mod parameters.f08
mod timers.f08
Run Code Online (Sandbox Code Playgroud)
主要计划是characterize.f08
.错误消息是
Fatal Error: Can't open module file ‘mprecisiondefinitions.mod’ for reading at (1): No such file or directory
主程序中的第一个语句是use mPrecisionDefinitions
,中定义的模块mod precision definitions.f08
.
以下基于创建FORTRAN makefile的makefile是:
# compiler
FC := /usr/local/bin/gfortran
# compile flags
FCFLAGS = -g -c -Wall -Wextra -Wconversion -Og -pedantic -fcheck=bounds -fmax-errors=5
# link flags
FLFLAGS =
# source files and objects
SRCS = $(patsubst …
Run Code Online (Sandbox Code Playgroud) 现代Fortran提供了一些跨平台机制来记录用于构建应用程序的编译器版本和设置.C++ 17有哪些方法可以捕获这些信息?Horton和Van Weert的着作,Beginning C++ 17,似乎没有解决这个问题.
Fortran工具在下面进行了调查.
在iso_fortran_env
Fortran中提供一种标准方法来访问用于编译代码的编译器版本和设置.随后是一个示例代码段.
program check_compiler
use, intrinsic :: iso_fortran_env, only : compiler_options, compiler_version
implicit none
write ( *, 100 ) "compiler version = ", compiler_version ()
write ( *, 100 ) "compiler options = ", trim ( compiler_options () )
100 format ( A, A, / )
stop "normal termination . . ."
end program check_compiler
Run Code Online (Sandbox Code Playgroud)
$ gfortran -o check_compiler check_compiler.f08
$ ./check_compiler
compiler version = GCC version …
Run Code Online (Sandbox Code Playgroud) 我们如何在sed
编辑字符串中使用变量?
文件statement.txt
就是这句话
我喜欢我的宠物鸟。
给定一个变量${myPet}
,我们如何使用中的值sed
替换?bird
${myPet}
sed -ie 's/bird/${myPet}/g' statement.txt
结果是
我喜欢我的宠物${myPet}。
我的目标是使用可以在DO CONCURRENT结构中使用的随机数编写纯函数.编译器似乎不允许这样做.
mwe.f95:8:30:
call init_seed ( )
1
Error: Subroutine call to ‘init_seed’ at (1) is not PURE
mwe.f95:9:36:
call random_number ( y )
1
Error: Subroutine call to intrinsic ‘random_number’ at (1) is not PURE
mwe.f95:16:8:
use myFunction
1
Fatal Error: Can't open module file ‘myfunction.mod’ for reading at (1): No such file or directory
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
为什么会这样,有没有办法在纯粹的例程中生成随机数?
MWE如下.编译命令是gfortran mwe.f95
.编译器版本是GCC 5.1.0.
module myFunction
implicit none
contains
pure real function action ( ) result ( new_number )
real …
Run Code Online (Sandbox Code Playgroud) 目标是创建一个单一的分配例程,它可以处理任何类型的一级分配。然后,我们的代码库可以使用标准化的错误捕获进行一次调用。
编译器错误如下:
generic_allocation.f08:32:27:
call myAllocator ( array_int, source_int, lambda )
1
Error: Actual argument to ‘myarray’ at (1) must be polymorphic
generic_allocation.f08:33:27:
call myAllocator ( array_real, source_real, lambda )
1
Error: Actual argument to ‘myarray’ at (1) must be polymorphic
Run Code Online (Sandbox Code Playgroud)
这段代码可以修改吗?
测试代码尝试分配一个整数数组,然后分配一个实数数组:
module mAllocator
implicit none
contains
subroutine myAllocator ( myArray, source_type, lambda )
class ( * ), allocatable, intent ( inout ) :: myArray ( : )
class ( * ), intent ( in ) :: source_type
integer, intent …
Run Code Online (Sandbox Code Playgroud) 值selected_int_kind(int16)
显示为1而不是2.这是编译器错误吗?
在下面的输出中请注意其差异bint
是2个字节,INT16
.(为清楚起见,添加了注释<===.)
compiler version = GCC version 5.1.0
compiler options = -fPIC -mmacosx-version-min=10.9.4 -mtune=core2 -Og -Wall -Wextra -Wconversion -Wpedantic -fcheck=bounds -fmax-errors=5
execution command = ./a.out
Number of bytes in type default = 4
Number of bytes in type int_8 = 1
Number of bytes in type int_16 = 2 <===
Number of bytes in type int_32 = 4
Number of bytes in type int_64 = 8
Number of bytes in type int_a = 1 …
Run Code Online (Sandbox Code Playgroud) fortran ×5
gfortran ×3
allocation ×1
arrays ×1
bash ×1
c++ ×1
c++17 ×1
compilation ×1
concurrency ×1
edit ×1
iso ×1
long-integer ×1
makefile ×1
module ×1
polymorphism ×1
random ×1
sed ×1
subroutine ×1