pro dsn_check,weekno,outfile,asca=asca,yohkoh=yohkoh
;+
; NAME
;    dsn_check
; PURPOSE:
;    Make and print out the DSN data check sheet based on the final schedule
;    Program will prompt the user about printing the file.
;
; CALLING SEQUENCE:
;    dsn_check,Weekno
;    dsn_check,48
;    dsn_check,48,/asca			; For Asuka summary
; INPUT:
;    weekno = DSN Week Number
; OPTIONAL INPUTS:
;    outfile= output file.  If not specified, will write the file to
;		the $DIR_GEN_ORBIT_RAW directory.
; OPTIONAL INPUT KEYWORD:
;    yohkoh = yohkoh
;    asca   = asca
; OUTPUT:
;    none
; HISTORY
;     2-dec-93, J. R. Lemen (LPARL), Written (based on H. Hara's dsnchk_sheet)
;    28-Feb-95, (JRL), Added Wallops station
;    15-May-95, (JRL), Added Santiago station
;-

path2  = '$DIR_GEN_ORBIT_RAW'	; Output path

qyohkoh = 1			; 1=Yohkoh, 0=ASCA
if not keyword_set(yohkoh) then if keyword_set(asca) then qyohkoh = 0
if (qyohkoh) then spacecraft = 'sola' else spacecraft = 'astd'

if n_elements(WeekNo) eq 0 then begin
  message,'Weekno was not specified -- no summary file',/cont
  return
endif

; ---- Read in the rasm data --------
;      Read the final (7-Day Current) file:

name = spacecraft + 'ss'
rd_rasm,name,weekno,pass,status,select=spacecraft,rasmfile=rasm_file,/verbose
;print,aaa
if status eq 0 then return

; ---- Set up the output file name -------

if n_elements(outfile) ne 0 then file_out = outfile else begin
  if qyohkoh then file_out = concat_dir(path2,'dsnchk_sheet.txt') else	$
                file_out = concat_dir(path2,'dsnchk_astd.txt')
;  input, '* Enter the output file name ', file_out, file_out
endelse

; Try to delete an existing output file -- so we can chmod later

if file_exist(file_out) then begin
  file_delete, file_out, status
  if not status then stop
endif


openw,unit1,file_out,/get_lun

printf,unit1,'  Printed on '+ systime() + '  Made from '+ rasm_file
printf,unit1,' '
printf,unit1,$
'  ------------------------------------------------------------------------------'
printf,unit1,$
'  DOY Station  BOT -  EOT   ID    BDR Rep.  DSN LOG   TO DGIB   SRS INF  REMARKS'
; modified by H. Hara on 11 Nov, 1996
printf,unit1,$
'  ------------------------------------------------------------------------------'
printf,unit1,' '

prev_doy = pass(0).doy
for i=0,n_elements(pass)-1 do begin

  if strlowcase(strtrim(pass(i).wrk,2)) eq '1a1' then begin

    if (i ge 1) and (pass(i).doy ne prev_doy) then printf,unit1,' '
    case pass(i).DSS of 
      16: st='G16'
      17: st='G17'
      46: st='C  '
      66: st='M  '
      74: st='S  '	; Santiago
      76: st='W  '	; Wallops
    endcase
;print,aaa
    printf,unit1,'  ',pass(i).doy,  '   '+st+'   ',pass(i).bot,' - ',pass(i).eot,	$
      '  ',pass(i).pass,$
; modified by H. Hara on 11 Nov, 1996
      '      -  '+'      --    '+'    --    '+'    --    ',$
      format='(a,i3.3,a,2(i4.4,a),a,a)'
    prev_doy = pass(i).doy
  endif
endfor

free_lun,unit1
print,'  The output file is called: ',file_out

spawn,'chmod 666 '+file_out
input,'* Print the check sheet on the flare1 printer?', ans, 'y'
if strmid(strupcase(ans),0,1) ne 'N' then 	$
		spawn,'lpr -h '+file_out

end
