小编Big*_* Al的帖子

子程序忽略模块中的类型声明

我model在模块中创建了一个类型,然后声明了一个md具有该类型的变量.在模块中包含的子例程中,md忽略上面的声明,我必须再次明确声明它.

在主程序中我不需要声明类型md,use语句似乎起作用.谁能解释为什么子程序忽略了类型声明md?

这是代码.我在Linux上使用gfortran编译器.

program main
  use struc_model
  call mod_gen(md)
  do i=1, md%ndof
    write(*,*) 'row =', i
    write(*,*) 'm=', md%m(i,:)
  end do  
end

module struc_model
  type model
    integer :: ndof
    real*8, allocatable, dimension(:,:) :: m
  end type
  type (model) :: md
  contains
  subroutine mod_gen(md)
  ! for some reason have to declare type of md again
  ! declaration above is ignored
    type (model) :: md  
    md%ndof=4
    allocate(md%m(md%ndof,md%ndof))
    md%m=0.d0
    do i=1, md%ndof
      md%m(i,i)=1.d0 …
Run Code Online (Sandbox Code Playgroud)

fortran

2
推荐指数
1
解决办法
77
查看次数

标签 统计

fortran ×1