I think, that if one uses the client-server approach, many things become
simpler:
If someone tries to solve a particular problem, he will maybe find, that
something like real*6 variables would be enough for his demands. So as a
client he would ask for a precision with about 12 decimal places.
If someone wants to install a set of solvers on a particular system, he
might try to install these for all available precisions, so from the
server view he would proceed as shown by van Snyder. Now anyone with a
reasonable demand could use that package.
Of course, quite often the client and the server programmer are the same
person or do not really take care for generic demands: If I need 6-byte
words and work on a system, where 8 bytes are double, I (speeking for
myself) will be tempted to simply do something like
integer, parameter :: RK = kind(1.0d0)
in the application code, and also in the solver package. This will
usually work quite well for myself.
If I expect to have to use both sources on a really different system, or
that my demands on the precision change, it would certainly be better to
use SELECTED_REAL_KIND in the client code and KIND(1.0x0) (with x in E,D
and maybe Z or Q) in the library code.
Again, if I only use that program for myself, it will likely be a little
bit simpler to use SELECTED_REAL_KIND also in the library code, but then
its usefulness will decrease.
With best wishes
Alois
Am 2017-04-06 um 08:43 schrieb Van Snyder:
> On Wed, 2017-04-05 at 11:29 +0200, Phillip Helbig wrote:
>> I understand the motivation for KIND. However, many people use
>> SELECTED_REAL_KIND with 1.0D0 or whatever to find the
>> "double-precision KIND". Why not just write DOUBLE PRECISION if that
>> is what you mean?
> I use INCLUDE as a poor-man's substitute for generic programming.
>
> I use a kind type parameter to specialize a function to default real or
> double precision, to produce a generic interface, like this:
>
> interface F
> module procedure F_d, F_s
> end interface
> ...
> function F_d ( X )
> integer, parameter :: RK = kind(1.0d0)
> include "F_body.f9h"
> end function F_d
>
> function F_s ( X )
> integer, parameter :: RK = kind(1.0e0)
> include "F_body.f9h"
> end function F_s
>
> with F_body.f9h containing
>
> ! function F_* ( X )
> real(rk) :: F
> real(rk), intent(in) :: F
> ...
>
> This doesn't work if I use DOUBLE PRECISION.
|