Home > Archive > Fortran > February 2005 > Type Declarations using kind
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Type Declarations using kind
|
|
|
| my type declaration statement for real is:
real(4) or real(8)
in a public code i found
integer(4),parameter :: k = kind(0.0d0)
real(kind=k)::xc
What does "0.0d0" means
Thanks in advance
Luis Solis
| |
| beliavsky@aol.com 2005-02-07, 4:03 pm |
|
luis wrote:
> my type declaration statement for real is:
> real(4) or real(8)
>
> in a public code i found
>
> integer(4),parameter :: k = kind(0.0d0)
> real(kind=k)::xc
>
> What does "0.0d0" means
It means 0.0 as a double precision constant. For a compiler where the
default real has kind of 4 (most common),
print*,kind(0.0),kind(0.0d0)
gives
4 8
| |
| Jan Vorbrüggen 2005-02-08, 9:01 am |
| > integer(4),parameter :: k = kind(0.0d0)
> real(kind=k)::xc
>
> What does "0.0d0" means
That having been explained, let me note that while the above code goes
in the right direction, it gets a crucial detail wrong: The declaration
of k should not contain the (4). The whole point of this construct is
to make it indepedent of whatever KIND numbering system the compiler
uses, but the (4) selects one such system again. Just get rid of it
- KIND numbers are defined to be of default integer kind in any case
(I hope just for the above reason 8-)).
Jan
| |
|
| Jan Vorbrüggen wrote:
>
>
> That having been explained, let me note that while the above code goes
> in the right direction, it gets a crucial detail wrong: The declaration
> of k should not contain the (4). The whole point of this construct is
> to make it indepedent of whatever KIND numbering system the compiler
> uses, but the (4) selects one such system again. Just get rid of it
> - KIND numbers are defined to be of default integer kind in any case
> (I hope just for the above reason 8-)).
>
> Jan
ok
integer,parameter :: DP = kind(0.0d0)
real(kind=DP)::xc
Could i declare integer(1), integer(4) or integer(8) in a similar way ?
Luis
| |
| Michael Metcalf 2005-02-08, 9:01 am |
|
"luis" <lsolis@mu.intecsa-inarsa.es> wrote in message
news:cJ0Od.225560$A7.322425@telenews.teleline.es...
> integer,parameter :: DP = kind(0.0d0)
> real(kind=DP)::xc
>
> Could i declare integer(1), integer(4) or integer(8) in a similar way ?
>
Here's what we suggest in "Fortran 90/95 Explained" (Section 5.5), if you
really need to specify kinds that are not default:
module numeric_kinds
! named constants for 4, 2, and 1 byte integers:
integer, parameter :: &
i4b = selected_int_kind(9), &
i2b = selected_int_kind(4), &
i1b = selected_int_kind(2)
! and for single, double and quadruple precision reals:
integer, parameter :: &
sp = kind(1.0), &
dp = selected_real_kind(2*precision(1.0_sp)), &
qp = selected_real_kind(2*precision(1.0_dp))
end module numeric_kinds
If you use exclusively default kinds (usually 4 bytes), you don't need any
kind specification.
Regards,
Mike Metcalf
|
|
|
|
|