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