function get_comp_name, file, return_base = return_base, _extra = _extra
;+
; NAME:
;	GET_COMP_NAME
;
;
; PURPOSE:
;	Return the actually existing possibly compressed name of the
;	file matching the requested name.
;
;
; CATEGORY:
;	Utils
;
;
; CALLING SEQUENCE:
;	cfile = get_comp_name(file)
;
;
; INPUTS:
;	file	string	The base filename (including directory if
;			needed) 
;
; KEYWORD INPUTS:
; 	/return_base	If set, then strip off any compression
; 			suffix. No checks are made for existence in
; 			this case.
; 			
;	Any keywords accepted by the FILE_TEST function may be passed.
;
;
; OUTPUTS:
;	cfile	string	The actually existing filename. (Returns the
;			empty string if nothing is found).
;
;
; PROCEDURE:
;	Just check for the existence of the possible compressed
;	forms. And returns the first match.
;
;
; MODIFICATION HISTORY:
;	 Original: 24/6/05; SJT
;	 Modify return_base case to accept array: 1/11/07; SJT
;-

csuffices = ['', '.gz', '.Z', '.GZ', '.z', '-gz', '-GZ', '-Z', '-z', $
             '.Gz', '.gZ', '-Gz', '-Gz', '.bz2', '.BZ2']
nsuff = n_elements(csuffices)

if keyword_set(return_base) then begin
    rcs = '^(.+)(\'+strjoin(csuffices[1:*], '|\')+')$'
    nm = stregex(file, rcs, /extr, /sub)
    locs = where(nm[1, *] eq '', nns)
    if nns ne 0 then nm[1, locs] = file[locs]
    return, reform(nm[1, *])
endif

for j = 0, nsuff-1 do if file_test(file+csuffices[j], _extra = $
                                   _extra) then return, $
                                     file+csuffices[j]

return, ''

end
