-
Notifications
You must be signed in to change notification settings - Fork 2
/
stime
217 lines (159 loc) · 5.73 KB
/
stime
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/local/bin/perl
=head1 NAME
stime - print current time information to standard out
=head1 SYNOPSIS
stime
stime UKIRT
stime -epoch 837459706 JCMT
stime -h
=head1 DESCRIPTION
This program prints current local time, UTC, Julian date,
modified Julian date, current equinox and year day to standard output.
Additionally, local sidereal time for the specified telescope is
also displayed.
=head1 ARGUMENTS
The optional argument can be used to specify the details for a
particular telescope. This affects the local sidereal time
calculation. The default is for the LST of Mauna Kea to be listed
(specifically the James Clerk Maxwell Telescope). The sidereal time
does not reflect the longitude of the computer used to run the
command.
The format of this string is identical to that required by
C<palObs> routine in the C<Astro::PAL> package.
=head1 OPTIONS
The following command line options are supported:
=over 4
=item B<-epoch>
Override the time for which the LST will be calculated. By default
will use the current time/date. This epoch should be supplied in
seconds in the Unix epoch (essentially the argument to the perl
localtime/gmtime functions).
=item B<-help>
Simple help message.
=item B<-man>
This manual page.
=back
=head1 OUTPUT
Example output of this program is:
At local date and time Fri Mar 24 14:50:31 2000
The UT date and time was: Sat Mar 25 00:50:31 2000
Julian date: 2451628.54
Modified Julian date: 51628.04
Equinox for today is 2000.23
Local Day number (UT): 84 (85)
For telescope JCMT
The local sidereal time was 2 39 46.16
=head1 SEE ALSO
L<Astro::PAL>
=head1 REVISION
$Id$
=head1 COPYRIGHT
Copyright (C) 1996-2000,2004 Particle Physics and Astronomy Research Council.
All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place,Suite 330, Boston, MA 02111-1307, USA
=head1 AUTHORS
Tim Jenness, Remo Tilanus
=cut
# History:
# 15 Jul 1996 (timj)
# Write first version in C
# Replacement for stime on the VMS machines.
# Output of VAX was:
#
# at local time 9 41 46.00
# local sidereal time was 4 55 36.46
# Universal Time 19 41 46.00
# Julian date 2450280.32
# equinox for today 1996.54
# day number 197
#
# For Unix epoch 837459706 seconds. This version of stime
# gives LST of 4 55 35.67 [within a second of the Vax version]
#
# 14 Feb 2000 (rpt)
# Port to perl using Astro::PAL
# $Log$
# Revision 1.2 2004/02/04 00:42:08 timj
# + Lots of tidying up
# + Now uses ut2lst_tel rather than lstnow_tel
# + Now have -h and -man options
# + Add -epoch option for overriding calculated date
# + Add GPL
#
# Revision 1.1 2000/03/29 03:28:48 timj
# First version
#
use strict;
use Astro::PAL;
# Read command line options
use Getopt::Long;
use Pod::Usage;
my ($help, $man, $epoch, $datetime);
my $status = GetOptions("epoch=s" => \$epoch,
"datetime=s" => \$datetime,
"help" => \$help,
"man" => \$man,
);
pod2usage(1) if ($help);
pod2usage(-verbose => 2) if ($man);
# Read telescope name from standard in (default to JCMT)
my $tel = 'JCMT';
$tel = shift(@ARGV) if @ARGV;
# Day and Month names
my @weekday = ("Sun", "Mon", "Tue", "Wed", "Thu" , "Fri", "Sat");
my @month = ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
# Get the current DATE and TIME.
# Use time variable to get for use in gmtime as well.
# Can be overridden from the command line using -epoch
my $time;
if (defined $epoch) {
$time = $epoch;
}
elsif (defined $datetime) {
require DateTime;
require DateTime::Format::ISO8601;
my $dt = DateTime::Format::ISO8601->parse_datetime($datetime);
$time = $dt->epoch;
}
else {
$time = time();
}
my ($ss, $mm, $hr, $md, $mo, $yr, $wd, $yd, $isdst) = localtime($time);
$yr += 1900;
# Get UT date and time
my ($us, $um, $uh, $umd, $umo, $uyr, $uwd, $uyd, $isdst) = gmtime($time);
$uyr += 1900;
# Get Local Sidereal Time and Modified Julian Date: LST and MJD
# Using the actual UT time from above [not current]
my ($lst, $mjd) = Astro::PAL::ut2lst_tel($uyr,($umo+1),$umd,$uh,$um,$us,$tel);
# Convert LST to HMS from radians
my $np = 2;
my ($sign, @hms) = Astro::PAL::palDr2tf($np, $lst);
# print out Local time
printf "At local date and time\t\t%3s %3s %2.2d %2.2d:%2.2d:%2.2d %4.4d\n",
$weekday[$wd], $month[$mo], $md, $hr, $mm, $ss, $yr;
# Print out UT time
printf "The UT date and time was:\t%3s %3s %2.2d %2.2d:%2.2d:%2.2d %4.4d\n",
$weekday[$uwd], $month[$umo], $umd, $uh, $um, $us, $uyr;
# Print out Julian date
printf "Julian date:\t\t\t%10.2f\n", $mjd + 2_400_000.5;
printf "Modified Julian date:\t\t%8.2f\n", $mjd;
# Get equinox of today from MJD
my $equinox = Astro::PAL::palEpj($mjd);
printf "Equinox for today is \t\t%7.2f\n", $equinox;
# Print Local and UT day number
printf "Local Day number (UT): \t\t%d (%d)\n", $yd+1, $uyd+1;
# Print out LST
print "For telescope $tel\n";
printf "The local sidereal time was\t%02d %02d %02d.%0".$np."d\n",
$hms[0], $hms[1], $hms[2], $hms[3];