Is it possible to identify and distinguish between types with Fortran Select Type?
It can Select Type
distinguish between Integer(Int8)
, Integer(Int16)
, Integer(Int32)
and Integer(Int64)
?
Also, can Select Type
an integer type be identified regardless of the number of bits it uses?
Yes, you can write something like the following. Here I am using real view constants from the built-in 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
Please note that you cannot 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, the real default type (probably real32
for most modern compilers) will correspond to two statements of type guard, as well as the error that the compiler should receive.
Different whole types represent different internal types. So yes, it does select type
allocate integers of different types.
I don't know of any way to ignore the view (i.e. not just the number of bytes, in theory). You must use a separate section type is
for each type.