source: issm/oecreview/Archive/14312-15392/ISSM-15125-15126.diff@ 15393

Last change on this file since 15393 was 15393, checked in by Mathieu Morlighem, 12 years ago

NEW: adding Archive/14312-15392 for oecreview

File size: 5.0 KB
  • TabularUnified ../trunk-jpl/src/m/lambert/lambert2xy.m

     
    1 function [x,y] = lambert2xy(lat,lon,projection_center_lat,projection_center_lon) 
     1function [x,y] = lambert2xy(lat,lon,sgn,projection_center_lat,projection_center_lon) 
    22%LAMBERT2XY - converts lat long from Lambert Azimuthal to Polar Stereographic
    33%
    44%   Converts from geodetic latitude and longitude that are
     
    66%   Stereographic (X,Y) coordinates for the polar regions.
    77%
    88%   Usage:
    9 %      [x,y] = ll2xy(lat,lon)
    10 %      [x,y] = ll2xy(lat,lon,projection_center_lat,projection_center_lon)
     9%      [x,y] = lambert2xy(lat,lon,sgn)
     10%      [x,y] = lambert2xy(lat,lon,sgn,projection_center_lat,projection_center_lon)
    1111%
    1212%      - provide lat in [-90,90] and lon in [-180,180].
    13 %
    14 %      - default: North hemisphere [projection center lat = 90 lon=0]
    15 %                 South hemisphere [projection center lat = -90 lon=0]
    1613
     14%      - sgn = +1 N hemisphere [default projection center lat = 90 lon=0]
     15%              -1 S hemisphere [default projection center lat = -90 lon=0]
     16
    1717%Get projection_center_lat and projection_center_lon
    18 if nargin==4,
     18if nargin==5,
    1919        latitude0  = projection_center_lat;
    2020        longitude0 = projection_center_lon;
    21 elseif nargin==2,
    22         if lat>0,
     21elseif nargin==3,
     22        if sgn==1,
    2323                latitude0 = 90; longitude0 = 0;
    2424                disp('Info: creating coordinates in polar stereographic (Projection center lat: 90N lon: 0)');
    25         elseif lat<0,
     25        elseif sgn==-1,
    2626                latitude0 = -90; longitude0 = 0;
    2727                disp('Info: creating coordinates in polar stereographic (Projection center lat: 90S lon: 0)');
     28        else
     29                error('Sign should be either +1 or -1');
    2830        end
    2931else
    3032        help lambert2xy
     
    5759B =Rq*sqrt(2/(1+sin(b0)*sin(b)+(cos(b0)*cos(b)*cos(lam-lam0))));
    5860
    5961% Calculation of x and y
    60 if(lat==90)
    61         rho=a*sqrt(qp-q);
    62         x=rho*sin(lam-lam0);
    63         y=-rho*cos(lam-lam0);
    64 elseif(lat==-90)
    65         rho=a*sqrt(qp+q);
    66         x=rho*sin(lam-lam0);
    67         y=rho*cos(lam-lam0);
     62if(abs(lat)==90)
     63        x=0.0;
     64        y=0.0;
    6865else
    6966        x=(B*D)*(cos(b)*sin(lam-lam0));
    7067        y=(B/D)*((cos(b0)*sin(b))-(sin(b0)*cos(b)*cos(lam-lam0)));
    7168end
     69
  • TabularUnified ../trunk-jpl/src/m/lambert/xy2lambert.m

     
     1function [lat,lon] = xy2lambert(x,y,sgn,projection_center_lat,projection_center_lon) 
     2%XY2LAMBERT - converts xy to lat lon in Lambert Azimuthal
     3%
     4%   Converts from Ploar Stereographic (X,Y) coordinates to geodetic
     5%   lat lon that are in Lambert Azimuthal (equal area) projection.
     6%
     7%   Usage:
     8%      [lat,lon] = xy2lambert(x,y,sgn)
     9%      [lat,lon] = xy2lambert(x,y,sgn,projection_center_lat,projection_center_lon)
     10%
     11%      - provide lat in [-90,90] and lon in [-180,180].
     12%
     13%      - sgn = +1 N hemisphere [default projection center lat = 90 lon=0]
     14%              -1 S hemisphere [default projection center lat = -90 lon=0]
     15
     16%Get projection_center_lat and projection_center_lon
     17if nargin==5,
     18        latitude0  = projection_center_lat;
     19        longitude0 = projection_center_lon;
     20elseif nargin==3,
     21        if sgn==1,
     22                latitude0 = 90; longitude0 = 0;
     23                disp('Info: creating coordinates in Lambert Azimuthal equal-area (Projection center lat: 90N lon: 0)');
     24        elseif sgn==-1,
     25                latitude0 = -90; longitude0 = 0;
     26                disp('Info: creating coordinates in Lambert Azimuthal equal-area (Projection center lat: 90S lon: 0)');
     27        else
     28                error('Sign should be either +1 or -1');
     29        end
     30else
     31        help xy2lambert
     32        error('bad usage');
     33end
     34
     35% Radius of the earth in meters
     36a = 6378137.0;
     37% Eccentricity of the Hughes ellipsoid squared
     38e = 0.081819191;
     39
     40% Projection center latitude and longitude in radians
     41phi0 = latitude0 * pi/180;
     42lam0 = longitude0 * pi/180;
     43
     44% Some constants based on phi0 and lam0
     45% (as in forward calculation)
     46qp= (1-e^2)*((1/(1-e^2))-((1/(2*e))*log((1-e)/(1+e))));
     47q0=(1-e^2)*((sin(phi0)/(1-e^2*sin(phi0)*sin(phi0)))-((1/(2*e))*log((1-e*sin(phi0))/(1+e*sin(phi0)))));
     48Rq=a*sqrt(qp/2);
     49b0=asin(q0/qp);
     50D =a*(cos(phi0)/sqrt(1-e^2*sin(phi0)*sin(phi0)))/(Rq*cos(b0));
     51
     52% Some other (x,y) dependent parameters
     53rho=sqrt((x/D)^2+(D*y)^2);
     54C=2*asin(rho/(2*Rq));
     55b_prime=asin((cos(C)*sin(b0))+((D*y*sin(C)*cos(b0))/rho));
     56
     57% Calculation of lat and lon
     58dist=sqrt(x^2+y^2);
     59if(dist<=0.1)
     60        lat=sgn*90.0;
     61        lon=0.0;
     62else
     63        lat_rad=b_prime+((e^2/3+31*e^4/180+517*e^6/5040)*sin(2*b_prime))+((23*e^4/360+251*e^6/3780)*sin(4*b_prime))+((761*e^6/45360)*sin(6*b_prime));
     64        lon_rad=lam0+atan(x*sin(C)/(D*rho*cos(b0)*cos(C)-D^2*y*sin(b0)*sin(C)));
     65        % in degrees
     66        lat=lat_rad*180/pi;
     67        lon=lon_rad*180/pi;
     68end
     69
Note: See TracBrowser for help on using the repository browser.