function WHERE_XYZ, Array_expression, Count, XIND=xind, YIND=yind, ZIND=zind ; works for 1, 2 or 3 dimensional arrays ; ; Returns the 1D indices (same as WHERE) ; ; ARGUMENTS ; - same as WHERE (see WHERE) ; ; KEYWORDS ; - Optionally returns X, Y, Z locations through: ; ; XIND: Output keyword, array of locations ; along the first dimension ; YIND: Output keyword, array of locations ; along the second dimension (if present) ; ZIND: Output keyword, array of locations ; along the third dimension (if present) ; ; If no matches where found, then XIND returns -1 ; index_array=where(Array_expression, Count) dims=size(Array_expression,/dim) xind=index_array mod dims[0] case n_elements(dims) of 2: yind=index_array / dims[0] 3: begin yind=index_array / dims[0] mod dims[1] zind=index_array / dims[0] / dims[1] end else: endcase return, index_array end