Fortran-Lbound引发错误6366“数组表达式的形状不符合"(错误). [英] Fortran - lbound throws error 6366 "The shapes of the array expressions do not conform"

查看:975
本文介绍了Fortran-Lbound引发错误6366“数组表达式的形状不符合"(错误).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I've been confounded again by Fortran. Go figure. Anyway, I'm trying to write a pretty simple routine the strips values off the end of an array. Everything complicated works fine, except I want to write the subroutine such that I don't have to pass the lower bound of the input array to it. Here is the subroutine:

    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]

Right now I'm passing the lower bound of the input list into the subroutine (lstart), but I'd like not to do that. Anyway, this code doesn't compile, the compiler throws the error 6366: The shapes of the array expressions do not conform [ISTART]

我不知道该如何解决.有什么建议?

I don't know how to fix this. Any suggestions?

推荐答案

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

Lbound() returns an array! Read The Fortran Manual (RTFM) at https://gcc.gnu.org/onlinedocs/gfortran/LBOUND.html

它返回一个数组,该数组具有与数组的等级(维度"一维,二维,...)一样多的元素.

It returns an array with as many elements as is the rank ("dimension" 1D,2D,...) of the array.

要获取一个特定尺寸的数字,请使用可选参数DIM.

To get a single number, for a specific dimension, use the optional argument DIM.

istart = lbound(list, 1)

这篇关于Fortran-Lbound引发错误6366“数组表达式的形状不符合"(错误).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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