;
;  CALLING SEQUENCE:  image=it_annotate(img,HDR1=hdr2,HDR2=hdr2
;					[,HDR3=hdr3])
;
;  PARAMETERS:		img is the (presumably final) version of the
;			composite image.  HDR1 and HDR2 are keywords to
;			set that contain the headers of each image 
;			represented in the composite (HDR3 is optional).
;
;  NOTES:		This function is designed to place the date, time,
;			telescope and origin of each image represented in
;			a composite image.  It places this text on the
;			right side of the composite.  You send it headers
;			of each dataset in the image and it_annotate will
;			pull out the information it needs.
;
;  RETURN TYPE:		INTARR
;
;  CALLS:		FXPAR, TVRD
;
;  HISTORY:		Drafted by Tony Darnell, 27-MAR-97
;
FUNCTION it_annotate,image,HDR1=hdr1,HDR2=hdr2,HDR3=hdr3

;---Begin by getting info from hdr1

  date1=it_getdate(hdr1)
  time1=fxpar(hdr1,'TIME-OBS')
  origin1=fxpar(hdr1,'ORIGIN')
  origin_err=!err
  IF (origin_err EQ -1) THEN BEGIN
    IF (fxpar(hdr1,'TELESCOP') EQ 'YOHKOH  ') THEN origin1='Yohkoh SXT'
    IF (fxpar(hdr1,'TELESCOP') EQ 'SOHO    ') THEN origin1='NASA GSFC'
  ENDIF
  IF (origin1 EQ 'Rocket Science') THEN origin1='NASA GSFC'
  IF (origin1 EQ 'HIGH ALTITUDE OBSERVATORY') THEN origin1='HAO'
  tele1=fxpar(hdr1,'TELESCOP')
  tele_err=!err
  IF (tele_err EQ -1) THEN tele1='YOHKOH'
  IF (tele1 EQ 'SOHO    ') OR (tele1 EQ 'SOHO') THEN $
    IF (fxpar(hdr1,'INSTRUME') EQ 'LASCO   ') THEN tele1='LASCO' ELSE $
    tele1='SOHO EIT'
  IF (tele1 EQ 'LASCO') THEN BEGIN
    detector=fxpar(hdr1,'DETECTOR')
    tele1=tele1+' '+detector
    origin1='NRL'
    subt=fxpar(hdr1,'SUBT')
    subt_err=!err
    IF (subt_err NE -1) THEN tele1=tele1+'Subt'
  ENDIF
  IF (tele1 EQ 'MLSO DIGITAL PROMINENCE MONITOR') THEN tele1='DPM'

;---If hdr2 is set then fill those vars

  IF KEYWORD_SET(hdr2) THEN BEGIN
    date2=it_getdate(hdr2)
    time2=fxpar(hdr2,'TIME-OBS')
    origin2=fxpar(hdr2,'ORIGIN')
    origin_err=!err
    IF (origin_err EQ -1) THEN BEGIN
      IF (fxpar(hdr2,'TELESCOP') EQ 'YOHKOH  ') THEN origin2='Yohkoh SXT'
      IF (fxpar(hdr2,'TELESCOP') EQ 'SOHO    ') THEN origin2='NASA GSFC'
    ENDIF
    IF (origin2 EQ 'Rocket Science') THEN origin2='NASA GSFC'
    IF (origin2 EQ 'HIGH ALTITUDE OBSERVATORY') THEN origin2='HAO'
    tele2=fxpar(hdr2,'TELESCOP')
    IF (!err EQ -1) THEN tele2='YOHKOH'
    IF (tele2 EQ 'SOHO    ') OR (tele2 EQ 'SOHO') THEN $
      IF (fxpar(hdr2,'INSTRUME') EQ 'LASCO   ') THEN tele2='LASCO' ELSE $
      tele2='SOHO EIT'
    IF (tele2 EQ 'LASCO') THEN BEGIN
      detector=fxpar(hdr2,'DETECTOR')
      tele2=tele2+' '+detector
      origin2='NRL'
      subt=fxpar(hdr2,'SUBT')
      subt_err=!err
      IF (subt_err NE -1) THEN tele2=tele2+'Subt'
    ENDIF
    IF (tele2 EQ 'MLSO DIGITAL PROMINENCE MONITOR') THEN tele2='DPM'
  ENDIF

