Fortran Gurus: say I have two unlimited polymorphic variables (CLASS(*)), and I want to check if they are equal. Does anyone know if there is a better way than having to write nested SELECT TYPE statements for all possible variable types? Basic example below. Assuming I only cared about built-in variables types (integers, etc.) I'd have to write cases for INT8, INT16, INT32, INT64, REAL32, REAL64, REAL128, and CHARACTERS kinds. This seems unsatisfactory to me, but I can't think of any other way to do it.
function equal(k1,k2)
implicit none
class(*),intent(in) :: k1
class(*),intent(in) :: k2
logical :: equal
equal = .false.
if (same_type_as(k1,k2)) then
select type (k1)
type is (integer)
select type (k2)
type is (integer)
equal = k1 == k2
end select
type is (character(len=*))
select type (k2)
type is (character(len=*))
equal = k1 == k2
end select
!type is (...), etc.
end select
end if
end function equal