我对 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)
包含一大堆pointer
s,如指定sitetype
. But sitetype
正在正确地use
d 来自另一个模块(ed_state_vars.f90
)在所有程序中。所以我仍然很困惑为什么它会给我显式接口错误?