I’m trying to read a code written in Fortran 90. In the variable declaration it has for example:
real(ra) :: X
I haven’t been able to find out what ra could refer to in this code. I thought it would be something like real(kind=8) Could someone explain this to me?
Yes
is like
In fact it is the same thing if ra=8! The kind= is optional here.
As to finding it ra will be a parameter. It may be in the same routine as the declaration above, it may be in a module used by the routine, or I suppose it might be in a file included in the routine. There may well be different options, but it will be in scope somehow.
So why not use the second form? It is because the kind numbers are not portable and do vary from compiler to compiler – e.g.
It is therefore better to use a parameter initialised with the selected_real_kind intrinsic to specify the kind:
will probably do what you want. A common alternative to selected_real_kind is
So in summary it is the same, just better in that if done carefully it is more portable.
(and finally I really should say that kind values need have no relationship whatsoever to the number of bytes use to store the variable)