input_split Subroutine

public subroutine input_split(str, delim, before)

Arguments

Type IntentOptional AttributesName
character(len=300) :: str
character :: delim
character(len=200) :: before

Contents

Source Code


Source Code

  subroutine input_split(str, delim, before)
    !     Routine splits the string 'str' by the first occurence of delim.
    !     The characters before the found delimiter are output in 'before'.
    !     The characters after the found delimiter are output in 'str'.


    character(len = 300) str
    character(len = 200) before
    character delim
    integer ipos

    str = trim(str)
    if (len(str) == 0) return ! string str is empty

    ipos = index(str, delim)
    if (ipos > 0) then ! next character is a delimiter
      before = str(1:ipos - 1)
      str = str(ipos + 1:)
      before = trim(before)
      str = trim(str)
    end if
    return

  end subroutine input_split