FUNCTION CARRDATE2,cr,clong=clong,el=el,wl=wl,cmp=cmp
;+
; NAME:
;	CARRDATE
;
; PURPOSE:
;	This function converts a carrington number and longitude into a 
;       date.
;
; CATEGORY:
;	LASCO Synoptic
;
; CALLING SEQUENCE:
;	Result = CARRDATE ( Cr )
;
; INPUTS:
;	Cr:	Carrington Rotation Number
;
; 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.
;	Clong:	Carrington Longitude
;
; OUTPUTS:
;	Result:	The function result is returned as a fractional modified
;		Julian date.
;	
; 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
;
;	11/20/96 by N. RIch	added read_carr_long call if cday=0; changed 
;				cday(n-1) to cday(n) and cday(n) to cday(n+1); 
;				made dte variable same as day; initialized clong
;				to 360 if not set and change clong to keyword;
;				changed +/- in computing el and wl day
;	12/30/96 by N. Rich	changed output to CDS structure
;
;	@(#)carrdate.pro	1.1 10/05/96 LASCO IDL LIBRARY
;-
;
COMMON CARR_LONG,cday,cnum

IF (NOT KEYWORD_SET(clong)) THEN clong = 360
sz1 = SIZE(cday)
IF (sz1(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)
;stop
delday = cday(n+1)-cday(n)
day = cday(n)+(1-clong/360.)*delday		; CMP date
;dte = cday(n)
IF (KEYWORD_SET(el)) THEN BEGIN
   quarter = delday/4
   day = day-quarter
ENDIF ELSE IF (KEYWORD_SET(wl)) THEN BEGIN
   quarter = delday/4
   day = day+quarter
ENDIF
RETURN,tai2utc(day)
END
