小编AlR*_*lRi的帖子

Fortran:'select type'子句中的参数化派生类型

我试图使用无限多态指针在子例程中使用参数化派生类型.

可以对参数化类型使用'select type'子句吗?

我已尝试过以下几行,但收到​​编译错误.(TYPE或附近的语法错误)

module mod_real
  implicit none

  type :: type1(k)
    integer, kind :: k = 4
    real(kind=k) :: val
  end type type1

  contains

    subroutine out(in)
      class(*) :: in
      select type(in)
        type is (type1(4))
          print *, 'real(4):', in%val
        type is (type1(8))
          print *, 'real(8):', in%val
      end select
    end subroutine out

end module mod_real 

program real_test
  use mod_real

  type(type1(4)) :: p
  type(type1(8)) :: p2 

  p%val = 3.14
  p2%val = 3.1456d0

  call out(p)
  call out(p2)       

end program real_test 
Run Code Online (Sandbox Code Playgroud)

具有"type is(type1(4))"和"type is(type1(8))"的行被指示为具有不正确的语法.我使用的是Portland Group …

polymorphism fortran types parameterized

6
推荐指数
1
解决办法
680
查看次数

标签 统计

fortran ×1

parameterized ×1

polymorphism ×1

types ×1