module mod
implicit none
private
public cssel

contains

function cssel(x) result(s)
   character(len=:), allocatable :: s
   class(*), dimension(..), optional, intent(in) :: x
   if (present(x)) then
      select rank (x)
      rank (0)
         s = '0'
      rank (1)
         s = '1'
      rank default
         s = '?'
      end select
   else
      s = '-'
   end if
end function cssel

end module mod

program classstar_rank
use mod
implicit none

integer :: x
real, dimension(1:3) :: y
logical, dimension(1:2,1:2) :: z

print *, cssel(x), cssel(y), cssel(z), cssel()

end program classstar_rank
