subroutine instant_gather_probe_var(vname, buf)
implicit none
character(len=*), intent(in) :: vname
real, intent(out) :: buf(:)
integer :: n, gi, gj, gk, li, lj, lk
do n = 1, nprobe
gi = iprobe(n)
gj = jprobe(n)
gk = kprobe(n)
! Check if local using decomp_2d zstart/zend
if (gi >= zstart(1) .and. gi <= zend(1) .and. &
gj >= zstart(2) .and. gj <= zend(2) .and. &
gk >= zstart(3) .and. gk <= zend(3)) then
li = gi - zstart(1) + 1
lj = gj - zstart(2) + 1
lk = gk - zstart(3) + 1
select case (vname)
case ('u0')
buf(n) = 0.5 * (um(li,lj,lk) + um(li+1,lj,lk))
case ('v0')
buf(n) = 0.5 * (vm(li,lj,lk) + vm(li,lj+1,lk))
case ('w0')
buf(n) = 0.5 * (wm(li,lj,lk) + wm(li,lj,lk+1))
case ('p0')
buf(n) = pres0(li,lj,lk)
case ('pa')
buf(n) = presf(gk)
case ('th')
if (ltempeq) buf(n) = thlm(li,lj,lk)
case ('ta')
if (ltempeq) buf(n) = air_temperature(thlm(li,lj,lk), ql0(li,lj,lk), exnf(gk))
case ('rh')
if (ltempeq .and. lmoist) buf(n) = relative_humidity(qtm(li,lj,lk), ql0(li,lj,lk), &
air_temperature(thlm(li,lj,lk), ql0(li,lj,lk), exnf(gk)), presf(gk))
case ('qt')
if (lmoist) buf(n) = qtm(li,lj,lk)
case ('ql')
if (lmoist) buf(n) = ql0(li,lj,lk)
case ('s1')
if (nsv>0) buf(n) = svm(li,lj,lk,1)
case ('s2')
if (nsv>1) buf(n) = svm(li,lj,lk,2)
case ('s3')
if (nsv>2) buf(n) = svm(li,lj,lk,3)
case ('s4')
if (nsv>3) buf(n) = svm(li,lj,lk,4)
end select
endif
end do
end subroutine instant_gather_probe_var