;---------------------------------------------------------------------------
; Document name: sunc2sohoc.pro
; Created by:    Dietmar Germerott, MPS, November 13, 2010
;
; Last Modified: Wed Jul  6 07:27:50 2011 (GERMEROTT.nospam(at)linmpi.mpg.de)
;---------------------------------------------------------------------------
;
FUNCTION sunc2sohoc, x, y, angle, sumer=sumer, date_t=date_t, errmsg=errmsg
;+
; PROJECT:
;       SOHO/SUMER
;
; NAME:
;       SUNC2SOHOC()
;
; PURPOSE: 
;       Convert Solar Coordinates to SOHO/SUMER Coordinates
;
; CATEGORY:
;       Operations
; 
; EXPLANATION:
;       This Routine computes the coordinates to be commanded
;       by SUMER in SOHO and SUMER coordinates for any SOHO
;       roll angle.
;       
; SYNTAX: 
;       Result = sunc2sohoc()
;
; EXAMPLES:
;       
; INPUTS:
;       x - X Pointing
;       y - Y Pointing
;
; OPTIONAL INPUTS: 
;       angle - SOHO rotation angle
;
; OUTPUTS:
;       structure
;
; OPTIONAL OUTPUTS:
;       None.
;
; KEYWORDS: 
;       date_t - the date for observation (overwrites the angle)
;       sumer  - return the coordinates in SUMER coordinate system
;
; COMMON:
;       None.
;
; RESTRICTIONS: 
;       None.
;
; SIDE EFFECTS:
;       None.
;
; HISTORY:
;       Version 1, November 13, 2010, Dietmar Germerott, MPS. Written
;       Version 2, January 21, 2011, Dietmar Germerott, MPS.
;           replaced unixtai2utc with get_utc.
;       Version 3, July 4, 2011, Dietmar Germerott, MPS Lindau
;           replaced get_sc_point with get_sc_att for correct roll.   
;
; CONTACT:
;       Dietmar Germerott, MPS (germerott.nospam@linmpi.mpg.de)
;-
;
   ON_ERROR, 2
      errmsg = ''

   ret = {xx:-1.0, yy:-1.0, angle:-1.0, date:'na', error:1}
   
   IF N_PARAMS() LT 2 THEN BEGIN
     PRINT, 'sunc2sohoc -- Syntax error.'
     PRINT, '   Usage: sunc2sohoc, '
     PRINT, ' '
     PRINT, ' x - X pointing'
     PRINT, ' y - Y pointing'
     PRINT, ' angle - rotation angle in degrees' 
     print, ''
     print, ' Keywords:'
     print, ''
     print, ' DATE_T - get the angle for the given date'
     print, ' SUMER  - return the coordinates in SUMER system'
     print, ' ERRMSG - return processing status'
     print, ''
     RETURN, ret
   ENDIF
   
   IF (N_PARAMS() LT 3) THEN BEGIN
     get_utc,now
     ret.date = anytim2utc(now, /ecs)
     actset = get_sc_att(now)
     theta = actset.sc_avg_roll
   ENDIF ELSE BEGIN
      theta = angle/!radeg
   ENDELSE
  

   IF KEYWORD_SET(date_t) THEN BEGIN
     actset = get_sc_att(date_t)       
     ret.date = anytim2utc(date_t, /ecs)
     theta = actset.sc_avg_roll
   ENDIF
 
   xx = x*COS(theta)-y*SIN(theta)
   yy = x*SIN(theta)+y*COS(theta)

   IF keyword_set(sumer) THEN yy = yy*(-1)

   ret.xx = xx
   ret.yy = yy
   ret.angle = theta*!radeg
   ret.error = 0
   RETURN, ret

END


;---------------------------------------------------------------------------
; End of 'sunc2sohoc.pro'.
;---------------------------------------------------------------------------
