module Physical_Field_pointer_mod
  use Physical_Field_Manager, only: Physical_Field

  type :: Physical_Field_pointer
    type(Physical_Field), pointer :: ptr
  end type Physical_Field_pointer

end module Physical_Field_pointer_mod

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

  use, intrinsic :: iso_c_binding

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

  use Physical_Field_Manager, only: &
    & Physical_Field, Physical_Field_Init

  use CBinding_Utility, only: &
    & c_f_string

  implicit none

  type(c_ptr), intent(out) :: cptr
  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(Physical_Field), 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 Physical_Field_Init(ptr, name, field_rank, long_name, units)

  cptr = c_loc(ptr)

end subroutine Physical_Field_new

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

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, Physical_Field_Final

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

  type(Physical_Field), pointer :: ptr

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

  cptr = c_null_ptr

end subroutine Physical_Field_del

subroutine Physical_Field_get_field_name( &
  & cptr, cname &
  & ) bind(C, name='Physical_Field_get_field_name')

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, get_field_name

  use dc_types, only: TOKEN

  use CBinding_Utility, only: &
    & f_c_string_ptr

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

  type(Physical_Field), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call f_c_string_ptr(get_field_name(ptr), cname)

end subroutine Physical_Field_get_field_name

subroutine Physical_Field_set_field_name( &
  & cptr, cname &
  & ) bind(C, name='Physical_Field_set_field_name')

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, set_field_name

  use dc_types, only: TOKEN

  use CBinding_Utility, only: &
    & c_f_string

  implicit none
  type(c_ptr), value :: cptr
  character(c_char), intent(in) :: cname(*)

  character(TOKEN) :: name
  type(Physical_Field), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call c_f_string(cname, name)
  call set_field_name(ptr, name)

end subroutine Physical_Field_set_field_name

subroutine Physical_Field_get_long_field_name( &
  & cptr, clong_name &
  & ) bind(C, name='Physical_Field_get_long_field_name')

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, get_long_field_name

  use dc_types, only: STRING

  use CBinding_Utility, only: &
    & f_c_string_ptr

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

  type(Physical_Field), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call f_c_string_ptr(get_long_field_name(ptr), clong_name)

end subroutine Physical_Field_get_long_field_name

subroutine Physical_Field_set_long_field_name( &
  & cptr, clong_name &
  & ) bind(C, name='Physical_Field_set_long_field_name')

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, set_long_field_name

  use dc_types, only: STRING

  use CBinding_Utility, only: &
    & c_f_string

  implicit none
  type(c_ptr), value :: cptr
  character(c_char), intent(in) :: clong_name(*)

  character(STRING) :: long_name
  type(Physical_Field), pointer :: ptr


  call c_f_pointer(cptr, ptr)
  call c_f_string(clong_name, long_name)
  call set_long_field_name(ptr, long_name)

end subroutine Physical_Field_set_long_field_name

subroutine Physical_Field_get_field_units( &
  & cptr, cunits &
  & ) bind(C, name='Physical_Field_get_field_units')

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, get_field_units

  use dc_types, only: TOKEN

  use CBinding_Utility, only: &
    & f_c_string_ptr

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

  type(Physical_Field), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call f_c_string_ptr(get_field_units(ptr), cunits)

end subroutine Physical_Field_get_field_units

subroutine Physical_Field_set_field_units( &
  & cptr, cunits ) &
  & bind(C, name='Physical_Field_set_field_units')

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, set_field_units

  use dc_types, only: TOKEN

  use CBinding_Utility, only: &
    & c_f_string

  implicit none
  type(c_ptr), value :: cptr
  character(c_char), intent(in) :: cunits(*)

  character(TOKEN) :: units
  type(Physical_Field), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  call c_f_string(cunits, units)

  call set_field_units(ptr, units)

end subroutine Physical_Field_set_field_units

function Physical_Field_get_field_rank( &
  & cptr &
  & ) result(rank) bind(C, name='Physical_Field_get_field_rank')

  use, intrinsic :: iso_c_binding

  use Physical_Field_Manager, only: &
    & Physical_Field, get_field_rank

  use dc_types, only: TOKEN

  implicit none

  type(c_ptr), value :: cptr
  integer rank

  type(Physical_Field), pointer :: ptr

  call c_f_pointer(cptr, ptr)
  rank = get_field_rank(ptr)

end function Physical_Field_get_field_rank
