function in_range, input, array, $

    values = values,  $
    where_flag = where_flag, $
    complement = complement,  $
    count = count, $
    inclusive = inclusive

if (~exist(input)) or ( ~exist(array)) then return,0b
default, inclusive, 1

if ~keyword_set( where_flag ) then begin
    np=n_elements(input)
    amax=max(array,min=amin)
    imax=max(input,min=imin)

    out= inclusive ? (imin lt amin) or (imax gt amax) : (imin le amin) or (imax ge amax)

    out = 1b-out
    endif else begin
    zrange = minmax( array )
    test = inclusive ? ( input ge zrange[0] ) and ( input le zrange[1] ) : $
        ( input gt zrange[0] ) and ( input lt zrange[1] )
    select = where( test, count, complement = complement)
    out = keyword_set( values ) && ( count < 1 ) ? input[ select ] : select

    endelse
return, out

end