问题标签 [fortran2003]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
4757 浏览

optimization - Heaviside 函数的优化实现

我想(超级)优化 Heaviside 函数的实现。

我正在研究一种速度特别重要的数值算法(在 Fortran 中)。这多次使用 Heaviside 函数,目前由 signum 内部函数实现,如下所示:

我主要对 x 是英特尔处理器上的双精度实数的情况感兴趣。

是否可以开发更有效的 Heaviside 功能实现?也许使用汇编语言、超级优化代码或调用现有的外部库?

0 投票
2 回答
140 浏览

oop - 如何根据多态变量的数据类型指定要执行的过程

考虑以下示例代码:

我想做的是子程序calculComplexType调用不同版本的子程序calcul,基于ptrBase1、ptrBase2和ptrBase3的动态类型。

该代码不起作用,因为编译器会查找具有以下接口的子例程:

无论 ptrBase1、ptrBase2 和 ptrBase3 的动态类型是什么。

我的问题是:在 Fortran 中有没有办法编写接口计算,以便根据参数的动态类型自动选择一个过程?

我想避免使用长序列的“选择类”。

欢迎任何重写代码的建议!

0 投票
2 回答
1594 浏览

fortran - 具有重载赋值的嵌套派生类型

我有一个派生类型 ( wrapper),其中包含另一个派生类型 ( over)。对于后者,赋值运算符已被重载。由于派生类型的分配是按默认组件进行的,我希望分配两个实例会在某些时候wrapper调用重载分配。over但是,使用下面的程序,似乎并非如此。wrapper仅当我还为包含实例之间的显式赋值而重载赋值时才调用重载赋值over(通过取消注释代码行)。为什么?我觉得这有点违反直觉。有什么办法可以避免包装类型的重载?

0 投票
2 回答
4215 浏览

fortran - Fortran 派生类型赋值

假设我有一个 Fortran 派生类型

我有两个这种类型的实例

当我做以下任务时到底会发生什么?

我对此感兴趣,因为我想正确地制作派生类型变量的副本,这意味着标量组件应该相等,数组组件的每个元素应该相等,可分配数组应该具有相同的分配大小并且元素应该相等。目前我只想编写一个子程序来正确复制和分配组件。

我将不胜感激有关标准中适当部分的指示。

我正在使用 gfortran 4.7。

0 投票
1 回答
2036 浏览

oop - 如何使用 ifort 链接包含类的 Fortran 库

我试图确定为什么在链接具有包含类型绑定过程的类的静态库时收到错误消息。

当我在命令行上编译和链接时:

这有效(并且生成的可执行文件正常运行)

ifort src/main.F90 C:\Temp\lib\test.lib /include:"C:\Temp\mod" $(Opts) /link $(Lnk)

但这不起作用

ifort src/main.F90 /include:"C:\Temp\mod" $(Opts) /link /LIBPATH:"C:\Temp\lib\test.lib" $(Lnk)

对于后一个命令为什么不起作用的任何建议,我将不胜感激。这是我链接典型库的命令行格式。下面来自后一个命令的链接错误指的是包含在 test.lib 中的 Fortran 类定义的类型绑定过程。

(请注意,ifort 和链接器版本包含在下面。平台是 Windows 7,我在上述两种情况下都通过 MinGW 使用 make)

0 投票
0 回答
93 浏览

r - R在Fortran中列出数据类型

我需要在 Fortran 中表示 R 数据类型的帮助。

我的 R 代码:

mList <- list()

我想mList通过将 Fortran 函数作为参数传递给 Fortran 函数来使用它。list()Fortran中对应的 R数据类型是什么?

我的 Fortran 代码

我应该用什么代替XXX

0 投票
1 回答
1508 浏览

recursion - Fortran 函数调用引发错误:(1) 处的语句函数在编译时是递归的

我继承了传统的Fortran 77代码,现在我尝试Fortran 2003标准中进行编译。我对 Fortran (我知道 C 和 Python)一无所知,我正在学习它。

下面的代码片段会导致编译器错误(也在下面给出)。说实话,光看这段代码就很头疼:我真的不明白怎么能写出这样一行代码

A(i) = A(i) + B(q)

其中 A 和 B 都是函数。我熟悉 C 和 Python 中递归函数的概念,如果我是此处介绍的这种情况下的编译器,我可能会抱怨并至少提出WTF警告。

我不希望任何人为我修复此代码。如果有人可以向我解释该行(尝试)要实现的目标,我将非常高兴:

或者把我介绍给我可以查到的好地方。

下面是代码片段和相应的编译器错误。

编译器将此输出消息作为错误提供

0 投票
1 回答
922 浏览

fortran - 这个 Fortran 程序有什么问题?

我不知道这个自由格式的 Fortran 程序有什么问题。它没有正确处理其命令行参数。

如果我对命令行参数使用静态数组而不是数组,它会起作用allocatable

另外,这是一个很好的第一个 Fortran 程序吗?这是 Fortran 有用的问题类型吗?我已经知道 C、C++ 和一点点 D。

0 投票
1 回答
88 浏览

fortran - changing pointer members of a subroutine argument with intent(in)

I'm writing a sparse matrix library in Fortran for fun but came into a little snag. I have a subroutine for matrix multiplication with the interface

This uses a sparse matrix type that I've defined myself, the implementation of which is unimportant. Now, I can make things nicer and have a lot less code if A contains an object called iterator:

which stores a few variables that keep track of things during matvec. But, if I change the state of iterator and in turn the state of A during matrix multiplication, the compiler will throw a fit because A has intent(in) for that subroutine.

Suppose I change things around and instead define

It's no problem if I change the state of iterator during a procedure in which a matrix has intent(in), because the value of the pointer to iterator doesn't change; only the memory stored at that address is affected. This is confirmed by making a reduced test case, which compiles and runs just fine using GCC.

Am I correct in thinking this is an appropriate fix? Or should I change the subroutine so that A has intent(inout)? The fact that it compiled with GCC doesn't necessarily mean it's standard-compliant, nor does it mean it's good programming practice.

To make an analogy with C, suppose I had a function foo(int* const p). If I wrote

this would be ok, as the value of the pointer doesn't change, only the data stored at the address pointed to. On the other hand, I couldn't write

because it's a constant pointer.

0 投票
1 回答
153 浏览

c - 无法链接小型 C 和 Fortran 程序

我有一个小型 C 程序,我想链接到一个小型 Fortran 程序,但得到链接器错误undefined reference to fibonacci_array

Fortran 代码:

C代码:

生成文件:

错误信息: