On Monday, December 18, 2017 at 4:58:11 AM UTC+9,
herrman...@gmail.com wrote:
> why would anyone use the non-portable REAL(8) when they could
> use the nice and portable REAL(SELECTED_REAL_KIND(12)) instead?
> Or maybe REAL(KIND(1.D0)) instead?
I think there are at least three possible reasons why many people keep on using
real(8) (excluding the amount of typing, which is not much different from
real(dp) etc).
[Reason 1] Some introductory textbooks can describe real(8) and complex(8)
explicitly to use double precision reals and complex numbers.
I learned Fortran90 using a locally (domestic) published introductory book
around 1999-2000, and assumed that real(8) is the Fortran-90 way for
writing real*8. The book also explained kind() etc also, but its merit was not
very clearly written in that book, and I didn't catch its significance (because
we can just write real(8)). Some time (1-2 years) after migrating
from Frotran77 to Fortran90, I got to know another style of writing
real(dp) etc and start considering "portability" a bit more.
Anyway, I think there are some (old or domestic) textbooks that explain
real(8) as "double precision" or 64-bit for learning Fortran90. Though
it is easy to blame that those books are "poorly written",
the point is that one's coding style could be affected pretty strongly
by the first textbook or any material used as "reference" (incl. other people's codes).
[Reason 2] Manual pages of major compilers are often written explicitly
using real(8) etc for explanation. For example, for cosine function,
https://gcc.gnu.org/onlinedocs/gfortran/COS.html
https://software.intel.com/en-us/node/679153
So, it seems very natural (to me) that one tends to follow this convention
because two major compilers use these numbers anyway.
[Reason 3] Though people here (on comp.lang.fortran or other forums) often
consider that portability is the highest issue, it is not of very high importance
in some cases. This is particularly so for students who use in-house PC or
workstations or clusters, and the choice of compilers is only from one or two
at most. I.e., the purpose of coding is not to distribute it on the net for
general use, or utilize it on many supercomputers with different compilers,
but just to make the work done using local machines. In such case, if we have
only gfortran (and sometimes Intel Fortran), why does one need to care portability?
[Reason 4] (This is a more minor possibility than 1-3 above.)
When people come to Fortran from other recent languages, the latter often
have types that specify the number of bits explicitly (e.g., Float64, real(64), f64, etc).
I think it is then possible for any "new comer" to Fortran to immediately
assume real(8) to be 8-byte reals (particularly when not consulting recent
textbooks, but just using Fortran empirically for other purposes, e.g., to
call it from Python.)
[Reason 5] (This is my most opinion-based one :-)
I believe we (= "human") prefer things that are more intuitive and their meaning
easy to imagine, while not prefer things that are not very intuitive and the meaning
immediately not clear. For example, I think real(1) and real(2) are also used
in some compilers, but I expect that people would prefer real(8) and real(16)
rather than real(1) and real(2), even the latter can have more advantages
(if all the KIND numbers are different). The latter is more similar to distinguishing
different types by numbers (e.g., Type1, Type2 rather than Applet_t and Orange_t),
in the sense that 1 or 2 does not remind anything concrete.
>
> Is it really so hard to type four or two times as much?
>
Typing real(dp) or real(wp) is not hard, but I want to avoid typing
REAL(SELECTED_REAL_KIND(12)) at least (it's simply long!)
I even want to avoid real(kind = dp) (<-- i.e., attaching "kind = ")...