Fortran Coder

查看: 2354|回复: 5
打印 上一主题 下一主题

[派生类型] Error: The AUTOMATIC object 'tempparticles' must not have the SAVE attribute...

[复制链接]

16

帖子

7

主题

0

精华

入门

F 币
66 元
贡献
36 点
跳转到指定楼层
楼主
发表于 2022-5-30 21:15:19 | 显示全部楼层 |只看大图 回帖奖励 |倒序浏览 |阅读模式
哪位大佬能解答一下我的困惑,为啥会在第8行报错?采用gfortran编译报错,intel fortran 不会报错。


下载.png (7.27 KB, 下载次数: 166)

函数

函数

下载 (1).png (5.83 KB, 下载次数: 156)

主程序

主程序

下载 (2).png (8.47 KB, 下载次数: 159)

报错内容

报错内容
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

16

帖子

7

主题

0

精华

入门

F 币
66 元
贡献
36 点
沙发
 楼主| 发表于 2022-5-30 23:19:52 | 显示全部楼层
[Fortran] 纯文本查看 复制代码
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


[Fortran] 纯文本查看 复制代码
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

16

帖子

7

主题

0

精华

入门

F 币
66 元
贡献
36 点
板凳
 楼主| 发表于 2022-5-31 18:50:11 | 显示全部楼层
感谢这个部分懂了
作为一个编程小白还想问一个问题,如果放弃参数化,怎么实现将结构体备份,如下所示

subroutine Copytype(TempParticles, CopyTempParticles)
implicit none
CopyTempParticles%MassGas = TempParticles%MassGas
end subroutine Copytype
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-14 09:44

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表