File: sph_chk.m

package info (click to toggle)
octave-mapping 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,132 kB
  • sloc: objc: 1,860; python: 438; cpp: 219; makefile: 87; xml: 37; sh: 4
file content (73 lines) | stat: -rw-r--r-- 2,681 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## Copyright (C) 2021-2022 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{ref_ell} =} sph_chk (@var{spheroid})
## @deftypefnx {} {@var{ref_ell} =} sph_chk (@var{spheroid}, @var{req_fields})
## Check validity of iput ellipsoids / spheroids.
##
## Inputs:
## @itemize
## @item
## @var{spheroid}: input ellipsoid or spheroid.  Can be an ellipsoid or
## spheroid name, or ditto code (character string or scalar numeric value), or
## a numeric 2-element vector containing  SemimajorAxis and Eccentricity
## values, or an ellipsoid / spheroid struct.  If omitted a WGS84 ellipsoid
## struct is returned.
##
## @item
## @var{req_fields}: cellstr array of required fields of input ellipsoid /
## spheroid struct; only used/useful when an ellipsoid / spheroid struct
## value is given.  The default required fields are "SemimajorAxis",
## "Flattening" and "LengthUnit". @*
## Note: the validity of the fields input this way isn't checked!
## @end itemize
##
## Output: @*
## Ellipsoid / spheroid struct.
##
## @seealso{}
## @end deftypefn

function [E] = sph_chk (spheroid, req_flds = {"SemimajorAxis", "Flattening", "LengthUnit"})

  if (isempty (spheroid))
    E = wgs84Ellipsoid;
  elseif (isstruct (spheroid))
    E = spheroid;
    ## Check fields
    flds = isfield (E, req_flds);
    if (! all (flds))
      error ("Vital fields missing from ellipsoid: %s", ...
             sprintf ("%s  ", req_flds(! flds)));
    endif
  elseif (isnumeric (spheroid) && isreal (spheroid) && isvector (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("sph_chk: eccentricity expected to be between 0 and 1");
    endif
  elseif (ischar (spheroid) || isnumeric (spheroid) && isscalar (spheroid))
    E = referenceEllipsoid (spheroid);
  endif

endfunction