File: zgtime.c

package info (click to toggle)
iraf 2.17-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 95,288 kB
  • sloc: ansic: 228,894; fortran: 75,606; lisp: 18,369; xml: 8,401; sh: 6,111; yacc: 5,648; lex: 596; makefile: 575; asm: 153; csh: 95; sed: 4
file content (58 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

#define	import_kernel
#define	import_knames
#define import_spp
#include <iraf.h>

/* ZGTIME -- Get the local standard (clock) time, in units of seconds
 * since 00:00:00 01-Jan-80.  Return the total cpu time consumed by the
 * process (and any subprocesses), in units of milliseconds.
 */
int
ZGTIME (
  XLONG	 *clock_time,				/* seconds */
  XLONG	 *cpu_time 				/* milliseconds */
)
{
	struct	tms t;
	time_t	gmt_to_lst(time_t gmt);
	long	cpu, clkfreq;


	clkfreq = sysconf(_SC_CLK_TCK);

	times (&t);
	time_t now = 0;
	char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
	if (source_date_epoch) {
	  now = strtoull(source_date_epoch, NULL, 10);
	}
	if (now != 0) {
	  *clock_time = now - 315532800L; // seconds 1970 to 1980; assume UTC
	} else {
	  *clock_time = gmt_to_lst (time(0));
	}

	/* We don't want any floating point in the kernel code so do the
	 * following computation using integer arithment, taking care to
	 * avoid integer overflow (unless unavoidable) or loss of precision.
	 */
	cpu = (t.tms_utime + t.tms_cutime);

	if (cpu > MAX_LONG/1000)
	  *cpu_time = cpu / clkfreq * 1000;
	else
	  *cpu_time = cpu * 1000 / clkfreq;

	return (XOK);
}