subroutine Field_Grid1D_new( &
  & cptr, &
  & grid1D, gridsize, cname, field_rank, clong_name, cunits &
  & ) bind(C, name='Field_Grid1D_new')

  use, intrinsic :: iso_c_binding

  use dc_types, only: &
    & DP, TOKEN, STRING

  use Field_Grid1D_Manager, only: &
    & Field_Grid1D, Field_Grid1D_Init

  use CBinding_Utility, only: &
    & c_f_string

  implicit none

  type(c_ptr), intent(out) :: cptr
  integer(c_int), value :: gridsize
  real(DP), intent(in) :: grid1D(gridsize)
  character(c_char), intent(in) :: cname
  integer(c_int), value :: field_rank
  character(c_char), intent(in) :: clong_name(*)
  character(c_char), intent(in) :: cunits(*)


  type(Field_Grid1D), pointer :: ptr
  character(TOKEN) :: name
  character(STRING) :: long_name, units

  call c_f_string(cname, name)
  call c_f_string(clong_name, long_name)
  call c_f_string(cunits, units)

  allocate(ptr)
  call Field_Grid1D_Init(ptr, grid1D(:), name, field_rank, long_name, units)

  cptr = c_loc(ptr)

end subroutine Field_Grid1D_new

subroutine Field_Grid1D_del( &
  & cptr &
  & ) bind(C, name='Field_Grid1D_del')

  use, intrinsic :: iso_c_binding

  use Field_Grid1D_Manager, only: &
    & Field_Grid1D, Field_Grid1D_Final

  implicit none

  type(c_ptr), intent(inout) :: cptr

  type(Field_Grid1D), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call Field_Grid1D_Final(ptr)
  deallocate(ptr)

  cptr = c_null_ptr

end subroutine Field_Grid1D_del

subroutine Field_Grid1D_get_Physical_Field( &
  & cptr, cptr_base &
  & ) bind(C, name='Field_Grid1D_get_Physical_Field')

  use, intrinsic :: iso_c_binding

  use Field_Grid1D_Manager, only: &
    & Field_Grid1D, get_Physical_Field
  use Physical_Field_Manager, only: &
    & Physical_Field

  implicit none

  type(c_ptr), value :: cptr
  type(c_ptr), intent(out) :: cptr_base

  type(Field_Grid1D), pointer :: ptr
  type(Physical_Field), pointer :: ptr_base

  call c_f_pointer(cptr, ptr)
  ptr_base => get_Physical_Field(ptr)

  cptr_base = c_loc(ptr_base)

end subroutine Field_Grid1D_get_Physical_Field

