小编dan*_*opa的帖子

如何在Fortran中将子例程名称作为参数传递?

将子例程名称作为参数传递的语法是什么?示意图:

  .
  .
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.

fortran subroutine

5
推荐指数
1
解决办法
5057
查看次数

如何使用模块为Fortran程序创建makefile

挑战在于创建一个包含模块列表的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 module makefile gfortran

3
推荐指数
1
解决办法
4145
查看次数

C++ 17是否提供了跨平台方案来记录编译器版本和Fortran等选项?

现代Fortran提供了一些跨平台机制来记录用于构建应用程序的编译器版本和设置.C++ 17有哪些方法可以捕获这些信息?Horton和Van Weert的着作,Beginning C++ 17,似乎没有解决这个问题.

Fortran工具在下面进行了调查.

1.访问编译器版本和选项

iso_fortran_envFortran中提供一种标准方法来访问用于编译代码的编译器版本和设置.随后是一个示例代码段.

代码示例

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)

c++ compilation c++17

3
推荐指数
1
解决办法
146
查看次数

将 sed 与 ${parameter} 一起使用

问题

我们如何在sed编辑字符串中使用变量?

例子

文件statement.txt就是这句话

我喜欢我的宠物鸟。

给定一个变量${myPet},我们如何使用中的值sed替换?bird${myPet}

什么不起作用

sed -ie 's/bird/${myPet}/g' statement.txt

结果是

我喜欢我的宠物${myPet}。

bash sed edit

2
推荐指数
1
解决办法
8819
查看次数

我们可以在Fortran中创建生成随机数的纯函数吗?

我的目标是使用可以在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)

random concurrency fortran gfortran

1
推荐指数
1
解决办法
385
查看次数

Fortran 中的多态数组分配例程

目标是创建一个单一的分配例程,它可以处理任何类型的一级分配。然后,我们的代码库可以使用标准化的错误捕获进行一次调用。

编译器错误如下:

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)

arrays polymorphism fortran allocation gfortran

1
推荐指数
1
解决办法
506
查看次数

现代Fortran中的整数精度

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)

iso fortran long-integer

0
推荐指数
1
解决办法
664
查看次数