#!/usr/bin/perl
#******************************************************************************
#  Copyright (C) 2000 ImageLinks Inc.
# 
# License:  LGPL
# 
# See LICENSE.txt file in the top level directory for more details.
# 
#  Author:  David Burken
#
# DESCRIPTION:
#     This script is used to convert degrees, minutes seconds (DMS) 
#     to decimal degrees.
#
#******************************************************************************
# $Id: dms2deg 6825 2004-09-30 15:13:58Z dburken $

print ("\nEnter \"q\" to quit.\n\n");

while (1)
{
   &getDegrees;

   &getMinutes;

   &getSeconds;

   # Compute the answer.
   $decdegrees = $deg + ($min/60) + ($sec/3600);

   if ($negativeHemisphere)
   {
      $decdegrees = $decdegrees * -1.0;
   }

   print ("Decimal degrees = $decdegrees \n\n");
}

# Get degrees
sub getDegrees
{
   {
      print ("Enter degrees:  ");
      $deg = <STDIN>;
      chop ($deg);

      if ($deg =~ /q/i)
      {
	  exit(0);
      }
   
      # Check for negative.  Some users will use negative to indicate 
      # hemisphere.

      $negativeHemisphere = 0;
      if ($deg < 0)
      { 
         $negativeHemisphere = 1;
         $deg = abs ($deg);
      }

      # Check the range.
      if ($deg > 179)
      {
         die ("Degrees must be 179 or less.  Exiting\n");
      }
   }
}

# Get minutes
sub getMinutes
{
   {
      print ("Enter minutes:  ");
      $min = <STDIN>;
      chop ($min);

      if ($min =~ /q/i)
      {
	  exit(0);
      }

      $min = abs ($min);

      # Check the range.
      if ($min > 60)
      {
         die ("Minutes must be 60 or less.  Exiting\n");
      }

   }
}

# Get seconds
sub getSeconds
{
   {
      print ("Enter seconds:  ");
      $sec = <STDIN>;
      chop ($sec);

      if ($sec =~ /q/i)
      {
	  exit(0);
      }

      $sec = abs ($sec);

      # Check the range.
      if ($sec > 60)
      {
         die ("Seconds must be 60 or less.  Exiting\n");
      }

   }
}



