- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not quite sure how to interpret the Fortran standard regarding use of arrays as unlimited polymorphic entities. I have a prcedure that accepts an unlimited polymorphic entity and I want to pass an array of real values. But when I try to assign a pointer to the array I get and error. Here's some sample code that illustrates the problem:
real(kind=kind(1.0)), dimension(3), target :: real_array
class(*), pointer :: real_array_ptr
real_array = [1.0, 2.0, 3.0]
real_array_ptr => real_array
The error is:
test.f(18): error #6794: The rank of the target is different from the pointer [REAL_ARRAY_PTR]
real_array_ptr => real_array
--^
Is a real array object type compatible with an unlimited polymorpic object, and if so, how should the code be written to handle this?
ifort -V
Intel® Fortran Intel® 64 Compiler XE for applications running on Intel® 64, Version 12.1.5.344 Build 20120612
Xcode version: 3.2.6
Mac OS X version 10.6.8
real(kind=kind(1.0)), dimension(3), target :: real_array
class(*), pointer :: real_array_ptr
real_array = [1.0, 2.0, 3.0]
real_array_ptr => real_array
The error is:
test.f(18): error #6794: The rank of the target is different from the pointer [REAL_ARRAY_PTR]
real_array_ptr => real_array
--^
Is a real array object type compatible with an unlimited polymorpic object, and if so, how should the code be written to handle this?
ifort -V
Intel® Fortran Intel® 64 Compiler XE for applications running on Intel® 64, Version 12.1.5.344 Build 20120612
Xcode version: 3.2.6
Mac OS X version 10.6.8
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
class(*) will match any type and kind, but you still are required to match rank (unless the called routine is ELEMENTAL). It is not a "C void *" type of thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve, thanks for your response. I think I'm missing something very basic here. The error message I reported is occuring before the call to the procedure. The pointer assignment of class(*) to real array is the source of the error. I apologize for what may be a basic question, but how do I assign a class(*) pointer to a real array (i.e. such that the objects have equal rank)? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you declare the pointer, specify that it points to a rank one array:
[fortran]class(*), pointer :: array(:) ! Note trailing (:)[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Steve. That change does fix the rank mismatch problem.
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