subroutine instant_write_islice_xcoord_local(ncid, local_n, nislice_total, islice_positions)
! Write x-coordinates for LOCAL islice positions only
implicit none
integer, intent(in) :: ncid, local_n, nislice_total
integer, dimension(nislice_total), intent(in) :: islice_positions
integer :: varid, ierr, i, local_idx
real, allocatable :: x_islice_f(:), x_islice_h(:)
integer, allocatable :: islice_indices(:)
! Allocate and fill x coordinates for LOCAL islices only
allocate(x_islice_f(local_n))
allocate(x_islice_h(local_n))
allocate(islice_indices(local_n))
local_idx = 0
do i = 1, nislice_total
if (islice_positions(i) >= zstart(1) .and. islice_positions(i) <= zend(1)) then
local_idx = local_idx + 1
x_islice_f(local_idx) = xf(islice_positions(i)) ! full level (cell center)
x_islice_h(local_idx) = xh(islice_positions(i)) ! half level (cell edge)
islice_indices(local_idx) = islice_positions(i)
end if
end do
! Write xt (full level)
ierr = nf90_inq_varid(ncid, 'xt', varid)
if (ierr == nf90_noerr) then
ierr = nf90_redef(ncid)
ierr = nf90_put_att(ncid, varid, 'islice_indices', islice_indices)
ierr = nf90_put_att(ncid, varid, 'long_name', 'x-coordinate of i-slices (cell center)')
ierr = nf90_enddef(ncid)
ierr = nf90_put_var(ncid, varid, x_islice_f)
end if
! Write xm (half level)
ierr = nf90_inq_varid(ncid, 'xm', varid)
if (ierr == nf90_noerr) then
ierr = nf90_redef(ncid)
ierr = nf90_put_att(ncid, varid, 'islice_indices', islice_indices)
ierr = nf90_put_att(ncid, varid, 'long_name', 'x-coordinate of i-slices (cell edge)')
ierr = nf90_enddef(ncid)
ierr = nf90_put_var(ncid, varid, x_islice_h)
end if
deallocate(x_islice_f)
deallocate(x_islice_h)
deallocate(islice_indices)
end subroutine instant_write_islice_xcoord_local