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)
Path: s9ni21683pbb.0!nntp.google.com!kt20no7206107pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 22 Oct 2012 08:00:02 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=150.146.145.254;
posting-account=qR3amAoAAAD7sL2JR2SeJQ0ywAVgFta2
NNTP-Posting-Host: 150.146.145.254
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <554f6e3c-79d9-46f3-977b-1180bf8a45d3@googlegroups.com>
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
Hi all,
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.
interface foo
module procedure foo_R8,foo_R4
endinterface
function foo_R8(x) result(foo)
...
real(8):: x
real(8):: foo
...
endfunction foo_R8
function foo_R4(x) result(foo)
...
real(4):: x
real(4):: foo
...
endfunction foo_R4
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.
Sincerely