下载.png (7.27 KB, 下载次数: 166)
函数
下载 (1).png (5.83 KB, 下载次数: 156)
主程序
下载 (2).png (8.47 KB, 下载次数: 159)
报错内容
PROGRAM Main
use ModParticle
implicit none
integer::i
! Local variables
type(ParticleType(x))::TempParticles
do i = 1, 1
TempParticles = CopyParticle(i)
end do
write(*,*) TempParticles
END PROGRAM Main
module ModParticle
implicit none
integer::x=1
type ParticleType(n)
integer(4), len :: n
!> Particle mass [kg] (corresponds to the gas density)(fixed during simulation - ensures conservation of mass)
real(4),allocatable:: MassGas(:)
end type
contains ! Routines of this module
type(ParticleType(x)) function CopyParticle( ID)
implicit none
integer(4), intent(in) :: ID
CopyParticle%MassGas = 0.1
write(*,*) CopyParticle%MassGas
end function
end module
module ModParticle
implicit none
integer,parameter::x=4
type ParticleType(n)
integer(4), len :: n
real(4):: MassGas(n)
end type
contains ! Routines of this module
Subroutine CopyParticle(this, ID)
type(ParticleType(*)) :: this
integer(4), intent(in) :: ID
this%MassGas = 0.1
End Subroutine CopyParticle
end module
PROGRAM Main
use ModParticle
implicit none
integer::i
type(ParticleType(x))::TempParticles
do i = 1, 1
call CopyParticle(TempParticles,i)
end do
write(*,*) TempParticles%MassGas
END PROGRAM Main
module ModParticle
implicit none
integer::x=4
type ParticleType(n)
integer(4), len :: n
real(4) :: MassGas(n)
contains
Procedure :: CopyParticle
end type
contains ! Routines of this module
Subroutine CopyParticle( this , ID )
integer(4), intent(in) :: ID
class(ParticleType(*)) :: this
this%MassGas = 0.1
End Subroutine CopyParticle
end module
PROGRAM Main
use ModParticle
implicit none
integer::i
type(ParticleType(:)),allocatable::TempParticles
allocate(ParticleType(x)::TempParticles)
do i = 1, TempParticles%n
call TempParticles%CopyParticle(i)
end do
write(*,*) TempParticles%MassGas
deallocate(TempParticles)
END PROGRAM Main
module ModParticle
implicit none
integer::x=4
type ParticleType
real(4) , allocatable :: MassGas(:)
contains
Procedure :: CopyParticle
end type
contains ! Routines of this module
Subroutine CopyParticle( this , ID )
integer(4), intent(in) :: ID
class(ParticleType) :: this
this%MassGas = 0.1
End Subroutine CopyParticle
end module
PROGRAM Main
use ModParticle
implicit none
integer::i
type(ParticleType)::TempParticles
allocate(TempParticles%MassGas(x))
do i = 1, size(TempParticles%MassGas)
call TempParticles%CopyParticle(i)
end do
write(*,*) TempParticles%MassGas
deallocate(TempParticles%MassGas)
END PROGRAM Main
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |