using System;

namespace VoServices.Footprint.Web
{
	/// <summary>
	/// Summary description for AstroUtil.
	/// </summary>
	public class AstroUtil
	{
		public AstroUtil()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// Converts ra into decimal degrees.
		/// </summary>
		public static double hms2deg(String s) 
		{	
			string[] a = s.Split(':');
			double v = 15.0 * Convert.ToDouble(a[0]) + Convert.ToDouble(a[1])/ 4.0 + Convert.ToDouble(a[2]) / 240.0;

			return v;
		}

		public static double rastring2deg(string s)
		{
			if (s.IndexOf(":") < 0)
				return double.Parse(s);
			else
				return hms2deg(s);
		}


		/// <summary>
		/// Converts dec into decimal degrees.
		/// </summary>
		public static double dms2deg(String s) 
		{	
			string[] a = s.Split(':');
			double v; 

			if (s.LastIndexOf("-") == 0)
				v = -(-1.0 * Convert.ToDouble(a[0]) + 
					Convert.ToDouble(a[1]) / 60.0   + 
					Convert.ToDouble(a[2]) / 3600.0);
			else
				v = (Convert.ToDouble(a[0])         + 
					Convert.ToDouble(a[1]) / 60.0   + 
					Convert.ToDouble(a[2]) / 3600.0 );
			return v;			
		}

		public static double decstring2deg(string s)
		{
			if (s.IndexOf(":") < 0)
				return double.Parse(s);
			else
				return dms2deg(s);
		}
	}
}
