function m_grid(varargin);
% M_GRID make a grid on a map.
% M_GRID('parameter','value',...) with any number (or no)
% optional parameters is used to draw a lat/long grid for a
% previously initialized map projection.
%
% The optional parameters allow the user
% to control the look of the grid. These parameters are listed
% by M_GRID('get'), with defualt parameters in M_GRID('set');
%
% see also M_PROJ
% Rich Pawlowicz (rich@ocgy.ubc.ca) 2/Apr/1997
%
% This software is provided "as is" without warranty of any kind. But
% it's mine, so you can't sell it.
%
% 19/6/97 - set visibility of titles and so forth to 'on' (they
% default to 'off' when axes visibility is turned off)
% 2/11/97 - for M5.1, the old way of making the patch at the bottom (i.e.
% by rearranging the axes children) instead causes matlab to lose
% track of titles. Try a different fix.
% 11/01/98 - Added way of making longitude lines cut off to prevent crowding near poles (you have
% to specify a vector for allowabale latitudes for this to work).
% 16/02/98 - Made a little fudge to allow the user to fully specify grid location
% without getting the edge points. It doesn't quite work if only *one* edge
% point is desired....but I hope it will be OK that way.
% 19/02/98 - PC-users complain about layers getting out of order! Their fault for using
% such an awful OS...however (with help from Eric Firing) I think I have
% a fix.
% 7/04/98 - Another fix to grid locations to not automatically add edge points
% (as requested by EF)
% 7/05/98 - Added 'fancy' outline box.
% 14/11/98 - Changed tag names from m_* to m_grid_*.
% 11/07/99 - Apparently fontname changing didn't work (thanks to Dave McCollum)
% 28/04/04 - Changed m_grid_color code so it works right under unix; old
% way retained for windows (ugh).
% 16/10/05 - Kirk Ireson discovered that the way to fix those annoying 'cut-throughs'
% in fancy_box was to add a 'large' zdata...so I've adapted his fix in
% fancybox and fancybox2.
% 21/11/06 - added 'backcolor'
% 16/4/07 - sorted ticklabels when user-specified (prevents an odd problem near in
% azimuthal projections).
% Note that much of the work in generating line data
% is done by calls to the individual projections -
% most of M_GRID is concerned with the mechanics of plotting
% These structures are initialized by m_proj()
global MAP_PROJECTION MAP_VAR_LIST
% Have to have initialized a map first
if isempty(MAP_PROJECTION),
disp('No Map Projection initialized - call M_PROJ first!');
return;
end;
% Otherwise we are drawing a grid!
% Set current projection to geographic
Currentmap=m_coord('set');
m_coord(MAP_PROJECTION.coordsystem.name);
% Default parameters for grid
xtick=6;
ytick=6;
xlabels=NaN;
ylabels=NaN;
gcolor='k';
gbackcolor='w'; %%get(gcf,'color');
glinestyle=':';
glinewidth=get(gca,'linewidth');
gbox='on';
gfontsize=get(gca,'fontsize');
gfontname=get(gca,'fontname');
gxaxisloc=get(gca,'xaxislocation');
gyaxisloc=get(gca,'yaxislocation');
gtickdir=get(gca,'tickdir');
gticklen=get(gca,'ticklen'); gticklen=gticklen(1);
gxticklabeldir='middle';
gyticklabeldir='end';
dpatch=5; % interpolation factor for fancy grids
% Parse parameter list for options. I really should do some
% error checking here, but...
k=1;
while k<=length(varargin),
switch lower(varargin{k}(1:3)),
case 'box',
gbox=varargin{k+1};
case 'xti',
if length(varargin{k})==5,
xtick=sort(varargin{k+1}); % Added 'sort' here for people who put things in
else % a random order near poles
xlabels=varargin{k+1};
end;
case 'yti',
if length(varargin{k})==5,
ytick=sort(varargin{k+1});
else
ylabels=varargin{k+1};
end;
case 'xla',
gxticklabeldir=varargin{k+1};
case 'yla',
gyticklabeldir=varargin{k+1};
case 'col',
gcolor=varargin{k+1};
case 'bac',
gbackcolor=varargin{k+1};
case 'lin',
switch lower(varargin{k}(1:5)),
case 'linew',
glinewidth=varargin{k+1};
case 'lines',
glinestyle=varargin{k+1};
end;
case 'fon',
switch lower(varargin{k}(1:5)),
case 'fonts',
gfontsize=varargin{k+1};
case 'fontn',
gfontname=varargin{k+1};
end;
case 'xax',
gxaxisloc=varargin{k+1};
case 'yax',
gyaxisloc=varargin{k+1};
case 'tic',
switch lower(varargin{k}(1:5)),
case 'tickl',
gticklen=varargin{k+1};
case 'tickd',
gtickdir=varargin{k+1};
end;
case {'get','usa'},
disp(' ''box'',( ''on'' | ''fancy'' | ''off'' )');
disp(' ''xtick'',( num | [value1 value2 ...])');
disp(' ''ytick'',( num | [value1 value2 ...])');
disp(' ''xticklabels'',[label1;label2 ...]');
disp(' ''yticklabels'',[label1;label2 ...]');
disp(' ''xlabeldir'', ( ''middle'' | ''end'' )');
disp(' ''ylabeldir'', ( ''end'' | ''middle'' )');
disp(' ''ticklen'',value');
disp(' ''tickdir'',( ''in'' | ''out'' )');
disp(' ''color'',colorspec');
disp(' ''backcolor'',colorspec');
disp(' ''linewidth'', value');
disp(' ''linestyle'', ( linespec | ''none'' )');
disp(' ''fontsize'',value');
disp(' ''fontname'',name');
disp(' ''XaxisLocation'',( ''bottom'' | ''middle'' | ''top'' ) ');
disp(' ''YaxisLocation'',( ''left'' | ''middle'' | ''right'' ) ');
return;
case 'set',
disp([' box = ' gbox]);
disp([' xtick = ' num2str(xtick)]);
disp([' ytick = ' num2str(ytick)]);
disp([' ticklen = ' num2str(gticklen)]);
disp([' tickdir = ' gtickdir]);
disp([' xlabeldir = ' gxticklabeldir]);
disp([' ylabeldir = ' gyticklabeldir]);
disp([' color = ' gcolor]);
disp([' linewidth = ' num2str(glinewidth)]);
disp([' linestyle = ' glinestyle]);
disp([' fontsize = ' num2str(gfontsize)]);
disp([' fontname = ' gfontname]);
disp([' XaxisLocation = ' gxaxisloc]);
disp([' YaxisLocation = ' gyaxisloc]);
return;
end;
k=k+2;
end;
if strcmp(gbox,'fancy'),
if strcmp(MAP_VAR_LIST.rectbox,'on') | strcmp(MAP_VAR_LIST.rectbox,'circle'),
gbox='on';
warning([' No fancy outline with ''rectbox'' set to ''' MAP_VAR_LIST.rectbox '''']);
end;
end;
% Draw the plot box
[X,Y]=feval(MAP_PROJECTION.routine,'box');
if strcmp(gbox,'on');
line(X(:),Y(:),'linest','-','linewi',glinewidth,'color',gcolor,'tag','m_grid_box','clip','off');
end;
% Axes background - to defeat the inverthardcopy, I need a non-white border (the edgecolor),
% but sneakily I can set it's width to (effectively) 0 so it doesn't actually show!
% This is a very problematic part of the code. It turns out the the interaction between
% PATCH objects and CONTOURF objects does not work correctly in the Painters renderer -
% this is true in all versions up to 7.7 at least. Patches with large negative Z just
% don't get drawn under contourgroup patches.
%
% There are several possible workarounds:
%
% 1) Make sure you use the 'v6' option in contourf calls (see m_contourf.m to see
% how I have tried to do that for some versions of matlab)
% - problem: the 'v6' option is going away soon, also you may want the
% contourgroup object that the v6 option destroys.
%
% 2) Change the renderer to something else:
% set(gcf,'renderer','opengl') or
% set(gcf,'renderer','zbuffer')
% - problem: These other renderers are not available on all systems, they may also
% give less-precise results.
%
% 3) Use the painters renderer,
评论0