pro pr_visible, startt, stopt, hc=hc, week=week, outarray=outarray, $
   now=now, noprint=noprint, file=file
;+
;   Name: pr_visible
;
;   Purpose: print KSC orbit data, optionally make hardcopy
;
;   Calling Statement:
;      pr_visible			; Print the current week
;      pr_visible,startt,stopt		; Start and Stop times (JST)
;      pr_visible,week='96_04		; Print week 96_04
;      pr_visible,file='outfile.dmp'	; Send output to a file
;
;   Input Parameters:
;      startt, stopt - start and stop times   (JST!!)
;      week - week# (default is current week)
;
;   Keyword Parameters
;     hc - if set, send to printer
;     week - week number for full week listing other than current week
;     noprint - dont echo info to terminal (usually with outarry keyword)
;     file     - Name of output file.
;     outarray - (output) string array of requested information
;
;   Calling Examples:
;      pr_visible [,/hc]	; print current week
;      pr_visible, day		; specified day (+24 hours)
;      pr_visible, t0,t1	; specified time range
;      pr_visible, t0,t1,outarr=outarr,/noprint	; return info, no print
;
;   History:
;      3-may-1995 (SLF)
;     10-jan-1996 (SLF) allow look at last years data...
;     22-Jan-1996 (JRL) Improved header and added file= for output file (via prstr)
;     11-dec-1996 (SLF) Added 1 hour to end of week determination (JST/GMT)
;
;   Restrictions: does not span weekly files 
;-

if n_params() eq 0 then startt = fmt_tim(!stime)

case data_chk(week,/type) of
   0: sweek=anytim2weekid(startt,/string)
   7: sweek=week
   else: sweek=(str2arr(gt_day(!stime,/string),'-'))(2) + '_' + $
	    string(week,format='(i2.2)')
endcase

pr_week2tim,sweek,t0,t1

case n_params() of
   0: begin
         startt=t0
         stopt=timegrid(t1,hour=32,/string)
   endcase
   1: stopt=timegrid(startt,/day,/string)
   else: if gt_day(stopt) gt gt_day(t1) and gt_time(stopt) gt 0 then begin
      tbeep
      message,/info,"supplied stop time in different week than start time..."
      message,/info,"(does not span weeks, output truncated at week boundry)"
   endif
endcase

weekstr=strmid(sweek,0,5)
;
; read visible contacts file
vfile=(concat_dir('$DIR_GEN_STATUS','visible_'+weekstr+'.dat'))(0)
alldat=rd_tfile(vfile,nocom=';')

; call routine to parse visible file for times 
cont2time, vfile, strt,stp, passn, /jst, numss=numss, visss=visss

spass=where(passn)				; only where passn defined
if spass(0) eq -1 then begin
   message,/info,"No passes found for week (check: " + vfile
   return
endif
strt=strt(spass)
visss=visss(spass)

strt=strtrim(strt,2)
ss=sel_timrange(strt,startt,stopt,/between)	; subset within input times

if ss(0) eq -1 then begin
   message,/info,"No passes found between " + startt + " and " + stopt
   return
endif 


jtim=strtrim(strsplit(alldat,'(',/head),2)	; strip jst start
sss=where_arr(jtim,strt(ss),scnt)		; match arrays

if scnt eq 0 then message,/info,"No visible orbits for input times..." else begin
   dat=alldat(sss)
   outarray=''
   invis=strpos(dat,'Visible') eq -1
   pass=strmid(dat,69,3)
   dat=strmid(dat,0,68)
   none=where(invis,icnt)
   if icnt gt 0 then dat(none)=' ---- no ksc ---- '
   for i=0,n_elements(dat)-1 do begin
      outarray=[outarray,pass(i) + '  ' + dat(i)]
      if pass(i) eq '[5]' then outarray=[outarray,'']
   endfor   
 endelse

outarray=[ 	$
'               Kagoshima Space Center Contacts             Minutes of',    $
'                      Starts                     Ends      Day  Ngt  Tot ', $
'P#             JST              (UT)             JST','',		   $
   outarray(1:*)]

if keyword_set(now) then outarray=[outarray,'','[Current JST is ' + jst()+ ']']

if not keyword_set(noprint) then prstr,outarray,file=file
if keyword_set(hc) then prstr,outarray,/hc

return
end   
