FUNCTION CARRDATE,cr,clong,el=el,wl=wl,cmp=cmp
;+
; NAME:
;	CARRDATE
;
; PURPOSE:
;	This function converts a carrington number and longitude into a 
;       CDS date structure.
;
; CATEGORY:
;	LASCO Synoptic
;
; CALLING SEQUENCE:
;	Result = CARRDATE ( Cr, Clong)
;
; INPUTS:
;	Cr:	Carrington Rotation Number
;	Clong:	Carrington Longitude
;
; OPTIONAL INPUTS:
;	None
;
; KEYWORDS:
;	EL:	This keyword specifies that the date should be returned as an 
;		East Limb Date
;	WL:	This keyword specifies that the date should be returned as a 
;		West Limb Date
;	CMP:	This keyword specifies that the date should be returned as a 
;		central meridian Date.  This is the default.
;
; OUTPUTS:
;	Result:	The function result is the date as a CDS date structure
;	
; COMMON BLOCKS:
;	carr_long:	Contains the start date of the carrington rotations 
;			from the almanac.  Generated by READ_CARR_LONG
;
; MODIFICATION HISTORY:
; 	Written by:	RA Howard, NRL, 3/18/96
;       10/17/96        RAH, Added check for cday being defined
;			   , Changed output to CDS structure
;
;	@(#)carrdate.pro	1.3 10/17/96 LASCO IDL LIBRARY
;-
;
COMMON CARR_LONG,cday,cnum
sz = SIZE(cday)
IF (sz(0) EQ 0)   THEN READ_CARR_LONG
w = WHERE (cnum EQ cr)
sz = SIZE(w)
IF (sz(0) EQ 0)  THEN BEGIN
   PRINT,'%CARRDATE:  Input Carrington Rotation number not in table'
   RETURN,-1
ENDIF
n = w(0)
day1 = cday(n+1)
day0 = cday(n)
delday = day1-day0
tai = day1-delday*clong/360.		; CMP date
dte = tai
IF (KEYWORD_SET(el)) THEN BEGIN
   quarter = delday/4
   dte = dte+quarter
ENDIF ELSE IF (KEYWORD_SET(wl)) THEN BEGIN
   quarter = delday/4
   dte = dte-quarter
ENDIF
RETURN,TAI2UTC(dte)
END
