我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 ×1