## Copyright (C) 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 . ## -*- texinfo -*- ## @deftypefn {} {@var{retval} =} __sph_chk__ (@var{input1}, @var{input2}) ## Internal auxiliary function for checking ellipsoid input. ## ## @seealso{} ## @end deftypefn function [E] = __ell_chk__ (ellipsoid) ## Elipsoid field names ## FIXME Are all these 12 really required or only "defining properties"? elflds = {"Name", "LengthUnit", "Code", "SemimajorAxis", "SemiminorAxis", ... "InverseFlattening", "Flattening", "Eccentricity", ... "ThirdFlattening", "MeanRadius", "SurfaceArea", "Volume"}'; if (isempty (ellipsoid)) E = wgs84Ellipsoid; elseif (isstruct (ellipsoid)) fldn = fieldnames (ellipsoid); ## Check for required fieldnames & get positions in struct [id, idf] = ismember (lower (elflds), lower (fldn)); ## Class of fields as cell array, assuming struct2cell preserves field order clss = struct2cell (structfun ("class", ellipsoid, "uniformoutput", 0)); if (all (id)) ## All required fields present, check types, first of the two char fields chfl = ismember (clss(idf(1:2)), "char"); if (! all (chfl)) error ("Char values expected for ellipsoid field(s):\n%s", ... strjoin (fldn(idf(1:2)(! chfl)), ", ")); else ellipsoid.LengthUnit = validateLengthUnit (ellipsoid.LengthUnit); endif ## Next, check numeric fields nmfl = ismember (clss(idf(3:end)), "double"); if (! all (nmfl)) error ("Numeric scalar values expected for ellipoid field(s):\n%s", ... strjoin (fldn (idf(3:end)(! nmfl)), ", ")); ## ?FIXME? Value / range checks here? endif E = ellipsoid; else error ("Ellipsoid field names missing:\n%s", strjoin (elflds (! id), ", ")); endif elseif (isvector (ellipsoid) && ! ischar (ellipsoid)) if (numel (ellipsoid) != 2) error ("__ell_chk__: 2-element vector expected"); elseif (ellipsoid(1) < 1) E.Eccentricity = ellipsoid(1); E.SemimajorAxis = ellipsoid(2); elseif (ellipsoid(2) < 1) E.Eccentricity = ellipsoid(2); E.SemimajorAxis = ellipsoid(1); else error ("Ellipsoid eccentricity expected to be between 0 and 1"); endif else endif endfunction