Fortran Coder

查看: 6972|回复: 1
打印 上一主题 下一主题

[派生类型] 定义子例程序时变量选用了派生数据类型,变量类型不匹配

[复制链接]

1

帖子

1

主题

0

精华

新人

F 币
10 元
贡献
4 点
跳转到指定楼层
楼主
发表于 2021-8-17 21:13:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
代码时下面就这个简单的代码
[Fortran] 纯文本查看 复制代码
program test
    implicit none
    real(kind=8) :: a
    type :: mytype
    real :: kk
    end type mytype


    type(mytype) :: tt(2)

    a=1
    write(*,*) tt(1)
    write(*,*) tt(2)
    call funcs_syn(a,tt)

end program test

subroutine funcs_syn(wavei,AtmospherePara)

real(kind=8) wavei
    type :: mytype
    real :: kk
    end type mytype
  type(mytype) :: AtmospherePara(2)  
  return
end

结果报错时出现这个1>c:\users\admin\documents\visual studio 2010\Projects\Console7\Console7\Console7.f90(28): error #6633: The type of the actual argument differs from the type of the dummy argument.   [TT]
1>compilation aborted for c:\users\admin\documents\visual studio 2010\Projects\Console7\Console7\Console7.f90 (code 1)

我用的visual fortran 求大神帮忙解答

分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

159

帖子

2

主题

1

精华

大师

Vim

F 币
961 元
贡献
469 点

规矩勋章

沙发
发表于 2021-8-17 22:00:48 | 只看该作者
本帖最后由 Transpose 于 2021-8-17 22:01 编辑

type的定义无法传递给子程序,即使是相同的定义方式,也无法认为是同一个类型。子程序使用type必须要借助module,
[Fortran] 纯文本查看 复制代码
module mytype
    implicit none
    type m
        real::a
    end type m
end module mytype

program main
    use mytype
    implicit none
    type(m)::b
    b%a=2.0
    call test(b) 
end program main

subroutine test(b)
    use mytype
    implicit none
    type(m)::b
    write(*,*)b%a
end subroutine test

评分

参与人数 1F 币 +3 收起 理由
fcode + 3 赞一个!

查看全部评分

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-4-19 14:15

Powered by Tencent X3.4

© 2013-2024 Tencent

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