function y=plotstate(long,lat,state,s,flag)
% Y=PLOTSTATE(LONG,LAT,STATE,CI,FLAG)
% contours a state vector (005C)
%
% STATE  is a vector representing coarse state
% CI     contour interval
% FLAG   0 default
%        1 use extcontour

if nargin < 5, flag=0; end
if nargin < 4, s=0; end

x=reshape(state,length(lat),length(long));
[lat,long,x]=coarse2fine(lat,long,x,64,128,8);
long=long(:);lat=lat(:);
plong=[(long(1)-8*(long(2)-long(1)):long(2)-long(1):2*long(1)-long(2))'; long];
plat=[(lat(1)-8*(lat(2)-lat(1)):lat(2)-lat(1):2*lat(1)-lat(2))'; lat];
x=[x(length(lat)-7:length(lat),:);x];
x=[x(:,length(long)-7:length(long)) x];

if flag==0

  if s==0, c=cntoura(plong,plat,x);
  else c=cntoura(plong,plat,x,4,[setstr(176) 'C'],s); end

elseif flag==1
    
  tmp=get (gca,'position');
  if tmp(4) > .8        % 1 vertical plot
    contour_label_interval = 160;
  else                  % more than 1 vertical plot
    contour_label_interval = 80;
  end

  if length(s) == 1
    cs=((ceil(mmin(x)/s)-.5)*s):s:(floor(mmax(x)/s+.5)*s);
    cs=cs(find(cs>mmin(x)&cs<mmax(x)));
  else
    cs = s;
  end
  
  ax=axis;
  ix=find(plong>=ax(1)&plong<=ax(2));
  if ix(1)>1, ix=[ix(1)-1;ix]; end
  if length(ix)<length(plong), ix=[ix;ix(length(ix))+1]; end
  iy=find(plat>=ax(3)&plat<=ax(4));
  if iy(1)>1, iy=[iy(1)-1;iy]; end
  if length(iy)<length(plat), iy=[iy;iy(length(iy))+1]; end
  [c h] = extcontour(plong(ix),plat(iy),x(iy,ix),cs, ...
      'fill','label', contour_label_interval,'fontsize',8);
  negdash(c,h);

else
  error('illegal argument flag for plotstate')
end
