Add a section.
If the section already exists, it is left unchanged.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(file_ini), | intent(inout) | :: | self | File data. |
||
integer(kind=I4P), | intent(out), | optional | :: | error | Error code. |
|
character, | intent(in) | :: | section_name | Section name. |
pure subroutine add_section(self, error, section_name)
!< Add a section.
!<
!< If the section already exists, it is left unchanged.
class(file_ini), intent(inout) :: self !< File data.
integer(I4P), optional, intent(out) :: error !< Error code.
character(*), intent(in) :: section_name !< Section name.
type(section), allocatable :: sections(:) !< Temporary sections array.
integer(I4P) :: errd !< Error code.
errd = err_section
if (allocated(self%sections)) then
if (self%index(section_name=section_name)==0) then
! section not present
allocate(sections(1:size(self%sections, dim=1)+1))
sections(1:size(self%sections, dim=1)) = self%sections
sections(size(self%sections, dim=1)+1) = section(section_name=trim(adjustl(section_name)))
call move_alloc(sections, self%sections)
self%Ns = self%Ns + 1
endif
else
allocate(self%sections(1:1))
self%sections(1) = section(section_name=section_name)
self%Ns = self%Ns + 1
endif
if (self%index(section_name=section_name)>0) errd = 0
if (present(error)) error = errd
endsubroutine add_section