Commit 12afe3c6 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

check bounds for qcatch

parent 68465f05
Loading
Loading
Loading
Loading
+32 −8
Original line number Diff line number Diff line
@@ -2109,12 +2109,16 @@ i1: if( xhisto(i) > 0 .and. histo(i) > 0) then
    integer                                 :: nt2, nq2

    integer                                 :: it, iq, i, ihm, it2
    integer                                 :: ier
    integer                                 :: ier, istat
    character(len=MAX_LINE_LENGTH)          :: cerrmsg

    integer,              allocatable       :: histoq(:)
    real(kind=DBL),       allocatable       :: qh(:)

    real(kind=DBL), parameter               :: QMAX = 4d0/ANGSTROEM
    integer, parameter                      :: NQ_MAX = 1000000
    real(kind=DBL),parameter                :: DQMIN  = 1e5
    integer                                 :: nqmax

    integer,              allocatable       :: iperm(:)
    real(kind=DBL),       allocatable       :: qnom(:)
@@ -2122,12 +2126,26 @@ i1: if( xhisto(i) > 0 .and. histo(i) > 0) then
    external :: DPSORT


    ! (paz) check the limits
    if (accepted_dq<DQMIN) then
        call msg_fatal('consolidate_colldata', &
            msg=msg_fmt("('dq must be bigger than ',g12.3, ' m^-1')",DQMIN), &
            err=ERROR_NO_MEMORY)
    end if

!    dq = 0.002d0/ANGSTROEM
    dq = accepted_dq

    nqmax = 2*nint(QMAX/dq)+1
    allocate(histoq(0:nqmax) , stat=istat, errmsg=cerrmsg)
    if ( istat/=0 ) then
        call msg_fatal('consolidate_colldata', msg='allocation error "histoq"', extra=cerrmsg, err=ERROR_NO_MEMORY)
    end if

    allocate(histoq(0:2*nint(QMAX/dq)+1))
    allocate(    qh(0:ubound(histoq,dim=1)))
    allocate(    qh(0:nqmax) , stat=istat, errmsg=cerrmsg) ! ubound(histoq,dim=1)))
    if ( istat/=0 ) then
        call msg_fatal('consolidate_colldata', msg='allocation error "qh"', extra=cerrmsg, err=ERROR_NO_MEMORY)
    end if

    nt = coll_data%t_bin%nbins
    nq = coll_data%q_bin%nbins
@@ -2173,8 +2191,14 @@ t1: do it=0,nt
         if(itemlist(it,iq)) then
           q = coll_data%tq_bin(it,iq)%fqt_Q
           i = nint( q / (2d0*dq) )
           if (0<=0 .and. i<nqmax) then
                histoq(i) = histoq(i) + 1
                qh(i)     = qh(i)     + q
           else
             call msg_error('consolidate_colldata', &
                msg=msg_fmt("('index must between 0 and ',i0,' got',i0)",[nqmax, i]), &
                extra=cerrmsg, err=ERROR_NO_MEMORY)
           endif
         endif
       enddo t1    
    enddo d1