## Copyright (C) 2016
##
## 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  {} {@var{ecc} =} flat2ecc (@var{flat}) 
## This will return the eccentricity given a flattening
## From https://en.wikipedia.org/wiki/Flattening
##
## e^2=2f-f^2
##
## where f is the flattening and e is the eccentricity
## earth_flattening=1/298.257=0.0033528
## and earth_eccentricity= 0.081819221456
## Note: the flattening needs to between 0 and 1
##
## @example
## >>ecc=flat2ecc(0.0033528)
## ecc = 0.081819
## @end example
## @seealso{ecc2flat}
## @end deftypefn
function ecc = flat2ecc( flat )
  if ( nargin != 1 )
    print_usage ();
  elseif ( flat > 1 || flat < 0 ) 
    error ("Flattening must be between 0 and 1"); 
  endif
  ecc = sqrt(2 * flat - flat ^ 2); 
endfunction

%!test
%! ecc=flat2ecc(1/298.257)
%! assert(ecc, 0.081819221456, 1e-12)