!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_list_output
 interface list_output

    subroutine list_output_comps(object, atmnum, data)
      use prm_type, only: list_comps
      real(8), intent(out), allocatable, optional    :: data(:)
      integer, intent(out), allocatable, optional :: atmnum(:) 
      type(list_comps), pointer                      :: object
    end subroutine list_output_comps

    subroutine list_output_data(object, temp, data)
      use prm_type, only: list_data
      real(8), intent(out), allocatable, optional    :: temp(:)
      real(8), intent(out), allocatable, optional    :: data(:)
      type(list_data), pointer                       :: object
    end subroutine list_output_data

    subroutine list_output_spl(object, temp, dat_int, dat_dvt_int)
      use prm_type, only: list_spl
      real(8), intent(out), allocatable, optional :: temp(:)
      real(8), intent(out), allocatable, optional :: dat_int(:)
      real(8), intent(out), allocatable, optional :: dat_dvt_int(:)
      type(list_spl), pointer            :: object
    end subroutine list_output_spl

 end interface
end module interface_list_output



subroutine list_output_comps(object, atmnum, enum)
  use prm_type, only: list_comps
  
  implicit none
  real(8), intent(out), allocatable, optional    :: enum(:)
  integer, intent(out), allocatable, optional :: atmnum(:) 
  type(list_comps), pointer                      :: object

  real(8)                      :: enum_tmp(1000)
  integer                   :: i, N
  integer                   :: atmnum_tmp(1000)
  type(list_comps), pointer    :: p


  !初期化
  i = 1
  atmnum_tmp = 0
  enum_tmp = 0.0d0

  !変数取得
  p => object
  do 
     if (.not. associated(p)) exit
     atmnum_tmp(i) = p%record%atmnum
     enum_tmp(i) = p%record%enum
     
     p => p%next
     i = i + 1
  end do

  !出力
  N = count(atmnum_tmp /= 0)  - 1!番兵分差し引く

  if(present(atmnum)) then 
     allocate(atmnum(N))
     atmnum(1:N) = atmnum_tmp(1:N)
  end if
  
  if(present(enum)) then 
     allocate(enum(N))
     enum(1:N) = enum_tmp(1:N)
  end if
  
end subroutine list_output_comps



subroutine list_output_data(object, temp, data)
  use prm_type, only: list_data
  
  implicit none
  real(8), intent(out), allocatable, optional  :: temp(:)
  real(8), intent(out), allocatable , optional :: data(:)
  type(list_data), pointer                     :: object

  real(8)                    :: temp_tmp(1000)
  real(8)                    :: data_tmp(1000)
  integer                 :: i, N
  type(list_data), pointer   :: p


  !初期化
  i = 1
  temp_tmp = 0.0d0
  data_tmp = 0.0d0

  !変数取得
  p => object
  do 
     if (.not. associated(p)) exit
     temp_tmp(i) = p%record%temp
     data_tmp(i) = p%record%data
     
     p => p%next
     i = i + 1
  end do

  !出力
  N = count(temp_tmp /= 0) - 1 !番兵分差し引く

  if(present(temp)) then 
     allocate(temp(N))
     temp(1:N) = temp_tmp(1:N)
  end if
  
  if(present(data)) then 
     allocate(data(N))
     data(1:N) = data_tmp(1:N)
  end if
  
end subroutine list_output_data



subroutine list_output_spl(object, temp, dat_int, dat_dvt_int)
  use prm_type, only: list_spl
  
  implicit none
  real(8), intent(out), allocatable, optional :: temp(:)
  real(8), intent(out), allocatable, optional :: dat_int(:)
  real(8), intent(out), allocatable, optional :: dat_dvt_int(:)
  type(list_spl), pointer            :: object

  real(8)                    :: temp_tmp(1000)
  real(8)                    :: dat_int_tmp(1000)
  real(8)                    :: dat_dvt_int_tmp(1000)
  integer                    :: i, N
  type(list_spl), pointer    :: p


  !初期化
  i = 1
  temp_tmp = 0.0d0

  !変数取得
  p => object
  do 
     if (.not. associated(p)) exit
     temp_tmp(i) = p%record%temp
     dat_int_tmp(i) = p%record%dat_int
     dat_dvt_int_tmp(i) = p%record%dat_dvt_int
     p => p%next
     i = i + 1
  end do

  !出力
  N = count(temp_tmp /= 0) - 1 !番兵分差し引く

  if(present(temp)) then 
     allocate(temp(N))
     temp(1:N) = temp_tmp(1:N)
  end if

  if(present(dat_int)) then 
     allocate(dat_int(N))
     dat_int(1:N) = dat_int_tmp(1:N)
  end if
  
  if(present(dat_dvt_int)) then 
     allocate(dat_dvt_int(N))
     dat_dvt_int(1:N) = dat_dvt_int_tmp(1:N)
  end if
  
 
  
end subroutine list_output_spl

