import re


def get_subroutines(listlines):
    """Return dictionary with text of the subroutines"""
    dict_subroutines = {}
    current_subroutine = None
    inside_interface = False
    for line in listlines:
        # Detect beginning of interface
        if re.match('\s*interface', line, re.IGNORECASE):
            inside_interface = True
        # Detect beginning of subroutine
        m = re.match('\s*subroutine (\w+)', line, re.IGNORECASE)
        if (not inside_interface) and m:
            current_subroutine = m.group(1).lower()
            dict_subroutines[current_subroutine] = ''  # Initialize empty string
        # Add line to text
        if current_subroutine is not None:
            dict_subroutines[current_subroutine] += line
        # Detect end of subroutine
        m = re.match('\s*end subroutine (\w+)', line, re.IGNORECASE)
        if (not inside_interface) and m:
            current_subroutine = None
        # Detect end of interface
        if re.match('\s*end interface', line, re.IGNORECASE):
            inside_interface = False
    return( dict_subroutines )