;+
; NAME:
;	BSC2BSD
; PURPOSE:
;       convert BSC file to a BSD file
; CALLING SEQUENCE:
;       BSC2BSD,BSCFILE,BSDFILE
; INPUTS:
;       BSCFILE    - BSC input file to convert
;	BSDFILE    - BSD output file
; PROCEDURE:
;            Calls CV_BSC2BSD
;            If BSDFILE is not entered, then BSD file name is constructed
;            from BSC file name by replacing BSC with BSD.
; HISTORY:
;       Written Dec. 1992 by D. Zarro (Applied Research Corp).
;-

pro BSC2BSD,BSCFILE,BSDFILE

on_error,1

;-- input ok?

if datatype(BSCFILE) ne 'STR' then message,'usage --> BSC2BSD,BSCFILE,BSDFILE'

bsc_pos=strpos(strlowcase(bscfile),'bsc')
if min(bsc_pos) eq -1 then message,'warning --> copying non-BSC file ',/contin

rd_bsc,bscfile,-1,bsc_index,bsc_data

if (size(bsc_data.counts))(0) eq 1 then message,'cannot convert a BSA file'

;-- convert BSC to BSD format 

cv_bsc2bsd,bsc_index,bsc_data,index=bsd_index,data=bsd_data,header=bsd_header

;-- write out to BSD file

if datatype(bsdfile) ne 'STR' then begin
 pos=strpos(bscfile,'bsc')
 if pos ge 0 then bsdfile=str_replace(bscfile,'bsc','bsd') else begin
  repeat begin
   bsdfile='' & read,'* please enter BSD file name: ',bsdfile
  endrep until bsdfile ne ''
 endelse
endif

message,'writing to file '+bsdfile,/continue
wr_bsd,bsdfile,bsd_header,bsd_index,bsd_data

return & end

