subroutine end_element(name)
character(len=*), intent(in) :: name
integer :: i, nnz
real(dp) :: Z
real(dp), parameter :: tol = 1.0e-20_dp !! Scale or other data dependence?
real(dp), pointer :: rg(:)
type(provenance_t), pointer :: q => null()
integer :: depth
if (debug_parsing) print *, "-- end Element: ", trim(name)
select case(name)
case ("radfunc")
in_radfunc = .false.
if (.not. associated(rp%data)) then
call die("No data for radfunc!")
endif
! Determine the effective range
! by skipping over (nearly) zeros
! For functions with tail, use r*f
rg => valGrid(rp%grid)
if (rp%has_coulomb_tail) then
Z = - rp%tail_factor
nnz = size(rp%data)
do while ( approx( (rg(nnz)*rp%data(nnz) + Z),0.0_dp, tol) )
nnz = nnz - 1
enddo
else
nnz = size(rp%data)
do while ( approx( rp%data(nnz) ,0.0_dp, tol) )
nnz = nnz - 1
enddo
endif
rp%nnz = nnz
if (nnz == size(rp%data)) then
rp%rcut_eff = rg(nnz)
else
rp%rcut_eff = rg(nnz+1)
if (debug_parsing) print "(a,i4,f10.4)",&
"Effective npts and range:", nnz+1, rp%rcut_eff
endif
case ("grid")
in_grid = .false.
!
if (.not. got_explicit_grid_data) then
call die("Need explicit grid data!")
endif
call delete(tmp_grid)
case ("data")
!
! We are done filling up the radfunc data
! Check that we got the advertised number of items
!
in_data = .false.
if (ndata /= size(rp%data)) then
call die("npts mismatch in radfunc data")
endif
case ("grid-data")
!
! We are done filling up the grid data
! Check that we got the advertised number of items
!
in_grid_data = .false.
if (ndata_grid /= size(gdata)) then
call die("npts mismatch in grid")
endif
if (debug_parsing) print *, "Got grid data: ", got_explicit_grid_data
case ("pseudocore-charge")
in_coreCharge = .false.
case ("valence-charge")
in_valenceCharge = .false.
case ("pseudocore-kinetic-energy-density")
in_coreKE = .false.
case ("valence-kinetic-energy-density")
in_valenceKE = .false.
case ("semilocal-potentials")
in_semilocal = .false.
slp => null()
case ("nonlocal-projectors")
in_nonlocal = .false.
nlp => null()
case ("slps")
in_slps = .false.
case ("proj")
in_proj = .false.
case ("local-potential")
in_local_potential = .false.
lop => null()
case ("local-charge")
in_chlocal = .false.
case ("pseudo-wave-functions")
in_pseudowavefun = .false.
case ("pswf")
in_pswf = .false.
case ("valence-configuration")
in_valence_config = .false.
case ("exchange-correlation")
in_xc = .false.
case ("libxc-info")
in_libxc_info = .false.
if (n_funct /= xp%n_functs_libxc) &
call die("Too few <functional> elements in <libxc-info>")
case ("provenance")
in_provenance = .false.
case ("input-file")
in_input_file = .false.
case ("header", "pseudo-atom-spec") ! v1.0, v1.1
in_header = .false.
case ("psml")
in_psml = .false.
!
! Check provenance elements
!
! First, determine how many there are
depth = 0
q => pseudo%provenance
do while (associated(q))
depth = depth + 1
q => q%next
enddo
!
! Assign record numbers. For now, we
! require that the records are ordered in the file
!
q => pseudo%provenance
do while (associated(q))
! A value of zero means that there is no (optional) record number
if ( (q%record_number /= 0) .and. &
(q%record_number /= depth)) then
call die("Provenance records out of order")
endif
q%record_number = depth
q => q%next
depth = depth - 1
enddo
end select
end subroutine end_element