1. Incorporated sh/st, (un)set/lockout, forward/opername from Iain G0RDI
[spider.git] / perl / DXUtil.pm
index 605bfca4aa6bf23da413b96a1652bb2e4aeab7ce..9f63c8908234eea858730c314d99493d1d69364a 100644 (file)
@@ -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