C subroutine to supply the time in seconds
The second.c module contains a C routine that calls the timer.s routines to access the upper and lower register contents.
It returns a double-precision real value of time in seconds.
double second()
{
int ts, tl, tu;
ts = rtc_upper(); /* seconds */
tl = rtc_lower(); /* nanoseconds */
tu = rtc_upper(); /* Check for a carry from */
if (ts != tu) /* the lower reg to the upper. */
tl = rtc_lower(); /* Recover from the race condition. */
return ( tu + (double)tl/1000000000 );
}
The subroutine second() can be called from either a C routine or a FORTRAN routine.
Note: Depending on the length of
time since the last system reset, the second.c module
might yield a varying amount of precision. The longer the time since reset,
the larger the number of bits of precision consumed by the whole-seconds part
of the number. The technique shown in the first part of this appendix avoids
this problem by performing the subtraction required to obtain an elapsed time
before converting to floating point.