- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个程序,主要由 Fortran 77 和一个 C++ 包装器组成,可以读取和写入数据库。应用程序的两个部分通过使用一个功能共享数据,如果您使用一个名为 Fortran 公共(public) block 的全局 C/C++ 结构。我很确定这种 C++/Fortran 集成的别名方法 1) 适用于许多编译器套件,2) 是 *not8 标准。我尝试维护我的代码,以便它尽可能多地使用标准组件。此外,这种集成已被证明是脆弱的。
在 utd.h 中:
/*************************************************************
* This struct must follow the common block points.
* See the Fortran include file points.i
*************************************************************/
typedef struct ALIGN points
{
double point[3][MAX_PTS];
double edge[3][MAX_PTS];
double edgenorm[3][MAX_PTS];
double edgerho[MAX_PTS];
int nfacets[MAX_PTS];
double facet1[3][MAX_PTS];
double facet2[3][MAX_PTS];
double gaussk[MAX_PTS];
int sbstin[MAX_PTS];
int coatin[MAX_PTS];
int sbstout[MAX_PTS];
int coatout[MAX_PTS];
int ncorners[MAX_PTS];
double cnrpoint[3][MAX_CNRS][MAX_PTS];
int ncnredgs[MAX_CNRS][MAX_PTS];
double cnredge[3][MAX_CNREDS][MAX_CNRS][MAX_PTS];
int cnrsbst[MAX_CNREDS][MAX_CNRS][MAX_PTS];
int cnrcoat[MAX_CNREDS][MAX_CNRS][MAX_PTS];
int npoints;
} POINTS;
extern POINTS points_;
在 utd.cpp 中:
POINTS points_;
在 points.i 中:
! maxpnt - maximum number of points in a path.
integer maxpnt
parameter ( maxpnt = 1000 )
integer npoints, nfacets(maxpnt)
integer ncorners(maxpnt), ncnredgs(maxpnt,maxcorners)
integer sbstin(maxpnt), coatin(maxpnt)
integer sbstout(maxpnt), coatout(maxpnt)
double precision point(maxpnt,3)
double precision edge(maxpnt,3), edgenorm(maxpnt,3)
double precision edgerho(maxpnt)
double precision facet1(maxpnt,3), facet2(maxpnt,3)
double precision gaussk(maxpnt), cnrpoint(maxpnt,maxcorners,3)
double precision cnredge(maxpnt,maxcorners,maxcnredges,3)
integer cnrsbst(maxpnt,maxcorners,maxcnredges)
integer cnrcoat(maxpnt,maxcorners,maxcnredges)
common /points/ point, edge, edgenorm, edgerho,
* nfacets, facet1, facet2, gaussk,
* sbstin, coatin, sbstout, coatout,
* ncorners, cnrpoint, ncnredgs,
* cnredge, cnrsbst, cnrcoat,
* npoints
有没有更好的方法?我可能想将公共(public) block 转换为模块。然后,我确定这种使用全局结构为公共(public) block 别名的业务已经过时了。您如何从 C++ 构建 Fortran 模块?你如何从这样的模块中读取数据?
您对 C++/Fortran 集成有何建议?
最佳答案
Fortran 2003 的 ISO C 绑定(bind)使 C 和 Fortran 的互操作性成为 Fortran 语言标准的一部分,因此编译器和平台可移植。如果您只使用 C 的功能,它很可能会在 C++ 中工作,尽管这可能不能绝对保证。您可以混合使用 Fortran 2003 和 FORTRAN 77,可以在一个源文件中混合使用,也可以混合使用两种语言版本编写的例程。 ISO C 绑定(bind)支持结构和模块变量作为全局变量,因此它可以实现您的目标。这两个都显示在 gfortran 手册的混合语言编程章节中。 (ISO C 绑定(bind)不是 gfortran 特有的,我引用它作为一个很好的文档。)
公用 block 也受支持,但我同意你的看法,最好避免...公用 block 添加在 FORTRAN 存储序列和布局上,这是不必要的。我看不出有任何方法可以手动维护 C 和 Fortran“结构”以具有等效声明。如果这是脆弱的原因,你只需要小心(除非编写一个程序来从通用指令编写)。一种使它更容易一点的方法是不将变量放入结构中......然后让一个新变量出错不太可能影响旧变量并且可能更容易注意到或调试错误。
关于c++ - 如何从公共(public) block 重新设计 Fortran 和 C++ 混合语言库 - 全局结构别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11811114/
是的,我知道..,这不是想象的...这是一个真正的 Fortran 问题。 以前的版本是指 Fortran 2003、95、90,甚至 77。 我所说的“向后兼容”是指可以轻松运行为 2008 年以前
我有一个程序,它的变量中有一个值。一旦确定了该值,我想调用另一个程序并使用该变量的值来确定在新程序中的位置。有人知道该怎么做吗? 最佳答案 如果您有 Fortran 2008 编译器,您将拥有标准子例
namelist 是一种有用的 fortran 结构,可以从文件中快速初始化变量。 namelist 有一个名称并包含一组具有已知类型的变量。这使得它类似于 type 结构。 通常情况下,给程序或子例
我正在遍历索引,我正在检查我是否不在第一个循环交互和另一个条件中。如果第一个条件是 .False.,我不想评估第二个条件。 do i = 1, n if ( i /= 1 .and. var(
Fortran 2003 具有用于数组连接的方括号语法,Intel fortran 编译器也支持它。我在这里为矩阵连接写了一个简单的代码: program matrix implicit none r
我正在尝试通过重载类型名称来制作自定义数据类型构造函数。但是,在进行调用时,将调用默认构造函数。我不明白我做错了什么。 这是有问题的代码片段。 module test type, pu
我的最终目标是在 Fortran 中有一个通用的映射函数,即一个接受任意类型 A 的数组和一个 A->B 类型的函数的函数,将此函数应用于给定数组的所有元素并返回一个B 类型的数组。我无法用数组实现它
我正在学习 Fortran,在使用格式编写时发现了一些奇怪的东西(我使用的是 Fortran onlinegdb) Program Hello real, dimension(3,2):: array
Fortran 中的INTERFACE 语句是否使其成为正式实现multiple dispatch 的编程语言? ? (我问是因为所链接的维基百科文章在其看似全面的支持相关范式的示例编程语言列表中并未
我可以使用 Fortran 95 编译器编译 Fortran 90 文件吗? Fortran 95 似乎有很多,但 Fortran 90 没有。 最佳答案 这个可以: NAGWare f95 Comp
嗨,我在 Fortran 中对二维离散化问题强加边界条件时遇到了麻烦。我的离散化网格是一个二维正方形,在 x,y 方向上从 -L 到 L。 我想强加这样的边界条件, 在 x=L 的边界线上,指定了函数
Fortran 是否有与 C assert 等效的标准函数/关键字? ? 我找不到 assert我在Fortran2003标准中提到过。我发现了一些如何使用预处理器的方法,但是在这个 answer建议
我有一系列的作业,使用“;”将它们分配给同一个ike。分开statemnts,但我收到此错误: 1.0;磅(1,9) 1个 错误:(1)处无法分类的陈述 在文件LJ.F90:223中 如果每个语句都在
我正在使用 gfortran -std=f2008。我有一个函数,它返回一个包含可分配数组的派生类型。该函数在返回之前调用allocate()。似乎在分配数组的函数返回之后,数组会自动释放一段时间,并
我制作了这个小型测试程序来“证明”在编译之前(或者如果你让它们可分配),你不能在不指定它们的大小的情况下使用向量。我的观点失败了。我期待本地向量“num”会失败。程序在执行程序之前无法知道它的大小。大
出于优化原因,Fortran 强制子例程或函数的虚拟参数不是别名,即它们不指向相同的内存位置。 我想知道相同的约束是否适用于函数的返回值。 换句话说,对于给定的 myfunc 函数: function
我已经在Fortran 90中编写了一个相当大的程序。它已经运行了一段时间了,但是今天我尝试将其提高一个档次并增加问题的大小(这是研究非标准的有限元求解器,如果那样的话)。可以帮助任何人...)现在,
在 C 和 C++ 中,有许多操作会导致未定义的行为,即允许编译器做任何它想做的事情的情况。 Examples包括在释放变量后使用它,释放变量两次和取消引用空指针。 Fortran 是否也有未定义的行
通常我使用fortran进行数值分析,然后使用matlab、R和python进行后期和前期工作。 我发现 matlab、R 和 python 在终端中提供了命令提示符,以便您可以运行脚本以及从命令行立
在 Fortran 中将变量设置为 +Infinity 的最安全方法是什么?目前我正在使用: program test implicit none print *,infinity() con
我是一名优秀的程序员,十分优秀!