home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xephem / part07 / time.c < prev   
Encoding:
C/C++ Source or Header  |  1993-05-15  |  1.1 KB  |  70 lines

  1. /* get the time from the os.
  2.  */
  3.  
  4. #include <stdio.h>
  5. #include <time.h>
  6. #include "astro.h"
  7. #include "circum.h"
  8.  
  9. #if defined(__STDC__) || defined(__cplusplus)
  10. #define P_(s) s
  11. #else
  12. #define P_(s) ()
  13. #endif
  14.  
  15. extern void rnd_second P_((double *t));
  16.  
  17. void set_t0 P_((Now *np));
  18. void time_fromsys P_((Now *np));
  19. void inc_mjd P_((Now *np, double inc));
  20.  
  21. #undef P_
  22.  
  23. static long c0;
  24. static double mjd0;
  25.  
  26. /* save current mjd and corresponding system clock for use by inc_mjd().
  27.  * this establishes the base correspondence between the mjd and system clock.
  28.  */
  29. void
  30. set_t0 (np)
  31. Now *np;
  32. {
  33.     mjd0 = mjd;
  34.     c0 = time (NULL);
  35. }
  36.  
  37. /* fill in n_mjd from the system clock.
  38.  */
  39. void
  40. time_fromsys (np)
  41. Now *np;
  42. {
  43.     long t;
  44.  
  45.     /* t is seconds since 00:00:00 1/1/1970 UTC.
  46.      * mjd was 25567.5 then.
  47.      */
  48.     t = time(NULL);
  49.     mjd = 25567.5 + t/3600.0/24.0;
  50. }
  51.  
  52. void
  53. inc_mjd (np, inc)
  54. Now *np;
  55. double inc;
  56. {
  57.     if (inc == RTC) {
  58.         long c;
  59.         (void) time (&c);
  60.         mjd = mjd0 + (c - c0)/SPD;
  61.     } else
  62.         mjd += inc/24.0;
  63.  
  64.     /* round to nearest whole second.
  65.      * without this, you can get fractional days so close to .5 but
  66.      * not quite there that mjd_hr() can return 24.0
  67.      */
  68.     rnd_second (&mjd);
  69. }
  70.