|
本帖最后由 kyra 于 2022-5-31 09:20 编辑
你这代码我在 intel fortran 上也编译不过呀。
派生类型参数化,本来大家支持得就不好。尽量避免使用。
我想到的修改方案:
第一个:
integer::x=1 改为: integer , parameter :: x = 1 取消派生类型参数化后的 allocatable ,如果你要 allocatable,就没有参数化的意义了。
[Fortran] 纯文本查看 复制代码 03 | integer , parameter :: x = 4 |
10 | Subroutine CopyParticle ( this , ID ) |
11 | type ( ParticleType ( * ) ) :: this |
12 | integer ( 4 ) , intent ( in ) :: ID |
14 | End Subroutine CopyParticle |
22 | type ( ParticleType ( x ) ) :: TempParticles |
24 | call CopyParticle ( TempParticles , i ) |
26 | write ( * , * ) TempParticles % MassGas |
如果不取消 parameter,在 gfortran 9.x 上无法实现。intel fortran 可以这样
[Fortran] 纯文本查看 复制代码 08 | Procedure :: CopyParticle |
12 | Subroutine CopyParticle ( this , ID ) |
13 | integer ( 4 ) , intent ( in ) :: ID |
14 | class ( ParticleType ( * ) ) :: this |
16 | End Subroutine CopyParticle |
24 | type ( ParticleType ( : ) ) , allocatable :: TempParticles |
25 | allocate ( ParticleType ( x ) :: TempParticles ) |
26 | do i = 1 , TempParticles % n |
27 | call TempParticles % CopyParticle ( i ) |
29 | write ( * , * ) TempParticles % MassGas |
30 | deallocate ( TempParticles ) |
第三,放弃参数化
[Fortran] 纯文本查看 复制代码 05 | real ( 4 ) , allocatable :: MassGas ( : ) |
07 | Procedure :: CopyParticle |
11 | Subroutine CopyParticle ( this , ID ) |
12 | integer ( 4 ) , intent ( in ) :: ID |
13 | class ( ParticleType ) :: this |
15 | End Subroutine CopyParticle |
23 | type ( ParticleType ) :: TempParticles |
24 | allocate ( TempParticles % MassGas ( x ) ) |
25 | do i = 1 , size ( TempParticles % MassGas ) |
26 | call TempParticles % CopyParticle ( i ) |
28 | write ( * , * ) TempParticles % MassGas |
29 | deallocate ( TempParticles % MassGas ) |
|
|