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

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/mtrack.m

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

Initial import of Stark code.

Line 
1 function mtrack(X,Y,navTimes,varargin);
2 %MTRACK Draw a trackline on a figure
3 %
4 %   MTRACK draws navigation tracklines on a figure. The trackline
5 %   itself is optionally annontated with tick marks, time labels, and
6 %   date labels.
7 %
8 %   MTRACK is a modification of M_MAP's M_TRACK, that does not
9 %   project the lon/lat coordinates into the map projection coordinate
10 %   system.  It draws directly in (x,y), which may of course be (lo,la).
11 %   MTRACK tags objects with 'mtrack*' instead of 'm_track*'. 
12 %   See M_MAP's M_TRACK for options, and DATENUM (part of the timefun
13 %   toolbox from RPS) for computing navigation times.
14 %
15 %   MTRACK (lon,lat) draws just a plain line. lon&lat are in decimal
16 %   degrees, +N, -S, +E, -W.
17 %
18 %   MTRACK (lon,lat,navtimes) draws a line, with tick marks every
19 %   hour, time labels every four hours, and date labels every twelve
20 %   hours. navtimes is in MatLab "serial date numbers," representing the
21 %   number of days since January 1, 0000. By convention, ticks and
22 %   time labels are drawn on the starboard side, dates on the port.
23 %
24 %   MTRACK (lon,lat,navtime, 'string', property/value pairs) can be
25 %   used to change tick marks, time and date label properties. Allowable
26 %   combinations are:
27 %
28 %   'ticks'             tickmark interval in minutes, default=60
29 %   'times'             time label interval in minutes, default=240
30 %   'dates'             date label interval in hours, default=12
31 %   'timef[ormat]'      format of time string, see datestr(), default=15
32 %   'datef[ormat]'      format of date string, see datestr(), default=2
33 %   'color'             color of track/labels, default is black
34 %   'linew[idth]'       width of trackline, default is current
35 %   'lines[tyle]'       style of line, default is solid line
36 %   'fonts[ize]'        size of font, default is current
37 %   'fontn[ame]'        name of font, default is current
38 %   'fontw[eight]'      weight of font, default is current
39 %      'clip',         'on' or 'off' (clipping to map)
40 %
41 %   time labels need to be whole multiples of tick intervals. date
42 %   labels need to be whole multiples of time labels. using '0' for
43 %   any value will tick/label all points. using a negative number
44 %   will suppress tick/label.
45
46 % m_track.m, Peter Lemmond, peter@whoi.edu 13/Nov/98
47 % RP - 14/Nov/98 - corrected angle for first label, added tags, added CLIP
48 %                  options, made labels always face upwards
49 % This is a modification of m_track.m that does not need the projection
50 % specifications.  It draws directly in data coordinates, be it meters
51 % or Lo/La/.  BOB 19 Apr, 99.
52
53
54
55 numinputs = nargin;                     % save this
56
57 TICKS = 60;                             % default of 60 minute ticks
58 TIMES = 240;                            % default of 4 hour times
59 DATES = 720;                            % default of 12 hour dates
60 TIMEF = 15;                             % default of HH:MM
61 DATEF = 2;                              % default of mm/dd/yy
62 COLOR = 'k';                            % default is black
63 LINES = '-';                            % default is solid line
64 LINEW = get(gca,'linewidth');           % default is current width
65 FONTS = get(gca,'fontsize');            % default is current fontsize
66 FONTN = get(gca,'fontname');            % default is current fontname
67 FONTW = get(gca,'fontweight');          % default is current fontname
68 CLIP='on';
69
70 MINSPERDAY = 1440;
71
72 % need at least X & Y vectors
73
74 if numinputs < 2
75   disp ('Need at least X & Y vectors!');
76   return;
77 else
78   l=length(Y);
79   m=length(X);
80   if (l ~= m)
81     disp ('long and lat vectors must be the same length!');
82     return;
83   end;
84 end;
85
86
87 % look at any options
88
89 k=1;
90 while k<length(varargin),
91   optn=[lower(varargin{k}) '   '];
92   switch optn(1:5),
93     case 'ticks',
94       TICKS=varargin{k+1};
95     case 'times',
96       TIMES=varargin{k+1};
97     case 'dates',
98       DATES=varargin{k+1};
99     case 'timef',
100       TIMEF=varargin{k+1};
101     case 'datef',
102       DATEF=varargin{k+1};
103     case 'color',
104       COLOR=varargin{k+1};
105     case 'linew',
106       LINEW=varargin{k+1};
107     case 'lines',
108       LINES=varargin{k+1};
109     case 'fontn',
110       FONTN=varargin{k+1};
111     case 'fontw',
112       FONTW=varargin{k+1};
113     case 'fonts',
114       FONTS=varargin{k+1};
115     case 'clip ',
116       CLIP=varargin{k+1};
117   end;
118   k=k+2;
119 end;
120
121 DATES = DATES*60;                       % want things in minutes
122
123 if (TICKS < 0 )
124   numinputs = 2;                        % w/o ticks, just do line
125 elseif (TIMES < 0)
126   TIMES = realmax;
127   DATES = realmax;
128 elseif (DATES < 0)
129   DATES = realmax;
130 end
131
132
133 if TICKS == 0
134   tickAll = 1;
135   TICKS = eps;
136 else
137   tickAll = 0;
138 end;
139
140 if TIMES == 0
141   timeAll = 1;
142   TIMES = eps;
143 else
144   timeAll = 0;
145 end;
146
147 if DATES == 0
148   dateAll = 1;
149   DATES = eps;
150 else
151   dateAll = 0;
152 end;
153
154 line(X,Y,'linest',LINES,'linewi',LINEW,'color',COLOR,'tag','mtrack_line','clip',CLIP);
155
156 % we're done if only lon/lat given
157
158 if (numinputs < 3)
159   return;
160 end;
161
162 n=length(navTimes);
163 if (l ~= n)
164   disp('X, Y, and navtimes vectors must be same length');
165   return;
166 end;
167
168
169 % really don't want to loop, but ...
170
171 lastTick = -1;
172 lastTime = -1;
173 lastDate = -1;
174
175 lastLat = Y(1)-(Y(2)-Y(1));
176 lastLon = X(1)-(X(2)-X(1));
177
178 navMinutes = round(navTimes*MINSPERDAY);% convert to whole minutes
179                                         % round instead of floor - RP 15/11/98
180 for i=1:n
181
182   if (~(rem(navMinutes(i),TICKS)) | tickAll)
183     dlat = Y(i) - lastLat;
184     dlon = X(i) - lastLon;
185     angle = atan2(dlat,dlon)*180/pi - 90;
186    
187     % Make sure labels always face up.
188     if abs(angle)<90,
189        leadstr=' ';tailstr='';ang_off=0;tmlab='left';datlab='right';
190     else
191        leadstr='';tailstr=' ';ang_off=180;tmlab='right';datlab='left';
192     end;
193    
194     if ((navMinutes(i) ~= lastTick) | tickAll)
195       text(X(i), Y(i), '-', 'vertical', 'middle', 'horizontal', 'left', ...
196           'color', COLOR, 'fontsize', FONTS, 'fontname', FONTN,...
197           'fontweight', FONTW, 'rotation', angle,'tag','mtrack_tick');
198       lastTick=navMinutes(i);
199     end
200    
201     if (~(rem(navMinutes(i),TIMES)) | timeAll)
202       if ((navMinutes(i) ~= lastTime) | timeAll)
203         text(X(i), Y(i), [leadstr leadstr datestr(navTimes(i),TIMEF) tailstr tailstr], ...
204             'color', COLOR, 'fontsize', FONTS, 'fontname', FONTN, 'fontweight', FONTW, ...
205             'vertical', 'middle', 'horizontal', tmlab, 'rotation', angle+ang_off,...
206             'tag','mtrack_time');
207         lastTime=navMinutes(i);
208       end
209      
210       if (~(rem(navMinutes(i),DATES)) | dateAll)
211         if ((navMinutes(i) ~= lastDate) | dateAll)
212           text(X(i), Y(i), [tailstr datestr(navTimes(i),DATEF) leadstr], ...
213               'color', COLOR, 'fontsize', FONTS, 'fontname', FONTN, 'fontweight', FONTW, ...
214               'vertical', 'middle', 'horizontal', datlab, 'rotation', angle-ang_off,...
215               'tag','mtrack_date');
216           lastDate=navMinutes(i);
217         end
218        
219       end
220     end
221   end
222  
223   lastLat = Y(i);
224   lastLon = X(i);
225  
226 end
227
228
229
Note: See TracBrowser for help on using the browser.