params
if ~exist('templot.mat','file') || ~exist('nt','var')
    setplot;
end
load templot
clf
colormap('default')
colormap(trackcolormap)
vcolor=colormap;
if strcmp(cbath,'n') && strcmp(ctopo,'y')
   colormap(topocolor)
else
   colormap(bathcolor)
end   
if cres == 0 && strcmp(ctopo,'y') && strcmp(tfill,'y')
   uc=colormap;
   topocolor=[landcolor;uc];
   colormap(topocolor); 
end   

if strcmp(mapmode,'auto')
   delcrit=15;
   if (max(max(x))-min(min(x)))<delcrit
      dellong=dellong+delcrit-max(max(x))+min(min(x));
   end   
   xmin=min(min(x))-dellong;
   xmax=max(max(x))+dellong;
   ymin=min(min(y))-dellat;
   ymax=max(max(y))+dellat;
end   
%
clf('reset')
axesm('MapProjection',projection,'MapLatLimit',[ymin ymax],'MapLonLimit',[xmin xmax], ...
    'fontname',axisfont,'fontsize',axisfontsize,'fontweight',axisfontweight,'labelrotation','on', ...
    'frame','on','ffacecolor',oceancolor,'flinewidth',1)
delx=floor((xmax-xmin)/5);
dely=floor((ymax-ymin)/5);
gridm('mlinelocation',delx,'plinelocation',dely,'mlabellocation',delx,'plabellocation',dely)
if strcmp(gridline,'none')
    gridm('off')
end
plabel('fontweight','bold'); mlabel('fontweight','bold');
axis off
setm(gca,'MLabelParallel','south')
%
geoback(xmin, xmax, ymin, ymax)
if strcmp(cspline,'y')
   a=size(x);
   b=a(1,2);
   bx=1:b;
   tint=floor(6/trackres);
   tintin=1/tint;
   bxm=1:tintin:b;
   x=spline(bx,x,bxm);
   y=spline(bx,y,bxm);
   v=spline(bx,v,bxm);
   pres=spline(bx,pres,bxm);
   vpot=spline(bx,vpot,bxm);
   shear=spline(bx,shear,bxm);
   monthm=spline(bx,monthm,bxm);
   daym=spline(bx,daym,bxm);
   hour=spline(bx,hour,bxm);
   vtrans=spline(bx,vtrans,bxm);
end   
a=size(x);
b=a(1,2);
%
% Plot tracks
%
if colorscheme == 0
    h=scatterm(y,x,11,tcolor,'filled');
elseif colorscheme == 1
   vtcolor=zeros(b,3);
   for i=1:b
       vta=(1852/3600)*v(i);
         if vta < 33
            vtcolor=vcolor(1,:);
         elseif vta >= 33 && vta < 45
            vtcolor=vcolor(round(0.2*qcolor),:);
         elseif vta >= 45 && vta < 54.4
            vtcolor=vcolor(round(0.47*qcolor),:);
         elseif vta >= 54.4 && vta < 62.4
            vtcolor=vcolor(round(0.6*qcolor),:);
         elseif vta >= 62.4 && vta < 69.5
            vtcolor=vcolor(round(.77*qcolor),:);
         else
            vtcolor=vcolor(round(0.95*qcolor),:);
         end
   end  
   h=scatterm(y,x,11,vtcolor,'filled');
else
   h=scatterm(y,x,11,v,'filled');
end  
if strcmp(dplot,'y')  
    offset=zeros(1,bd);
    clear ul vl
if bd > 1   
    ul=zeros(1,bd); 
    vl=zeros(1,bd);
   for kl=2:bd-1
      ul(kl)=0.5*(xd(kl+1)-xd(kl-1));
      vl(kl)=0.5*(yd(kl+1)-yd(kl-1));
   end
   ul(1)=4*(x(2)-x(1));
   vl(1)=4*(y(2)-y(1));
   ul(bd)=4*(x(b)-x(b-1));
   vl(bd)=4*(y(b)-y(b-1));
else
   ul(1)=x(2)-x(1);
   vl(1)=y(2)-y(1);
end   
for kl=1:bd
   offset(kl)=-0.2;
   if day(kl)>9
      offset(kl)=-0.5;
   end
end   
vabs=0.001+sqrt(ul.^2+vl.^2);
mfactorx=(xmax-xmin)/30;
mfactory=(ymax-ymin)/30;
dx=mfactorx.*textdfactor.*((vl./vabs)+offset);
dy=mfactory.*textdfactor.*(-ul./vabs);
xdb=xd+dx;
ydb=yd+dy;
g=textm(ydb,xdb,date);
set(g,'fontname',gfont,'fontweight',gfontweight,'fontsize',textfontsize,'color',textcolor)
end
ua=x(a(1,2))-x(a(1,2)-1);
va=y(a(1,2))-y(a(1,2)-1);
uabs=sqrt(ua^2+va^2)+0.001;
scalef=sqrt(mfactorx^2+mfactory^2);
ua=2*ua*scalef/uabs;
va=2*va*scalef/uabs;
xq=x(a(1,2));
yq=y(a(1,2));
g1=quiverm(yq,xq,0.8*va,0.8*ua,0);
set(g1,'linewidth',thick)
set(g1,'color',lc)
if strcmp(cplot,'y')
   plotm(yd,xd,'.','color',ccol,'MarkerSize',csize)   
end   
title(tit3,'fontsize',11,'fontweight','bold','interpreter','none')
if colorcoded > 0 && strcmp(cbar,'y')
   if colorscheme == 1
      ucolor=[vcolor(1,:);vcolor(round(0.2*qcolor),:);vcolor(round(0.47*qcolor),:); ...
          vcolor(round(0.6*qcolor),:);vcolor(round(0.77*qcolor),:);vcolor(round(0.95*qcolor),:)];
      aa={'TS';'1';'2';'3';'4';'5';' '};
      bb=1/6;
      tstring='Category';
   else
      ucolor=vcolor;
      aa=40:10:140;
      bb=1/10;
      tstring=wunitslabel;
   end   
   colormap(ucolor);
   rts=colorbar('horiz');
   posit=get(gca,'position');
   rr=get(rts,'position');
   xl=get(gca,'xlim');
   yl=get(gca,'ylim');
   yfrac=(yl(2)-yl(1))./(xl(2)-xl(1));
   rr2=rr;
   rr2(3)=0.75.*rr(3);
   rr2(3)=max(rr2(3),0.4);
   rr2(1)=posit(1)+0.5.*posit(3)-0.5*rr2(3);
   rr2(2)=0.3.*rr2(2);
   rr2(4)=0.015;
   %
   set(rts,'position',rr2)
   set(rts,'ticklength',0)
   set(rts,'xaxislocation','bottom')
   set(rts,'fontname',gfont,'fontweight','bold')
   if colorscheme == 1
        set(rts,'xtick',0:bb:1,'xticklabel',aa)
   end     
   set(gca,'position',posit)
   set(get(rts,'xlabel'),'String',tstring,'fontweight','bold')
end
tightmap
%
% Add button to access documentation of script
%
if strcmp(Docdisp,'y')
    try
        delete(hButton)
    catch
    end    
    tempname='trplotmt';
    mname = strcat('graphics_docs/html/',tempname,'_doc.html');
    comstr=['open ',mname,';delete(hButton)'];
    labelStr = '<html><center><a href="">Doc';
    hButton = uicontrol('string',labelStr,'pos',[10,10,50,20],'callback',comstr); 
end           