summaryrefslogtreecommitdiffstats
path: root/sources/time.cpp
diff options
context:
space:
mode:
authorAngelo Rossi <angelo.rossi.homelab@gmail.com>2023-06-21 12:04:16 +0000
committerAngelo Rossi <angelo.rossi.homelab@gmail.com>2023-06-21 12:04:16 +0000
commitb18347ffc9db9641e215995edea1c04c363b2bdf (patch)
treef3908dc911399f1a21e17d950355ee56dc0919ee /sources/time.cpp
Initial commit.
Diffstat (limited to 'sources/time.cpp')
-rw-r--r--sources/time.cpp153
1 files changed, 153 insertions, 0 deletions
diff --git a/sources/time.cpp b/sources/time.cpp
new file mode 100644
index 0000000..d8622ea
--- /dev/null
+++ b/sources/time.cpp
@@ -0,0 +1,153 @@
+//-*- mode: c++; indent-tabs-mode: t; coding: utf-8; show-trailing-whitespace: t -*-
+
+// file time.cpp
+
+#include "time.hpp"
+
+extern long int spycom::nKWTSpy;
+
+namespace date_time {
+
+ std::clock_t nCPUTime;
+
+ bool date44(std::string *a)
+ {
+ // The purpose of subroutine DATE44 is to interrogate the
+ // installation calendar, and return the current date through the
+ // argument of the subroutine. Eight BCD characters are allowed,
+ // with the first (left) four characters to be placed in a(1) ,
+ // and the final (right) four placed in a(2) . A statement like
+ // write (lunit6, 4041) a
+ // 4041 format ( 1x, 2a4 )
+ // Thus outputs the current date as first the month, then the day,
+ // and finally the year, separated by slashes (MM/DD/YY) .
+ // subroutine DATE44 is of course installation dependent.
+ // European (or generally non-United-States, perhaps) users of this
+ // program may want to reverse the order of appearance of the month
+ // and the day, in conformity with established european usage.
+ // Installation-dependent EMTP module written for the DEC
+ // VAX-11/780. 'IDATE' is a DEC system subroutine which
+ // returns the month, day, and year (of century) as three integer*2
+ // numerical values.
+ bool bReturnValue = false;
+ int year, decade;
+ std::stringstream ss;
+ std::time_t sCurrentTime;
+ std::tm *pLocalTime;
+
+ if(a) {
+ sCurrentTime = std::time(NULL);
+ pLocalTime = std::localtime(&sCurrentTime);
+ if(pLocalTime) {
+ ss << std::setfill('0') << std::setw(2) << (1 + pLocalTime -> tm_mon);
+ ss << ".";
+ ss << std::setfill('0') << std::setw(2) << pLocalTime -> tm_mday;
+ ss << ".";
+ year = pLocalTime -> tm_year + 1900;
+ decade = 100 * (((float) year) / 100.0 - (float) floor (year / 100.0));
+ ss << std::setfill('0') << std::setw(2) << decade;
+ a[ 0 ] = ss.str().substr(0, 4);
+ a[ 1 ] = ss.str().substr(4, 8);
+ bReturnValue = true;
+ }
+ }
+ return bReturnValue;
+ }
+
+ bool time44(std::string *a)
+ {
+ // The purpose of subroutine TIME44 is to interrogate the
+ // installation clock, and return the wall-clock time through the
+ // argument of the subroutine. Eight BCD characters are allowed,
+ // with the first (left) four characters to be placed in a(1) ,
+ // and the final (right) four placed in a(2) . A statement like
+ // write (lunit6, 4041) a
+ // 4041 format ( 1x, 2a4 )
+ // Thus outputs the wall-clock time as first hours, then minutes,
+ // and finally seconds, separated by periods (HH.MM.SS) .
+ // subroutine TIME44 is of course installation dependent.
+ // Installation-dependent EMTP module written for the DEC
+ // VAX-11/780. 'TIME' is a DEC system subroutine which
+ // returns the wall-clock time as an 8-byte character string.
+ // This is just what the EMTP needs, except that we want periods
+ // rather than colons, and of course we require 2a4 format.
+ bool bReturnValue = false;
+ std::stringstream ss;
+ std::time_t sCurrentTime;
+ std::tm *pLocalTime;
+
+ if(a) {
+ sCurrentTime = std::time(NULL);
+ pLocalTime = std::localtime(&sCurrentTime);
+ if(pLocalTime) {
+ ss << std::setfill('0') << std::setw(2) << pLocalTime -> tm_hour;
+ ss << ".";
+ ss << std::setfill('0') << std::setw(2) << pLocalTime -> tm_min;
+ ss << ".";
+ ss << std::setfill('0') << std::setw(2) << pLocalTime -> tm_sec;
+ a[ 0 ] = ss.str().substr(0, 4);
+ a[ 1 ] = ss.str().substr(4, 8);
+ bReturnValue = true;
+ }
+ }
+ return bReturnValue;
+ }
+
+ void settym(void)
+ {
+ // VAX-11 Installation-dependent EMTP module.
+ // Called only by VAX "RUNTYM"; destroy for other computers.
+ // Include '[SCOTT]COMMUK.FOR' --- share with "RUNTYM" in-line:
+ date_time::nCPUTime = std::clock ();
+ }
+
+ void runtym(double &d1, double &d2)
+ {
+ // This subroutine returns with the current job-execution time, as
+ // broken down into two categories ....
+ // d1 = central processor job time, in seconds
+ // d2 = peripheral processor (or input/output) job time,
+ // in seconds.
+ // If two such figures are not available ont the user's computre,
+ // 'd2' should be set to zero so that case-summary statistics
+ // will not print out garbage values. Such is the only use of
+ // the values gotten by calling this subroutine ---- for the case-
+ // summary printout. Hence if one wants to convert time into
+ // dollars, or some other measure of job effort, it is easily done.
+ // Include '[SCOTT]COMMUK.FOR' --- share with "SETTYM" in-line:
+ std::clock_t nNowCPUTime;
+ //
+ nNowCPUTime = std::clock ();
+ d1 = std::difftime (date_time::nCPUTime, nNowCPUTime) / CLOCKS_PER_SEC;
+ d2 = 0.0;
+ }
+
+ // subroutine tdelay.
+
+ void tdelay(int &d8)
+ {
+ // Module of interactive EMTP only, which services "emtspy".
+ // If no interactive use, this module can be deleted.
+ // VAX-11 module designed to stall for d8 seconds.
+ // Present use of disk writes is temporary only, and should
+ // later be replaced by a less-wasteful, true hibernation.
+ clock_t sNow = clock();
+ //
+ int nDelay; // integer number of seconds for hibernation
+ //
+ nDelay = d8 * CLOCKS_PER_SEC;
+ while((clock() - sNow) < nDelay) { // loop once for each second of delay
+ utilities::quiter(); // check for user-keyed interrupt signal
+ if (spycom::nKWTSpy == 0) { // no user abort of alarm
+ ;
+ } else {
+ spycom::nKWTSpy = 0; // reset interrupt indicator as we begin service
+ d8 = -7654; // argument flag remembering abort (for honker)
+ break; // jump out of time-delay loop, to return
+ }
+ }
+ }
+
+}
+
+// end of file time.cpp