Viewing contents of file '../idllib/iuedac/iuelib/pro/fdate.pro'
;**************************************************************
;+
;*NAME:
;
;	FDATE
;
;*PURPOSE:
;
;	FDATE converts day-of-year to Gregorian date in a format
;       required by FITS conventions (i.e. dd/mm/yy).
;	Works on cumulative day from 1-JAN-1979 (for instance),
;	as well as more well-mannered days-of-year.
;
;*CALLING SEQUENCE:
;
;	FDATE,YEAR,DAY,D_STRING
;
;*PARAMETERS:
;
;	YEAR (REQ) (I) (0) (I)
;       Years after 1900 may either be written out in full
;	(e.g. 1986) or with just the last two digits (e.g. 86)
;
;       DAY  (REQ) (I) (0) (I)
;       number of days after Jan 1 of the specified year
;
;	D_STRING (REQ) (O) (0) (S)
;       String giving date in format 'DD/MM/YY' (e.g., 256,1990
;       returns 13/03/90).
;
;*SUBROUTINES CALLED:
;
;	PARCHECK
;
; RESTRICTIONS:
;
;	Will only work for years after 1900.
;
;*NOTES:
;
;	tested with IDL Version 2.1.0 (sunos sparc)	 7 Aug 91
;       tested with IDL Version 2.1.0 (ultrix mipsel)	N/A
;       tested with IDL Version 2.1.0 (vms vax)		 7 Aug 91
;
; MODIFICATION HISTORY:
;
;       D.M. fecit  24 October,1983
;       09/13/90 RWT modify output format to give date as DD/MM/YY
;       12/13/90 RWT add '0' to MONTH if MONTH LE 9 not LAST_MONTH LE 9
;	03/27/91 PJL modified for unix/sun; changed from a function 
;                to procedure; added n_param(0) check and PARCHECK
;       05/06/94 RWT add '0' to day if < 10
;
;-
;******************************************************************
 pro fdate,year,day,d_string
;
 if n_params(0) eq 0 then begin
    print,'FDATE,YEAR,DAY,D_STRING'
    retall
 endif  ; n_params(0)
 parcheck,n_params(0),3,'FDATE'
;
 if day le 0 then begin
    d_string = '%DATE-F-DAY.LE.ZERO'
 endif else begin
    last_day = [31,59,90,120,151,181,212,243,273,304,334,365]
    ld = [0,intarr(11)+1]
    day_of_year = day
    months = 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'
    if year gt 1899 then yr = year - 1900 else yr = year
    n_days = 365 + ((yr mod 4) eq 0)
    while day_of_year gt n_days do begin
       day_of_year = day_of_year - n_days
       yr = yr + 1
       n_days = 365 + ((yr mod 4) eq 0)
    endwhile  ; day_of_year
    end_date = '/' + strtrim(yr,2)
    if (yr mod 4) eq 0 then last_day = last_day + ld
    last_month = day_of_year le last_day
    where_ld = where(last_month,n_month)
    if n_month eq 12 then begin
       if (day_of_year le 9) then day_of_year = '0' + strtrim(day_of_year,2)
       d_string = strtrim(day_of_year,2) + '/01' + end_date
    endif else begin
       last_month = where_ld(0)
       month = strtrim(string(last_month+1),2)
       if (month le 9) then month = '0' + month
       day_of_month = day_of_year - last_day(last_month-1)
       if (day_of_month le 9) then day_of_month = '0' + strtrim(day_of_month,2)
       d_string = strtrim(day_of_month,2) + '/' + month + end_date
    endelse  ; n_month
 endelse  ; day
 return
 end  ; fdate