;+
;                   BCS_UNPACK
;   
;   Procedure to decompress BCS data files.  VMS specific.
;   See BCS note 11 for further details.
;
;  Use:    IDL>  bcs_unpack, files [,/test]
;  
;                                    where files specifies the files to be
;                                    decompressed. Wild cards are permitted.
; 
;                                    keyword /test will just give a list of
;                                    files to decompress without actually 
;                                    doing it.
;
;          IDL>  bcs_unpack,'921010.*',/test
;
;  NOTE that this procedure expects the VMS '_Z' compressed flag on the input
;  file name, any file name without this will be ignored. Do not include any
;  disk or directory in the name, the normal search paths are used.
;
;
;  cdp   Apr 93
;  cdp   Apr 93 Cater for non-wild card in filename extension
;
;-

pro bcs_unpack, infil, test=test

if n_params() lt 1 then begin
   print,'Use: bcs_unpack, files'
   print,' '
   print,'where files is the file specification.'
endif

;
;  find the data file, first check whether BDA bit is present
;
if (strpos(strupcase(infil),'BDA') lt 0) then infil =  'BDA' + infil

ff  = file_list(data_paths(),infil)

;
;  if there are files then...
;
if ff(0) ne '' then begin
    for i = 0,n_elements(ff)-1 do begin
;
;  forget non-compressed ones
;
      if strpos(ff(i),'Z') ge 0 then begin
         st = strpos(ff(i),'BDA9')
         en = strpos(ff(i),'_')
         
         com = 'unpack ' + strmid(ff(i),st,strlen(ff(i))-(en-st-1))
         if keyword_set(test) then begin
            print,com
         endif else begin
            spawn,com
         endelse

      endif
    endfor

endif


end
