def _ctypes_clean(parameter):
    """Returns the lines of code required to assign the correct values to the integers
    representing the indices of the output arrays in the ctypes wrapper subroutine.
    """
    if ('out' in parameter.direction and parameter.dimension is not None and
        ':' in parameter.dimension and ('pointer' in parameter.modifiers or
        'allocatable' in parameter.modifiers)):
        params = parameter.ctypes_parameter()
        result = []
        spacer = '    '
        if 'optional' in parameter.modifiers:
            if 'pointer' in parameter.modifiers:
                result.append('{}if (associated({})) then'.format(spacer,
                    parameter.name))
                spacer += '  '
            elif 'allocatable' in parameter.modifiers:
                result.append('{}if (allocated({})) then'.format(spacer,
                    parameter.name))
                spacer += '  '
        result.append('{0}{1}_t = {1}'.format(spacer, parameter.name))
        if parameter.direction == '(inout)':
            result.append('{1}{0}_o = C_LOC({0}_t)'.format(parameter.name,
                spacer))
            for i, p in enumerate(params[1:-1]):
                result.append('{}{} = size({}, {})'.format(spacer, p,
                    parameter.name, i + 1))
        else:
            result.append('{1}{0}_c = C_LOC({0}_t)'.format(parameter.name,
                spacer))
            for i, p in enumerate(params[1:]):
                result.append('{}{} = size({}, {})'.format(spacer, p,
                    parameter.name, i + 1))
        if 'optional' in parameter.modifiers and ('pointer' in parameter.
            modifiers or 'allocatable' in parameter.modifiers):
            result.append('    end if')
        return '\n'.join(result), True
    elif parameter.dtype == 'logical' and 'out' in parameter.direction:
        return '    {0}_c = {0}'.format(parameter.name), False
