Skip to content

Commit

Permalink
Mark all subnodes processed when using readSpeciesList (dftbplus#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi authored Nov 18, 2024
1 parent 01fe9a3 commit 19f89ea
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
37 changes: 26 additions & 11 deletions src/dftbp/dftbplus/specieslist.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module dftbp_dftbplus_specieslist
use dftbp_common_unitconversion, only : TUnit
use dftbp_extlibs_xmlf90, only : char, fnode, string
use dftbp_io_hsdutils, only : getChild, getChildValue
use dftbp_io_hsdutils2, only : convertUnitHsd
use dftbp_io_hsdutils2, only : convertUnitHsd, setProcessed
implicit none

private
Expand All @@ -32,26 +32,30 @@ module dftbp_dftbplus_specieslist


!> Read a list of real valued species data
subroutine readSpeciesListReal(node, speciesNames, array, default, units)
subroutine readSpeciesListReal(node, speciesNames, array, default, units, markAllProcessed)

!> Node to process
type(fnode), pointer :: node

!> Data array to read
real(dp), intent(inout) :: array(:)

!> Names of all species
character(len=*), intent(in) :: speciesNames(:)

!> Data array to read
real(dp), intent(inout) :: array(:)

!> Optional default values of data array to be read
real(dp), intent(in), optional :: default(:)

!> Conversion factor
type(TUnit), intent(in), optional :: units(:)

!> Whether all unread subnodes should also be marked as processed (default: .true.)
logical, optional, intent(in) :: markAllProcessed

type(fnode), pointer :: child
type(string) :: modifier
integer :: iSp
logical :: markAllProcessed_

if (present(default)) then
if (present(units)) then
Expand Down Expand Up @@ -79,25 +83,33 @@ subroutine readSpeciesListReal(node, speciesNames, array, default, units)
end if
end if

markAllProcessed_ = .true.
if (present(markAllProcessed)) markAllProcessed_ = markAllProcessed
if (markAllProcessed_) call setProcessed(node, recursive=.true.)

end subroutine readSpeciesListReal


!> Read a list of integer valued species data
subroutine readSpeciesListInt(node, speciesNames, array, default)
subroutine readSpeciesListInt(node, speciesNames, array, default, markAllProcessed)

!> Node to process
type(fnode), pointer :: node

!> Data array to read
integer, intent(out) :: array(:)

!> Names of all species
character(len=*), intent(in) :: speciesNames(:)

!> Data array to read
integer, intent(in), optional :: default(:)
integer, intent(out) :: array(:)

!> Data array to read
integer, optional, intent(in) :: default(:)

!> Whether all unread subnodes should also be marked as processed (default: .true.)
logical, optional, intent(in) :: markAllProcessed

integer :: iSp
logical :: markAllProcessed_

if (present(default)) then
do iSp = 1, size(speciesNames)
Expand All @@ -110,7 +122,10 @@ subroutine readSpeciesListInt(node, speciesNames, array, default)
end do
end if

end subroutine readSpeciesListInt
markAllProcessed_ = .true.
if (present(markAllProcessed)) markAllProcessed_ = markAllProcessed
if (markAllProcessed_) call setProcessed(node, recursive=.true.)

end subroutine readSpeciesListInt

end module dftbp_dftbplus_specieslist
39 changes: 37 additions & 2 deletions src/dftbp/io/hsdutils2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module dftbp_io_hsdutils2
use dftbp_common_unitconversion, only : TUnit, unitConvStat => statusCodes, convertUnit
use dftbp_extlibs_xmlf90, only : fnode, fnodeList, string, trim, len, assignment(=), parsefile,&
& getLength, item, char, removeAttribute, getAttribute, setAttribute, setTagName,&
& normalize, append_to_string, destroyNodeList, removeAttribute, getItem1
& normalize, append_to_string, destroyNodeList, removeAttribute, getItem1, getFirstChild,&
& getNextSibling
use dftbp_io_charmanip, only : newline, tolower, i2c
use dftbp_io_hsdparser, only : attrName, attrModifier
use dftbp_io_hsdutils, only : attrProcessed, getChild, setChildValue, detailedError,&
Expand All @@ -30,7 +31,7 @@ module dftbp_io_hsdutils2
public :: getUnprocessedNodes, warnUnprocessedNodes
public :: readHSDAsXML
public :: getNodeName2, setNodeName, removeModifier, splitModifier
public :: setUnprocessed, getDescendant
public :: setUnprocessed, getDescendant, setProcessed
public :: convertUnitHsd
public :: renameChildren

Expand Down Expand Up @@ -67,6 +68,40 @@ subroutine setUnprocessed(node)
end subroutine setUnprocessed


!> Sets the processed flag on a node (and eventually on all its children)
recursive subroutine setProcessed(node, recursive)

!> The node to process
type(fnode), pointer, intent(in) :: node

!> Whether also all subnodes should be recursively included
logical, optional, intent(in) :: recursive

if (.not. associated(node)) return
call setAttribute(node, attrProcessed, "")
if (present(recursive)) then
if (recursive) call setChildrenProcessed_(node)
end if

contains

recursive subroutine setChildrenProcessed_(node)
type(fnode), pointer, intent(in) :: node

type(fnode), pointer :: child

child => getFirstChild(node)
do while (associated(child))
call setAttribute(node, attrProcessed, "")
call setChildrenProcessed_(child)
child => getNextSibling(child)
end do

end subroutine setChildrenProcessed_

end subroutine setProcessed


!> Prints a warning message about unprocessed nodes

subroutine getUnprocessedNodes(node, nodeList)
Expand Down

0 comments on commit 19f89ea

Please sign in to comment.