Fortran Coder

查看: 9529|回复: 1
打印 上一主题 下一主题

[混编] 实现C++的整个多维数组的数据向fortran dll的函数中传递

[复制链接]

14

帖子

4

主题

0

精华

入门

F 币
11 元
贡献
42 点
QQ
跳转到指定楼层
楼主
发表于 2017-7-17 14:18:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
20F 币
本帖最后由 cfortran 于 2017-7-17 14:21 编辑

fortran代码:
[Fortran] 纯文本查看 复制代码
module hydromodelUtil
  use iso_c_binding
  implicit none
  double precision, parameter :: pi=acos(-1.d0)
  !这部分为输出值
  type ,Bind(C):: singleinfo
    integer(c_int) :: controlno
    integer(c_int) :: unittype
    integer(c_int) :: solid
    real(c_double) :: coearea
    real(c_double):: volume
    real(c_double), dimension(3) :: center
    integer (c_int):: pointcount, trianglecount
    type(C_PTR) :: pointchain , trianglechain
  end type singleinfo
contains
    subroutine prismmeshing(pn, plistdown, plistup, h, prisminfo) Bind(C,Name="prismmeshing")
    !DEC$ ATTRIBUTES DLLEXPORT::prismmeshing  
    implicit none
 
    integer(c_int) :: pn  
    real(c_double), dimension(2, pn) :: plistdown, plistup 
    real(c_double) :: h 
    type(singleinfo) :: prisminfo 
    real(c_double),dimension(:,:),allocatable,target,save::pointchain
    integer(c_int) :: meshi 
    prisminfo%pointcount=2*pn 
    allocate(pointchain(3, prisminfo%pointcount+2))         
    do meshi=1, pn
      pointchain(1:2,2*meshi-1)=plistdown(:,meshi)
      pointchain(3  ,2*meshi-1)=0.d0
      pointchain(1:2,2*meshi)=plistup(:,meshi)
      pointchain(3  ,2*meshi)=h
    end do
    pointchain(:,2*pn+1)=pointchain(:,1)
    pointchain(:,2*pn+2)=pointchain(:,2)
    prisminfo%pointchain=c_loc(pointchain) 
    end subroutine prismmeshing   
end module hydromodelUtil
C++代码:
[C++] 纯文本查看 复制代码
struct singleinfo
{
        int cotrolno;
        int unittype;
        int solid;
        double coearea;
        double volume;
        double center[3];
        int pointcount;
        int trianglecount;
        double *pointchain;
        double *trianglechain;
};
public:
        singleinfo cylinderinfo;
extern "C"{
        void prismmeshing(int &,double (*plistdown)[][2],double (*plistup)[][2],double &,struct singleinfo*);
}
void Chydro2View::OnMeshing()
{

    
        int pn=3;
        double plistdown[][2]={
                {0,0},
                {0,-8},
                {12.5,0}
        };
        double plistup[][2]={
                {0,0},
                {0,-8},
                {12.5,0}
        };

        double h1=15;
        prismmeshing(pn,&(plistdown),&(plistup),h1,&cylinderinfo);
        CString str3;
        str3.Format("%lf",cylinderinfo.trianglechain[24]);
        this->MessageBox(str3);
}

在网上找的传递方法,可是怎么改都不对,想问一下如何实现C++的整个多维数组的数据向fortran dll的函数中传递


最佳答案

查看完整内容

传递时,视为单变量传递。(即传递第一个元素的地址即可) [mw_shl_code=fortran,true]extern "C" { void prismmeshing(int &, double * plistdown, double *plistup , double &, struct singleinfo*); } struct singleinfo cylinderinfo; int main() { int pn = 3; double plistdown[][2] = { { 0, 0 }, { 0, -8 }, { 12.5, 0 } }; double plistup[][2] = { { 0, 0 }, ...
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

235

帖子

0

主题

0

精华

版主

World Analyser

F 币
630 元
贡献
464 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
沙发
发表于 2017-7-17 14:18:37 | 只看该作者
传递时,视为单变量传递。(即传递第一个元素的地址即可)
[Fortran] 纯文本查看 复制代码
extern "C" {
    void prismmeshing(int &, double * plistdown, double *plistup , double &, struct singleinfo*);
  }
  struct singleinfo cylinderinfo;
  int main()
  {


    int pn = 3;
    double plistdown[][2] = {
      { 0, 0 },
      { 0, -8 },
      { 12.5, 0 }
    };
    double plistup[][2] = {
      { 0, 0 },
      { 0, -8 },
      { 12.5, 0 }
    };

    double h1 = 15;
    prismmeshing(pn, &plistdown[0][0], &plistup[0][0], h1, &cylinderinfo);
    cout << cylinderinfo.trianglechain[24] ;
  }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-4-23 17:23

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表