package Seismic::Station; use strict; use warnings; use Exporter; use constant { Easting => 0, Northing => 1, Other => 2, Elevation => 3 }; our @ISA = qw[ Exporter ]; our @EXPORT = qw[ Easting Northing Other Elevation ]; sub dms2real { my( $degrees, $minutes, $seconds ) = @_; return $degrees + ( $minutes / 60 ) + ( $seconds / 3600 ); } sub new { my( $class, $x, $y, $other, $z ) = @_; my $self = bless [], $class; die "Bad Easting ($x)" unless $x =~ m[^( ([01]\d{2}) ([0-5]\d) ([0-5]\d{2}) ([NS]) )$]x; $self->[ Easting ] = dms2real( $4 eq 'N' ? $2 : - $2, $3, $4 / 10 ); die "Bad Northing ($y)" unless $y =~ m[^( (\d{2}) ([0-5]\d) ([0-5]\d{3}) ([EW]) )$]x; $self->[ Northing ] = dms2real( $4 eq 'E' ? $2 : -$2, $3, $4 / 100 ); die "Bad other ($other)" unless $other =~ m[^\d{15}$]x; $self->[ Other ] = 0 + $other; die "Bad Elevation ($z)" unless $z =~ m[^( [ 0-9]{3}\d )$]x; $self->[ Elevation ] = 0 + $1; return $self; } 1;