From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 18-APR-1994 09:07:55.08
To:	EVERHART
CC:	
Subj:	Re: Julian Day at GMT

From: pack@acd.ucar.edu (Daniel Packman)
X-Newsgroups: comp.os.vms
Subject: Re: Julian Day at GMT
Date: 8 Apr 1994 15:08:35 GMT
Organization: Ntl Center for Atmospheric Research - Atmospheric Chemistry Div
Lines: 101
Message-Id: <2o3s1j$4nq@ncar.ucar.edu>
Nntp-Posting-Host: acd.ucar.edu
Summary: Here is source for Julian Day, not day of year
To: Info-VAX@CRVAX.SRI.COM
X-Gateway-Source-Info: USENET

In article <1994Apr8.055144.121369@yuma> dean%phobos.dnet@sirius.cira.colostate.edu writes:
>
>   I would like to get the Julian day at the GMT time ( not local time)
> using F$CVTIME(). Can someone give some pointers on how to do it?

I suspect that you really want the Day of Year.  Within DCL it is
straightforward to get the year, month, and day via f$cvtime:

 $ tt = f$time()
 $ year = f$cvtime(tt,,"YEAR")
 $ month = f$cvtime(tt,"MONTH")
 $ day = f$cvtime(tt,,"DAY")

 If you are straightforward yourself and set your system time to GMT
 (or, for the nit-picky, Coordinated Universal Time), then all is simple.
 [In addition, you avoid idiocy like changing the system clock for changes
 to/from daylight savings time] If not, you must, through the non-standard
 way you have implemented a local time on your system, find the offset from
 GMT and remove this from the the hour offset.  If negative, subtract one
 from the previous day, if greater than 24, add one.

 The following c program "julday" calculates, given month, day, and year,
 the Julian Day.  If you really want day of year you can then subtract off
 julday(1,1,year) and then add 1.  There is also good reading here about
 what a Julian Day really is.

/*
 * purpose:
 * -------
 *	    This algorithm converts a correctly given calendar date,
 *     given on the Julian calendar on and before Oct 4, 1582 and on
 *     the  Gregorian calendar on and following Oct 15, 1582 through
 *     Feb 28, 4000 AD, to the correct Julian date.
 *
 * parameters:
 * ----------
 * year    -->   to input year BC, subtract year from 0 to get its
 *		 astronomical  representation.  e.g.,  4713 BC  is
 *		 input as -4713.
 * month   -->   month (as integer 1 to 12)
 * day     -->   day of month
 * julday  <--   julian date (begins at 12:00 noon GMT of input date;
 *			      12 noon, Jan 1, 4713 BC = JD 0)
 *
 * references:
 * ----------
 *
 * 1) CACM 11 (Oct 1968) 657.
 * 2) Abell, George - Exploration of the Universe, 2nd ed. (1969) p.147-151.
 *
 * notes:
 * -----
 *
 * 1) The function as presented in reference article assumes  the  Gregorian
 *    calendar indefinitely back in time, so it will not give proper results
 *    for input date prior to Oct 15, 1582.  This routine has been  modified
 *    to correct this error.
 *
 * 2) Input of the dates Oct 5 thru 14, 1582, which did not  exist,
 *    will  cause  return  of  Julian date for date 10 days before.
 *    (e.g., output for Oct 9, 1582 will be correct Julian date for
 *    Sept 29 1582).  An error message is printed.
 *
 * 3) By  1582,  the  Julian  calendar  was  10  days fast.  Pope Gregory XIII
 *    reformed the calendar by proclaiming the day following  Oct 4,  1582  to
 *    be  Oct 15, and  by  decreeing that only century years divided by 400 to
 *    be leap years.  The reform was adopted immediately by Catholic countries
 *    but  resisted  by Eastern Church and Protestant countries.  This routine
 *    corrects for the missing dates of  1582 ( notes 1 and 2 ) but  does  not
 *    correct  for  the missing dates when other nations made the change.  For
 *    example, England and America  adopted  the  new  style calendar in 1752.
 *    By parliamentary decree Sept 2, 1752 was followed by Sept 14.  Moreover,
 *    the start of the year was moved back from Mar 25 to Jan 1, thus  in  the
 *    English domains 1751 contained no Jan, Feb, or Mar 1-24.
 *
 * 4) The Gregorian calendar  has now been modified to obtain closer  conformity
 *    with the tropical year by making common years those years divided by 4000.
 *    Thus 4000 AD is not a leap year.  This  modification  makes  the  calendar
 *    accurate to 1 day in about 20,000 years.
 */

int
julday (month, dy, yr) int *month, *dy, *yr; {
    register int i, year, day;

    i = (*month - 14) / 12;	/* i = *month <= 2 ? 1 : 0 */
    year = *yr;
    if (year < 0) year += 1;
    year += i;

    day = *dy + 1461 * (year + 4716) / 4 - 1432
	  + 367 * (*month - 2 - i * 12) / 12;

    if (day >= 2299161) day -= (3 * ((year - 1500) / 100)) / 4 + 10;

    return (day);
}
-- 
Dan Packman     NCAR                             INTERNET: pack@ncar.UCAR.EDU
(303) 497-1427  P.O. Box 3000
                Boulder, CO  80307-3000        NSI/DECNET: 9583::PACK

