[2271] | 1 | function [alat,alon]=mapxy(x,y,hem,varargin);
|
---|
[1] | 2 | %MAPXY - compute latitude and longitude from x and y
|
---|
| 3 | %
|
---|
[2734] | 4 | % hemisphere must be 'n' for north and 's' for south
|
---|
| 5 | % One can specify the standard parallel and center meridien.
|
---|
| 6 | % Default values are (70,45) for northern hemisphere and (71,0) for southerm hemisphere.
|
---|
[1] | 7 | %
|
---|
| 8 | % Usage:
|
---|
| 9 | % [latitude,longitude]=mapxy(x,y,hemisphere)
|
---|
[2734] | 10 | % [latitude,longitude]=mapxy(x,y,hemisphere,parallel,meridien)
|
---|
[1] | 11 | %
|
---|
[2734] | 12 | % Example:
|
---|
| 13 | % [lat,long]=mapxy(x,y,'s')
|
---|
| 14 | % [lat,long]=mapxy(x,y,'n',71,39)
|
---|
| 15 | %
|
---|
[1] | 16 | % See also MAPLL, LL2XY
|
---|
| 17 |
|
---|
[2271] | 18 | %check number of arguments.
|
---|
| 19 | if ~((nargin==3) | (nargin==5)),
|
---|
| 20 | mapxyerrorusage();
|
---|
| 21 | end
|
---|
| 22 |
|
---|
| 23 | %hem: must be either 's' or 'n'
|
---|
| 24 | if ~ischar(hem),
|
---|
| 25 | error('mapxy error message: hemisphere argument should be ''n'' or ''s''');
|
---|
| 26 | end
|
---|
| 27 |
|
---|
| 28 | %check hem is either 'n' or 's':
|
---|
[2275] | 29 | if ~(strcmpi(hem,'n') | strcmpi(hem,'s')),
|
---|
[2271] | 30 | error('mapxy error message: hem should be ''s'' or ''n''');
|
---|
| 31 | end
|
---|
| 32 |
|
---|
| 33 | %set sn:
|
---|
[2275] | 34 | if strcmpi(hem,'s'),
|
---|
[2271] | 35 | slat=71;
|
---|
| 36 | sn=-1.0;
|
---|
| 37 | xlam=0;
|
---|
| 38 | else
|
---|
| 39 | slat=70;
|
---|
| 40 | sn=1.0;
|
---|
| 41 | xlam=45;
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 | %set defaults for standard parallels and centre meridians.
|
---|
| 45 | if nargin==5,
|
---|
| 46 | slat=varargin{1};
|
---|
| 47 | xlam=varargin{2};
|
---|
| 48 | end
|
---|
| 49 |
|
---|
[1] | 50 | re = 6378137;
|
---|
| 51 | e2 = 0.00669437999015;
|
---|
| 52 |
|
---|
| 53 | e=sqrt(e2);
|
---|
| 54 |
|
---|
[2271] | 55 | slat=slat/180*pi;
|
---|
[1] | 56 |
|
---|
| 57 | rho=sqrt(x.^2+y.^2);
|
---|
| 58 | cm=cos(slat)./sqrt(1.0-e2*(sin(slat).^2));
|
---|
[2271] | 59 | t=tan((pi/4)-(slat/2.))./((1.0-e*sin(slat))./(1.0+e*sin(slat))).^(e/2.);
|
---|
[1] | 60 |
|
---|
[2271] | 61 | t=rho.*t./(re*cm);
|
---|
[1] | 62 |
|
---|
[2271] | 63 | chi=(pi/2.)-2.*atan(t);
|
---|
[1] | 64 |
|
---|
| 65 | alat=chi+((e2/2.)+(5.0*e2^2/24.)+(e2^3/12.))*sin(2*chi)+...
|
---|
| 66 | ((7.0*e2^2/48.)+(29.*e2^3/240.))*sin(4.0*chi)+...
|
---|
[2271] | 67 | (7.0*e2^3/120.)*sin(6.0*chi);
|
---|
[1] | 68 |
|
---|
| 69 | alat=(sn*alat/pi*180);
|
---|
| 70 | xpr=sn*x;
|
---|
| 71 | ypr=sn*y;
|
---|
| 72 | alon=atan2(xpr,-ypr)/pi*180-sn*xlam;
|
---|
| 73 | alon=sn*alon;
|
---|
| 74 |
|
---|
| 75 | indice=find(alon<0);
|
---|
[2271] | 76 | if length(indice)>0,
|
---|
| 77 | alon(indice)=alon(indice)+360;
|
---|
| 78 | end
|
---|
[1] | 79 |
|
---|
| 80 | indice=find(alon>360);
|
---|
[2271] | 81 | if length(indice)>0,
|
---|
[1] | 82 | alon(indice)=alon(indice)-360;
|
---|
| 83 | end
|
---|
[2271] | 84 |
|
---|
| 85 |
|
---|
| 86 | end
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | function mapxyerrorusage()
|
---|
| 90 | help mapxy
|
---|
| 91 | end
|
---|