create_gaussian_coord Function

private function create_gaussian_coord(k, finish, start, ncells)

Arguments

Type IntentOptional Attributes Name
integer :: k
real(kind=ESMF_KIND_R8) :: finish
real(kind=ESMF_KIND_R8) :: start
integer :: ncells

Return Value real(kind=esmf_kind_r8)


Source Code

  real(ESMF_KIND_R8) function create_gaussian_coord(k, finish, start, ncells)
  !-----------------------------------------------------------------------------
  ! define the coordinates for a gaussian grid in terms of the global index k,
  ! the top and bottom of the range (finish and start), and the total number
  ! of cells.
  ! create_uniform_coord(1) = start
  ! create_uniform_coord(ncells) = finish
  !-----------------------------------------------------------------------------
  integer :: k, ncells
  real(ESMF_KIND_R8) :: finish, start, coord
  real(ESMF_KIND_R8), allocatable :: root(:), w(:)

  ! allocate work space
  allocate( root(ncells), w(ncells) )

  !-----------------------------------------------------------------------------
  ! compute all the roots (we only are asking for one, but I can't figure out
  ! how to only compute the one we want).
  !-----------------------------------------------------------------------------
  call legendre_roots(ncells,root,w)

  !-----------------------------------------------------------------------------
  ! pih - root(ncells+1-k) constructs gaussian grid on the interval -pi to pi
  ! shift to 0:2*(root(ncells)-pih)
  !-----------------------------------------------------------------------------
  coord =  root(ncells) - root(ncells+1-k)

  ! adjust range from start to finish
  create_gaussian_coord = coord * 0.5*(finish - start)/(root(ncells)-pih) + start

  !-----------------------------------------------------------------------------
  ! clean up
  !-----------------------------------------------------------------------------
  deallocate( root, w )

  !-----------------------------------------------------------------------------
  end function create_gaussian_coord