Can Select Type distinguish between Integer(Int8), Integer(Int16), Integer(Int32) and Integer(Int64)?
Also, can Select Type identify an integer type irrespective of the number of bits it uses?
Yes, you can write something like the following. Here I'm using real kind constants from the intrinsic module iso_fortran_env.
SELECT TYPE(areal)
TYPE is (REAL(real32))
WRITE(*,*) '... real32'
TYPE is (REAL(real64))
WRITE(*,*) '... real64'
CLASS default
WRITE(*,*) '... default'
END SELECT
Note, though, that you can't write
SELECT TYPE(areal)
TYPE is (REAL(real32))
WRITE(*,*) '... real32'
TYPE is (REAL(real64))
WRITE(*,*) '... real64'
TYPE is (REAL)
WRITE(*,*) '... real'
CLASS default
WRITE(*,*) '... default'
END SELECT
In this case a real of default kind (probably real32 for most current compilers) will match two of the type guard statements, and that's an error the compiler should pick up.
Different integer kinds constitute different intrinsic types. So yes, select type distinguishes integers of different kinds.
I am not aware of any possibility to disregard the kind (i.e. not just the number of bytes, theoretically). You must use a distinct type is section for each kind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With