;---Now for hdr3 (if set)

  IF KEYWORD_SET(hdr3) THEN BEGIN
    date3=it_getdate(hdr3)
    time3=fxpar(hdr3,'TIME-OBS')
    origin3=fxpar(hdr3,'ORIGIN')
    origin_err=!err
    IF (origin_err EQ -1) THEN BEGIN
      IF (fxpar(hdr3,'TELESCOP') EQ 'YOHKOH  ') THEN origin3='Yohkoh SXT'
      IF (fxpar(hdr3,'TELESCOP') EQ 'SOHO    ') THEN origin3='NASA GSFC'
    ENDIF
    IF (origin3 EQ 'Rocket Science') THEN origin3='NASA GSFC'
    IF (origin3 EQ 'HIGH ALTITUDE OBSERVATORY') THEN origin3='HAO'
    tele3=fxpar(hdr3,'TELESCOP')
    tele_err=!err
    IF (tele_err EQ -1) THEN tele3='YOHKOH'
    IF (tele3 EQ 'SOHO    ') OR (tele3 EQ 'SOHO') THEN $
      IF(fxpar(hdr3,'INSTRUME') EQ 'LASCO   ') THEN tele3='LASCO' ELSE $
      tele3='SOHO EIT'
    IF (tele3 EQ 'LASCO') THEN BEGIN
      detector=fxpar(hdr3,'DETECTOR')
      tele3=tele3+' '+detector
      origin3='NRL'
      subt=fxpar(hdr3,'SUBT')
      subt_err=!err
      IF (subt_err NE -1) THEN tele3=tele3+'Subt'
    ENDIF
    IF (tele3 EQ 'MLSO DIGITAL PROMINENCE MONITOR') THEN tele3='DPM'
  ENDIF

;---Create a larger array with space on right side of image for text

  sz=SIZE(image)
  ann_array=INTARR(sz(1)+300,sz(2))
  ann_array(0:sz(1)-1,0:sz(2)-1)=image

;---Begin placing text

  !P.font=0
  color1=255
  color2=255
  color3=255
  WINDOW,/FREE,XSIZE=300,YSIZE=sz(2)
  y_loc=(sz(2)/2)+200
  device, $
  font='-adobe-helvetica-bold-r-normal--34-240-100-100-p-182-iso8859-1'
        xyouts, color = color1, 0,y_loc, charsize=2.0, $
          origin1, /DEVICE
        xyouts, color = color1, 0,y_loc-35, charsize=2.0, $
          tele1, /DEVICE
        xyouts, color = color1, 0,y_loc-70, Charsize=2.0, $
          date1, /DEVICE
        xyouts, color = color1, 0,y_loc-105, charsize=2.0, $
          time1, /DEVICE

  IF KEYWORD_SET(hdr2) THEN BEGIN
        xyouts, color = color2, 0,y_loc-155, charsize=2.0, $
          origin2, /DEVICE
        xyouts, color = color2, 0,y_loc-190, charsize=2.0, $
          tele2, /DEVICE
        xyouts, color = color2, 0,y_loc-225, Charsize=2.0, $
          date2, /DEVICE
        xyouts, color = color2, 0,y_loc-260, charsize=2.0, $
          time2, /DEVICE
  ENDIF

  IF KEYWORD_SET(hdr3) THEN BEGIN
        xyouts, color = color3, 0,y_loc-310, charsize=2.0, $
          origin3, /DEVICE
        xyouts, color = color3, 0,y_loc-345, charsize=2.0, $
          tele3, /DEVICE
        xyouts, color = color3, 0,y_loc-380, Charsize=2.0, $
          date3, /DEVICE
        xyouts, color = color3, 0,y_loc-415, charsize=2.0, $
          time3, /DEVICE
  ENDIF

  
  txtarray=TVRD()
  t=SIZE(txtarray)
  WDELETE

  ann_array(sz(1):sz(1)+t(1)-1,0:t(2)-1)=txtarray

RETURN,ann_array
END