!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_emol
  interface def_emol

     subroutine def_emol_solar(anum, srate, emol_ini)
       integer, intent(in)                 :: anum(:)
       real(8), intent(in)                 :: srate(:)
       real(8), intent(out), allocatable   :: emol_ini(:)
     end subroutine def_emol_solar
     
     subroutine def_emol_int(emol, anum, emol_ini)
       integer, intent(in)                 :: anum(:)
       real(8), intent(in)                 :: emol(:)
       real(8), intent(out), allocatable   :: emol_ini(:)
     end subroutine def_emol_int
     
  end interface
end module interface_def_emol



subroutine def_emol_solar(anum, srate, emol_ini)
  use prm_solar

  implicit none
  integer, intent(in)                 :: anum(:)
  real(8), intent(in)                 :: srate(:)
  real(8), intent(out), allocatable   :: emol_ini(:)
       
  integer       :: smax
  integer       :: emax
  integer       :: i, e


  call SolarInfo

  smax = size(anum, 1)
  emax = maxval(anum, 1)
  
  allocate(emol_ini(smax))
  emol_ini = 0.0d0

  do i = 1, smax
     CHECK: do e = 1, emax
        if (anum(i) == e) then 
           emol_ini(i) = solar(e) * srate(e)
           exit CHECK
        end if
     end do CHECK
  end do
  emol_ini(1) = 1.0d0   ! H は常に 1


!!!
!!!確認
!!!
  if (minval(emol_ini, 1) == 0.0d0) then 
     write(*,*) "def_emol: emol is eregular", emol_ini
     stop
  end if

end subroutine def_emol_solar



subroutine def_emol_int(emol, anum, emol_ini)
  implicit none
  integer, intent(in)                 :: anum(:)
  real(8), intent(in)                 :: emol(:)
  real(8), intent(out), allocatable   :: emol_ini(:)
       
  integer       :: smax
  integer       :: emax
  integer       :: i, e


  smax = size(anum, 1)
  emax = maxval(anum, 1)
  
  allocate(emol_ini(smax))
  emol_ini = 0.0d0

  do i = 1, smax
     CHECK: do e = 1, emax
        if (anum(i) == e) then 
           emol_ini(i) = emol(e)
           exit CHECK
        end if
     end do CHECK
  end do


!!!
!!!確認
!!!
  if (minval(emol_ini, 1) == 0.0d0) then 
     write(*,*) "def_emol: emol is eregular", emol_ini
     stop
  end if

end subroutine def_emol_int
