function plot_fld (long,latg,Fld,clvls);
%
% function plot_fld (long,latg,Fld,clvls);
%
% This script creates a color map of
% the given field.

%-------------------------------------------------------------------------------
% Determine MATLAB version number.
%-------------------------------------------------------------------------------

vstr = version;
vnum = str2num(vstr(1));

%-------------------------------------------------------------------------------
% Determine if the EXTCONTOUR package of Rich Pawlowicz is in the MATLAB path.
%-------------------------------------------------------------------------------

if (vnum<5),
   use_ext = exist('extcontour') == 2;
 else
   use_ext = 0;
end;

%-------------------------------------------------------------------------------
% Create new plot.
%-------------------------------------------------------------------------------

figure;

%-------------------------------------------------------------------------------
% Select contour clvls to contain entire range of the field.
% Prevents holes in the color-filled contour map.  Only for EXTCONTOUR.
%-------------------------------------------------------------------------------

%if (use_ext | (vnum>4)),
%   clvls=nice(extrem(Fld),4);
%end;

%-------------------------------------------------------------------------------
% Draw the color-filled contour map.
%-------------------------------------------------------------------------------

if ( (vnum>4) & (diff(extrem(Fld))>0) ),

   [C,H,CF] = contourf (long,latg,Fld,clvls); ...
   set(gca,'XLim',[min(min(long)) max(max(long))], ...
           'YLim',[min(min(latg)) max(max(latg))], ...
           'FontName','Times','FontSize',14,'Box','On', ...
           'DataAspectRatio',[1 cos(mean(latg(:))*pi/180) 1]);
%   colormap(gjet(length(clvls)+1));
   nclr = length(clvls)+1;
   cmp1 = gjet(nclr);
   cmp2 = cool(nclr);
   cmp3 = hot(nclr);
   cmp4 = bone(nclr);
%   cmap = [cmp1(1:4:nclr,:); cmp2(2:4:nclr,:); ...
%           cmp3(3:4:nclr,:); cmp4(4:4:nclr,:)];
   cmap = [cmp4(4:4:nclr,:); cmp3(3:4:nclr,:); ...
           cmp2(2:4:nclr,:); cmp1(1:4:nclr,:)];
%   clrind = [(1:4:nclr) (2:4:nclr) (3:4:nclr) (4:4:nclr)];
%   colormap(cmap(clrind,:)); ...
   colormap(cmap); ...
   indx = 1:length(clvls);
   for n = 1:length(H),
      wk = get(H(n),'CData');
      wk = interp1 (clvls,indx,wk);
      wk = min([max([wk 1]) length(indx)]);
%      set(H(n),'CData',wk,'EdgeColor','k','LineWidth',1/24);
      set(H(n),'CData',wk,'EdgeColor','none');
   end;
%   h=colorbarf (C,H); ...
   h=colorbarclvl (C,H,clvls); ...
   set(h,'FontName','Times','FontSize',14);
   clear C H CF h n;

 elseif ( use_ext & (diff(extrem(Fld))>0) ),

   extcontour(long,latg,Fld,'fill'); ...
   set(gca,'XLim',[min(min(long)) max(max(long))], ...
           'YLim',[min(min(latg)) max(max(latg))], ...
           'FontName','Times', ...
           'AspectRatio',[1 cos(mean(mean(latg))*pi/180)]);
   caxis([clvls(1) clvls(length(clvls))]); ...
   colormap(jet(length(clvls)-1)); ...
   colorbar;

 elseif (diff(extrem(Fld))>0),

   pcolor (long,latg,Fld,-topo); ...
   set(gca,'XLim',[min(min(long)) max(max(long))], ...
           'YLim',[min(min(latg)) max(max(latg))], ...
           'FontName','Times', ...
           'AspectRatio',[1 cos(mean(mean(latg))*pi/180)]);
   shading interp; ...
   colormap (jet); ...
   colorbar;

 else

   [ny nx] = size(long);
   plot (long( 1, :),latg( 1, :),'k', ...
         long( :,nx),latg( :,nx),'k', ...
         long(ny, :),latg(ny, :),'k', ...
         long( :, 1),latg( :, 1),'k')
   set (gca,'XLim',[min(min(long)) max(max(long))], ...
            'YLim',[min(min(latg)) max(max(latg))], ...
            'FontName','Times','FontSize',14,'Box','On', ...
            'DataAspectRatio',[1 cos(mean(mean(latg))*pi/180) 1]);
   text (mean(long(:)),mean(latg(:)), ...
         ['Constant Value ',num2str(Fld(1))], ...
         'FontName','Times', ...
         'FontSize',18, ...
         'HorizontalAlignment','Center', ...
         'VerticalAlignment','Middle');
   clear nx ny;

end;
