X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUtil.pm;h=9f63c8908234eea858730c314d99493d1d69364a;hb=0f8cb479221e09bae8e03447c78527604cf69be4;hp=605bfca4aa6bf23da413b96a1652bb2e4aeab7ce;hpb=e5b0e3dee551a224de284a5ba550098256fcb268;p=spider.git diff --git a/perl/DXUtil.pm b/perl/DXUtil.pm index 605bfca4..9f63c890 100644 --- a/perl/DXUtil.pm +++ b/perl/DXUtil.pm @@ -8,10 +8,13 @@ package DXUtil; +use Date::Parse; +use Carp; + require Exporter; @ISA = qw(Exporter); @EXPORT = qw(atime ztime cldate cldatetime slat slong yesno promptf parray parraypairs - print_all_fields + print_all_fields cltounix ); @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); @@ -56,6 +59,16 @@ sub cldatetime return "$date $time"; } +# return a unix date from a cluster date and time +sub cltounix +{ + my $date = shift; + my $time = shift; + $date =~ s/^\s*(\d+)-(\w\w\w)-(19\d\d)$/$1 $2 $3/; + $time =~ s/^(\d\d)(\d\d)Z$/$1:$2 +0000/; + return str2time("$date $time"); +} + # turn a latitude in degrees into a string sub slat { @@ -64,7 +77,7 @@ sub slat $let = $n >= 0 ? 'N' : 'S'; $n = abs $n; $deg = int $n; - $min = int (($n - $deg) * 60); + $min = int ((($n - $deg) * 60) + 0.5); return "$deg $min $let"; } @@ -76,7 +89,7 @@ sub slong $let = $n >= 0 ? 'E' : 'W'; $n = abs $n; $deg = int $n; - $min = int (($n - $deg) * 60); + $min = int ((($n - $deg) * 60) + 0.5); return "$deg $min $let"; } @@ -105,7 +118,8 @@ sub promptf # take an arg as an array list and print it sub parray { - return join(', ', @{shift}); + my $ref = shift; + return join(', ', @{$ref}); } # take the arg as an array reference and print as a list of pairs