etime.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Implementation of the ETIME intrinsic.
  2. Copyright (C) 2004-2015 Free Software Foundation, Inc.
  3. Contributed by Steven G. Kargl <kargls@comcast.net>.
  4. This file is part of the GNU Fortran runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #include "time_1.h"
  22. extern void etime_sub (gfc_array_r4 *t, GFC_REAL_4 *result);
  23. iexport_proto(etime_sub);
  24. void
  25. etime_sub (gfc_array_r4 *t, GFC_REAL_4 *result)
  26. {
  27. GFC_REAL_4 tu, ts, tt, *tp;
  28. long user_sec, user_usec, system_sec, system_usec;
  29. if (((GFC_DESCRIPTOR_EXTENT(t,0))) < 2)
  30. runtime_error ("Insufficient number of elements in TARRAY.");
  31. if (gf_cputime (&user_sec, &user_usec, &system_sec, &system_usec) == 0)
  32. {
  33. tu = (GFC_REAL_4)(user_sec + 1.e-6 * user_usec);
  34. ts = (GFC_REAL_4)(system_sec + 1.e-6 * system_usec);
  35. tt = tu + ts;
  36. }
  37. else
  38. {
  39. tu = (GFC_REAL_4)-1.0;
  40. ts = (GFC_REAL_4)-1.0;
  41. tt = (GFC_REAL_4)-1.0;
  42. }
  43. tp = t->base_addr;
  44. *tp = tu;
  45. tp += GFC_DESCRIPTOR_STRIDE(t,0);
  46. *tp = ts;
  47. *result = tt;
  48. }
  49. iexport(etime_sub);
  50. extern GFC_REAL_4 etime (gfc_array_r4 *t);
  51. export_proto(etime);
  52. GFC_REAL_4
  53. etime (gfc_array_r4 *t)
  54. {
  55. GFC_REAL_4 val;
  56. etime_sub (t, &val);
  57. return val;
  58. }