- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to create a function CHECK_SIZE_COMPATIBILITY which takes two array arguments. The function returns 1 if the array have the same allocation status, shape and dimension, and 0 otherwise. I want this function to work with multiple array types (for instance, one array would be a logical array, the other a real array; or a integer array and a real array).
One way of doing this is to create a (large) bunch of argument specific procedures, then group them in a generic function. But this is very cumbersome given the number of combinations.
Is there a more convenient way of doing this?
Olivier
One way of doing this is to create a (large) bunch of argument specific procedures, then group them in a generic function. But this is very cumbersome given the number of combinations.
Is there a more convenient way of doing this?
Olivier
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a proposal to add features to Fortran 2008 (as a "Technical Report", not the official standard) which would help you here. In the meantime, I would suggest using the extension !DEC$ ATTRIBUTES NO_ARG_CHECK on the arguments, which will allow them to match anything. You will then need to write code to decode the descriptors (documented in the manuals) and compare the size and allocation status.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
There is a proposal to add features to Fortran 2008 (as a "Technical Report", not the official standard) which would help you here. In the meantime, I would suggest using the extension !DEC$ ATTRIBUTES NO_ARG_CHECK on the arguments, which will allow them to match anything. You will then need to write code to decode the descriptors (documented in the manuals) and compare the size and allocation status.
Here's the example. Adjust the function IsShapeEqual at will. It must be external, because there's inherent interface mismatch.
P.S. Steve, can I officially ask that the type definitions below be added into IFCORE.f90? What we currently have there is half-baked, i.e. only needed to support FOR_DESCRIPTOR_ASSIGN.
[plain]module m_shape
interface
logical function IsShapeEqual(arg1, arg2)
!DEC$ATTRIBUTES NO_ARG_CHECK:: arg1, arg2
integer:: arg1(:,:), arg2(:,:)
end function IsShapeEqual
end interface
end module m_shape
!===============================================================
program Descript
use m_shape
implicit none
real:: x(5,3)
character:: y(5,3)
logical:: z(3,5)
character(17):: u(3,5)
character(17):: w(3,5,7)
write(*,*) shape(x), "| ", shape(y), "| ", IsShapeEqual(x, y)
write(*,*) shape(x(1:2,1:2)), "| ", shape(y), "| ", IsShapeEqual(x(1:2,1:2), y)
write(*,*) shape(x), "| ", shape(z), "| ", IsShapeEqual(x, z)
write(*,*) shape(x), "| ", shape(u), "| ", IsShapeEqual(x, u)
write(*,*) shape(u), "| ", shape(z), "| ", IsShapeEqual(u, z)
write(*,*) shape(x), "| ", shape(w), "| ", IsShapeEqual(x, w)
end program Descript
!===============================================================
logical function IsShapeEqual(arg1, arg2) result(bequal)
use ifcore, only: FOR_DESCRIPTOR_MAX_RANK, &
FOR_DESCRIPTOR_ARRAY_DEFINED, &
FOR_DESCRIPTOR_ARRAY_NODEALLOC , &
FOR_DESCRIPTOR_ARRAY_CONTIGUOUS
type t_dim_info
integer iExtent
integer iStride
integer lBound
end type
type t_array_descriptor
INTEGER(INT_PTR_KIND()) :: pBase
INTEGER(4) :: size
INTEGER(4) :: iOffset
INTEGER(4) :: iFlags
INTEGER(4) :: iRank
INTEGER(4) :: iReserved
type (t_dim_info):: dims(FOR_DESCRIPTOR_MAX_RANK)
end type
type(t_array_descriptor):: arg1, arg2
bEqual = arg1%irank .eq. arg2%irank
if (bEqual) bEqual = all(arg1%dims(1:arg1%irank)%iExtent .eq. &
arg2%dims(1:arg2%irank)%iExtent)
end function IsShapeEqual
[/plain]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to both - that's what I need. I can't wait until these Fortran 2008 features (and some of the others I read about) are implemented as part of the standard. I am amazed at the progress that Fortran has made since I started coding with it in the early 90s. I really like the direction in which it's being headed!
The included example was very helpful.
Olivier
The included example was very helpful.
Olivier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We're more likely to provide an implementation of the F2008 proposal. Indeed, I have had in mind to do that but have been too busy to get to it. See here for the current proposal.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page