Fortran 运行时警告:临时数组 [英] Fortran runtime warning: temporary array

查看:15
本文介绍了Fortran 运行时警告:临时数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行我的代码(使用 gfortran 编译)时收到 fortran 运行时警告已创建临时数组",我想知道是否有更好的方法来解决此警告.

I get the fortran runtime warning "An array temporary was created" when running my code (compiled with gfortran) and I would like to know if there is a better way to solve this warning.

我的原始代码是这样的:

My original code is something like this:

allocate(flx_est(lsign,3))
allocate(flx_err(lsign,3))
do i=1,lsign
call combflx_calc(flx_est(i,:),flx_err(i,:))
enddo

在子例程中,我这样定义变量:

Inside the subroutine I define the variables like this:

subroutine combflx_calc(flx_est,flx_err)
use,intrinsic              :: ISO_Fortran_env, only: real64
implicit none
real(real64),intent(inout) :: flx_est(3),flx_err(3)

flux_estflx_err 向量可能会根据几个条件在子程序内部发生变化,我需要相应地更新它们的值.

flux_est and flx_err vectors may change inside the subroutine depending on several conditions and I need to update their values accordingly.

Fortran 似乎不喜欢这种结构.我可以通过定义临时变量来解决它:

Fortran does not seem to like this structure. I can solve it defining temporary variables:

tmp_flx_est=flx_est(i,:)
tmp_flx_err=flx_err(i,:)
call combflx_calc(tmp_flx_est,tmp_flx_err)
flx_est(i,:)=tmp_flx_est
flx_err(i,:)=tmp_flx_err

但在我看来,修复它的方法很愚蠢.

But it seems to me quite a silly way to fix it.

正如您所见,我不是 Fortran 专家,因此非常欢迎任何帮助.

As you may see I'm not an expert with Fortran, so any help is more than welcome.

推荐答案

一种方法是传递一个假定的形状数组

One way is to pass an assumed shape array

real(real64),intent(inout) :: flx_est(:),flx_err(:)

另一种是交换数组的维度,以便您可以传递二维数组的连续部分.

the other is to exchange the dimensions of your array, so that you can pass a contiguous section of the 2D array.

call combflx_calc(flx_est(:,i),flx_err(:,i))

问题在于您的过程 (var(n)) 的显式大小虚拟参数需要连续的数组.假设的形状数组可以有一定的跨度.

The problem is that the explicit size dummy arguments of your procedure (var(n)) require contiguous arrays. The assumed shape arrays can have some stride.

这篇关于Fortran 运行时警告:临时数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