Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SELECT TYPE Pointer Re-Targeting

12 views
Skip to first unread message

Andrew Baldwin

unread,
May 4, 2011, 10:14:03 PM5/4/11
to
I'm back, now with a question about the select type construct. I am
using select type in a particular situation where I expect to receive
a certain type from a class. Then, based on the components of that
type I want to change the target of my class pointers. Here's an
example program (that compiles under gfortran 4.7.0 20110430) that
does just that in two ways:

program qtest

type dog
integer :: woof
end type dog

type (dog), target :: terrier, dachshund
class (dog), pointer :: spot, fido

terrier%woof = 1
dachshund%woof = 2
spot => terrier
fido => dachshund

select type (spot)
type is (dog)
select type (fido)
type is (dog)
if (spot%woof .lt. fido%woof) spot => fido
end select
end select

print *, associated(spot, target=dachshund)

select type (woofer => spot)
type is (dog)
select type (fido)
type is (dog)
if (woofer%woof .lt. fido%woof) spot => fido
end select
end select

print *, associated(spot, target=dachshund)

end program qtest

At this point I think I understand roughly why the first method does
not work: spot acts as its target and not as itself within the select
type construct (or to put it another way, spot is an alias for terrier
and nothing more within the select type construct). I'm a bit
confused as to what the line

if (spot%woof .lt. fido%woof) spot => fido

actually does after compilation. Does it do anything? Or perhaps
more importantly, is that line conforming within the select type
construct? And, is there a better way to go about this than either of
the methods?

Wolfgang Kilian

unread,
May 5, 2011, 4:48:18 AM5/5/11
to

My nagfor 5.2 complains about that line:

Error: woof.f90, line 19: SPOT is not a POINTER
detected at SPOT@=>
[NAG Fortran Compiler pass 1 error termination, 1 error]

nagfor is probably right. If I read the standard correctly (8.1.5), the
first method associates the name 'spot' with the (target of) the
expression 'spot'. The name inherits some properties of the expression.
It doesn't inherit the pointer attribute because the pointer is
dereferenced before doing the association. Within the select type
construct, the associate name 'spot' shadows the variable 'spot'.

The same happens for 'fido', but the target attribute is inherited from
the expression 'fido', so this is no problem.

The second method does it right, I guess.

About what the compiler does with that line: it may issue an error
because the line is not standard-conforming. I don't know whether it is
required to issue an error.

-- Wolfgang


--
E-mail: firstnameini...@domain.de
Domain: yahoo

Paul van Delst

unread,
May 5, 2011, 11:01:57 AM5/5/11
to
Wolfgang Kilian wrote:
> On 05/05/2011 04:14 AM, Andrew Baldwin wrote:
>> I'm back, now with a question about the select type construct.

[snip program]

>> At this point I think I understand roughly why the first method does
>> not work: spot acts as its target and not as itself within the select
>> type construct (or to put it another way, spot is an alias for terrier
>> and nothing more within the select type construct). I'm a bit
>> confused as to what the line
>>
>> if (spot%woof .lt. fido%woof) spot => fido
>>
>> actually does after compilation. Does it do anything? Or perhaps
>> more importantly, is that line conforming within the select type
>> construct? And, is there a better way to go about this than either of
>> the methods?
>
> My nagfor 5.2 complains about that line:
>
> Error: woof.f90, line 19: SPOT is not a POINTER
> detected at SPOT@=>
> [NAG Fortran Compiler pass 1 error termination, 1 error]

xlf2003 complains about it also:

ftest : xlf2003 qtest.f90
"qtest.f90", line 19.35: 1515-038 (S) Only an object with the POINTER attribute is permitted on the left hand side of a
pointer assignment.
** qtest === End of Compilation 1 ===
1501-511 Compilation failed for file qtest.f90.

ftest : xlf2003 -qversion
IBM XL Fortran for AIX, V12.1
Version: 12.01.0000.0001

cheers,

paulv

0 new messages