pro carrlong,date,cr,clong,el=el,wl=wl,cmp=cmp
;+
; NAME:
;	CARRLONG
;
; PURPOSE:
;	This procedure computes the carrington number and longitude given the 
;	date.
;
; CATEGORY:
;	LASCO Synoptic
;
; CALLING SEQUENCE:
;	CARRLONG, Date, Cr, Clong
;
; INPUTS:
;	Date:	The date in CDS date/time structure
;
; OPTIONAL INPUTS:
;	None
;	
; KEYWORD PARAMETERS:
;	EL:	Set this keyword to obtain information for East Limb date
;
;	WL:	Set this keyword to obtain information for West Limb date
;
;	CMP:	Set this keyword to obtain information for central meridian    
;		This is the default.
;
; OUTPUTS:
;	Cr:	The carrington rotation number corresponding to the input date
;	Clong:	The carrington longitude corresponding to the input date
;
; COMMON BLOCKS:
;	carr_long:	Contains the start date of the carrington rotations from
;			the almanac.  Generated by READ_CARR_LONG
;
; EXAMPLE:
;	CARRLONG, date, cnum, clong, /EL
;
; MODIFICATION HISTORY:
; 	Written by:	RA Howard, NRL, 3/18/96
;	10/17/95		RAH, Converted dates to CDS time structure
;	13/10/00	nbr, Changed "tai LT cday" to "tai LE cday"
;
;	@(#)carrlong.pro	1.4 11/05/01 LASCO IDL LIBRARY
;-
;
common carr_long,cday,cnum
sz = SIZE(cday)
IF (sz(0) EQ 0) THEN READ_CARR_LONG
help,date
tai = UTC2TAI(date)
w = WHERE (tai LE cday)
sz = sz(w)
IF (sz(0) EQ 0)    THEN BEGIN
   PRINT,'%CARRLONG:  Date not found'
   RETURN
ENDIF
n = w(0)
cr = cnum(n-1)
cd1 = cday(n)
cd0 = cday(n-1)
clong = 360.*(1.-(tai-cd0)/(cd1-cd0))
IF (clong LT 0)  THEN BEGIN
   clong = clong+360.
   cr = cr-1
ENDIF
IF (clong GE 360)  THEN BEGIN
   clong = clong-360.
   cr = cr+1
ENDIF
;stop
IF (KEYWORD_SET(el)) THEN BEGIN
   clong = clong-90.
   IF (clong LT 0) THEN BEGIN
      cr = cr+1
      clong = clong+360.
   ENDIF
   RETURN
ENDIF ELSE IF (KEYWORD_SET(wl)) THEN BEGIN
   clong = clong+90.
   IF (clong GE 360) THEN BEGIN
      cr = cr-1
      clong = clong-360.
   ENDIF
   RETURN
ENDIF
RETURN
END
