#!/local/bin/perl

=head1 NAME

stime - print current time information to standard out

=head1 SYNOPSIS

  stime

  stime UKIRT

=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. 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<slaObs> routine in the C<Astro::SLA> package.

=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 was		2 39 46.16

=head1 SEE ALSO

L<Astro::SLA>

=head1 REVISION

$Id: stime,v 1.1 2000/03/29 03:28:48 timj Exp $

=head1 COPYRIGHT

Copyright (C) 1996-2000 Particle Physics and Astronomy Research Council.
All Rights Reserved.

=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
#
#    14 Feb 2000 (rpt)
#       Port to perl using Astro::SLA
#    $Log: stime,v $
#    Revision 1.1  2000/03/29 03:28:48  timj
#    First version
#


use strict;
use Astro::SLA;


# 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.
my $time = time();
my ($ss, $mm, $hr, $md, $mo, $yr, $wd, $yd, $isdst) = localtime($time);

# Get Local Sidereal Time and Modified Julia date: LST and MJD 
my ($lst, $mjd) = lstnow_tel($tel);
# Convert LST to HMS from radians 
my @hms;                 # Hours, minutes, seconds, fraction 
my $sign;                # + or minus 
slaDr2tf(2, $lst, $sign, @hms);

# Get UT date and time  - I realise that localtime() and gmtime()
# will give a slightly different answer to the return of lstnow()
# but it should not be a problem.
my ($us, $um, $uh, $umd, $umo, $uyr, $uwd, $uyd, $isdst) = gmtime($time);

# Add back 1900 to year numbers
$yr += 1900;
$uyr += 1900;

# 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+2400000.5;
printf "Modified Julian date:\t\t%8.2f\n", $mjd;

# Get equinox of today from MJD 
my $equinox = slaEpb($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 was\t\t%d %d %d.%d\n", 
      $hms[0], $hms[1], $hms[2], $hms[3];

