【问题标题】:Fortran - lbound throws error 6366 "The shapes of the array expressions do not conform"Fortran - lbound 抛出错误 6366“数组表达式的形状不符合”
【发布时间】:2020-01-13 18:43:25
【问题描述】:

所以我又被 Fortran 搞糊涂了。去搞清楚。无论如何,我正在尝试编写一个非常简单的例程,将值从数组的末尾剥离。一切复杂的工作都很好,除了我想编写子例程,这样我就不必将输入数组的下限传递给它。这是子程序:

    subroutine Strip(list,lstart, index)        
        implicit none 
        integer :: i, index, isize, tsize, lstart, istart
        real, dimension(:), allocatable, intent(inout) :: list
        real, dimension(:), allocatable :: tlist             
        isize = size(list)             
        tsize = index-1                
        print *, 'index', index 
        print *, 'isize', isize
        print*, 'lbound', INT(lbound(list))
        print*, 'tsize', tsize      
        istart = lbound(list) !<---- This lines throws the error 
        !These are commented out because everything below here works 
        !allocate(tlist(lstart:tsize))
        !tlist = list(lstart:index-1)
        !deallocate(list) 
        !call move_alloc(tlist,list) 
    end subroutine Strip 

现在我将输入列表的下限传递给子例程 (lstart),但我不想这样做。反正这段代码没有编译通过,编译器抛出错误6366: The shapes of the array expressions do not conform [ISTART]

我不知道如何解决这个问题。有什么建议?

【问题讨论】:

  • 这是哪个编译器?不同的编译器有不同的错误信息。

标签: fortran


【解决方案1】:

Lbound() 返回一个数组!阅读 Fortran 手册 (RTFM),地址为 https://gcc.gnu.org/onlinedocs/gfortran/LBOUND.html

它返回一个数组,其元素数量与数组的秩(“维度”1D、2D、...)一样多。

要获取单个数字,对于特定维度,请使用可选参数 DIM。

istart = lbound(list, 1)

【讨论】:

  • 我从字面上读过​​一篇教程,说它返回一个整数。重量级。感谢您的帮助,如果这不能解决问题,我会尽快与您联系。
  • 好的,这样就解决了这个问题,但是现在使用“deallocate(list)”和“move_alloc(tlist,list)”会引发访问冲突错误。我也不知道如何解决。你能帮忙吗?
  • tsize 和 index-1 是同一个值吗?您不需要此处的分配或解除分配 - 分配给 tlist 将执行分配(您使用的是 ifort,所以使用版本 17 或添加 -standard-semantics)。同样,move_alloc 将释放列表。我的猜测是您在某处损坏了内存。在编译中添加 -CB 可能会有所帮助,但 ifort 尚未在运行时进行形状​​检查。
  • Soooo....我应该如何更改功能来解决我的问题?而且你的 index-1 和 tsize 应该是一样的。
  • 没有完整的代码很难说。这是一个不同的问题,值得提出不同的问题。我同意 Steve Lionel 的上述建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2016-08-17
  • 2021-08-23
  • 1970-01-01
  • 2015-08-07
相关资源
最近更新 更多