json_results Subroutine

public subroutine json_results(unit, indentation, energy, gradient, sigma, cn, c6, pairwise_energy2, pairwise_energy3, param)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
character(len=*), intent(in), optional :: indentation
real(kind=wp), intent(in), optional :: energy
real(kind=wp), intent(in), optional :: gradient(:,:)
real(kind=wp), intent(in), optional :: sigma(:,:)
real(kind=wp), intent(in), optional :: cn(:)
real(kind=wp), intent(in), optional :: c6(:,:)
real(kind=wp), intent(in), optional :: pairwise_energy2(:,:)
real(kind=wp), intent(in), optional :: pairwise_energy3(:,:)
class(damping_param), intent(in), optional :: param

Source Code

subroutine json_results(unit, indentation, energy, gradient, sigma, cn, c6, &
      & pairwise_energy2, pairwise_energy3, param)
   integer, intent(in) :: unit
   character(len=*), intent(in), optional :: indentation
   real(wp), intent(in), optional :: energy
   real(wp), intent(in), optional :: gradient(:, :)
   real(wp), intent(in), optional :: sigma(:, :)
   real(wp), intent(in), optional :: cn(:)
   real(wp), intent(in), optional :: c6(:, :)
   real(wp), intent(in), optional :: pairwise_energy2(:, :)
   real(wp), intent(in), optional :: pairwise_energy3(:, :)
   class(damping_param), intent(in), optional :: param
   character(len=:), allocatable :: indent, version_string
   character(len=*), parameter :: jsonkey = "('""',a,'"":',1x)"
   real(wp), allocatable :: array(:)

   call get_dftd3_version(string=version_string)

   if (present(indentation)) then
      indent = indentation
   end if

   write(unit, '("{")', advance='no')
   if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
   write(unit, jsonkey, advance='no') 'version'
   write(unit, '(1x,a)', advance='no') '"'//version_string//'"'
   if (present(energy)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'energy'
      write(unit, '(1x,es25.16)', advance='no') energy
   end if
   if (present(sigma)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'virial'
      array = reshape(sigma, [product(shape(sigma))])
      call write_json_array(unit, array, indent)
   end if
   if (present(gradient)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'gradient'
      array = reshape(gradient, [product(shape(gradient))])
      call write_json_array(unit, array, indent)
   end if
   if (present(cn)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'coordination numbers'
      call write_json_array(unit, cn, indent)
   end if
   if (present(c6)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'c6 coefficients'
      array = reshape(c6, [product(shape(c6))])
      call write_json_array(unit, array, indent)
   end if
   if (present(pairwise_energy2)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'additive pairwise energy'
      array = reshape(pairwise_energy2, [size(pairwise_energy2)])
      call write_json_array(unit, array, indent)
   end if
   if (present(pairwise_energy3)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'non-additive pairwise energy'
      array = reshape(pairwise_energy3, [size(pairwise_energy3)])
      call write_json_array(unit, array, indent)
   end if
   if (present(param)) then
      write(unit, '(",")', advance='no')
      if (allocated(indent)) write(unit, '(/,a)', advance='no') repeat(indent, 1)
      write(unit, jsonkey, advance='no') 'damping parameters'
      select type(param)
      type is(rational_damping_param)
         call write_json_param(unit, "rational", s6=param%s6, s8=param%s8, &
            & s9=param%s9, a1=param%a1, a2=param%a2, alp=param%alp, indent=indent)
      type is(zero_damping_param)
         call write_json_param(unit, "zero", s6=param%s6, s8=param%s8, &
            & s9=param%s9, rs6=param%rs6, rs8=param%rs8, alp=param%alp, indent=indent)
      type is(mzero_damping_param)
         call write_json_param(unit, "mzero", s6=param%s6, s8=param%s8, s9=param%s9, &
            & rs6=param%rs6, rs8=param%rs8, alp=param%alp, bet=param%bet, indent=indent)
      type is(optimizedpower_damping_param)
         call write_json_param(unit, "optimizedpower", s6=param%s6, s8=param%s8, &
            & s9=param%s9, a1=param%a1, a2=param%a2, alp=param%alp, bet=param%bet, &
            & indent=indent)
      class default
         call write_json_param(unit, "unknown", indent=indent)
      end select
   end if
   if (allocated(indent)) write(unit, '(/)', advance='no')
   write(unit, '("}")')

end subroutine json_results