pro plot_rth_ht,name,rs,pa
;;+
; NAME:
;	PLOT_RTH_HT
;
; PURPOSE:
;	This procedure plots the height-time information in an image format
;
; CATEGORY:
;	DATA_ANAL
;
; CALLING SEQUENCE:
;	PLOT_RTH_HT,Name
;
; INPUTS:
;	Name:	The file name of the height-time file
;
; OUTPUTS:
;	This procedure generates a plot file
;
; OPTIONAL OUTPUTS:
;	Rs:	The array of distances in solar radii
;	Pa:	The array of position angles.
;
; MODIFICATION HISTORY:
; 	Written by:	R.A. Howard, Apr 11, 1997
;
;	@(#)plot_rth_ht.pro	1.1 05/14/97 LASCO IDL LIBRARY
;-
;
  maxpts = 100
  rs=fltarr(maxpts)
  tai=dblarr(maxpts)
  pa=fltarr(maxpts)
  i=0                    
  instr=''
  date_obs=''
  time_obs=''
  comment=''
  timestr = ''
;
; Read in the height-time file
; Test to see if the first character is a #, which means a comment
; The file should not have any blank lines
; Convert the date/time string to TAI time
;
OPENR,lu,name,/get_lun
  WHILE (not eof(lu)) DO BEGIN
     READF,lu,instr
     IF (strmid(instr,0,1) ne '#') THEN BEGIN
        i=i+1
        READS,instr,temp,timestr,p,FORMAT='(F6.2,A20,f6.0)'
        rs(i)=temp
        tai(i)=utc2tai(str2utc(timestr))
        pa(i)=p         ; position angle
     ENDIF ELSE BEGIN
        IF (strmid(instr,0,10) eq '#DATE-OBS:') $
           THEN date_obs=strmid(instr,11,10)$
           ELSE IF (strmid(instr,0,10) eq '#TIME-OBS:') $
                THEN time_obs=strmid(instr,11,8) $
                ELSE IF (strmid(instr,0,9) eq '#COMMENT:') $
                     THEN comment=strmid(instr,10,strlen(instr))
        IF (strmid(instr,0,10) EQ '#DETECTOR:')  $
           THEN telescope=STRMID(instr,11,2)

     ENDELSE
  ENDWHILE
  FREE_LUN,lu
;
;   Truncate the array to include only valid points
;   Then sort by time
;
  tai= tai(1:i)
  rs = rs(1:i)
  pa = pa(1:i)
  ind=SORT(rs)
  rs=rs(ind)
  tai=tai(ind)
  ts = TAI2UTC(tai)            
;
;  Now plot the data
;
npts = i
solar_radius = 16*60.		;solar radius in arc seconds
CASE telescope OF
'C1':  BEGIN
	xcen = 511.
        ycen = 494.5
	radius = solar_radius/5.6
     END
'C2':  BEGIN
        xcen = 512.6
        ycen = 505.3
	radius = solar_radius/11.2
     END
'C3':  BEGIN
	xcen = 517.8
	ycen = 531.0
	radius = solar_radius/56.
     END
ENDCASE
;print,xcen,ycen,solar_radius,radius
REPEAT BEGIN
w = WHERE(tai EQ tai(0),nw)
tstr = UTC2STR(TAI2UTC(tai(0)),/ecs)
ps_setup,0
plot_size=6.	; inches
device,xsize=plot_size,ysize=plot_size,/inches,/portrait,yoffset=1.
norm_fac=1./512
!x.style=4
!y.style=4
!x.margin=[0,0]
!y.margin=[0,0]
plot,[0,0,1,1,0],[0,1,1,0,0],/normal
XYOUTS,0.3,.95,telescope+':  '+tstr,/normal
xyouts,xcen*.5*norm_fac,ycen*.5*norm_fac,'C',/normal
xyouts,xcen*.5*norm_fac,norm_fac*(ycen*.5+200),'N',/normal
FOR i=0,nw-1 DO BEGIN
    col = 0.5*(xcen-rs(w(i))*radius*SIN(pa(w(i))/57.296))
    row = 0.5*(ycen+rs(w(i))*radius*COS(pa(w(i))/57.296))
;print,col,row,rs(w(i)),pa(w(i))
;    col = 0>col
;    col = col<511
;    row = 0<row
;    row = row<511
    XYOUTS,col*norm_fac,row*norm_fac,'X',/normal
ENDFOR
w = WHERE (tai NE tai(0),nw)
IF (nw EQ 0)  THEN DONE=1 ELSE BEGIN
   DONE=0
   tai = tai(w)
   pa  = pa(w)
   rs  = rs(w)
ENDELSE
ps_setup,1
ENDREP UNTIL done EQ 1
RETURN
END
