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

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

问题描述

运行我的代码(用gfortran编译)时,我得到了fortran运行时警告创建了一个临时数组,我想知道是否有更好的方法来解决这个警告。



我的原始代码如下所示:

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

在子程序中,我定义了这样的变量:

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

flux_est flx_err 矢量可能会在子例程内发生变化,这取决于几个条件,我需要相应地更新它们的值。



Fortran似乎不喜欢这种结构。

  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
pre>

但是,在我看来,修复它非常愚蠢。



正如你所看到的, m不是Fortran的专家,所以任何帮助都是值得欢迎的。解决方案

一种方法是将假定的形状数组

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

另一个是交换数组的维数,以便传递2D数组的连续部分。

 调用combflx_calc(flx_est(:i),flx_err(:,i))
pre>

问题是您的过程的显式大小虚拟参数( var(n))需要连续数组。假定的形状数组可以有一些步幅。


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_est and flx_err vectors may change inside the subroutine depending on several conditions and I need to update their values accordingly.

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.

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))

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天全站免登陆