!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-14    作成
!c
!c Copyright (C) SUGIYAMA Ko-ichiro, 2003, All rights reserved

module interface_def_struct
  interface

     subroutine def_struct(property, struct)
       use prm_type, only: type_property
       real(8), intent(out), allocatable :: struct(:,:)
       type(type_property), intent(in)   :: property(:)
     end subroutine def_struct

  end interface
end module interface_def_struct



subroutine def_struct(property, struct)
  use prm_type, only: type_property
  use interface_list_output
  use interface_def_atmnum

  implicit none
  real(8), intent(out), allocatable :: struct(:,:)
  type(type_property), intent(in)   :: property(:)

  real(8), allocatable              :: rvar(:) 
  integer                           :: i, e, s, N, M
  integer, allocatable              :: atmnum(:) 
  integer, allocatable              :: ivar(:) 


  !原子番号を取得
  call def_atmnum(property, atmnum)

  !配列のサイズを求め, 配列を初期化
  N = size(property, 1)
  M = size(atmnum, 1)
  allocate(struct(N, M))
  struct = 0.0d0

  do s = 1, N
     !物性値からリストを取り出す
     call list_output(property(s)%comps, ivar, rvar)

     !値の設定
     do e = 1, M
        do i = 1, size(ivar, 1)
           if (ivar(i) == atmnum(e)) then 
              struct(s,e) = rvar(i)
           end if
        end do
     end do

     !配列の開放
     deallocate(ivar, rvar)
  end do

  !配列の開放
  deallocate(atmnum)

end subroutine def_struct
