!c Description:
!c  物性値から元素番号を求める
!c
!c Current Code Owner: 
!c   sugiyama@gfd-dennou.org
!c
!c Histry: 
!c   Version    Date          Comment
!c   -------    ----------    --------
!c   1.0        2003-02-05    作成
!c
!c Copyright (C) SUGIYAMA Ko-ichiro, 2003, All rights reserved

module interface_def_atmnum
  interface

     subroutine def_atmnum(property, anum)
       use prm_type, only: type_property, type_tree
       integer, intent(out), allocatable :: anum(:) 
       type(type_property), intent(in)      :: property(:)
     end subroutine def_atmnum

  end interface
end module interface_def_atmnum



subroutine def_atmnum(property, anum)
  use prm_type, only: type_property, type_tree
  use interface_binsort_store
  use interface_binsort_output
  use interface_list_output
  
  implicit none
  integer, intent(out), allocatable :: anum(:) 
  type(type_property), intent(in)      :: property(:)
  
  integer                       :: s
  integer                       :: N
  integer                       :: e
  integer                       :: anum_tmp(100)
  integer, allocatable          :: ivar(:)
  type(type_tree), pointer      :: root
  
  
  !初期化
  nullify(root)
  N = size(property, 1)

  !値の入力
  do s = 1, N
     call list_output(property(s)%comps, atmnum=ivar)

     loop: do e = 1, size(ivar, 1)
        call binsort_store(root, ivar(e))
     end do loop
     
     deallocate(ivar)
  end do
  
  !変数の出力
  anum_tmp = 0
  e = 0
  call binsort_output(root, e, anum_tmp)

  !変数作成
  allocate(anum(e))
  anum(1:e) = anum_tmp(1:e)

  
end subroutine Def_atmnum
