-
Notifications
You must be signed in to change notification settings - Fork 10
/
islatlon.m
92 lines (84 loc) · 2.17 KB
/
islatlon.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function tf = islatlon(lat,lon)
% islatlon determines whether lat,lon is likely to represent geographical
% coordinates.
%
%% Citing Antarctic Mapping Tools
% This function was developed for Antarctic Mapping Tools for Matlab (AMT). If AMT is useful for you,
% please cite our paper:
%
% Greene, C. A., Gwyther, D. E., & Blankenship, D. D. Antarctic Mapping Tools for Matlab.
% Computers & Geosciences. 104 (2017) pp.151-157.
% http://dx.doi.org/10.1016/j.cageo.2016.08.003
%
% @article{amt,
% title={{Antarctic Mapping Tools for \textsc{Matlab}}},
% author={Greene, Chad A and Gwyther, David E and Blankenship, Donald D},
% journal={Computers \& Geosciences},
% year={2017},
% volume={104},
% pages={151--157},
% publisher={Elsevier},
% doi={10.1016/j.cageo.2016.08.003},
% url={http://www.sciencedirect.com/science/article/pii/S0098300416302163}
% }
%
%% Syntax
%
% tf = islatlon(lat,lon) returns true if all values in lat are numeric
% between -90 and 90 inclusive, and all values in lon are numeric between
% -180 and 360 inclusive.
%
%% Example 1: A single location
%
% islatlon(110,30)
% = 0
%
% because 110 is outside the bounds of latitude values.
%
%% Example 2: A grid
%
% [lon,lat] = meshgrid(-180:180,90:-1:-90);
%
% islatlon(lat,lon)
% = 1
%
% because all values in lat are between -90 and 90, and all values in lon
% are between -180 and 360. What if it's really, really close? What if
% just one value violates these rules?
%
% lon(1) = -180.002;
%
% islatlon(lat,lon)
% = 0
%
%% Author Info
% This function was written by Chad A. Greene of the University of Texas at
% Austin's Institute for Geophysics (UTIG). http://www.chadagreene.com.
% March 30, 2015.
%
% See also wrapTo180, wrapTo360, projfwd, and projinv.
% Make sure there are two inputs:
narginchk(2,2)
% Set default output:
tf = true;
%% If *any* inputs don't look like lat,lon, assume none of them are lat,lon.
if ~isnumeric(lat)
tf = false;
return
end
if ~isnumeric(lon)
tf = false;
return
end
if any(abs(lat(:))>90)
tf = false;
return
end
if any(lon(:)>360)
tf = false;
return
end
if any(lon(:)<-180)
tf = false;
end
end