subroutine Field_IcGrid3D_new( &
  & cptr, cptr_IcGrid3D, cname, field_rank, clong_name, cunits &
  & ) bind(C, name='Field_IcGrid3D_new')

  use, intrinsic :: iso_c_binding

  use dc_types, only: &
    & TOKEN, STRING

  use Field_IcGrid3D_Manager, only: &
    & Field_IcGrid3D, Field_IcGrid3D_Init

  use IcGrid3D_FVM_Manager, only: &
    & IcGrid3D_FVM

  use CBinding_Utility, only: &
    & c_f_string

  implicit none

  type(c_ptr), intent(out) :: cptr
  type(c_ptr), value :: cptr_icgrid3D
  character(kind=c_char), intent(in) :: cname(*)
  integer(c_int), value :: field_rank
  character(kind=c_char), intent(in) :: clong_name(*)
  character(kind=c_char), intent(in) :: cunits(*)

  type(Field_IcGrid3D), pointer :: ptr
  type(IcGrid3D_FVM), pointer :: ptr_icgrid3D
  character(TOKEN) :: fname
  character(STRING) :: flong_name
  character(STRING) :: funits

  allocate(ptr)
  call c_f_pointer(cptr_icgrid3D, ptr_icgrid3D)

  call c_f_string(cname, fname)
  call c_f_string(clong_name, flong_name)
  call c_f_string(cunits, funits)

  call Field_IcGrid3D_Init( &
     & ptr, &
     & ptr_icgrid3D, fname, field_rank, flong_name, funits)

  cptr = c_loc(ptr)

end subroutine Field_IcGrid3D_new

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

  use, intrinsic :: iso_c_binding

  use Field_IcGrid3D_Manager, only: &
    & Field_IcGrid3D, Field_IcGrid3D_Final

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

  type(Field_IcGrid3D), pointer :: ptr

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

  cptr = c_null_ptr

end subroutine Field_IcGrid3D_del

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

  use, intrinsic :: iso_c_binding

  use Field_IcGrid3D_Manager, only: &
    & Field_IcGrid3D, 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_IcGrid3D), 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_IcGrid3D_get_Physical_Field

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

  use, intrinsic :: iso_c_binding

  use Field_IcGrid3D_Manager, only: &
    & Field_IcGrid3D, paste_field3D_margin

  implicit none
  type(c_ptr), value :: cptr

  type(Field_IcGrid3D), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call paste_field3D_margin(ptr)

end subroutine Field_IcGrid3D_paste_field3d_margin

subroutine Field_IcGrid3D_fill_value( &
  & cptr, val &
  & ) bind(C, name='Field_IcGrid3D_fill_value')

  use, intrinsic :: iso_c_binding

  use dc_types, only: &
    & DP

  use Field_IcGrid3D_Manager, only: &
    & Field_IcGrid3D, fill_value

  implicit none
  type(c_ptr), value :: cptr
  real(DP), value :: val

  type(Field_IcGrid3D), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call fill_value(ptr, val)

end subroutine Field_IcGrid3D_fill_value

subroutine Field_IcGrid3D_copy_field3D( &
  & cptr, cptr_copied_field &
  & )  bind(C, name='Field_IcGrid3D_copy_field3D')

  use, intrinsic :: iso_c_binding

  use Field_IcGrid3D_Manager, only: &
    & Field_IcGrid3D, copy_field3D

  implicit none
  type(c_ptr), value :: cptr
  type(c_ptr), value :: cptr_copied_field

  type(Field_IcGrid3D), pointer :: ptr
  type(Field_IcGrid3D), pointer :: ptr_copied_field

  call c_f_pointer(cptr, ptr)
  call c_f_pointer(cptr_copied_field, ptr_copied_field)

  call copy_field3D(ptr, ptr_copied_field)

end subroutine Field_IcGrid3D_copy_field3D

subroutine Field_IcGrid3D_get_icgrid3d( &
  & cptr, cptr_icgrid &
  & ) bind(C, name='Field_IcGrid3D_get_icgrid3D')

  use, intrinsic :: iso_c_binding

  use Field_IcGrid3D_Manager, only: &
    & Field_IcGrid3D, get_icgrid3D

  use IcGrid3D_FVM_Manager, only: &
    & IcGrid3D_FVM

  implicit none
  type(c_ptr), value :: cptr
  type(c_ptr), intent(inout) :: cptr_icgrid

  type(Field_IcGrid3D), pointer :: ptr
  type(IcGrid3D_FVM), pointer :: ptr_icgrid

  call c_f_pointer(cptr, ptr)
  ptr_icgrid => get_icgrid3D(ptr)

  cptr_icgrid = c_loc(ptr_icgrid)

end subroutine Field_IcGrid3D_get_icgrid3d
