## Copyright (C) 2017
##
## 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{ecc} =} flat2ecc (@var{flat}) 
## This will return the eccentricity given a flattening
##
## @example
## >>f_earth = 0.0033528
## >>flat2ecc ( f_earth )
## ans =   0.081819
## @end example
##
## Also can do a vector
## @example
## >>flat = 0:.01:.05;
## >>flat2ecc ( flat )
## ans =
##
##          0     0.14107       0.199      0.2431        0.28     0.31225
## @end example
##
## @seealso{ecc2flat}
## @end deftypefn
function e = flat2ecc(f)
  if nargin < 1
    print_usage ();
  endif
  if ( ischar ( f ) )
      error ('Cannot be a string');
  else
  e = sqrt(2 * f - f.^ 2);
  endif
endfunction

%! test
%! flat = 0.00335281317793612; 
%! f_vec = 0:.01:.05;
%! assert ( flat2ecc ( flat ),0.0818192214560008,10^-12 )
%! assert ( flat2ecc ( f_vec ) , [ 0 , .141067 , .198997 , .2431049 , .28 , .31225 ] , 10^-6)
