简体   繁体   中英

Error Message about Array Arguments in Code for Mean

I have a variable length (L) that changes for each particle in a group of a few hundred thousand particles with every time step. I'm trying to add a code that will tell me the average length of the particles at each time step in the model. I keep getting this error: "An array-valued argument is required in this context" for my mean equation. What does this mean? It seems to have a problem with my length variable, which I extract from the model using get_state. Here is my code:

function checkstatus(ng,g,time) result(validsim)
    use utilities
    implicit none
    logical :: validsim
    integer, intent(in)      :: ng
    type(igroup), intent(in) :: g(ng)
    real(sp), intent(in)     :: time
    real(sp), pointer        :: L(:)
    real(sp), dimension(ng)  :: mean
    integer, pointer         :: istatus(:)
    integer, allocatable     :: mark(L)
    integer :: n,NI
    integer, save :: dumphead = 0

    do n=1,ng
    NI = g(n)%Nind
    call get_state('L',g(n),L)
    mean(NI) = sum(L(NI)) / size(L(NI))
    end do

    write(*,103)time,mean(NI)
    

In your code, L is a pointer to a one-dimensional real array, and so L(NI) is a scalar real . The intrinsics sum and size take array arguments, so the statement sum(L(NI)) / size(L(NI)) is invalid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM