Created
September 1, 2017 00:31
-
-
Save arbennett/3487078eff98da32ffe199960338f897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module testmod | |
implicit none | |
integer, parameter :: i4b = SELECTED_INT_KIND(9) | |
integer, parameter :: dp = KIND(1.0D0) | |
type t1 | |
integer :: i | |
end type t1 | |
type t2 | |
real :: j | |
end type t2 | |
type, public :: dlength | |
real(dp),allocatable :: dat(:) | |
endtype dlength | |
type, public :: ilength | |
integer(i4b),allocatable :: dat(:) | |
endtype ilength | |
type, public :: var_dlength | |
type(dlength),allocatable :: var(:) | |
endtype var_dlength | |
type, public :: var_ilength | |
type(ilength),allocatable :: var(:) | |
endtype var_ilength | |
contains | |
subroutine selectTest(thing) | |
class(*), intent(in) :: thing | |
select type(thing) | |
type is (real) | |
print*, "Type is real" | |
type is (integer) | |
print*, "Type is integer" | |
type is (t1) | |
print*, "Type is wrapped integer" | |
type is (t2) | |
print*, "Type is wrapped real" | |
type is (dlength) | |
print*, "Type is dlength" | |
type is (ilength) | |
print*, "Type is ilength" | |
type is (var_ilength) | |
print*, "Type is var_ilength" | |
type is (var_dlength) | |
print*, "Type is var_dlength" | |
class default | |
print*, "Type is undetermined" | |
end select | |
end subroutine selectTest | |
end module testmod | |
program test | |
use testmod | |
implicit none | |
integer :: i | |
real :: j | |
character(len=4) :: k | |
type(t1) :: i2 | |
type(t2) :: j2 | |
type(dlength) :: dl | |
type(ilength) :: il | |
type(var_dlength) :: vdl | |
type(var_ilength) :: vil | |
call selectTest(i) | |
call selectTest(j) | |
call selectTest(k) | |
call selectTest(i2) | |
call selectTest(j2) | |
call selectTest(dl) | |
call selectTest(il) | |
call selectTest(vdl) | |
call selectTest(vil) | |
end program test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output gives: