Azzera filtri
Azzera filtri

libstruct error when structures contains a pointer

1 visualizzazione (ultimi 30 giorni)
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 !

Risposte (0)

Categorie

Scopri di più su Fortran with MATLAB in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by