! find which bin has biggest cumulative average subroutine decide(span,jm,jx,ipk,pk) use creep_module implicit none integer:: span,jm,jx integer:: ii,i,j,nss,ipk real:: pk,aves,fn,w pk=0 ; ipk=(jm+jx)/2 do i=jm,jx !scan saved data aves=0.0 ; fn=0. nss=ns(i) do j=0,span-1 !lookback ii=(nss-j).and.31 ; w=wei(i,ii) !bin, weight if(w.gt.0) then !weight 0 => no data fn=fn+w ;aves=aves+d(i,ii)*w endif enddo if(fn.gt.0) then !some data found aves=aves/fn if(aves.gt.pk) then pk=aves ; ipk=i endif endif enddo return end