## Copyright (C) 2021 2021 The Octave Project Developers 
## 
## 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{retval} =} sph_chk (@var{input1}, @var{input2})
##
## @seealso{}
## @end deftypefn

function [E] = sph_chk (spheroid)
  
  if (isempty (spheroid))
    E = wgs84Ellipsoid;
  elseif (isstruct (spheroid))
    if (length(fieldnames (spheroid)) == 12)
      B = wgs84Ellipsoid;
      if isequaln (fieldnames (spheroid), fieldnames (B))
        E = spheroid;
      else
        disp("Expected structure fieldnames:\n") #TODO is there a cleaner method
        fieldnames(B)
        disp("Issues found\n")
        setxor(fieldnames (spheroid), fieldnames (B))
        error("sph_chk:fieldnames of stucture incorrect:\n");
      endif
      
    else
      error("sph_chk: structure does not have enough fields expecting 12")
    endif
    
  elseif (isvector (spheroid) && ! ischar (spheroid))
    if (numel (spheroid) != 2)
      error("sph_chk: 2-element vector expected");
    elseif (spheroid(1) < 1)
      E.Eccentricity = spheroid(1);
      E.SemimajorAxis = spheroid(2);
    elseif (spheroid(2) < 1)
      E.Eccentricity = spheroid(2);
      E.SemimajorAxis = spheroid(1);
    else
      error("geodeticfwd: eccentricity expected to be between 0 and 1");
    endif
  else
    
  endif

endfunction
