load Subroutine

private subroutine load(self, separator, filename, source, error)

Get file data from a file or a source string.

Usage

Loading from a file
type(file_ini):: fini
call fini%load(filename='path_to_my_file.ini')
Loading from a source string
type(file_ini):: fini
call fini%load(source='[section-1] option-1=one [section-2] option-2=due')

Arguments

TypeIntentOptionalAttributesName
class(file_ini), intent(inout) :: self

File data.

character(len=1), intent(in), optional :: separator

Separator of options name/value.

character, intent(in), optional :: filename

File name.

character, intent(in), optional :: source

File source contents.

integer(kind=I4P), intent(out), optional :: error

Error code.


Contents

Source Code


Source Code

  subroutine load(self, separator, filename, source, error)
  !< Get file data from a file or a source string.
  !<
  !<### Usage
  !<
  !<##### Loading from a file
  !<```bash
  !<type(file_ini):: fini
  !<call fini%load(filename='path_to_my_file.ini')
  !<```
  !<
  !<##### Loading from a source string
  !<```bash
  !<type(file_ini):: fini
  !<call fini%load(source='[section-1] option-1=one [section-2] option-2=due')
  !<```
  class(file_ini), intent(inout)         :: self      !< File data.
  character(1),    intent(in),  optional :: separator !< Separator of options name/value.
  character(*),    intent(in),  optional :: filename  !< File name.
  character(*),    intent(in),  optional :: source    !< File source contents.
  integer(I4P),    intent(out), optional :: error     !< Error code.
  integer(I4P)                           :: errd      !< Error code.
  type(string)                           :: source_   !< File source contents, local variable.

  errd = ERR_SOURCE_MISSING
  if (present(separator)) self%opt_sep = separator
  if (present(filename)) then
    self%filename = trim(adjustl(filename))
    call source_%read_file(file=self%filename, iostat=errd)
  elseif (present(source)) then
    source_ = source
    errd = 0
  elseif (allocated(self%filename)) then
    call source_%read_file(file=self%filename, iostat=errd)
  endif
  if (errd <= 0) call self%parse(source=source_, error=errd)
  if (present(error)) error = errd
  endsubroutine load