- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I have some problems to declare an array into a structure type.
Thedimensions are passed as an argument of a subroutine.
For example:
Subroutine FSUB(Gn,Cv,Mv,NCdim,NVdim,NPdim)
structure Fortran
real*4 arrayA(NCdim,NVdim)
real*4 arrayB(NVdim,NPdim)
end structure
I receive the following message:
Error: Adjustable, assumed-size, or passed-length declarations are invalid in fielddeclarations. [arrayA]
Can anybody help me?
Thanks in advance.
MSantos
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A structure (or defined) type has a fixed size in Fortran. You're asking it to create a type whose size changes depending on run-time values, and that's not doable in Fortran. What you can do is use ALLOCATABLE arrays as the structure elements - these can be allocated to any dimension.
I suggest using the standard Fortran TYPE syntax rather than the STRUCTURE/RECORD extension.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
But, if I use ALLOCATABLE arrays as the structure elements, the structure has a variable size. Its works?
The problem is that the arrayA and arrayB will be determined from arrays passed as argument from C.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not really -- an allocatable array within a structure approximately works like a C pointer -- it's a fixed-size reference to data which actually exist elsewhere in memory.m.santos:But, if I use ALLOCATABLE arrays as the structure elements, the structure has a variable size.
Note that approximately above means it's not the same as C pointer (it's an approx. 8-word descriptor in IVF implementation), and you can't exchange it with C as such (if you'd like to).
Perhaps we could offer some broader perspective suggestions if you could explain more precisely what you're trying to do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I understand your problem andI have a suggestion. The C program is passing you the address of a structure with one or more variable length sub-structures within the C structure. The suggestion I have is to create a structure reference structure the purpose of which is to map the C structure in a manner acceptible to Fortran
type CFixedData
! define the fixed data layout
end type CFixedData
type CRefStruct
type(CFixedData), pointer :: pFixed
integer, pointer :: pVariable(:)
end type cRefStruct
type(CRefStruct) :: aCRefStruct
Then upon receipt of the C structure pointer, initialize the aCRefStruct.
You can extend this such that if the variable data consists of a small number of different sub structures then you can define the C structure using a UNION with the different sub structures
type Cstructure
sequence
! define fixed portion
union
map
! define 1st variant
end map
map
! define 2nd variant
end map
! more map, defines, end map
end union
end type Cstructure
Jim Dempsey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page