def check_array_indices(imin, imax, jmin, jmax, framedim=None):
    """
    Return 4 indices for array slice compatible with framedim

    Parameters
    imin, imax, jmin, jmax: 4 integers
                            mini. and maxi. indices in both directions
    framedim : iterable of 2 integers
               shape of the array to be sliced by means of the 4 indices

    Return
    imin, imax, jmin, jmax: 4 integers
                            mini. and maxi. indices in both directions

    .. todo:: merge with getindices2cropArray()
    """
    if framedim is None:
        print('framedim is empty in check_array_indices()')
        return
    imin = max(imin, 0)
    jmin = max(jmin, 0)
    imax = min(framedim[0], imax)
    jmax = min(framedim[1], jmax)
    return imin, imax, jmin, jmax
