subroutine finish_dist_fn_arrays
use dist_fn_arrays, only: g, gnew, g_work, kx_shift, theta0_shift
use dist_fn_arrays, only: gexp_1, gexp_2, gexp_3
use dist_fn_arrays, only: antot, antota, antotp
use dist_fn_arrays, only: fieldeq, fieldeqa, fieldeqp
#ifdef SHMEM
use shm_mpi3, only : shm_free
#endif
implicit none
if (.not. initialized_dist_fn_arrays) return
initialized_dist_fn_arrays = .false.
call finish_dist_fn_level_1
if (allocated(g)) deallocate (g, gnew, g_work)
if (allocated(source_coeffs)) deallocate(source_coeffs)
#ifndef SHMEM
if (allocated(gexp_1)) deallocate (gexp_1, gexp_2, gexp_3)
#else
if (allocated(gexp_2)) deallocate (gexp_2, gexp_3)
if (associated(gexp_1)) call shm_free(gexp_1)
#endif
if (allocated(g_h)) deallocate (g_h)
if (allocated(save_h)) deallocate (save_h)
if (allocated(kx_shift)) deallocate (kx_shift)
if (allocated(theta0_shift)) deallocate (theta0_shift)
if (allocated(antot)) deallocate(antot)
if (allocated(antota)) deallocate(antota)
if (allocated(antotp)) deallocate(antotp)
if (allocated(fieldeq)) deallocate(fieldeq)
if (allocated(fieldeqa)) deallocate(fieldeqa)
if (allocated(fieldeqp)) deallocate(fieldeqp)
initialized_dist_fn_arrays = .false.
end subroutine finish_dist_fn_arrays