NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/matlab_cen/xy2ll.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function [lat,lon]=xy2ll(x,y,reflat,reflon)
2
3 % [LAT,LON]=XY2LLGOM(X,Y,REFLAT,REFLON)
4 %
5 % Returns vectors of latitudes and longitudes, LAT and LON,
6 % for X and Y vectors (as distance in meters from arbitrary
7 % origin REFLAT and REFLON).  Uses a Newton-Raphson Method
8 % to calculate latitude.  In situations where one or more
9 % values do not converge, that location is assigned the value
10 % NaN and a warning is issued.
11 %
12 % REFLAT and REFLON default to Boston
13 %
14 % X and Y may be specified as X+i*Y
15 %
16 % Specifying only a single output yields LON+i*LAT
17
18 % CVL, 7-10-97
19 % Hacked from mercgom2 from C. Naimie.
20
21 if nargin<3
22         reflon=-71.03*pi/180;
23         reflat=42.35*pi/180;
24 end
25
26 if nargin==1
27         y=imag(x);
28         x=real(x);
29 end
30
31 r=6.3675e+6;
32 xo=r*cos(reflat)*reflon;
33 yo=r*cos(reflat)*log((1.0+sin(reflat))/cos(reflat));
34
35 rlon=(x+xo)/(r*cos(reflat));
36
37 y=y+yo;
38
39 tol=0.0001;
40 n=1000;
41
42 po=reflat*ones(size(x));
43 for in=1:n
44         p1=po-((1.0+sin(po))./cos(po)-exp(y./(r*cos(reflat))))...
45                 ./((1.0+sin(po))./(cos(po).^2.0));
46         if max(abs(p1-po))<tol
47                 break
48         end
49         po=p1;
50 end
51
52 if in==n
53         in=find(max(abs(p1-po))<tol);
54         p1(in)=NaN*p1(in);
55         rlon(in)=NaN*rlon(in);
56         disp('Did not converge after 1000 iterations, some values NaN')
57 end
58
59 rlat=p1;
60 lon=rlon*180/pi;
61 lat=rlat*180/pi;
62
63 if nargout<=1
64         lat=lon+i*lat;
65 end
Note: See TracBrowser for help on using the browser.