使用 SUM 内部函数时出错

发布于 2024-11-02 05:17:07 字数 501 浏览 1 评论 0原文

使用 g95 编译器时,我收到一条错误消息:

ERROR: Procedure attribute conflicts with INTENT attribute in 'quantityarray'

我试图查找数组的总和。以下是出现此错误的子例程:

SUBROUTINE findTotals(pricearray,quantityarray,totalprice, totalquantity)

INTEGER, INTENT(IN)::quantityarray
REAL, INTENT(IN):: pricearray
INTEGER, INTENT(OUT)::totalquantity
REAL, INTENT(OUT)::totalprice


totalquantity = SUM(quantityarray)
totalprice = SUM(pricearray)


END SUBROUTINE

非常感谢您的宝贵时间。

using the g95 compiler, I get an error that says:

ERROR: Procedure attribute conflicts with INTENT attribute in 'quantityarray'

I was trying to take find the total sum of the array. Here is the subroutine in which this error appears:

SUBROUTINE findTotals(pricearray,quantityarray,totalprice, totalquantity)

INTEGER, INTENT(IN)::quantityarray
REAL, INTENT(IN):: pricearray
INTEGER, INTENT(OUT)::totalquantity
REAL, INTENT(OUT)::totalprice


totalquantity = SUM(quantityarray)
totalprice = SUM(pricearray)


END SUBROUTINE

Thanks so much for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻泪 2024-11-09 05:17:07
program SummingAnArray
implicit none
integer, dimension(10) :: array=(/ (i, i=1,10) /)
integer :: i, Total

call VectorSum(array,Total)
print *,Total
read(*,*)



contains
    !===================================================
    subroutine VectorSum(Vector,Total)
    implicit none
    integer, intent(in), dimension(:) :: Vector
    integer, intent(out) :: Total

    Total = SUM(Vector)
    end subroutine VectorSum
    !===================================================
end program SummingAnArray

这也许是您希望实现的目标吗?

program SummingAnArray
implicit none
integer, dimension(10) :: array=(/ (i, i=1,10) /)
integer :: i, Total

call VectorSum(array,Total)
print *,Total
read(*,*)



contains
    !===================================================
    subroutine VectorSum(Vector,Total)
    implicit none
    integer, intent(in), dimension(:) :: Vector
    integer, intent(out) :: Total

    Total = SUM(Vector)
    end subroutine VectorSum
    !===================================================
end program SummingAnArray

Is this perhaps what you wished to achieve?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文