Types Fortran:在';选择类型';条款

Types Fortran:在';选择类型';条款,types,polymorphism,fortran,parameterized,Types,Polymorphism,Fortran,Parameterized,我试图在子例程中使用参数化派生类型,使用无限多态指针 是否可以对参数化类型使用“select type”子句 我尝试了以下几点,但遇到了编译错误。 (类型处或附近的语法错误) 带有“type is(type1(4))”和“type is(type1(8))”的行表示语法不正确。我正在使用Portland Group Fortran编译器(13.5-0版)。在撰写问题时,问题很可能是编译器支持,请查看此页: 至于实际问题,在这种情况下,您可以使用编译时解决方案和模块过程,这不需要多态性,因此

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

是否可以对参数化类型使用“select type”子句

我尝试了以下几点,但遇到了编译错误。 (类型处或附近的语法错误)


带有“type is(type1(4))”和“type is(type1(8))”的行表示语法不正确。我正在使用Portland Group Fortran编译器(13.5-0版)。

在撰写问题时,问题很可能是编译器支持,请查看此页:

至于实际问题,在这种情况下,您可以使用编译时解决方案和
模块过程
,这不需要多态性,因此可能会有较少的开销:

module mod_real

type type1(k)
  ... ! as before
end type

interface out
  module procedure out4, out8
end interface

contains

 subroutine out_type4(x)
   type(type1(4)), intent(in) :: x
   print*, 'real(4):' x%val   
 end subroutine

 subroutine out_type8(x)
   type(type1(8)), intent(in) :: x
   print*, 'real(8):' x%val   
 end subroutine

end module
program 
  ... ! as before
end program

看起来不错,您使用的是哪一版本的PGI Fortran?我使用的是13.5-0版本注意,大多数编译器尚未完全实现参数化派生类型。也许你的编译器也只是部分支持它。在写问题时,PGI已经声明完全符合Fortran 2003。您没有回答是否可以在
select type
module mod_real

type type1(k)
  ... ! as before
end type

interface out
  module procedure out4, out8
end interface

contains

 subroutine out_type4(x)
   type(type1(4)), intent(in) :: x
   print*, 'real(4):' x%val   
 end subroutine

 subroutine out_type8(x)
   type(type1(8)), intent(in) :: x
   print*, 'real(8):' x%val   
 end subroutine

end module
program 
  ... ! as before
end program