pro smei_mask_bits, ref, bits, index = index, help = help

;+
; SMEI_MASK_BITS
;	Return the masking bits for Pipe-2.0 images.
;
; Usage:
;	smei_mask_bits, ref, bits[, index=index]
;
; Arguments:
;	ref	objref	input	A smei sequence or image object
;				reference.
;	bits	struct	output	A named variable to receive the
;				masking bit values.
;
; Keyword:
;	index	int	input	If called on a sequence then the
;				(1-based) index of the image in the
;				sequence. (Default is first image).
;
; History:
;	Original: 8/7/09; SJT
;-

if keyword_set(help) then begin
    self_help
    return
endif

if ~arg_present(bits) then begin 
    smei_msg, /warn, ['The second argument to SMEI_MASK_BITS must be', $
                      'a named variable to receive the bits ' + $
                      'structure']
    return
endif

if obj_isa(ref, 'SMEI_IMAGE') then bits = ref -> get_mask_bits() $
else if obj_isa(ref, 'SMEI_SEQUENCE') then begin
    if keyword_set(index) then image = ref -> get_image(index-1) $
    else image = ref -> get_first()
    bits = image -> get_mask_bits()
endif else begin
    smei_msg, /warn, ['The first argument to SMEI_MASK_BITS must be', $
                      'a reference to a SMEI_IMAGE or a ' + $
                      'SMEI_SEQUENCE']
endelse

end
                      
