home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / daytime / cvt2jd.c < prev    next >
Text File  |  1996-11-18  |  987b  |  34 lines

  1. long int cvt2jd(yr,mo,day)
  2. int yr;
  3. int mo;
  4. int day;
  5. {
  6. long int mjd;  /*holds result*/
  7. int ilp;       /*number of leap years from 1900 not counting current*/
  8. static int dmo[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
  9. /*
  10.     this subroutine receives a date in the form year, month and day
  11.     and returns the MJD corresponding to that day.  the year may
  12.     be specified as 90 or 1990.
  13. */
  14.     if(yr > 1900) yr -= 1900;    /* convert to years since 1900 */
  15.     ilp=(yr-1)/4;             /* number of leap years since 1900*/
  16. /*
  17.     compute number of days since 1900 + 1 day for each leap year
  18.     + number of days since start of this year
  19. */
  20.     mjd = 365*(long int) yr + (long int) (ilp + dmo[mo-1] + day - 1);
  21.     mjd += 15020;      /* add MJD of 1900 */
  22. /*
  23.     if current month is jan or feb then it does not matter if
  24.     current year is a leap year
  25. */
  26.     if(mo < 3) return(mjd);
  27. /*
  28.     if current month is march or later then must add 1 day if
  29.     current year is divisible by 4
  30. */
  31.     if( (yr & 3) == 0) mjd++;
  32.     return(mjd);
  33. }
  34.