assignS Subroutine

private subroutine assignS(buffer, variable, found, keyword, fs)

Assign a string to variable

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: buffer

Input buffer

character(len=*), intent(out) :: variable

Variable to assign data to

integer, intent(inout) :: found

Count for finding variable

character(len=*), intent(in), optional :: keyword

Keyword to start from

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

Field separator


Source Code

  subroutine assignS(buffer, variable, found, keyword, fs)
    !! Assign a string to variable
    implicit none

    ! Arguments
    character(*), intent(inout) :: buffer
    !! Input buffer
    character(*), intent(out) :: variable
    !! Variable to assign data to
    integer, intent(inout) :: found
    !! Count for finding variable
    character(*), optional, intent(in) :: keyword
    !! Keyword to start from
    character(1), optional, intent(in) :: fs
    !! Field separator

    ! Local variables
    character(1024) :: buffer2
    !! Temporary buffer
    character(1) :: fs_
    !! Field separator

    fs_ = '='
    if(present(fs)) fs_ = fs

    if(present(keyword)) buffer = buffer(index(buffer, keyword):)
    if(scan(buffer, fs_) .ne. 0) buffer2 = get_val(buffer, fs_)
    if(trim(adjustl(buffer2)) .ne. '')then
       found = found + 1
       if( &
            ( &
                 buffer2(1:1) .eq. '"' .and. &
                 buffer2(len(trim(buffer2)):len(trim(buffer2))) .eq. '"' &
            ) .or. ( &
                 buffer2(1:1) .eq. '''' .and. &
                 buffer2(len(trim(buffer2)):len(trim(buffer2))) .eq. '''' &
            ) &
       )then
          buffer2 = buffer2(2:len(trim(buffer2))-1)
       end if
       read(buffer2, '(A)') variable
    end if
  end subroutine assignS