#!/usr/bin/perl

use strict;
use warnings;

my @j2w = ([qw(-0.000083043 -0.000046038 0.010040 )],
           [qw( 0.000017464 -0.00010695  0.0046017)]);
my @w2j = ([qw( 0.000083049 0.000046047 -0.010041 )],
           [qw(-0.000017467 0.00010696  -0.0046020)]);

@ARGV == 2 or usage();

my $lng = toDec('E', $ARGV[0]);
my $lat = toDec('N', $ARGV[1]);

my $tLng = $lng + $j2w[0][0] * $lng + $j2w[0][1] * $lat + $j2w[0][2];
my $tLat = $lat + $j2w[1][0] * $lng + $j2w[1][1] * $lat + $j2w[1][2];

print sprintf("x%.5fy%.5f\n", $tLng, $tLat);

exit;

sub usage {
  die "Usage: gcstrans E... N...\n";
}

sub toDec {
  my ($fst, $str) = @_;
  substr($str, 0, 1) eq $fst or usage();
  my $rest = substr($str, 1);
  my ($x0, $x1, $x2) = $rest =~ /^(\d+)\.(\d+)\.(\d+(?:\.\d*)?)\s*$/;
  defined($x2) or usage();
  return  (($x2 / 60) + $x1) / 60 + $x0;
}
