【发布时间】:2013-05-05 09:46:40
【问题描述】:
我对 Fortran 很陌生,为了我的研究,我需要运行一个模型怪物,所以我边走边学。所以如果我问一个“愚蠢”的问题,我很抱歉。 我正在尝试编译(Mac OSX,从命令行)并且我已经设法解决了一些问题,但是现在我遇到了一些我不确定如何解决的问题。我想我明白了错误背后的想法,但同样不知道如何解决。
模型很大,所以我只会发布我认为相关的代码部分(尽管我可能是错的)。我有一个包含几个子例程的文件,开头为:
!==========================================================================================!
! This subroutine simply updates the budget variables. !
!------------------------------------------------------------------------------------------!
subroutine update_budget(csite,lsl,ipaa,ipaz)
use ed_state_vars, only : sitetype ! ! structure
implicit none
!----- Arguments -----------------------------------------------------------------------!
type(sitetype) , target :: csite
integer , intent(in) :: lsl
integer , intent(in) :: ipaa
integer , intent(in) :: ipaz
!----- Local variables. ----------------------------------------------------------------!
integer :: ipa
!----- External functions. -------------------------------------------------------------!
real , external :: compute_water_storage
real , external :: compute_energy_storage
real , external :: compute_co2_storage
!---------------------------------------------------------------------------------------!
do ipa=ipaa,ipaz
!------------------------------------------------------------------------------------!
! Computing the storage terms for CO2, energy, and water budgets. !
!------------------------------------------------------------------------------------!
csite%co2budget_initialstorage(ipa) = compute_co2_storage(csite,ipa)
csite%wbudget_initialstorage(ipa) = compute_water_storage(csite,lsl,ipa)
csite%ebudget_initialstorage(ipa) = compute_energy_storage(csite,lsl,ipa)
end do
return
end subroutine update_budget
!==========================================================================================!
!==========================================================================================!
我收到错误消息
budget_utils.f90:20.54:
真实的,外部的 :: compute_co2_storage
1
错误:(1) 处的过程“compute_co2_storage”的虚拟参数“csite”具有需要此过程的显式接口的属性
(我得到了一堆,但它们基本上都是一样的)。现在,查看 ed_state_vars.f90(在子例程中“使用”),我发现
!============================================================================!
!============================================================================!
!---------------------------------------------------------------------------!
! Site type:
! The following are the patch level arrays that populate the current site.
!---------------------------------------------------------------------------!
type sitetype
integer :: npatches
! The global index of the first cohort in all patches
integer,pointer,dimension(:) :: paco_id
! The number of cohorts in each patch
integer,pointer,dimension(:) :: paco_n
! Global index of the first patch in this vector, across all patches
! on the grid
integer :: paglob_id
! The patches containing the cohort arrays
type(patchtype),pointer,dimension(:) :: patch
等等 - 这需要另外 500 行左右。 因此,为了能够使用(虚拟)参数 csite,原始子例程似乎需要为其过程提供显式接口。同样,我对 Fortran 很陌生,但我真的很想了解它是如何“思考”的。我一直在寻找拥有显式接口的含义,何时(以及如何!)使用它等。但我无法弄清楚它在我的案例中是如何应用的。我是否应该使用不同的编译器(英特尔?)。有什么提示吗?
编辑:所以csite 在所有过程中都被声明为target,并且声明type(site type) 包含一大堆pointers,如sitetype 中所指定。但是 sitetype 在所有过程中都来自另一个模块 (ed_state_vars.f90) 的 used。所以我仍然很困惑为什么它会给我显式接口错误?
【问题讨论】:
-
你的模块中有
compute_water_storage和其他函数吗? -
我们需要在
compute_co2_storage()中查看csite的声明,因为错误消息指的是该例程中声明的属性,而不是update_budget()中的属性。我怀疑它被声明为OPTIONAL或POINTER或类似的东西。 -
感谢所有反馈。 @SethMMorton:是的,就像
real function。 @Deditos:在compute_co2_storage()中,csite的声明与我发布的子例程中的相同:type(sitetype) , target :: csite。 -
@Geraldine 曾经解决过这个问题吗?有同样的问题
-
@badgley 我想最后可能是我的编译器或 MPI 或 makefile 中的某些设置有问题。我最终与我们大学高性能计算机中心的人一起工作,他们让它运行没有问题......
标签: compilation fortran explicit-interface