home *** CD-ROM | disk | FTP | other *** search
- /* get the time from the os.
- */
-
- #include <stdio.h>
- #include <time.h>
- #include "astro.h"
- #include "circum.h"
-
- #if defined(__STDC__) || defined(__cplusplus)
- #define P_(s) s
- #else
- #define P_(s) ()
- #endif
-
- extern void rnd_second P_((double *t));
-
- void set_t0 P_((Now *np));
- void time_fromsys P_((Now *np));
- void inc_mjd P_((Now *np, double inc));
-
- #undef P_
-
- static long c0;
- static double mjd0;
-
- /* save current mjd and corresponding system clock for use by inc_mjd().
- * this establishes the base correspondence between the mjd and system clock.
- */
- void
- set_t0 (np)
- Now *np;
- {
- mjd0 = mjd;
- c0 = time (NULL);
- }
-
- /* fill in n_mjd from the system clock.
- */
- void
- time_fromsys (np)
- Now *np;
- {
- long t;
-
- /* t is seconds since 00:00:00 1/1/1970 UTC.
- * mjd was 25567.5 then.
- */
- t = time(NULL);
- mjd = 25567.5 + t/3600.0/24.0;
- }
-
- void
- inc_mjd (np, inc)
- Now *np;
- double inc;
- {
- if (inc == RTC) {
- long c;
- (void) time (&c);
- mjd = mjd0 + (c - c0)/SPD;
- } else
- mjd += inc/24.0;
-
- /* round to nearest whole second.
- * without this, you can get fractional days so close to .5 but
- * not quite there that mjd_hr() can return 24.0
- */
- rnd_second (&mjd);
- }
-