## Copyright (C) 2017 Carnë Draug <carandraug@octave.org>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn  {Function File} {@var{km} =} earthRadius ()
## @deftypefnx	 {Function File} {@var{km} =} earthRadius("kilometer")
## @deftypefnx	 {Function File} {@var{m} =} earthRadius("m")
## @deftypefnx	 {Function File} {@var{m} =} earthRadius("meter")
## Returns mean radius of earth.
## @end deftypefn

## Author: Mithil Leua <mithilleua@gmail.com>

function R = earthRadius(unit,varargin)
	if (nargin > 1)
		print_usage();
	elseif (nargin == 0)
		R = 6371	
	else
		validinput = validatestring(unit,{"kilometer","km","m","meter"});
		switch(validinput(1))
			case {"k"}
				R = 6371
			case {"m"}
				R = 6371000
		endswitch
	endif
endfunction  
		 
%!assert (earthRadius(),6371)
%!assert (earthRadius("km"),6371)
%!assert (earthRadius("kilometer"),6371)
%!assert (earthRadius("m"),6371000)
%!assert (earthRadius("meter"),6371000)



