function anytim2weekid, intime, t1, t2, ndays, string=str, year=years
;+
; NAME:
;   anytim2weekid
; PURPOSE:
;   Convert time in any format to Yohkoh week ID
; CALLING SEQUENCE:
;   Week_ID = anytim2weekid(index(0))
;   Week_ID = anytim2weekid()			; Current Week ID
;   Week_ID = anytim2weekid(index,t1,t2,ndays)
;   Week_ID = anytim2weekid(index(0),/str)	; return as YY_WW string
;
; RETURNS:
;   Week_ID is Yohkoh week number
; OPTIONAL INPUTS:
;   intime	= Time in any Yohkoh format
; OPTIONAL KEYWORD INPUTS:
;   string	= Set to return as YY_WW string
; OPTIONAL OUTPUTS:
;   t1, t2	= Time range of specified week(s) (string-type)
;   ndays	= Number of days in the week      (integer)
; OPTIONAL KEYWORD OUTPUTS:
;   year	= Year number
; PROCEDURE:
;   Calls anytim2ex, ex2week, week2ex, anytim2ints, gt_day
;   This differs from anytim2weeks in that:
;	1. Returns week numbers for specified input times
;	   (anytim2weeks returns a range of week numbers)
;	2. Does not back up 90 min if near 00:00 UT on Sunday
; Warning - this is an obsolete routine (2 digit years only)
;       New softare should use 'anytim2weekinfo.pro'
;  
; MODIFICATION HISTORY:
;   22-jan-94, J. R. Lemen, Written
;    4-jan-2000, S. L. Freeland - Y2K modification (2000->00)
;-

; If no time is specified, use the current time (!stime)

if n_elements(intime) eq 0 then time = !stime else time = intime
; -----------------------------------------------------------------------
; Convert time to week and year numbers
; -----------------------------------------------------------------------
tarr = anytim2ex(time) 		; External
weeks = ex2week(tarr)
years = reform(tarr(6,*))

; -----------------------------------------------------------------------
; Set up the output variables
; -----------------------------------------------------------------------
npts = n_elements(weeks)
ndays = replicate(7,npts)
week_id = strarr(npts)

; -----------------------------------------------------------------------
;  Work out the first and last day of the week
; -----------------------------------------------------------------------

t1 = week2ex(years,weeks)
t1 = anytim2ints(t1)
t2 = anytim2ints(t1, offset=6 * 24.*60*60. + 10*60.)	; Add 6 days plus 10 minutes

; Take care of the first/last week of the year
w2 = ex2week(anytim2ex(t2))

years=years-([0,100])(years ge 100)             ; Y2K, SLF, 4-Jan-2000

for i=0,npts-1 do begin
   dd = 5					; dd = number of days in week -1
   while weeks(i) ne w2(i) do begin		; Until start/stop days are in the same week
        ndays(i) = dd + 1
	t2(i) = anytim2ints(t1(i), offset=dd * 24.*60*60. + 10*60.) ; Add dd days plus 10 minutes
	dd = dd - 1
	w2(i) = ex2week(anytim2ex(t2(i)))		; Compute a new week number
   endwhile
   week_id(i) = string(years(i),'_',weeks(i),'a',format='(2(i2.2,a))')
endfor

t1 = gt_day(t1,/str)			; Return first day of week as a string-type
t2 = gt_day(t2,/str)			; Return last  day of week as a string-type

if keyword_set(str) then return,week_id else return,weeks
end
