%
% routine to put lat/lon ticks and labels in degrees/minutes
%
% function lllabel(inta,into,mila,mala,milo,malo);
%
%  where into and inta are the desired intervals of long & lat in minutes
%        mila and mala are the desired min & max latitudes
%        milo and malo are the desired min & max longitudes
%
%   (ALL PARAMETERS are optional)
%
function lllabel(inta,into,mila,mala,milo,malo);
%   
ax=axis;

if nargin<6;

% find a nice "into" to space labels and "milo" to start
  milo=floor(ax(1));
  malo=ax(2)+(ax(2)-ax(1))/10;
  rang=malo-milo;
  if rang>=.75&rang<1.5;
    into=15;
    if rem(milo,1)>=.25&rem(milo,1)<0.5;
      milo=floor(milo)+0.25;
    elseif rem(milo,1)>=0.5&rem(milo,1)<0.75;
      milo=floor(milo)+0.5;
    elseif rem(milo,1)>=0.75;
      milo=floor(milo)+0.75;
    else;
      milo=floor(milo);
    end;
  elseif rang>=1.5&rang<3;
    into=30;
    if rem(milo,1)>=0.5;
      milo=floor(milo)+0.5;
    else;
      milo=floor(milo);
    end;
  elseif rang<.75|rang>=3;
    into=round(((ax(2)-ax(1))/4)*60);
  end;

% find a nice "inta" to space lat labels and "mila" to start lat
  mila=floor(ax(3));
  mala=ax(4)+(ax(4)-ax(3))/10;
  rang=mala-mila;
  if rang>=.75&rang<1.5;
    inta=15;
    if rem(mila,1)>=.25&rem(mila,1)<0.5;
      mila=floor(mila)+0.25;
    elseif rem(mila,1)>=0.5&rem(mila,1)<0.75;
      mila=floor(mila)+0.5;
    elseif rem(mila,1)>=0.75;
      mila=floor(mila)+0.75;
    else;
      mila=floor(mila);
    end;
  elseif rang>=1.5&rang<3;
    inta=30;
    if rem(mila,1)>=0.5;
      mila=floor(mila)+0.5;
    else;
      mila=floor(mila);
    end;
  elseif rang<.75|rang>=3;
    inta=round(((ax(4)-ax(3))/4)*60);
  end;
end;


% find the "inta" minute intervals in latitude
first=ceil((mila-floor(mila))/(inta/60))*inta;
yt=[floor(mila)+(first/60):inta/60:mala];
for i=1:length(yt);
  minu=floor(first+i*inta-inta);
  if rem(minu,60)<10;
    if rem(minu,60)==0;
 ytl(i,:)=[num2str(floor(mila+floor(minu/60))),' N   '];
    else;
 ytl(i,:)=[num2str(floor(mila+floor(minu/60))),' ',num2str(rem(minu,60)),'''N '];
    end;
  else;
    ytl(i,:)=[num2str(floor(mila+floor(minu/60))),' ',num2str(rem(minu,60)),'''N'];
  end;
end;

% find the "into" minute intervals in longitude
clear xtl;
first=floor((milo-floor(milo))/(into/60))*into-60;
if first==-60;first=0;end;
xt=[ceil(milo)+(first/60):into/60:malo];
for i=1:length(xt);
  lon1=abs(fix(xt(i)));
  lonmin=round((abs(xt(i))-abs(fix(xt(i))))*60);
  if lonmin==60;lonmin=0;end;
  if lonmin<10;
    if lonmin==0;
      xtl(i,:)=[num2str(lon1),' W   '];
    else;
      xtl(i,:)=[num2str(lon1),' ',num2str(lonmin),'''W '];
    end;
  else;
    xtl(i,:)=[num2str(lon1),' ',num2str(lonmin),'''W'];
  end;
end;
%set(0,'defaulttextfontsize',6);
set(gca,'fontsize',10,'xtick',xt,'xticklabels',xtl);
set(gca,'fontsize',10,'ytick',yt,'yticklabels',ytl);

xlabel('Longitude');
ylabel('Latitude');
