delete_tag Subroutine

private elemental subroutine delete_tag(self, name)

Arguments

Type IntentOptional AttributesName
class(xml_file), intent(inout) :: self

XML file.

character(len=*), intent(in) :: name

XML tag name.

Description

Delete tag from XML file.


Variables

TypeVisibility AttributesNameInitial
type(xml_tag), public, allocatable:: tag_new(:)

New (extended) tags array.

integer(kind=I4P), public :: t

Counter.


Source Code

  elemental subroutine delete_tag(self, name)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Delete tag from XML file.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(xml_file), intent(inout) :: self       !< XML file.
  character(*),    intent(in)    :: name       !< XML tag name.
  type(xml_tag), allocatable     :: tag_new(:) !< New (extended) tags array.
  integer(I4P)                   :: t          !< Counter.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (self%Nt>0_I4P) then
    do t=1, self%Nt
      if (name==self%tag(t)%name()) then
        allocate(tag_new(1:self%Nt - 1))
        if (t==1) then
          tag_new(t:) = self%tag(t+1:)
        elseif (t==self%Nt) then
          tag_new(:t-1) = self%tag(:t-1)
        else
          tag_new(:t-1) = self%tag(:t-1)
          tag_new(t:) = self%tag(t+1:)
        endif
        call move_alloc(from=tag_new, to=self%tag)
        self%Nt = self%Nt - 1
        exit
      endif
    enddo
  endif
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine delete_tag