diff -r 037b67701b72 INDEX
--- a/INDEX	Sat Feb 22 23:43:33 2014 +0100
+++ b/INDEX	Wed Mar 05 05:41:20 2014 -0800
@@ -28,3 +28,26 @@
  extractfield
  removeExtraNanSeparators
  validateLengthUnit
+Geodesy
+ aer2ecef
+ aer2enu
+ aer2geodetic
+ aer2ned
+ ecef2aer
+ ecef2enu
+ ecef2enuv
+ ecef2geodetic
+ ecef2ned
+ ecef2nedv
+ enu2aer
+ enu2ecef
+ enu2ecefv
+ enu2geodetic
+ geodetic2aer
+ geodetic2ecef
+ geodetic2enu
+ geodetic2ned
+ ned2aer
+ ned2ecef
+ ned2ecefv
+ ned2geodetic
diff -r 037b67701b72 inst/aer2ecef.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/aer2ecef.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,45 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+
+function [x,y,z] = aer2ecef(az,elev,slantRange,lat0,lon0,h0,spheroid,angleut)
+%AER2ECEF converts Local spherical AER to geocentric ECEF
+%Checking if in Degrees or Radians
+if nargin<8
+    angleut = 'degree';
+end
+% Origin of the local system in geocentric coordinates.
+[x0,y0,z0] = geodetic2ecef(lat0,lon0,h0,spheroid,angleut);
+% Convert Local Spherical AER to ENU
+[xEast, yNorth, zUp] = aer2enu(az, elev, slantRange,angleut);
+% Rotating ENU to ECEF
+[dx, dy, dz] = enu2ecefv(xEast, yNorth, zUp, lat0, lon0,angleut);
+% Origin + offset from origin equals position in ECEF
+x = x0+dx;
+y = y0+dy;
+z = z0+dz;
+end
\ No newline at end of file
diff -r 037b67701b72 inst/aer2enu.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/aer2enu.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,46 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [xEast,yNorth,zUp] = aer2enu(az,elev,slantRange,angleut)
+%AER2ENU
+%Checking if input is in degree or radian
+    if nargin < 4 || strcmpi(angleut,'degree')
+    sinfun = @sind;
+    cosfun = @cosd;
+    elseif strcmpi(angleut,'radian')
+    sinfun = @sin;
+    cosfun = @cos;
+    else
+        disperror('Unknown: %s input argument for unit',angleut);
+    end
+%Calculation of AER2ENU
+zUp = slantRange .* sinfun(elev);
+r   = slantRange .* cosfun(elev);
+xEast  = r .* sinfun(az);
+yNorth = r .* cosfun(az);
+
+end
\ No newline at end of file
diff -r 037b67701b72 inst/aer2geodetic.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/aer2geodetic.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,38 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [lat1,lon1,h1] = aer2geodetic(az,elev,slantRange,lat0,lon0,h0,spheroid,angleut)
+%AER2GEODETIC
+%Convert AER2ECEF
+if nargin<8
+    angleut = 'degree';
+end
+[x,y,z] = aer2ecef(az,elev,slantRange,lat0,lon0,h0,spheroid,angleut);
+%Convert ECEF2GEODETIC
+[lat1,lon1,h1] = ecef2geodetic(x,y,z,spheroid,angleut);
+
+end
\ No newline at end of file
diff -r 037b67701b72 inst/aer2ned.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/aer2ned.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,35 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [xNorth,yEast,zDown] = aer2ned(az,elev,slantRange,angleut)
+%AER2NED Local spherical AER to Cartesian NED
+if nargin<4
+    angleut = 'degree';
+end
+[xNorth,yEast,zUp] = aer2enu(az,elev,slantRange,angleut);
+zDown = -zUp;
+end
\ No newline at end of file
diff -r 037b67701b72 inst/ecef2aer.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ecef2aer.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,35 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [az,elev,slantRange] = ecef2aer(x, y, z, lat0, lon0, h0, spheroid, angleut)
+
+if nargin<8
+    angleut = 'degree';
+end
+[xEast, yNorth, zUp] = ecef2enu(x, y, z, lat0, lon0, h0, spheroid,angleut);
+[az,elev,slantRange] = enu2aer(xEast, yNorth, zUp,angleut);
+end
diff -r 037b67701b72 inst/ecef2enu.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ecef2enu.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,34 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [xEast,yNorth,zUp] = ecef2enu(x, y, z, lat0, lon0, h0, spheroid, angleut)
+if nargin<8
+    angleut = 'degree';
+end
+[x0,y0,z0] = geodetic2ecef(lat0, lon0, h0,spheroid, angleut);
+[xEast, yNorth, zUp] = ecef2enuv(x - x0, y - y0, z - z0, lat0, lon0,angleut);
+end
\ No newline at end of file
diff -r 037b67701b72 inst/ecef2enuv.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ecef2enuv.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,47 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [uEast, vNorth, wUp] = ecef2enuv(u, v, w, lat0, lon0, angleut)
+
+    if nargin<6 || strcmpi(angleut,'degree')
+    sinfun = @sind;
+    cosfun = @cosd;
+    elseif strcmpi(angleut,'radian')
+    sinfun = @sin;
+    cosfun = @cos;
+    else
+    disperror('Unknown: %s input argument for units',angleut);
+    end
+
+t     =  cosfun(lon0) .* u + sinfun(lon0) .* v;
+uEast = -sinfun(lon0) .* u + cosfun(lon0) .* v;
+
+wUp    =  cosfun(lat0) .* t + sinfun(lat0) .* w;
+vNorth = -sinfun(lat0) .* t + cosfun(lat0) .* w;
+
+
+end
\ No newline at end of file
diff -r 037b67701b72 inst/ecef2geodetic.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ecef2geodetic.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,324 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function coord_geod = ecef2geodetic(x0,y0,z0,ellipsoid,method)
+%ECEF2GEODETIC: Adds an additional method parameter that is not present in
+%matlab
+    coord_cart = [x0,y0,z0];
+    if (nargin < 4) || isempty(ellipsoid),  ell = get_ellipsoid();  
+    elseif (istruct(ellipsoid)~= 1), ell = get_ellipsoid(ellipsoid); end
+    if (nargin < 5)
+        method = 'vec';
+%       method = 'jones';
+    end
+    method = lower(method);
+    if ~any(strcmp(method(1), {'c','j','v'}))
+        error ('Method "%s" unknown.', method);
+    end
+
+    if isstruct(ell) && ~isfield(ell, 'f')
+        ell.f = 1 - sqrt(1 - ell.e^2);
+    end
+    
+    if isempty(coord_cart)
+        coord_geod = zeros(size(coord_cart));
+        %coord_geod = [];  % WRONG!
+        return;
+    end
+    
+    num_pts = size(coord_cart, 1);
+    coord_geod = zeros(size(coord_cart));
+    
+    if (method(1) == 'v')  % jones vectorized
+        x = coord_cart(:, 1);
+        y = coord_cart(:, 2);
+        z = coord_cart(:, 3);
+        [lat, lon, h] = convert_to_geodetic_jones_vec (x, y, z, ell);
+        coord_geod = [lat*180/pi, lon*180/pi, h];
+        return;
+    end
+        
+    for i = 1:num_pts
+        x = coord_cart(i, 1);
+        y = coord_cart(i, 2);
+        z = coord_cart(i, 3);
+       
+        switch method(1)
+        case 'c'
+            [lat, lon, h] = convert_to_geodetic_classical (x, y, z, ell);
+        case 'j' 
+            [lat, lon, h] = convert_to_geodetic_jones (x, y, z, ell);
+        end
+
+        coord_geod(i, :) = [lat*180/pi lon*180/pi h];
+    end
+    
+return;
+
+
+end
+
+function [lat, lon, h] = ...
+convert_to_geodetic_classical (x, y, z, ellips)
+ 
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    % Tolerances for steps in the 
+    % iterative solution of lat and h.
+    % Note that the tolerance (as used in this function) 
+    % does not guarantee an error with similar magnitude.
+    
+    tol_lat = eps;
+    tol_h   = eps/ellips.a;
+    % eps is a system variable. It is the 
+    % largest relative spacing between any two 
+    % adjacent numbers in the machine's
+    % floating point system. 
+    % E.g., on a Celeron PC, eps = 2.2204e-16
+
+    
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    % Shortcuts.
+    b = ellips.b;
+    e = ellips.e;
+    
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    % Compute lat and h
+    
+    % latitudinal radius
+    p = sqrt(x^2 + y^2);
+
+    if (p == 0)  
+        % special case: point on either pole.
+        
+        if (z > 0)
+            lat = +pi/2;
+        elseif (z < 0)
+            lat = -pi/2;
+        elseif (z == 0)
+            lat = 0;
+        end
+        h = abs(z) - b;
+    else  
+        % general case: solve lat and h by an iterative procedure. 
+        
+        % initial approximations
+        h   = 0;
+        lat = 0;
+        N   = compute_prime_vertical_radius (lat * 180/pi, ellips);
+        
+        lat_0 = lat + 2*tol_lat; 
+        h_0	  = h + 2*tol_h; 
+
+        i = 0;
+        while ( abs(lat - lat_0) > tol_lat || abs(h - h_0) > tol_h )
+            lat_0 = lat;
+            h_0   = h;
+
+            lat = atan2( (z / p), (1 - e^2 * N / (N + h)) );
+            N = compute_prime_vertical_radius (lat * 180/pi, ellips);
+            h = p / cos(lat) - N;
+
+            i = i + 1;
+        end
+        %display(i)  % DEBUG
+    end 
+
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    % Compute lon
+    lon = atan2(y, x);
+    
+return;  % end of function
+end
+
+% The code below was given by G. C. Jones at the end of the 
+% following paper:
+% G. C. Jones, New solutions for the geodetic coordinate transformation,
+% Journal of Geodesy, Volume 76, Issue 8, Nov 2002, Pages 437 - 446
+% <http://springerlink.metapress.com/openurl.asp?genre=article&id=doi:10.1007/s00190-002-0267-4>
+%
+% I had problems copying and pasting the source code from the PDF file,
+% so I had to replace several characters that were wrongly copied.
+%
+% I left the code as intact as I could. E.g., when I had to modify something,
+% I kept the original lines as comment lines, instead of removing or changing
+% them.
+
+function [phi, lambda, h] = convert_to_geodetic_jones(x, y, z, ell)
+%function jones(x, y, z)
+%JONES Transformation of Cartesian coordinates (x,y,z)
+% to geodetic coordinates (phi,lambda,h). This works
+% for any (x,y,z), any a > 0 and any 0 < flat < 1
+    a = ell.a;
+    flat = ell.f;
+%    a = 6378137;
+%    flatinv = 298.257223563;
+%    flat = 1/flatinv; %the flattening. (1 - e^2) = (1 - flat)^2
+
+    rhostar = a*flat*(2 - flat); %rightmost point of evolute
+    rho = sqrt(x^2 + y^2);
+    if z<0, z = -z; southern = 1; else southern = 0; end
+    if z > 0
+        if rho > 0
+            lambda = atan2(y,x);
+            if rho^2 + z^2/(1 - flat)^2 >= a^2 %Region 1
+                t = atan(z/(rho*(1 - flat)));
+            elseif rho <= rhostar + z/(1 - flat) %Region 2
+                t = atan((z*(1 - flat) + rhostar)/rho);
+            else %Region 3
+                t = atan(z*(1 - flat)/(rho - rhostar));
+            end
+            t_old = t + .1;
+            while abs(t_old - t) > eps
+                A = ((1 - flat)*z + rhostar*sin(t))/rho;
+                f = atan (A);
+                fprime = rhostar*cos(t)/(rho*(1 + A^2));
+                t_old = t;
+                t = t - (f - t)/(fprime - 1);
+            end
+            phi = atan(tan(t)/(1 - flat));
+        else phi = pi/2; h = z - a*(1 - flat); lambda = 0;
+        end
+    else %z = 0
+        phi = 0; h = rho - a;
+        if rho > 0, lambda = atan2(y,x); else lambda = 0; end
+    end
+    h = rho*cos(phi) + z*sin(phi) - a*sqrt(1 - flat*(2 - flat)*(sin(phi))^2);
+    if southern == 1, phi = -phi; end
+%    if lambda < 0, lambda = lambda + 2*pi; end
+
+%    fprintf('\n Latitude: %1.15f',phi)
+%    fprintf('\n Height: %7.10f',h)
+%    fprintf('\n Longitude: %1.15f \n',lambda) 
+%%%%%%%%%%%%% end jones.m %%%%%%%%%%%%%
+
+    %'hw' % debug
+    idx = isnan(x) | isnan(y) | isnan(z);
+    if any(idx)
+        phi(idx) = NaN;
+        lambda(idx) = NaN;
+        h(idx) = NaN;
+    end
+return;
+end
+% Vectorized version of Jones.
+function [phi, lambda, h] = convert_to_geodetic_jones_vec(x, y, z, ell)
+%function jones(x, y, z)
+%JONES Transformation of Cartesian coordinates (x,y,z)
+% to geodetic coordinates (phi,lambda,h). This works
+% for any (x,y,z), any a > 0 and any 0 < flat < 1
+    a = ell.a;
+    flat = ell.f;
+%    a = 6378137;
+%    flatinv = 298.257223563;
+%    flat = 1/flatinv; %the flattening. (1 - e^2) = (1 - flat)^2
+
+    phi = zeros (size(x));
+    lambda = zeros (size(x));
+    h = zeros (size(x));
+
+    rhostar = a*flat*(2 - flat); %rightmost point of evolute
+    rho = sqrt(x.^2 + y.^2);
+    southern = (z<0); z(southern) = -z(southern);    
+%    if z<0, z = -z; southern = 1; else southern = 0; end
+    idx_z_gt_0 = (z > 0);
+    idx_rho_gt_0 = (rho > 0);
+%    if z > 0
+%        if rho > 0
+            lambda = atan2(y,x);
+            idx_reg_1 = ( (rho.^2 + z.^2./(1 - flat)^2) >= a^2 ); %Region 1
+            idx = zeros(size(x));
+            t = zeros (size(x));
+%            if rho^2 + z^2/(1 - flat)^2 >= a^2 %Region 1
+                idx = (idx_z_gt_0 & idx_rho_gt_0 & idx_reg_1);
+                t (idx) = atan(z(idx)./(rho(idx).*(1 - flat)));
+%                t = atan(z/(rho*(1 - flat)));
+            idx_reg_2 = ( rho <= (rhostar + z./(1 - flat)) ); %Region 2
+%            elseif rho <= rhostar + z/(1 - flat) %Region 2
+                idx = (idx_z_gt_0 & idx_rho_gt_0 & idx_reg_2);
+                t (idx) = atan((z(idx).*(1 - flat) + rhostar)./rho(idx));
+%                t = atan((z*(1 - flat) + rhostar)/rho);
+            idx_reg_3 = ~ (idx_reg_1 | idx_reg_2);
+%            else %Region 3
+                idx = (idx_z_gt_0 & idx_rho_gt_0 & idx_reg_3);
+                t (idx) = atan(z(idx).*(1 - flat)./(rho(idx) - rhostar));
+%                t = atan(z*(1 - flat)/(rho - rhostar));
+%            end
+            t_old = t + .1;
+            idx = (idx_z_gt_0 & idx_rho_gt_0 & (abs(t_old - t) > eps));
+            A = zeros (size(x));
+            f = zeros (size(x));
+            fprime = zeros (size(x));
+            while any(idx)
+%            while abs(t_old - t) > eps
+                A = ((1 - flat).*z + rhostar.*sin(t))./rho;
+%                A = ((1 - flat)*z + rhostar*sin(t))/rho;
+                f = atan (A);
+                fprime = rhostar.*cos(t)./(rho.*(1 + A.^2));
+%                fprime = rhostar*cos(t)/(rho*(1 + A^2));
+                t_old = t;
+                t(idx) = t(idx) - (f(idx) - t(idx))./(fprime(idx) - 1);
+%                t = t - (f - t)/(fprime - 1);
+                idx = (idx_z_gt_0 & idx_rho_gt_0 & (abs(t_old - t) > eps));
+            end
+            phi = zeros(size(x));
+            idx = (idx_z_gt_0 & idx_rho_gt_0);
+            phi(idx) = atan(tan(t(idx))./(1 - flat));
+%            phi = atan(tan(t)/(1 - flat));
+%        else phi = pi/2; h = z - a*(1 - flat); lambda = 0;
+            idx = (idx_z_gt_0 & ~idx_rho_gt_0);
+            phi(idx) = pi/2; h(idx) = z(idx) - a*(1 - flat); lambda(idx) = 0;
+%        end
+    idx = ~idx_z_gt_0;
+%    else %z = 0
+        phi(idx) = 0; h(idx) = rho(idx) - a;
+%        phi = 0; h = rho - a;
+        idx = (~idx_z_gt_0 & idx_rho_gt_0);
+        lambda(idx) = atan2(y(idx),x(idx));
+        idx = (~idx_z_gt_0 & ~idx_rho_gt_0);
+        lambda(idx) = 0;
+%        if rho > 0, lambda = atan2(y,x); else lambda = 0; end
+%    end
+    h = rho.*cos(phi) + z.*sin(phi) - a.*sqrt(1 - flat.*(2 - flat).*(sin(phi)).^2);
+%    h = rho*cos(phi) + z*sin(phi) - a*sqrt(1 - flat*(2 - flat)*(sin(phi))^2);
+    phi(southern) = -phi(southern);
+%    if southern == 1, phi = -phi; end
+%    if lambda < 0, lambda = lambda + 2*pi; end
+
+%    fprintf('\n Latitude: %1.15f',phi)
+%    fprintf('\n Height: %7.10f',h)
+%    fprintf('\n Longitude: %1.15f \n',lambda) 
+%%%%%%%%%%%%% end jones.m %%%%%%%%%%%%%
+
+    %'hw' % debug
+    idx = isnan(x) | isnan(y) | isnan(z);
+    if any(idx)
+        phi(idx) = NaN;
+        lambda(idx) = NaN;
+        h(idx) = NaN;
+    end
+return;
+end
\ No newline at end of file
diff -r 037b67701b72 inst/ecef2ned.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ecef2ned.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,35 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [xNorth, yEast, zDown] = ecef2ned(x, y, z, lat0, lon0, h0, spheroid, angleut)
+if nargin<8
+    angleut = 'degree';
+end
+[yEast, xNorth, zUp] = ecef2enu(x, y, z, lat0, lon0, h0, spheroid, angleut);
+zDown = -zUp;
+
+end
\ No newline at end of file
diff -r 037b67701b72 inst/ecef2nedv.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ecef2nedv.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,36 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [xEast, yNorth, zDown] = ecef2nedv(x, y, z, lat0, lon0,angleut)
+if nargin<6
+    angleut = 'degree';
+end
+[xEast, yNorth, zUp] = ecef2enuv(x, y, z, lat0, lon0,angleut);
+
+zDown = -zUp;
+
+end
\ No newline at end of file
diff -r 037b67701b72 inst/enu2aer.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/enu2aer.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,43 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [az, elev, slantRange] = enu2aer(xEast, yNorth, zUp, angleut)
+
+if nargin < 4 || strcmpi(angleut,'degree')
+    atan2fun = @atan2d;
+elseif strcmpi(angleut,'radian')
+    atan2fun = @atan2;
+else
+    disperror('Unknown: %s input argument for unit',angleut)
+end
+
+r = sqrt(xEast.^2 + yNorth.^2);
+slantRange = sqrt(r.^2 + zUp.^2);
+elev = atan2fun(zUp,r);
+az = mod(atan2fun(xEast,yNorth),2*atan2fun(0,-1));
+
+end
\ No newline at end of file
diff -r 037b67701b72 inst/enu2ecef.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/enu2ecef.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,40 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [x, y, z] = enu2ecef(xEast, yNorth, zUp, lat0, lon0, h0, spheroid, angleut)
+
+if nargin<8
+    angleut = 'degree';
+end
+
+
+[x0, y0, z0] = geodetic2ecef(lat0, lon0, h0,spheroid, angleut);
+[dx, dy, dz] = enu2ecefv(xEast, yNorth, zUp, lat0, lon0,angleut);
+x = x0 + dx;
+y = y0 + dy;
+z = z0 + dz;
+end
\ No newline at end of file
diff -r 037b67701b72 inst/enu2ecefv.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/enu2ecefv.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,45 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [u, v, w] = enu2ecefv(uEast, vNorth, wUp, lat0, lon0, angleut)
+
+    if nargin<6 || strcmpi(angleut,'degree')
+    sinfun = @sind;
+    cosfun = @cosd;
+    elseif strcmpi(angleut,'radian')
+    sinfun = @sin;
+    cosfun = @cos;
+    else
+    disperror('Unknown: %s input argument for units',angleut);
+    end
+
+t = cosfun(lat0) .* wUp - sinfun(lat0) .* vNorth;
+w = sinfun(lat0) .* wUp + cosfun(lat0) .* vNorth;
+
+u = cosfun(lon0) .* t - sinfun(lon0) .* uEast;
+v = sinfun(lon0) .* t + cosfun(lon0) .* uEast;
+end
\ No newline at end of file
diff -r 037b67701b72 inst/enu2geodetic.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/enu2geodetic.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,35 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [lat, lon, h] = enu2geodetic(xEast, yNorth, zUp, lat0, lon0, h0, spheroid, angleut)
+if nargin<8
+    angleut = 'degree';
+end
+[x, y, z] = enu2ecef(xEast, yNorth, zUp, lat0, lon0, h0, spheroid, angleut);
+[lat, lon, h] = ecef2geodetic(x, y, z,spheroid,angleut);
+
+end
\ No newline at end of file
diff -r 037b67701b72 inst/geodetic2aer.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/geodetic2aer.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,35 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [az, elev, slantRange] = geodetic2aer(lat, lon, h, lat0, lon0, h0, spheroid, angleut)
+if nargin<8
+    angleut = 'degree';
+end
+[xEast, yNorth, zUp] = geodetic2enu(lat, lon, h, lat0, lon0, h0, spheroid,angleut );
+[az, elev, slantRange] = enu2aer(xEast, yNorth, zUp,angleut);
+end
+
diff -r 037b67701b72 inst/geodetic2ecef.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/geodetic2ecef.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,204 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function coord_cart = geodetic2ecef (phi,lambda,h, ellipsoid,angleut)
+%CONVERT_TO_CARTESIAN: Convert to global Cartesian coordinates (ECEF), given geodetic curvilinear coordinates.
+    coord_geod = [phi,lambda,h];
+    if (nargin < 4) || isempty(ellipsoid),  ell = get_ellipsoid();  
+    elseif (istruct(ellipsoid)~= 1), ell = get_ellipsoid(ellipsoid); end
+    if isempty(coord_geod)
+        coord_cart = zeros(size(coord_geod));
+        %coord_cart = [];  % WRONG!
+        return;
+    end
+
+    if nargin<5 || strcmpi(angleut,'degree')
+    sinfun = @sind;
+    cosfun = @cosd;
+    elseif strcmpi(angleut,'radian')
+    sinfun = @sin;
+    cosfun = @cos;
+    else
+    disperror('Unknown: %s input argument for units',angleut);
+    end
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    % Auxiliary quantities
+
+    % radius of curvature of the prime vertical section
+    N = compute_prime_vertical_radius (coord_geod(:, 1), ell);
+
+    
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    % Some shortnames for variables used often.
+    a = ell.a;  b = ell.b;
+    
+    lat = coord_geod(:, 1) * (pi/180);
+    lon = coord_geod(:, 2) * (pi/180);
+    h   = coord_geod(:, 3);
+    
+    
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    % Compute cartesian (geocentric) coordinates given 
+    % (curvilinear) geodetic coordinates.
+    x = (N + h) .* cosfun(lat) .* cosfun(lon);
+    y = (N + h) .* cosfun(lat) .* sinfun(lon);
+    z = (N .* (b/a)^2 + h) .* sinfun(lat);
+    coord_cart = [x y z];
+    
+end
+
+%!shared
+%! n = 10;  % number of points in each test set
+%! 
+%! % The error below was determied experimentally, running all 
+%! % tests below.
+%! error = 1e-8;
+%!
+%! a = 6378206.4;  b = 6356583.8;  e = sqrt ( (a^2 - b^2) / (a^2));
+%! ell.a = a;  ell.b = b;  ell.e = e;
+
+%!test
+%! % Points at south pole, random heights, random longitudes.
+%! lat = -90*ones(n, 1);
+%! lon = rand(n, 1)*360 - 180;  % random longitudes between [-180, +180)
+%! h = rand(n, 1) * 200 - 100;  % random heights between [-100, +100)
+%! coord_geod = [lat, lon, h];
+%! 
+%! x = zeros(n, 1);
+%! y = zeros(n, 1);
+%! z = -(ell.b+h);
+%! correct_answer = [x y z];
+%! 
+%! coord_cart = convert_to_cartesian (coord_geod, ell);
+%! myassert ( all(abs(coord_cart - correct_answer) < error) );
+
+%!test
+%! % Points on equatorial plane, at Greenwich meridian, random heights.
+%! lat = 0*ones(n, 1);
+%! lon = 0*ones(n, 1);
+%! h = rand(n, 1) * 200 - 100;  % random heights between [-100, +100)
+%! coord_geod = [lat, lon, h];
+%! 
+%! x = (ell.a+h);
+%! y = zeros(n, 1);
+%! z = zeros(n, 1);
+%! correct_answer = [x y z];
+%! 
+%! coord_cart = convert_to_cartesian (coord_geod, ell);
+%! myassert ( all(abs(coord_cart - correct_answer) < error) );
+
+%!test
+%! % Points on equatorial plane, at +90 degrees meridian, random heights.
+%! lat = 0*ones(n, 1);
+%! lon = +90*ones(n, 1);
+%! h = rand(n, 1) * 200 - 100;  % random heights between [-100, +100)
+%! coord_geod = [lat, lon, h];
+%! 
+%! x = zeros(n, 1);
+%! y = (ell.a+h);
+%! z = zeros(n, 1);
+%! correct_answer = [x y z];
+%! 
+%! coord_cart = convert_to_cartesian (coord_geod, ell);
+%! myassert ( all(abs(coord_cart - correct_answer) < error) );
+
+%!test
+%! % Points on equatorial plane, at -90 degrees meridian, random heights.
+%! lat = 0*ones(n, 1);
+%! lon = -90*ones(n, 1);
+%! h = rand(n, 1) * 200 - 100;  % random heights between [-100, +100)
+%! coord_geod = [lat, lon, h];
+%! 
+%! x = zeros(n, 1);
+%! y = -(ell.a+h);
+%! z = zeros(n, 1);
+%! correct_answer = [x y z];
+%! 
+%! coord_cart = convert_to_cartesian (coord_geod, ell);
+%! myassert ( all(abs(coord_cart - correct_answer) < error) );
+
+%!test
+%! % Points on equatorial plane, at 180 degrees meridian, random heights.
+%! lat = 0*ones(n, 1);
+%! lon = 180*ones(n, 1);
+%! h = rand(n, 1) * 200 - 100;  % random heights between [-100, +100)
+%! coord_geod = [lat, lon, h];
+%! 
+%! x = -(ell.a+h);
+%! y = zeros(n, 1);
+%! z = zeros(n, 1);
+%! correct_answer = [x y z];
+%! 
+%! coord_cart = convert_to_cartesian (coord_geod, ell);
+%! myassert ( all(abs(coord_cart - correct_answer) < error) );
+
+%!test
+%! % Points on equatorial plane, random longitudes, random heights.
+%! lat = 0*ones(n, 1);
+%! lon = rand(n, 1)*360 - 180;  % random longitudes between [-180, +180)
+%! h = rand(n, 1) * 200 - 100;  % random heights between [-100, +100)
+%! coord_geod = [lat, lon, h];
+%! 
+%! coord_cart = convert_to_cartesian (coord_geod, ell);
+%! x = coord_cart(:, 1);
+%! y = coord_cart(:, 2);
+%! z = coord_cart(:, 3);
+%! equatorial_radius = sqrt(x.^2 + y.^2) - h;
+%! 
+%! myassert ( all( abs( equatorial_radius - ell.a*ones(n, 1) ) < error) );
+%! myassert ( all( abs( z - 0 ) < error) );
+
+%!test
+%! % Points on a sphere, random latitudes, random longitudes, random heights.
+%! a = 6378206.4;  b = a;  e = sqrt ( (a^2 - b^2) / (a^2));
+%! ell.a = a;  ell.b = b;  ell.e = e;
+%!
+%! lat = rand(n, 1)*180 - 90;   % random latitudes between [-90, +90)
+%! lon = rand(n, 1)*360 - 180;  % random longitudes between [-180, +180)
+%! h = rand(n, 1) * 200 - 100;  % random heights between [-100, +100)
+%! coord_geod = [lat lon h];
+%!
+%! % sherical formulas:
+%! x = (h + ell.a) .* cos(lon * pi/180) .* cos(lat * pi/180);
+%! y = (h + ell.a) .* sin(lon * pi/180) .* cos(lat * pi/180);
+%! z = (h + ell.a)                      .* sin(lat * pi/180);
+%! coord_cart = [x y z];
+%! 
+%! answer_coord_cart = convert_to_cartesian (coord_geod, ell);
+%! answer_x = coord_cart(:, 1);
+%! answer_y = coord_cart(:, 2);
+%! answer_z = coord_cart(:, 3);
+%! 
+%! %answer_coord_cart - coord_cart
+%! myassert ( all(abs(answer_x - x) <= error) );
+%! myassert ( all(abs(answer_y - y) <= error) );
+%! myassert ( all(abs(answer_z - z) <= error) );
+
+%!test
+%! % empty in, empty out.
+%! myassert(isempty(convert_to_cartesian([])));
+
diff -r 037b67701b72 inst/geodetic2enu.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/geodetic2enu.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,41 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [xEast, yNorth, zUp] = geodetic2enu(lat, lon, h, lat0, lon0, h0, ellipsoid, angleut)
+
+if nargin<8
+    angleut = 'degree';
+end
+[x1,y1,z1] = geodetic2ecef(lat,lon,h,ellipsoid,angleut);
+[x2,y2,z2] = geodetic2ecef(lat0,lon0,h0,ellipsoid,angleut);
+dx = x1-x2;
+dy = y1-y2;
+dz = z1-z2;
+[xEast, yNorth, zUp] = ecef2enuv(dx, dy, dz, lat0, lon0, angleut);
+
+end
+
diff -r 037b67701b72 inst/geodetic2ned.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/geodetic2ned.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,36 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [xNorth, yEast, zDown] = geodetic2ned(lat, lon, h, lat0, lon0, h0, spheroid, angleut)
+
+if nargin<8
+    angleut = 'degree';
+end
+[yEast, xNorth, zUp] = geodetic2enu(lat, lon, h, lat0, lon0, h0, spheroid, angleut);
+zDown = -zUp;
+end
+
diff -r 037b67701b72 inst/ned2aer.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ned2aer.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,33 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [az, elev, slantRange] = ned2aer(xNorth, yEast, zDown, angleut)
+if nargin<4
+    angleut = 'degree';
+end
+[az, elev, slantRange] = enu2aer(yEast, xNorth, -zDown, angleut);
+end
diff -r 037b67701b72 inst/ned2ecef.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ned2ecef.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,34 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [x, y, z] = ned2ecef(xNorth, yEast, zDown, lat0, lon0, h0, spheroid, angleut)
+if nargin<8
+    angleut = 'degree';
+end
+
+[x, y, z] = enu2ecefFormula(yEast, xNorth, -zDown, lat0, lon0, h0, spheroid, angleut);
+end
\ No newline at end of file
diff -r 037b67701b72 inst/ned2ecefv.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ned2ecefv.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,33 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [u, v, w] = ned2ecefv(uNorth, vEast, wDown, lat0, lon0, angleut)
+if nargin<6
+    angleut = 'degree';
+end
+[u, v, w]= enu2ecefv(vEast, uNorth, -wDown, lat0, lon0, angleut);
+end
\ No newline at end of file
diff -r 037b67701b72 inst/ned2geodetic.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ned2geodetic.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,37 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function [phi, lambda, h] = ned2geodetic(xNorth, yEast, zDown, lat0, lon0, h0, spheroid, angleut)
+
+if nargin<8
+    angleut = 'degree';
+end
+
+[x, y, z] = enu2ecefFormula(yEast, xNorth, -zDown, lat0, lon0, h0, spheroid, angleut);
+[phi, lambda, h]=ecef2geodetic(x, y, z,spheroid,angleut);
+
+end
diff -r 037b67701b72 inst/private/compute_prime_vertical_radius.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/private/compute_prime_vertical_radius.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,31 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function N = compute_prime_vertical_radius (lat, ell)
+    N = get_radius_normal (lat, ell);
+end
+
diff -r 037b67701b72 inst/private/get_ellipsoid.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/private/get_ellipsoid.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,160 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function ell = get_ellipsoid (name)
+%GET_ELLIPSOID: Return geodetic ellipsoid information.
+
+    if (nargin < 1) || isempty(name),  name = 'grs80';  end
+    switch lower(name)
+    case 'clk1866'
+        ell.a = 6378206.40;
+        ell.b = 6356583.80;
+        ell.f = (ell.a - ell.b) / ell.a;
+        ell.e = sqrt( (ell.a^2 - ell.b^2) / ell.a^2 );
+    case 'iau_earth'
+        ell.a = 6378.14e3;
+        ell.b = 6356.75e3;
+        ell.f = (ell.a - ell.b) / ell.a;
+        ell.e = sqrt( (ell.a^2 - ell.b^2) / ell.a^2 );
+    case 'grs80'
+        ell.a = 6378137;
+        ell.e_sq = 0.00669438002290;
+        ell.e = sqrt(ell.e_sq);
+        ell.b = ell.a * sqrt(1 - ell.e_sq);
+        ell.f = (ell.a - ell.b) / ell.a;
+    case 'int24'
+        % RESOLU��O IBGE 1/2005.
+        ell.a = 6378388;
+        ell.f = 1/297;
+        ell.b = ell.a * (1 - ell.f);
+        ell.e = sqrt( (ell.a^2 - ell.b^2) / ell.a^2 );
+    case 'int67'
+        % RESOLU��O IBGE No 23, DE 21 DE FEVEREIRO DE 1989
+        ell.a = 6378160;
+        ell.b = 6356774.719;
+        ell.f = (ell.a - ell.b) / ell.a;
+        ell.e = sqrt( (ell.a^2 - ell.b^2) / ell.a^2 );
+    case 'fake'
+        % I've made this ellipsoid really different from 
+        % Earth's shape, so as to have large discrepancies
+        % in gedetic coordinates expressed in this ellipsoid,
+        % compared to, say, GRS80 or WGS84.
+        ell.a = 6378000;
+        ell.b = 6300000;
+        ell.f = (ell.a - ell.b) / ell.a;
+        ell.e = sqrt( (ell.a^2 - ell.b^2) / ell.a^2 );
+    case 'wgs84'
+        %-% WGS-84 ellipsoid parameters.
+        
+        %   <http://earth-info.nga.mil/GandG/tr8350_2.html>
+        %   <ftp://164.214.2.65/pub/gig/tr8350.2/wgs84fin.pdf>
+
+        ell.a = 6378137.0;  % semi-major axis
+        ell.f = 1.0 / 298.2572235630;  % flattening
+        ell.b = ell.a * (1 - ell.f);  % semi-minor axis
+        ell.e = sqrt ( (ell.a^2 - ell.b^2) / (ell.a^2));  % first eccentricity
+
+        %-%
+        % Paremeters needed to evaluate the geopotential.
+        % I got them from the US National Geospatial-Inteligence Agency's
+        % website, "NGA/NASA EGM96, N=M=360 Earth Gravity Model" 
+        % (NGA > Products and Services >Geospatial Sciences Division 
+        % > Physical Geodesy Home)
+        % <http://earth-info.nga.mil/GandG/wgsegm/egm96.html>
+            
+        % Earth's Gravitational Constant w/ atmosphere:
+        ell.GM = 0.3986004418e15;  % m^3/s^2
+        
+        % Earth's angular speed:
+        ell.omega = 7292115.0e-11;   % rad/s
+        
+        % Dynamical form factor of the Earth:
+        % The four defining paramenters of WGS-84 are
+        % GM, omega, a, and 1/f. We need J2 instead of f:
+        ell.J2 = get_J2 (ell.a, ell.b, ell.omega, ell.GM);
+
+        % value used to compute N from the EGM96 harmonic coefficients:
+        % (even though W_0 is not strictly related to the ellipsoid,
+        %  I thought that's the best place to keep it)
+        ell.W0 = 62636856.88;  % m^2 s^2
+        % Accordingly to eq. (11.2-3) in Chapter 11, "The EGM96 Geoid 
+        % Undulation With Respect to the WGS84 Ellipsoid", of the following 
+        % publication: The Development of the Joint NASA GSFC and NIMA 
+        % Geopotential Model EGM96, F. G. Lemoine, S. C. Kenyon, J. K. Factor, 
+        % R.G. Trimmer, N. K. Pavlis, D. S. Chinn, C. M. Cox, S. M. Klosko, 
+        % S. B. Luthcke, M. H. Torrence, Y. M. Wang, R. G. Williamson, 
+        % E. C. Pavlis, R. H. Rapp and T. R. Olson, NASA Goddard Space Flight 
+        % Center, Greenbelt, Maryland, 20771 USA, July 1998. Available at:
+        % <http://cddis.gsfc.nasa.gov/926/egm96/doc/S11.HTML>
+       
+        %-%
+        % Value taken from NIMA Technical Report TR8350.2, 
+        % "Department of Defense World Geodetic System 1984, Its Definition 
+        % and Relationships With Local Geodetic Systems", Third Edition, 
+        % 4 July 1997, available at
+        % <ftp://164.214.2.65/pub/gig/tr8350.2/wgs84fin.pdf>
+        % Table 3.4 (Derived physical constants), printed page 3-7, PDF page 40.
+        ell.U0 = 62636851.7146;  %  m^2/s^2
+        ell.U0_tol =    0.00005;  % half the least significant digit in U0
+    case {'wgs84_sph', 'sph', 'sphere'}
+        ell = get_ellipsoid('wgs84');
+        R = (ell.a + ell.b) / 2;
+        ell.a = R;
+        ell.b = R;
+        ell.f = 0;
+        ell.e = 0;
+        ell.J2 = 0;
+    case 'mean sphere'
+        R = 6371e3;
+        ell.a = R;
+        ell.b = R;
+        ell.f = 0;
+        ell.e = 0;
+    otherwise
+        error('MATLAB:get_ellipsoid:unkEll', 'Unknown ellipsoid name "%s".', name);
+    end
+end
+
+%!test
+%! names = {'grs80', 'int24', 'int67', 'fake', 'wgs84', 'wgs84_sph', 'sph'};
+%! for i=1:length(names)
+%!     get_ellipsoid (names{i});
+%! end
+
+%!test
+%! % get_ellipsoid ()
+%! lasterror('reset')
+
+%!error
+%! get_ellipsoid('WRONG');
+
+%!test
+%! % get_ellipsoid ()
+%! s = lasterror;
+%! %s
+%! myassert(strcmp(s.identifier, 'MATLAB:get_ellipsoid:unkEll'));
+
diff -r 037b67701b72 inst/private/get_radius_normal.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/private/get_radius_normal.m	Wed Mar 05 05:41:20 2014 -0800
@@ -0,0 +1,74 @@
+% Copyright (c) 2013, Sandeep V. Mahanthi
+% Copyright (c) 2013, Felipe G. Nievinski
+% Copyright (c) 2011, Felipe G. Nievinski
+%
+% All rights reserved.
+% 
+% Redistribution and use in source and binary forms, with or without
+% modification, are permitted provided that the following conditions are
+% met:
+% 
+%     * Redistributions of source code must retain the above copyright
+%       notice, this list of conditions and the following disclaimer.
+%     * Redistributions in binary form must reproduce the above copyright
+%       notice, this list of conditions and the following disclaimer in
+%       the documentation and/or other materials provided with the distribution
+% 
+% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+% POSSIBILITY OF SUCH DAMAGE.
+function N = get_radius_normal (lat, ell)
+%GET_RADIUS_NORMAL: Return the normal (i.e., along the prime vertical section) ellipsoidal radius of curvature, at a given geodetic latitude.
+
+    a = ell.a;  b = ell.b;
+    lat2 = lat .* (pi/180);
+    N = a^2 ./ sqrt( a^2 .* (cos(lat2)).^2 + b^2 .* (sin(lat2)).^2 );
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Test block (see help test on GNU Octave).
+
+%!shared
+%! ell = get_ellipsoid('grs80');
+%! n = ceil(10*rand);
+%! lat = rand(n, 1);
+
+%!test
+%! % When a = b (i.e., the the ellipsoid degenerates into a sphere),
+%! % N = a everywhere.
+%! ell.a = 1;  ell.b = ell.a;  ell.e = 0;
+%! lat = 0:90:360;
+%! N = get_radius_normal (lat, ell);
+%! correct_answer = ell.a * ones(size(lat));
+%! myassert (N, correct_answer, -sqrt(eps));
+
+%!test
+%! % At the equator:
+%! lat = 0;
+%! N = get_radius_normal(lat, ell);
+%! correct_answer = ell.a;
+%! myassert (N, correct_answer, -sqrt(eps));
+
+%!test
+%! % At the north pole:
+%! lat = +90;
+%! N = get_radius_normal(lat, ell);
+%! correct_answer = ell.a^2 / ell.b;
+%! myassert (N, correct_answer, -sqrt(eps));
+
+%!test
+%! % At the south pole:
+%! lat = -90;
+%! N = get_radius_normal(lat, ell);
+%! correct_answer = ell.a^2 / ell.b;
+%! myassert (N, correct_answer, -sqrt(eps));
+
