home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / fblnk224.zip / time.c < prev    next >
C/C++ Source or Header  |  1999-01-28  |  2KB  |  82 lines

  1. /*  time.c      */
  2. /*  Time routines for the orbits program   */
  3. /*  (c) Jure Skvarc                        */
  4. /*  Equations are taken from J. Meeus: Astronomical Algorithms  */
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <time.h>
  8.  
  9. #include "functs.h"
  10. char error[256];
  11.  
  12. /*============================================================*/
  13. /*  Calculate a Julian day for a given year, month and day  */
  14. /*  Fractional part of the day can be given    */
  15. /*============================================================*/
  16. double
  17. julian_day(int year, int month, double day)
  18.  
  19. {
  20.   int a, b;
  21.   static int dm[] = {0, 32, 30, 32, 31, 32, 31, 32, 32, 31, 32, 31, 32};
  22.   if (year < -4712 || month < 1 || month > 12 || day < 0 || day >= dm[month]) {
  23.     return -1;
  24.   }
  25.   if (year == 1582 && month == 10 && day >=5 && day < 15) {
  26.    return -1;
  27.   }
  28.   if (month < 3) {
  29.     year--;
  30.     month += 12;
  31.   }
  32.   a = year / 100;
  33.   if (year > 1582 || (year == 1582 && (month > 10 || 
  34.                        (month == 10 && day >= 15.0)))) {
  35.     b = 2 - a + a / 4;
  36.   }
  37.   else {
  38.     b = 0;
  39.   }
  40.   return floor(365.25 * (year + 4716)) + floor(30.6001 * (month + 1)) + day + b - 1524.5;
  41. }
  42.  
  43. /*=================================================================*/
  44. /*  Calculate a fractional day from day number, hours, minutes and */
  45. /*  seconds (which may have a fractional part)                     */
  46. /*=================================================================*/
  47. double
  48. make_a_day(int day, int hours, int minutes, double seconds)
  49.  
  50. {
  51.   if (day < 1 || day > 31 
  52.       || hours < 0 || hours > 23 
  53.       || minutes < 0 || minutes > 59
  54.       || seconds < 0 || seconds >= 60) {
  55.     return -1;
  56.   }
  57.   return day + (hours + (minutes + seconds / 60.0) / 60.0) / 24.0;
  58. }
  59.  
  60.  
  61. /*=================================================================*/
  62. /*  Calculate a local sidereal day from a Julian day and           */
  63. /*  longitude (in decimal degrees                                  */
  64. /*=================================================================*/
  65. double
  66. sidereal(double jd, double longitude)
  67.  
  68. {
  69.   double sidereal, t;
  70.  
  71.   t = (jd - 2451545.0) / 36525.0;
  72.   /*  sidereal time at ut in Greenwich  */
  73.   sidereal = 280.46061837 + 360.98564736629 * (jd - 2451545.0) +
  74.     (0.000387933 - t / 38710000.0) * t * t;
  75.   sidereal -= longitude;
  76.   return fmod(sidereal, 360.0);
  77. }
  78.  
  79.  
  80.  
  81.  
  82.