1 | function m_track(lon,lat,varargin); |
---|
2 | % M_TRACK Draw a trackline on a map |
---|
3 | % |
---|
4 | % M_TRACK draws navigation tracklines on a map. The trackline |
---|
5 | % itself is optionally annontated with tick marks, time labels, and |
---|
6 | % date labels. |
---|
7 | % |
---|
8 | % M_TRACK (lon,lat) draws just a plain line. lon&lat are in decimal |
---|
9 | % degrees, +N, -S, +E, -W. |
---|
10 | % |
---|
11 | % M_TRACK (lon,lat,navtimes) draws a line, with tick marks every |
---|
12 | % hour, time labels every four hours, and date labels every twelve |
---|
13 | % hours. navtimes is in MatLab "serial date numbers," representing the |
---|
14 | % number of days since January 1, 0000. By convention, ticks and |
---|
15 | % time labels are drawn on the starboard side, dates on the port. |
---|
16 | % |
---|
17 | % M_TRACK (lon,lat,navtime, 'string', property/value pairs) can be |
---|
18 | % used to change tick marks, time and date label properties. Allowable |
---|
19 | % combinations are: |
---|
20 | % |
---|
21 | % 'ticks' tickmark interval in minutes, default=60 |
---|
22 | % 'times' time label interval in minutes, default=240 (4hrs) |
---|
23 | % 'dates' date label interval in minutes, default=720 (12hrs) |
---|
24 | % 'timef[ormat]' format of time string, see datestr(), default=15 |
---|
25 | % 'datef[ormat]' format of date string, see datestr(), default=2 |
---|
26 | % 'color' color of track/labels, default is black |
---|
27 | % 'linew[idth]' width of trackline, default is current |
---|
28 | % 'lines[tyle]' style of line, default is solid line |
---|
29 | % 'fonts[ize]' size of font, default is current |
---|
30 | % 'fontn[ame]' name of font, default is current |
---|
31 | % 'clip' 'on' or 'off' (clipping to map) |
---|
32 | % 'orien[t]' label orientation, 'true' or 'upright', default='true' |
---|
33 | % |
---|
34 | % time labels need to be whole multiples of tick intervals. date |
---|
35 | % labels need to be whole multiples of time labels. using '0' for |
---|
36 | % any value will tick/label all points. using a negative number |
---|
37 | % will suppress tick/label. |
---|
38 | |
---|
39 | % m_track.m, Peter Lemmond, peter@whoi.edu 13/Nov/98 |
---|
40 | % |
---|
41 | % RP - 14/Nov/98 - corrected angle for first label, added tags, added CLIP |
---|
42 | % options, made labels always face upwards |
---|
43 | % PL - 04/Dec/98 - added orientation option, to allow labels to either |
---|
44 | % always follow heading ('true') or to always face upwards |
---|
45 | % ('upright'). changed quite a bit internally to make |
---|
46 | % faster and fix some bugs |
---|
47 | % - 23/Aug/01 - if numinputs = 2 an extra initialization statement |
---|
48 | % was needed (thanks to Dan Lowen for this fix). |
---|
49 | |
---|
50 | |
---|
51 | global MAP_PROJECTION MAP_VAR_LIST |
---|
52 | |
---|
53 | % Have to have initialized a map first |
---|
54 | |
---|
55 | if isempty (MAP_PROJECTION), |
---|
56 | disp ('No Map Projection initialized - call M_PROJ first!'); |
---|
57 | return; |
---|
58 | end; |
---|
59 | |
---|
60 | numinputs = nargin; % save this |
---|
61 | |
---|
62 | TICKS = 60; % default of 60 minute ticks |
---|
63 | TIMES = 240; % default of 4 hour times, 240 mins |
---|
64 | DATES = 720; % default of 12 hour dates, 720 minutes |
---|
65 | TIMEF = 15; % default of HH:MM |
---|
66 | DATEF = 2; % default of mm/dd/yy |
---|
67 | COLOR = 'k'; % default is black |
---|
68 | LINES = '-'; % default is solid line |
---|
69 | LINEW = get(gca,'linewidth'); % default is current width |
---|
70 | FONTS = get(gca,'fontsize'); % default is current fontsize |
---|
71 | FONTN = get(gca,'fontname'); % default is current fontname |
---|
72 | CLIP = 'on'; % default is to clip |
---|
73 | ORIEN = 'true'; % default is always follow heading |
---|
74 | |
---|
75 | MINSPERDAY = 1440; |
---|
76 | |
---|
77 | % need at least lon & lat |
---|
78 | |
---|
79 | if numinputs < 2 |
---|
80 | disp ('Need at least lon & lat vectors!'); |
---|
81 | return; |
---|
82 | else |
---|
83 | l=length(lat); |
---|
84 | m=length(lon); |
---|
85 | if (l ~= m) |
---|
86 | disp ('long and lat vectors must be the same length'); |
---|
87 | return; |
---|
88 | end; |
---|
89 | end; |
---|
90 | |
---|
91 | % check for time input. has to be the first varargin |
---|
92 | |
---|
93 | if numinputs > 2 |
---|
94 | if ischar(varargin{1}) |
---|
95 | navTimes = []; |
---|
96 | k = 1; |
---|
97 | else |
---|
98 | navTimes=varargin{1}; |
---|
99 | k = 2; |
---|
100 | end |
---|
101 | else % numinputs = 2 % Extra case courtesy Dan Lowen. |
---|
102 | navTimes = []; |
---|
103 | k = 1; |
---|
104 | end |
---|
105 | |
---|
106 | % look at any remaining options |
---|
107 | |
---|
108 | while k<length(varargin), |
---|
109 | optn=[lower(varargin{k}) ' ']; |
---|
110 | switch optn(1:5), |
---|
111 | case 'ticks', |
---|
112 | TICKS=varargin{k+1}; |
---|
113 | case 'times', |
---|
114 | TIMES=varargin{k+1}; |
---|
115 | case 'dates', |
---|
116 | DATES=varargin{k+1}; |
---|
117 | case 'timef', |
---|
118 | TIMEF=varargin{k+1}; |
---|
119 | case 'datef', |
---|
120 | DATEF=varargin{k+1}; |
---|
121 | case 'color', |
---|
122 | COLOR=varargin{k+1}; |
---|
123 | case 'linew', |
---|
124 | LINEW=varargin{k+1}; |
---|
125 | case 'lines', |
---|
126 | LINES=varargin{k+1}; |
---|
127 | case 'fontn', |
---|
128 | FONTN=varargin{k+1}; |
---|
129 | case 'fonts', |
---|
130 | FONTS=varargin{k+1}; |
---|
131 | case 'clip ', |
---|
132 | CLIP=varargin{k+1}; |
---|
133 | case 'orien', |
---|
134 | ORIEN=varargin{k+1}; |
---|
135 | end; |
---|
136 | k=k+2; |
---|
137 | end; |
---|
138 | |
---|
139 | % always want the line drawn at full resolution. |
---|
140 | |
---|
141 | [x,y] = m_ll2xy(lon,lat,'clip',CLIP); |
---|
142 | |
---|
143 | line(x,y,'clip',CLIP,'lines',LINES,'linew',LINEW,'color',COLOR, ... |
---|
144 | 'tag', 'm_track_line'); |
---|
145 | |
---|
146 | |
---|
147 | n=length(navTimes); |
---|
148 | if ~n |
---|
149 | return % no navtimes, all done |
---|
150 | elseif (l ~= n) |
---|
151 | disp('long, lat, and navtimes vectors must be same length'); |
---|
152 | return; |
---|
153 | end; |
---|
154 | |
---|
155 | if TICKS < 0 % w/o ticks, nothing more |
---|
156 | return; |
---|
157 | end |
---|
158 | |
---|
159 | % which points to tick. will interpolate to exact, whole minute values, |
---|
160 | % unless all requested |
---|
161 | |
---|
162 | if (TICKS == 0) |
---|
163 | ty = y; |
---|
164 | tx = x; |
---|
165 | ttim = navTimes; |
---|
166 | else |
---|
167 | tmp = TICKS/MINSPERDAY; |
---|
168 | i = tmp*ceil(min(navTimes)/tmp); |
---|
169 | j = tmp*floor(max(navTimes)/tmp); |
---|
170 | ttim = i:tmp:j; |
---|
171 | ty = interp1(navTimes,y,ttim,'linear'); |
---|
172 | tx = interp1(navTimes,x,ttim,'linear'); |
---|
173 | end |
---|
174 | nt = length(ttim); |
---|
175 | |
---|
176 | % where do the time labels go? |
---|
177 | |
---|
178 | if TIMES < 0 |
---|
179 | ltim=zeros(1,nt); % no time lables |
---|
180 | elseif TIMES == 0 |
---|
181 | ltim=ones(1,nt); % time label every tick |
---|
182 | else |
---|
183 | tmp=TIMES/MINSPERDAY; |
---|
184 | ltim=~(mod(ttim,tmp)); |
---|
185 | end |
---|
186 | |
---|
187 | % and date labels? |
---|
188 | |
---|
189 | if DATES < 0 |
---|
190 | dtim=zeros(1,nt); % no date labels |
---|
191 | elseif DATES == 0 |
---|
192 | dtim=ltim; % date label every time label |
---|
193 | else |
---|
194 | tmp=DATES/MINSPERDAY; |
---|
195 | dtim=~(mod(ttim,tmp)); |
---|
196 | end |
---|
197 | |
---|
198 | % since the 'rotation' attribute must be a scalar, have to loop thru |
---|
199 | % and plot everything one at a time |
---|
200 | |
---|
201 | for i=1:nt |
---|
202 | |
---|
203 | % angle for plotting. ticks are always perpendicular. will use the |
---|
204 | % point before and after this one to compute the angle |
---|
205 | |
---|
206 | dy = ty(min(nt,i+1)) - ty(max(1,i-1)); |
---|
207 | dx = tx(min(nt,i+1)) - tx(max(1,i-1)); |
---|
208 | angle = atan2(dy,dx)*180/pi - 90; |
---|
209 | |
---|
210 | % go ahead and tick here |
---|
211 | |
---|
212 | text(tx(i),ty(i),'-', 'vertical', 'middle', 'horizontal', 'left', ... |
---|
213 | 'color', COLOR, 'fontsize', FONTS, 'fontname', FONTN, ... |
---|
214 | 'clip',CLIP,'rotation', angle,'tag','m_track_tick'); |
---|
215 | |
---|
216 | % maybe time label here? |
---|
217 | |
---|
218 | if ltim(i) |
---|
219 | |
---|
220 | % make label at desired orientation |
---|
221 | |
---|
222 | if ((abs(angle) < 90) | ~strcmp(ORIEN,'upright')) |
---|
223 | leadstr = ' '; |
---|
224 | tailstr = ''; |
---|
225 | ang_off = 0; |
---|
226 | tmlab = 'left'; |
---|
227 | datlab = 'right'; |
---|
228 | else |
---|
229 | leadstr =''; |
---|
230 | tailstr =' '; |
---|
231 | ang_off =180; |
---|
232 | tmlab ='right'; |
---|
233 | datlab ='left'; |
---|
234 | end |
---|
235 | |
---|
236 | % go ahead and plot the time |
---|
237 | |
---|
238 | text(tx(i),ty(i), ... |
---|
239 | [leadstr leadstr datestr(ttim(i),TIMEF) tailstr tailstr], ... |
---|
240 | 'color', COLOR, 'fontsize', FONTS, 'fontname', FONTN, ... |
---|
241 | 'vertical', 'middle', 'horizontal', tmlab, 'rotation', ... |
---|
242 | angle+ang_off, 'clip', CLIP, 'tag','m_track_time'); |
---|
243 | |
---|
244 | |
---|
245 | % maybe date label here? |
---|
246 | |
---|
247 | if dtim(i) |
---|
248 | |
---|
249 | text(tx(i), ty(i), ... |
---|
250 | [tailstr datestr(ttim(i),DATEF) leadstr], ... |
---|
251 | 'color', COLOR, 'fontsize', FONTS, 'fontname', FONTN, ... |
---|
252 | 'vertical', 'middle', 'horizontal', datlab, 'rotation', ... |
---|
253 | angle-ang_off, 'clip', CLIP, 'tag','m_track_date'); |
---|
254 | |
---|
255 | end % end of date labelling |
---|
256 | end % end of time labelling |
---|
257 | end % end of ticking |
---|
258 | |
---|