;+ ; NAME: ; extract_last ; PURPOSE: (one line) ; Pull out a scalar or array from a scalar or 1 or 2-D array ; DESCRIPTION: ; Pull out a scalar or array from a scalar or 1 or 2-D array ; given an index into the last dimension of the input ; CATEGORY: ; Utility ; CALLING SEQUENCE: ; arr_k = extract_last(mat) ; INPUTS: ; mat - scalar, [n_last], [n_other,n_last] ; OUTPUTS: ; If mat is a scalar, return mat (scalar) ; If mat is an array, return mat[k] (scalar) ; If mat is 2-D, return mat[*,k] (1-D) ; OPTIONAL OUTPUTS: ; dim - number of dimensions for mat ; n_last - length of the last dimension ; MODIFICATION HISTORY: ; Written 2012 Jan 9, by Leslie Young, SwRI ; 2016 Mar 23 LAY. Edited documentation and move into layoung library ;- function extract_last,mat,k,dim, n_last dim = size(mat, /n_dim) n_last=n_elements(mat) case dim of 0: return, mat 1: return, mat[k] 2: begin n_last = n_elements(mat[0,*]) return, mat[*,k] end endcase end