subroutine instant_write_kslice implicit none real, allocatable :: tmp_slice(:,:,:) integer :: k, kk if (nkslice == 0) return ! Allocate temporary array to hold all kslice levels: (x, y, nkslice) allocate(tmp_slice(ib:ie, jb:je, nkslice)) ! Write time variable (only myidy==0 writes) if (myidy == 0) then call writestat_nc(ncidkslice, 'time', timee, nreckslice, .true.) end if ! u velocity if (ispresent('u0')) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = um(ib:ie, jb:je, kk) end do call writeoffset(ncidkslice, 'u', tmp_slice, nreckslice, xdim, ydim, kdim) end if ! v velocity if (ispresent('v0')) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = vm(ib:ie, jb:je, kk) end do call writeoffset(ncidkslice, 'v', tmp_slice, nreckslice, xdim, ydim, kdim) end if ! w velocity (interpolated to cell centers) if (ispresent('w0')) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = 0.5 * (wm(ib:ie, jb:je, kk) + wm(ib:ie, jb:je, kk+1)) end do call writeoffset(ncidkslice, 'w', tmp_slice, nreckslice, xdim, ydim, kdim) end if ! pressure if (ispresent('p0')) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = pres0(ib:ie, jb:je, kk) end do call writeoffset(ncidkslice, 'p', tmp_slice, nreckslice, xdim, ydim, kdim) end if if (ispresent('pa')) then do k = 1, nkslice tmp_slice(:,:,k) = presf(kslice(k)) end do call writeoffset(ncidkslice, 'pabs', tmp_slice, nreckslice, xdim, ydim, kdim) end if ! temperature if (ispresent('th') .and. ltempeq) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = thlm(ib:ie, jb:je, kk) end do call writeoffset(ncidkslice, 'thl', tmp_slice, nreckslice, xdim, ydim, kdim) end if if (lslicetemp .and. ltempeq) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = air_temperature(thlm(ib:ie,jb:je,kk), ql0(ib:ie,jb:je,kk), exnf(kk)) end do call writeoffset(ncidkslice, 'tha', tmp_slice, nreckslice, xdim, ydim, kdim) end if if (lslicerh) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = relative_humidity(qtm(ib:ie,jb:je,kk), ql0(ib:ie,jb:je,kk), & air_temperature(thlm(ib:ie,jb:je,kk), ql0(ib:ie,jb:je,kk), exnf(kk)), presf(kk)) end do call writeoffset(ncidkslice, 'rh', tmp_slice, nreckslice, xdim, ydim, kdim) end if ! moisture if (ispresent('qt') .and. lmoist) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = qtm(ib:ie, jb:je, kk) end do call writeoffset(ncidkslice, 'qt', tmp_slice, nreckslice, xdim, ydim, kdim) end if if (ispresent('ql') .and. lmoist) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = ql0(ib:ie, jb:je, kk) end do call writeoffset(ncidkslice, 'ql', tmp_slice, nreckslice, xdim, ydim, kdim) end if ! scalars s1-s4 if (ispresent('s1') .and. nsv>0) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = svm(ib:ie, jb:je, kk, 1) end do call writeoffset(ncidkslice, 's1', tmp_slice, nreckslice, xdim, ydim, kdim) end if if (ispresent('s2') .and. nsv>1) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = svm(ib:ie, jb:je, kk, 2) end do call writeoffset(ncidkslice, 's2', tmp_slice, nreckslice, xdim, ydim, kdim) end if if (ispresent('s3') .and. nsv>2) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = svm(ib:ie, jb:je, kk, 3) end do call writeoffset(ncidkslice, 's3', tmp_slice, nreckslice, xdim, ydim, kdim) end if if (ispresent('s4') .and. nsv>3) then do k = 1, nkslice kk = kslice(k) tmp_slice(:,:,k) = svm(ib:ie, jb:je, kk, 4) end do call writeoffset(ncidkslice, 's4', tmp_slice, nreckslice, xdim, ydim, kdim) end if deallocate(tmp_slice) end subroutine instant_write_kslice