Print

Print




On Wed, Oct 13, 2010 at 2:09 PM, Tobias Brandt <[log in to unmask]> wrote:
Hi all,

is there a kind analogue to assumed shape?

To clarify, I can do this:

subroutine foo (bar)
 real :: bar(:)
 print *, size(bar)
end subroutine

But not this:

subroutine foo (bar)
 real(kind=:) :: bar
 print *, kind(bar)
end subroutine

Why is that?

I think it's not allowed because it wouldn't have any real use.  Printing out the KIND of an argument is pretty useless.  What would you actually use it for?  Do you want computations to be done interpretively at run time?  Suppose you have a subroutine like
     subroutine bad_example(a,b,c,d,e,.......zzzzz)
     real(kind=:) ::  a,b,c,        ,zzzzz
     a = b + c + d + .....+zzzzz
what should happen?  Especially if the a,b,c,... have different types.

If you really need broad type independence, you can use polymorphic derived types (see a good Fortran Handbook).  You'll pay as performance penalty, but you can do sort of what you describe.

Dick Hendrickson
 
And how do the intrinsic procedures work that
can take arguments of arbitrary kind, like sin(). Are they
implemented for every possible kind and then exposed through
a generic interface?

That's the general way compilers do it.  The intrinsic procedures have a relatively limited set of interfaces and compilers invoke the correct routine.

Regard,
Tobias