Changeset 27627


Ignore:
Timestamp:
03/01/23 12:03:43 (2 years ago)
Author:
Mathieu Morlighem
Message:

CHG: latest version

Location:
issm/trunk-jpl/src/m/coordsystems
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/coordsystems/ll2utm.m

    r18478 r27627  
    1818%       meters) and F is flattening of the user-defined ellipsoid.
    1919%
    20 %       LL2UTM(...,ZONE) forces the UTM ZONE (scalar integer) instead of
    21 %       automatic set.
     20%       LL2UTM(...,ZONE) forces the UTM ZONE (scalar integer or same size as
     21%   LAT and LON) instead of automatic set.
    2222%
    2323%       [X,Y,ZONE]=LL2UTM(...) returns also the computed UTM ZONE (negative
     
    3737%                  Notes Techniques NT/G 76, janvier 1995.
    3838%
    39 %       Acknowledgments: Mathieu.
     39%       Acknowledgments: Mathieu, Frederic Christen.
    4040%
    4141%
    4242%       Author: Francois Beauducel, <beauducel@ipgp.fr>
    4343%       Created: 2003-12-02
    44 %       Updated: 2014-08-24
    45 
    46 
    47 %       Copyright (c) 2001-2014, François Beauducel, covered by BSD License.
     44%       Updated: 2019-05-29
     45
     46
     47%       Copyright (c) 2001-2019, François Beauducel, covered by BSD License.
    4848%       All rights reserved.
    4949%
     
    9393end
    9494
    95 if isnumeric(varargin{1}) & size(varargin{1},2) == 2
     95if nargin > 1 && isnumeric(varargin{1}) && isnumeric(varargin{2}) ...
     96                && (all(size(varargin{1})==size(varargin{2})) ...
     97                || isscalar(varargin(1)) || isscalar(varargin{2}))
     98        lat = varargin{1};
     99        lon = varargin{2};
     100        v = 2;
     101elseif isnumeric(varargin{1}) && size(varargin{1},2) == 2
    96102        lat = varargin{1}(:,1);
    97103        lon = varargin{1}(:,2);
    98104        v = 1;
    99 elseif nargin > 1 & isnumeric(varargin{2})
    100         lat = varargin{1};
    101         lon = varargin{2};
    102         v = 2;
    103105else
    104106        error('Single input argument must be a 2-column matrix [LAT,LON].')
     
    109111end
    110112
     113if any(abs(lat)>90)
     114        error('LAT absolute values must be lower than 90.')
     115end
     116
     117% checks for DATUM and/or ZONE syntax
     118% NOTE: the following strategy works in any case except if ZONE argument
     119% has a size of 1x2 (in that case it will be interpreted as a DATUM). To
     120% force the ZONE syntax with 2 elements, just use ZONE(:) to make a colum
     121% vector of 2x1.
    111122for n = (v+1):nargin
    112123        % LL2UTM(...,DATUM)
    113         if ischar(varargin{n}) | (isnumeric(varargin{n}) & numel(varargin{n})==2)
     124        if ischar(varargin{n}) || (isnumeric(varargin{n}) ...
     125                        && all(size(varargin{n})==[1,2]))
    114126                datum = varargin{n};
    115127        % LL2UTM(...,ZONE)
    116         elseif isnumeric(varargin{n}) & isscalar(varargin{n})
    117                         zone = round(varargin{n});
     128        elseif isnumeric(varargin{n}) && (isscalar(varargin{n}) ...
     129                        || (isscalar(lat) || all(size(varargin{n})==size(lat))) ...
     130                        && (isscalar(lon) || all(size(varargin{n})==size(lon))))
     131                zone = round(varargin{n});
    118132        else
    119133                error('Unknown argument #%d. See documentation.',n)
     
    142156        F0 = round((l1*D0 + 183)/6);
    143157else
    144         F0 = zone;
     158        F0 = abs(zone);
    145159end
    146160
     
    148162E1 = sqrt((A1*A1 - B1*B1)/(A1*A1));
    149163P0 = 0/D0;
    150 L0 = (6*F0 - 183)/D0;           % UTM origin longitude (rad)
     164L0 = (6*F0 - 183)/D0;   % UTM origin longitude (rad)
    151165Y0 = 1e7*(p1 < 0);              % UTM false northern (m)
    152166N = K0*A1;
     
    166180% same size as x/y in case of crossed zones
    167181if nargout > 2
    168         fu = unique(F0.*sign(lat));
     182        f = F0.*sign(lat);
     183        fu = unique(f);
    169184        if isscalar(fu)
    170185                f = fu;
    171         else
    172                 f = F0;
    173186        end
    174187end
  • TabularUnified issm/trunk-jpl/src/m/coordsystems/utm2ll.m

    r18478 r27627  
    55%       (in degrees). Default datum is WGS84.
    66%
    7 %       X and Y can be scalars, vectors or matrix. Outputs LAT and LON will
     7%       X, Y and F can be scalars, vectors or matrix. Outputs LAT and LON will
    88%       have the same size as inputs.
    99%
     
    3232%       Author: Francois Beauducel, <beauducel@ipgp.fr>
    3333%       Created: 2001-08-23
    34 %       Updated: 2014-04-20
    35 
    36 
    37 %       Copyright (c) 2001-2014, François Beauducel, covered by BSD License.
     34%       Updated: 2019-05-29
     35
     36%       Revision history:
     37%
     38%       [2019-05-29]
     39%         - fix an issue when X or Y are matrices.
     40
     41%       Copyright (c) 2001-2019, François Beauducel, covered by BSD License.
    3842%       All rights reserved.
    3943%
     
    7478end
    7579
    76 if all([numel(x),numel(y)] > 1) && any(size(x) ~= size(y))
    77         error('X and Y must be the same size or scalars.')
    78 end
    79 
    80 if ~isnumeric(f) || ~isscalar(f) || f ~= round(f)
    81         error('ZONE must be a scalar integer.')
     80% checks if input arguments have compatible sizes using unique(complex)
     81sz = [size(x);size(y);size(f)];
     82sz = complex(sz(:,1),sz(:,2));
     83if length(unique(sz(sz~=complex(1,1)))) > 1
     84        error('X, Y and ZONE must be scalar or vector/matrix of the same size.')
     85end
     86
     87if ~isnumeric(f) || any(f ~= round(f))
     88        error('ZONE must be integer value.')
    8289end
    8390
     
    101108end
    102109
     110% calculations are made on column vectors
     111x = x(:);
     112y = y(:);
     113f = f(:);
     114
    103115% constants
    104116D0 = 180/pi;    % conversion rad to deg
     
    133145p0 = NaN;
    134146n = 0;
    135 while any(isnan(p0) | abs(p - p0) > eps) & n < maxiter
     147while any(isnan(p0) | abs(p - p0) > eps) && n < maxiter
    136148        p0 = p;
    137149        es = E1*sin(p0);
     
    141153
    142154if nargout < 2
    143         lat = D0*[p(:),l(:)];
     155        lat = D0*[p,l];
    144156else
    145         lat = p*D0;
    146         lon = l*D0;
     157        % reshapes vectors to x/y/f original size
     158        sz = max([size(x);size(y);size(f)]);
     159        lat = reshape(p*D0,sz);
     160        lon = reshape(l*D0,sz);
    147161end
    148162
Note: See TracChangeset for help on using the changeset viewer.