1 | function [values,longs,lats]=m_etopo2(varargin); |
---|
2 | % M_ETOPO2 Contour elevation onto a map using the 2-minute ETOPO2 database |
---|
3 | % M_ETOPO2 contours elevations at 1000m intervals for the map. |
---|
4 | % M_ETOPO2(OPTN (,LEVELS) (,ARGS,...) ) lets you change various options. |
---|
5 | % if OPTN=='contour', contour lines are drawn. for OPTN=='contourf', |
---|
6 | % filled contours are drawn. LEVELS are the levels used, and ARGS |
---|
7 | % are optional patch arguments of line types, colors, etc. |
---|
8 | % |
---|
9 | % [CS,H]=M_ETOPO2E(...) allows access to the return arguments of the |
---|
10 | % contour/contourf call. |
---|
11 | % |
---|
12 | % [ELEV,LONG,LAT]=M_ETOPO2([LONG_MIN LONG_MAX LAT_MIN LAT_MAX]) |
---|
13 | % extracts elevation data for the given lat/long limits (without plotting). |
---|
14 | % |
---|
15 | % See also M_PROJ, M_GRID, M_COAST |
---|
16 | |
---|
17 | |
---|
18 | % Rich Pawlowicz (rich@ocgy.ubc.ca) 10/Sep/97 |
---|
19 | % |
---|
20 | % This software is provided "as is" without warranty of any kind. But |
---|
21 | % it's mine, so you can't sell it. |
---|
22 | % |
---|
23 | % 17/1/98 - Allowed output of raw data, fixed small bug in selection that left |
---|
24 | % some things off by 1/12 deg lat. |
---|
25 | % 6/Nov/00 - eliminate returned stuff if ';' neglected (thx to D Byrne) |
---|
26 | % 28/Mar/04 - defaulted to m_elev database (prevents problems with m-demo) |
---|
27 | % 21/Mar/06 - modified for etopo2 |
---|
28 | |
---|
29 | %%% This will have to be set by YOU the USER! |
---|
30 | |
---|
31 | PATHNAME='/ocean/rich/more/mmapbase/etopo2/'; % Be sure to end the path with a "/" or |
---|
32 | % whatever your separator is. |
---|
33 | |
---|
34 | %%% You probably won't want to change this... |
---|
35 | decmax=500; |
---|
36 | % What it does is set an upper limit (of DECMAX points) in the |
---|
37 | % displayed resolution of the database. Why do I do this? Because the |
---|
38 | % problem with a 5-minute database is that it is often way, way too much detail |
---|
39 | % for a simple map of, e.g., the Pacific Ocean. And that means it takes a looong |
---|
40 | % time to contour the data, not to mention scads of memory. But feel free |
---|
41 | % to change that number to something else if you think I have done something |
---|
42 | % unreasonable! (PS - I'd appreciate knowing *why* you changed it). |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | %%% Don't change anything below this... |
---|
47 | |
---|
48 | efid=fopen([PATHNAME 'etopo2_2006apr.raw'],'r','b'); % in big-endian format |
---|
49 | |
---|
50 | if efid==-1, |
---|
51 | warning(sprintf(['Cannot open ' PATHNAME 'tbase.int !! \n Have you installed the TerrainBase database correctly?' ... |
---|
52 | '\n This (optional) database must be installed separately - see the M_Map user''s guide for instructions' ... |
---|
53 | '\n ----Using default elevation database instead'])); |
---|
54 | if nargout==0, |
---|
55 | m_elev(varargin{:}); |
---|
56 | elseif nargout==2, |
---|
57 | [values,longs]=m_elev(varargin{:}); |
---|
58 | elseif nargout==3, |
---|
59 | [values,longs,lats]=m_elev(varargin{:}); |
---|
60 | end; |
---|
61 | return; |
---|
62 | end; |
---|
63 | |
---|
64 | |
---|
65 | global MAP_PROJECTION MAP_VAR_LIST |
---|
66 | |
---|
67 | % Have to have initialized a map first |
---|
68 | |
---|
69 | draw_map=1; |
---|
70 | if nargin==1 & ~isstr(varargin{1}) & length(varargin{1})==4, |
---|
71 | draw_map=0; |
---|
72 | end; |
---|
73 | |
---|
74 | if draw_map==1 & isempty(MAP_PROJECTION), |
---|
75 | disp('No Map Projection initialized - call M_PROJ first!'); |
---|
76 | return; |
---|
77 | end; |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | if draw_map, |
---|
82 | |
---|
83 | blat=floor(MAP_VAR_LIST.lats(1)*30); |
---|
84 | tlat=ceil(MAP_VAR_LIST.lats(2)*30); |
---|
85 | llong=floor(MAP_VAR_LIST.longs(1)*30); |
---|
86 | rlong=ceil(MAP_VAR_LIST.longs(2)*30); |
---|
87 | |
---|
88 | lngdec=ceil((rlong-llong)/decmax); |
---|
89 | latdec=ceil((tlat-blat)/decmax); |
---|
90 | |
---|
91 | else |
---|
92 | |
---|
93 | blat=floor(varargin{1}(3)*30); |
---|
94 | tlat=ceil(varargin{1}(4)*30); |
---|
95 | llong=floor(varargin{1}(1)*30); |
---|
96 | rlong=ceil(varargin{1}(2)*30); |
---|
97 | lngdec=1; |
---|
98 | latdec=1; |
---|
99 | |
---|
100 | end; |
---|
101 | |
---|
102 | lgs=[llong:lngdec:rlong]/30; |
---|
103 | lts=fliplr([blat:latdec:tlat]/30); |
---|
104 | |
---|
105 | if rlong>(180*30), rlong=rlong-360*30; llong=llong-360*30; end; |
---|
106 | if llong<-(180*30), rlong=rlong+360*30; llong=llong+360*30; end; |
---|
107 | |
---|
108 | eaxes=[llong+180*30 rlong+180*30 90*30-blat 90*30-tlat]; |
---|
109 | |
---|
110 | |
---|
111 | if (eaxes(2)>10800 ), % Read it in in 2 pieces! |
---|
112 | |
---|
113 | |
---|
114 | nlat=round((eaxes(3)-eaxes(4)))+1; |
---|
115 | nlgr=round( eaxes(2)-10800 )+1 |
---|
116 | nlgl=10800-eaxes(1); %%%nlng-nlgr |
---|
117 | nlng=nlgr+nlgl |
---|
118 | |
---|
119 | values=zeros(nlat,nlng); |
---|
120 | for ii=[1:nlat], |
---|
121 | fseek(efid,(ii-1+eaxes(4))*((360*30+1)*2),'bof'); |
---|
122 | values(ii,nlng+[-nlgr:-1]+1)=fread(efid,[1 nlgr],'int16'); |
---|
123 | fseek(efid,(ii-1+eaxes(4))*((360*30+1)*2)+eaxes(1)*2,'bof'); |
---|
124 | values(ii,1:nlgl)=fread(efid,[1 nlgl],'int16'); |
---|
125 | end; |
---|
126 | |
---|
127 | else % Read it in one piece |
---|
128 | |
---|
129 | nlat=round((eaxes(3)-eaxes(4)))+1; |
---|
130 | nlng=round((eaxes(2)-eaxes(1)))+1; |
---|
131 | values=zeros(nlat,nlng); |
---|
132 | for ii=[1:nlat], |
---|
133 | fseek(efid,(ii-1+eaxes(4))*((360*30+1)*2)+eaxes(1)*2,'bof'); |
---|
134 | values(ii,:)=fread(efid,[1 nlng],'int16'); |
---|
135 | end; |
---|
136 | |
---|
137 | end; |
---|
138 | |
---|
139 | |
---|
140 | if draw_map, |
---|
141 | |
---|
142 | % Set current projection to geographic |
---|
143 | Currentmap=m_coord('set'); |
---|
144 | m_coord('geographic'); |
---|
145 | |
---|
146 | if nargin==0, |
---|
147 | levels=[-7000:1000:-1000 000:1000:5000]; |
---|
148 | optn='contour'; |
---|
149 | n_opt=1; |
---|
150 | else |
---|
151 | if isstr(varargin{1}), |
---|
152 | optn=varargin{1}; |
---|
153 | end; |
---|
154 | if nargin==1, |
---|
155 | levels=[-7000:1000:-1000 000:1000:5000]; |
---|
156 | n_opt=2; |
---|
157 | else |
---|
158 | if isstr(varargin{2}), |
---|
159 | levels=[-7000:1000:-1000 000:1000:5000]; |
---|
160 | n_opt=2; |
---|
161 | else |
---|
162 | levels=varargin{2}; |
---|
163 | n_opt=3; |
---|
164 | end; |
---|
165 | end; |
---|
166 | end; |
---|
167 | |
---|
168 | topo=values(1:latdec:end,1:lngdec:end); |
---|
169 | |
---|
170 | if all(levels<0), |
---|
171 | topo=-topo; |
---|
172 | levels=-levels; |
---|
173 | end; |
---|
174 | |
---|
175 | hold on; |
---|
176 | switch optn, |
---|
177 | case 'contour', |
---|
178 | [values,longs]=m_contour(lgs,lts,topo,levels); |
---|
179 | case 'contourf', |
---|
180 | [values,longs]=m_contourf(lgs,lts,topo,levels); |
---|
181 | end; |
---|
182 | set(longs,'tag','m_etopo2'); |
---|
183 | if n_opt<length(varargin), |
---|
184 | for l=1:length(longs), set(longs(l),varargin{n_opt:end}); end; |
---|
185 | end; |
---|
186 | |
---|
187 | m_coord(Currentmap.name); |
---|
188 | |
---|
189 | else |
---|
190 | |
---|
191 | [longs,lats]=meshgrid(lgs,lts); |
---|
192 | |
---|
193 | end; |
---|
194 | |
---|
195 | |
---|
196 | if nargout==0 |
---|
197 | clear values longs lats |
---|
198 | end; |
---|