1 /* Implementation of the ETIME intrinsic.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Contributed by Steven G. Kargl <kargls@comcast.net>.
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include <sys/types.h>
24 #include "libgfortran.h"
28 #if defined (HAVE_SYS_TIME_H) && defined (HAVE_SYS_RESOURCE_H)
30 #include <sys/resource.h>
33 extern void etime_sub (gfc_array_r4
*t
, GFC_REAL_4
*result
);
34 iexport_proto(etime_sub
);
37 etime_sub (gfc_array_r4
*t
, GFC_REAL_4
*result
)
39 GFC_REAL_4 tu
, ts
, tt
, *tp
;
42 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
45 if (getrusage(RUSAGE_SELF
, &rt
) == 0)
47 tu
= (GFC_REAL_4
)(rt
.ru_utime
.tv_sec
+ 1.e
-6 * rt
.ru_utime
.tv_usec
);
48 ts
= (GFC_REAL_4
)(rt
.ru_stime
.tv_sec
+ 1.e
-6 * rt
.ru_stime
.tv_usec
);
63 if (((t
->dim
[0].ubound
+ 1 - t
->dim
[0].lbound
)) < 2)
64 runtime_error ("Insufficient number of elements in TARRAY.");
66 if (t
->dim
[0].stride
== 0)
72 tp
+= t
->dim
[0].stride
;
78 extern GFC_REAL_4
etime (gfc_array_r4
*t
);
82 etime (gfc_array_r4
*t
)
89 /* LAPACK's test programs declares ETIME external, therefore we
92 extern GFC_REAL_4
etime_ (GFC_REAL_4
*t
);
93 export_proto_np(etime_
);
96 etime_ (GFC_REAL_4
*t
)
101 /* We only fill in the fields that are used in etime_sub. */
102 desc
.dim
[0].lbound
= 0;
103 desc
.dim
[0].ubound
= 1;
104 desc
.dim
[0].stride
= 1;
107 etime_sub (&desc
, &val
);