libstruct error when structures contains a pointer
4 次查看(过去 30 天)
显示 更早的评论
I have an integer array of pointers called "Items" defined within a structure that is part of another structure in Fortran as follows:
subroutine ex(set)
!DEC$ ATTRIBUTES DLLEXPORT :: ex
!DEC$ ATTRIBUTES ALIAS: 'ex' :: ex
!DEC$ ATTRIBUTES REFERENCE :: set
Type LIST_INT
Integer :: Count = 0
Integer, Pointer :: Items(:)
End Type
Type Settings
Type(LIST_INT) :: Steps ! Steps between output times.
End Type
Type(Settings), Intent(INOUT) :: set ! Somewhere to put settings.
!Testing
set%Steps%Count = 5
set%Steps%Items(1) = 5
set%Steps%Items(2) = 7
end subroutine
My C header file looks like this:
#include<stdio.h>
struct sim{
struct step{
int Count;
int *Items[2];
};
};
void ex(struct sim*);
And the script I use to call the "ex" sub-routine looks like this:
set.steps.Count = 1;
set.steps.Items(1) = 1;
set.steps.Items(2) = 1;
loadlibrary('x64\Debug\ex.dll')
s = libstruct('sim',set);
[settings] = calllib('ex', 'ex', s);
When trying to launch the script that calls the Fortran routine I get the following error:
Error using feval
A field does not match one in the struct.
Error in libstruct (line 20)
ptr=feval(['lib.' structtype],initialvalue);
Error in program (line 31)
s = libstruct('sim',set);
This clearly refers to the way I am defining int *Items[2]. How can I solve this ?
Any help would be appreciated !
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!