Message from discussion procedures with "generic kind" dummy arguments
Received: by 10.66.74.102 with SMTP id s6mr2845836pav.21.1350918002891;
Mon, 22 Oct 2012 08:00:02 -0700 (PDT)
Received: by 10.68.219.198 with SMTP id pq6mr2521676pbc.0.1350918002875; Mon,
22 Oct 2012 08:00:02 -0700 (PDT)
Date: Mon, 22 Oct 2012 08:00:02 -0700 (PDT)
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=22.214.171.124;
Subject: procedures with "generic kind" dummy arguments
From: Stefano Zaghi <stefano.za...@gmail.com>
Injection-Date: Mon, 22 Oct 2012 15:00:02 +0000
Content-Type: text/plain; charset=ISO-8859-1
I would like to write procedures (functions and subroutines) that "mime" the behavior of some internal procedures like sin(x), cos(x)...
For these family of internal procedures the dummy argument "x" can be real or complex with any kind and the result is of the same kind of "x". The attention (for me) is focused on the precision of the operation (kind) performed and on its efficiency.
Up to now I obtain this behavior by means of the dynamic dispatching ability with a generic interface and programming each procedure for each different kind, e.g.
module procedure foo_R8,foo_R4
function foo_R8(x) result(foo)
function foo_R4(x) result(foo)
Is it possible to avoid to rewrite the same code for each procedure of different kind? It is boring, errors prone and I am not sure of the efficiency of dynamic dispatching. Note that I intensively use this approach with derived type.
Maybe the new polymorphic abilities of F2003 could help me. For example using class(*) for x argument can I avoid the dynamic dispatching?. But what about the efficiency of this polymorphic approach?
Thanks for suggestions.