function plotland(COL,RES,LON,LAT);
% PLOTLAND (COL, RES, LON, LAT)  plot world map
%    COL   colour, defaults to .8*[1 1 1]
%          or specify a linetype, such as 'k-' for a contour plot
%    RES   specify resolution: 1=  1-deg; 2= .5-deg;  3= .33-deg;
%                              4=.25-deg; 6=.17-deg; 12=.083-deg;
%    LON   longitude indices, defaults to  1/2/RES    :1/RES:360
%    LAT   latitude indices,  defaults to (1/2/RES-90):1/RES: 90

% require files tbase*.mat generated using following:
% for res=[1 2 3 4 6 12]
%   subsamp=12/res;                    % resolution is subsamp/12 deg
%   [map,maplegend]=tbase(subsamp);
%   lat=(-90+subsamp/24):(subsamp/12):(90-subsamp/24);
%   lon=(-180+subsamp/24):(subsamp/12):(180-subsamp/24);
%   ix=find(lon<0); lon(ix)=lon(ix)+360;
%   [lon ix]=sort(lon); map=map(:,ix);
%   eval(['save tbase' int2str(res) ' lon lat map'])
% end

if nargin > 3
  if min(LAT)<-90 | max(LAT)>90
    error('latitude out of range')
  end
end

if nargin > 2 
  if min(LON)<(RES/2-360) | max(LON)>(720-RES/2)
    error('longitude out of range')
  end
end

if nargin < 2
  RES=1;
else
  if all(RES~=[1 2 3 4 6 12])
    error('RES out of range')
  end
end

fname=['tbase' int2str(RES) '.mat'];
if exist(fname,'file')
  disp('... loading landmask')
  eval(['load ' fname])
else
  error(['File ' fname '.mat not found'])
end

if nargin < 1, COL=.8*[1 1 1]; end

if nargin < 3, LON=lon; end

if nargin < 4, LAT=lat; end

map=[map(1,:); map;map(length(lat),:)];
lat=[-90 lat 90];

if min(LON)<min(lon) & max(LON)>max(lon)
  map=[map map map];
  lon=[lon-360 lon lon+360];
elseif min(LON)<min(lon)
  map=[map map];
  lon=[lon-360 lon];
elseif max(LON)>max(lon)
  map=[map map];
  lon=[lon lon+360];
end

map=interp2(lon,lat',map,LON,LAT');
ix=find(map>=0); map(ix)=ones(size(ix));
ix=find(map<0); map(ix)=zeros(size(ix));

hold on
if isstr(COL)
  if nargin < 2, lt=2; end
  contour(LON,LAT,map,[1 1],COL);
else
  shadeland(LON,LAT,map,COL);
end
