保留函数数组结果的界限 [英] Preserve the bounds of a function array result

查看:52
本文介绍了保留函数数组结果的界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用声明为数组类型的Fortran函数.问题是编译器没有保留数组的边界,例如,我声明了

I'm using a Fortran function declared with array type. The problem is that the compiler doesn't preserve the bounds of arrays, for example, I declared

function normalize(vector)

  real,dimension(0:)::vector
  real,dimension(0:size(vector)-1)::normalize
  real scale
  integer dim

  scale=norm_real(vector)
  if (scale/=0) then
    do dim=0,size(vector)-1
      normalize(dim)=vector/scale
    end do
  end if

  write(*,*) Lbound(normalize,1)
end function normalize

...

real, dimension(:), allocatable :: B

B = normalize(vector)

write(*,*) Lbound(B,1)

在这种情况下,我验证函数的Lbound归一化并且为0,但在主程序或另一端的Lbound为1.那么如何保存它的Lbound?

In this case I verify the Lbound of the function normalize and it's 0, yet it's Lbound In main program or in another side is 1. So how can I preserve it's Lbound?

推荐答案

我不认为可以,但是另一方面,这并不重要.Fortran认为数组形状是更基本的属性.即使函数返回的lbound变为1,您也可以将其分配给lbound为0或任何其他值的数组.您有重要的案例吗?

I don't think that you can, but on the other hand that it doesn't matter. Fortran considers array shapes to be the more fundamental property. Even though the lbound of the function return becomes one, you can assign it to an array with lbound of 0, or any other value. Do you have a case where it matters?

这篇关于保留函数数组结果的界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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