| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#PODNAME: Lab::XPRESS::Utilities |
|
2
|
|
|
|
|
|
|
#ABSTRACT: Global utility functions for XPRESS |
|
3
|
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
98
|
use v5.20; |
|
|
8
|
|
|
|
|
30
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
45
|
no strict; # FIXME |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
278
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#note: this is no "package" |
|
9
|
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
45
|
use Term::ReadKey; |
|
|
8
|
|
|
|
|
18
|
|
|
|
8
|
|
|
|
|
485
|
|
|
11
|
8
|
|
|
8
|
|
48
|
use Time::HiRes qw/usleep/, qw/time/; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
61
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# collection of some useful subroutines: |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub my_sleep { |
|
16
|
0
|
|
|
0
|
0
|
0
|
my $sleeptime = shift; |
|
17
|
0
|
|
|
|
|
0
|
my $self = shift; |
|
18
|
0
|
|
|
|
|
0
|
my $user_command = shift; |
|
19
|
0
|
0
|
|
|
|
0
|
if ( $sleeptime >= 5 ) { |
|
20
|
0
|
|
|
|
|
0
|
countdown( $sleeptime * 1e6, $self, $user_command ); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
else { |
|
23
|
0
|
|
|
|
|
0
|
usleep( $sleeptime * 1e6 ); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub my_usleep { |
|
28
|
0
|
|
|
0
|
0
|
0
|
my $sleeptime = shift; |
|
29
|
0
|
|
|
|
|
0
|
my $self = shift; |
|
30
|
0
|
|
|
|
|
0
|
my $user_command = shift; |
|
31
|
0
|
0
|
|
|
|
0
|
if ( $sleep_time >= 5 ) { |
|
32
|
0
|
|
|
|
|
0
|
countdown( $sleeptime, $self, $user_command ); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
else { |
|
35
|
0
|
|
|
|
|
0
|
usleep($sleeptime); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub countdown { |
|
40
|
0
|
|
|
0
|
0
|
0
|
my $duration = shift; |
|
41
|
0
|
|
|
|
|
0
|
my $self = shift; |
|
42
|
0
|
|
|
|
|
0
|
my $user_command = shift; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
ReadMode('cbreak'); |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
$duration /= 1e6; |
|
47
|
0
|
|
|
|
|
0
|
my $hours = int( $duration / 3600 ); |
|
48
|
0
|
|
|
|
|
0
|
my $minutes = int( ( $duration - $hours * 3600 ) / 60 ); |
|
49
|
0
|
|
|
|
|
0
|
my $seconds = $duration - $hours * 3600 - $minutes * 60; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
my $t_0 = time(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
local $| = 1; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
my $message = "Waiting for "; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
if ( $hours > 1 ) { $message .= "$hours hours "; } |
|
|
0
|
0
|
|
|
|
0
|
|
|
58
|
0
|
|
|
|
|
0
|
elsif ( $hours == 1 ) { $message .= "one hour "; } |
|
59
|
0
|
0
|
|
|
|
0
|
if ( $minutes > 1 ) { $message .= "$minutes minutes "; } |
|
|
0
|
0
|
|
|
|
0
|
|
|
60
|
0
|
|
|
|
|
0
|
elsif ( $minutes == 1 ) { $message .= "one minute "; } |
|
61
|
0
|
0
|
|
|
|
0
|
if ( $seconds > 1 ) { $message .= "$seconds seconds "; } |
|
|
0
|
0
|
|
|
|
0
|
|
|
62
|
0
|
|
|
|
|
0
|
elsif ( $seconds == 1 ) { $message .= "one second "; } |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
$message .= "\n"; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
print $message; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
while ( ( $t_0 + $duration - time() ) > 0 ) { |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
my $char = ReadKey(1); |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
0
|
0
|
|
|
0
|
if ( defined($char) && $char eq 'c' ) { |
|
|
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
last; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
elsif ( defined($char) ) { |
|
76
|
0
|
0
|
|
|
|
0
|
if ( defined $user_command ) { |
|
77
|
0
|
|
|
|
|
0
|
$user_command->( $self, $char ); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
else { |
|
80
|
0
|
|
|
|
|
0
|
user_command($char); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
my $left = ( $t_0 + $duration - time() ); |
|
85
|
0
|
|
|
|
|
0
|
my $hours = int( $left / 3600 ); |
|
86
|
0
|
|
|
|
|
0
|
my $minutes = int( ( $left - $hours * 3600 ) / 60 ); |
|
87
|
0
|
|
|
|
|
0
|
my $seconds = $left - $hours * 3600 - $minutes * 60; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
print sprintf( "%02d:%02d:%02d", $hours, $minutes, $seconds ); |
|
90
|
0
|
|
|
|
|
0
|
print "\r"; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#sleep(1); |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
0
|
|
|
|
|
0
|
ReadMode('normal'); |
|
96
|
0
|
|
|
|
|
0
|
$| = 0; |
|
97
|
0
|
|
|
|
|
0
|
print "\n\nGO!\n"; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub timestamp { |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my ( |
|
104
|
24
|
|
|
24
|
0
|
645
|
$Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, |
|
105
|
|
|
|
|
|
|
$Jahr, $Wochentag, $Jahrestag, $Sommerzeit |
|
106
|
|
|
|
|
|
|
) = localtime(time); |
|
107
|
|
|
|
|
|
|
|
|
108
|
24
|
|
|
|
|
85
|
$Monat += 1; |
|
109
|
24
|
|
|
|
|
35
|
$Jahrestag += 1; |
|
110
|
24
|
50
|
|
|
|
90
|
$Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat; |
|
111
|
24
|
50
|
|
|
|
63
|
$Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag; |
|
112
|
24
|
50
|
|
|
|
50
|
$Stunden = $Stunden < 10 ? $Stunden = "0" . $Stunden : $Stunden; |
|
113
|
24
|
50
|
|
|
|
47
|
$Minuten = $Minuten < 10 ? $Minuten = "0" . $Minuten : $Minuten; |
|
114
|
24
|
50
|
|
|
|
48
|
$Sekunden = $Sekunden < 10 ? $Sekunden = "0" . $Sekunden : $Sekunden; |
|
115
|
24
|
|
|
|
|
50
|
$Jahr += 1900; |
|
116
|
|
|
|
|
|
|
|
|
117
|
24
|
|
|
|
|
132
|
return "$Monatstag.$Monat.$Jahr", "$Stunden:$Minuten:$Sekunden"; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub user_command { |
|
122
|
|
|
|
|
|
|
my $cmd = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
print "test user_command = $cmd\n"; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# do something; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub seconds2time { |
|
130
|
0
|
|
|
0
|
0
|
|
my $duration = shift; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $hours = int( $duration / 3600 ); |
|
133
|
0
|
|
|
|
|
|
my $minutes = int( ( $duration - $hours * 3600 ) / 60 ); |
|
134
|
0
|
|
|
|
|
|
my $seconds = $duration - $hours * 3600 - $minutes * 60; |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $formated = $hours . "h " . $minutes . "m " . $seconds . "s "; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
return $formated; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
__END__ |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=pod |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=encoding UTF-8 |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 NAME |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Lab::XPRESS::Utilities - Global utility functions for XPRESS |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 VERSION |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
version 3.881 |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Copyright 2012 Stefan Geissler |
|
162
|
|
|
|
|
|
|
2013 Andreas K. Huettel |
|
163
|
|
|
|
|
|
|
2016 Simon Reinhardt |
|
164
|
|
|
|
|
|
|
2017 Andreas K. Huettel |
|
165
|
|
|
|
|
|
|
2020 Andreas K. Huettel |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
169
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |