;+
; SAFETAG - Return a tag value from a structure, safely
;
; USAGE: tag = safetag( structure, tag)
;	 ok = safetag(structure,/check)
;
; RETURNS: The tag value, or the null string if the tag is undefined;
;	OR tells whether the tag is defined or no.
;
;-
function safetag,structure,tag,check=check

if(ztype(structure)) eq 0 then return,'' else $
if(ztype(structure)) ne 8 then  begin
	if(keyword_set(check)) then return,0
	ret = replicate('',n_elements(structure)) 
end else begin 
	w = (where(strupcase(tag_names(structure)) eq strupcase(tag)))
	if keyword_set(check) then return,w(0) ge 0
	if(total(w) ge 0) then  			$
		ret=structure.(w(0)) 	$
	else ret=replicate('',n_elements(structure))
end

if n_elements(ret) eq 1 then return,ret(0) else return,ret

end
