;+
; NAME        : EIT_SUB_ROTATE
;
; PURPOSE     : Rotate subfield click and mark points.
;
; CATEGORY    :
;
; EXPLANATION :  Single middle click to draw window marks a point for rotation
;		 (stored in common rotation_click). Double click middle button
;		 unstores the click...(well, loads an out of range value to
;		 be rejected by this routine).
;
; SYNTAX      : 
;
; EXAMPLES    : none
; 
; CALLED BY   :
;
; CALLS TO    : none
;
; ARGUMENTS   :	none
;
; KEYWORDS    : none
;
; OUTPUTS     : none
;
; COMMON      : none
;
; RESTRICTIONS: none
;
; SIDE EFFECTS: none
;
; PROJECT     : SOHO - EIT
;
; HISTORY     : V1,  Elaine Einfalt (HSTX)
; 	1999-march  Einfalt - - passing group to more routines for V5 modal
;
; CONTACT     : eit@xanado.nascom.nasa.gov
;-

pro EIT_SUB_ROTATE, rot_hours=rot_hours, substruc=substruc, $
			event_x=event_x, event_y=event_y

 ; Convert device coords to data coords (which are in arcsec)
 ; Coords are loaded into common block rotation_click.
    
 data_coord = convert_coord(event_x, event_y, /device, /to_data)
 arc_rot_x = data_coord(0)
 arc_rot_y = data_coord(1)

 ; Do some checks for valid input

 if rot_hours le 0 then begin
    ack = respond_widg(mess= $
	['No rotation time was entered.', $
 	 ' ', $
	 'Already have rotation time entered into "ROTATED" window', $
	 'Click mouse button on point to be rotated.',$
	 ' ', $
	 'To redraw image without rotation marks: try some things.'],$
		button='Acknowledge',/row,  group=substruc.sub_base_id)
 return
 endif

 if abs(arc_rot_x) gt 1000 or abs(arc_rot_y) gt 1000 then begin
    ; Illegal values for middle mouse button
    ack = respond_widg(mess= $
	['Rotation mode click was outside solar disk.',$
 	 ' ', $
	 'Already have rotation time entered into "ROTATED" window', $
	 'Click mouse button on point to be rotated.',$
         ' ', $
	 'To redraw image without rotation marks: try some things.'],$
		button='Acknowledge',/row, group=substruc.sub_base_id)
    return
 endif

 ; Draw crosshairs at start rotation position

 oplot, [arc_rot_x-50,arc_rot_x+50], [arc_rot_y,arc_rot_y], thick=3
 oplot, [arc_rot_x,arc_rot_x], [arc_rot_y-50,arc_rot_y+50], thick=3


 image_date = anytim2utc(substruc.date, /ecs, /date)

 ; Convert arcsec to helio coords, 
 ; arc_rot_x is lat (E-W), arc_rot_y is lon (N-S)
 
 ref_helio = ARCMIN2HEL( [arc_rot_x/60.], [arc_rot_y/60.], $
			  date=image_date)  ;, /soho, off_limb=off_limb)
 

 ; Get rotated coords in arcsecs
 ; arcsec(0) is lat (E-W), arcsec(1) is lon (N-S)

 EIT_SUB_UTIL_ROT, ref_helio=ref_helio, rotat=rot_hours, date=image_date,$
       			arcsec=arcsec


 ; Draw crosshairs at rotated arcsec position (data plotting is in arcsecs)

 oplot, [arcsec(1)-50,arcsec(1)+50],[arcsec(0),arcsec(0)], thick=3
 oplot, [arcsec(1),arcsec(1)],[arcsec(0)-50,arcsec(0)+50], thick=3  

 ; Draw a line between the before and after rotation.

 oplot, [arc_rot_x,arcsec(1)], [arc_rot_y, arcsec(0)]

return
end

