小编use*_*640的帖子

将char数组从c ++传递给fortran

我无法将char数组从c ++传递给fortran(f90).

这是我的c ++文件'cmain.cxx':

#include <iostream>

using namespace std;

extern "C" int ftest_( char (*string)[4] );

int main() {
    char string[2][4];

    strcpy(string[0],"abc");
    strcpy(string[1],"xyz");

    cout << "c++: string[0] = '" << string[0] << "'" << endl;
    cout << "c++: string[1] = '" << string[1] << "'" << endl;

    ftest_(string);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是我的fortran文件'ftest.f90':

SUBROUTINE FTEST(string)

CHARACTER*3 string(2)
CHARACTER*3 expected(2)
data expected(1)/'abc'/
data expected(2)/'xyz'/

DO i=1,2
    WRITE(6,10) i,string(i)
10  FORMAT("fortran: string(",i1,") = '", a, "'" )

    IF(string(i).eq.expected(i)) THEN
        WRITE(6,20) string(i),expected(i)
20      FORMAT("'",a,"' …
Run Code Online (Sandbox Code Playgroud)

c++ arrays fortran

6
推荐指数
2
解决办法
6495
查看次数

Python:优化循环

我希望优化一些由两个嵌套循环组成的python代码.我对numpy并不那么熟悉,但据我所知,它应该能够帮助我提高这项任务的效率.下面是我编写的测试代码,它反映了实际代码中发生的情况.目前使用numpy范围和迭代器比通常的python更慢.我究竟做错了什么?这个问题的最佳解决方案是什么?

谢谢你的帮助!

import numpy
import time

# setup a problem analagous to that in the real code
npoints_per_plane = 1000
nplanes = 64
naxis = 1000
npoints3d = naxis + npoints_per_plane * nplanes
npoints = naxis + npoints_per_plane
specres = 1000

# this is where the data is being mapped to
sol = dict()
sol["ems"] = numpy.zeros(npoints3d)
sol["abs"] = numpy.zeros(npoints3d)

# this would normally be non-random input data
data = dict()
data["ems"] = numpy.zeros((npoints,specres))
data["abs"] = numpy.zeros((npoints,specres))
for ip in …
Run Code Online (Sandbox Code Playgroud)

python loops numpy

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

标签 统计

arrays ×1

c++ ×1

fortran ×1

loops ×1

numpy ×1

python ×1