Re: defining an arbitrary type in your newer Fortrans



Ancient_Hacker wrote:

Walter Spector wrote:


INTEGER, PARAMETER :: dbl_k = KIND (1.0d0) ! Double precision kind
REAL(dbl_k), ALLOCATABLE, DIMENSION(:,:) :: TwoDimmer

Whew! That's a little roundabout, but certainly better than my
ancient recourse to the old (IBMish?) REAL * 8. Of course we never used
that on the CDC's which didnt have bytes and single precision was quite
adequate.

So what you really want to use is the SELECTED_REAL_KIND intrinsic. Give
it the number of mantissa and/or exponent digits and it will return you
an appropriate kind for the computer in use:

INTEGER, PARAMETER :: real_k = SELECTED_REAL_KIND (14) ! enough for 14 digits, please
REAL(real_k), ALLOCATABLE :: TwoDimmer(:,:)

Then you will get single precision on the CDC (assuming that CDC had ever
implemented a F90 compiler - which they didn't), and double on most other
gear - without changing any code.

Note that you can't go hog-wild. If you asked for, say, 200 digits, and the
compiler did not support it, the intrinsic will return a negative value.
This then causes compilation errors - because kind values must be positive
integers.

W.
.



Relevant Pages

  • Re: BLAS: dgemm
    ... to a procedure requiring double precision data, ... be 'single precision correct' instead of 'double precision correct'. ... Where is the compiler supposed to get ...
    (comp.lang.fortran)
  • Re: DPROD issues
    ... expecting single precision inputs. ... that switch pass the single precision input version? ... The standard doesn't talk about compiler switches, ... a switch like that typically ...
    (comp.lang.fortran)
  • Re: PL/I in hardware
    ... >> done for a subset on the CDC Cyber. ... >The only problem with the CDC solution was that CDC had no PL/I compiler ... >so the U of I wrote that into the contract as a requirement. ...
    (comp.lang.pl1)
  • Re: pgf90 division errors?
    ... >> single precision real. ... >as if the type promotion during storage in numreal5 caused the inaccuracy. ... The single precision binary approximation to 0.2 when printed out ... either by you or the compiler vendor. ...
    (comp.lang.fortran)
  • Re: Precision of literal real constants, parameters, and Fortran ??standard
    ... glen herrmannsfeldt wrote: ... < I think that I am aware of the implication of optimizations. ... I thought I remembered some rule relating to single precision ... variables a compiler was allowed to supply extra precision ...
    (comp.lang.fortran)