function best_coast(varargin)
% best_coast(varargin)
% plot coast with m_map
%
%  varargin    :  default    :   action
%              :             :   
%  resolution  :  'c'        :    crude (no advantage here, except that
%              :             :             the crude database used is
%              :             :             m_coast, which is global
%              :             :   'l' low              [-70,70] latrange
%              :             :   'i' intermediate     [-70,70] latrange
%              :             :   'h' high             [-70,70] latrange
%              :             :
%  addglobal   :   0         :     add m_coast global resolution
%              :             :    0: do not; 1: yes, do
%  usefile     :   ''        :       use low, intermediate, or high coastline
%              :             :           with this filename.  (not 
%              :             :           implimented with crude coastline)
%              :             :           (default is no file)
%  savefile    :   ''        :   save low, intermediate, or high coastline
%              :             :           with this filename.  (not 
%              :             :           implimented with crude coastline)
%              :             :           (default is no save.  Cannot save
%              :             :           if loaded from a file)
%  fill        :    'line'   :   draw a line (default)
%              :    'patch'  :   fill
%  color       :    'k'      :   do the line (or patch) with this color


%2001/12/05
%JH

cfg.usefile = '';
cfg.savefile = '';
cfg.resolution = 'i';
cfg.fill = 'line';
cfg.color = 'k';
cfg.addglobal = 0;

cfg = fillstruct(cfg, varargin);


if (~isempty(cfg.usefile))
   cfg.savefile = '';
end


if (cfg.resolution == 'c')
   m_coast(cfg.fill, cfg.color);
else

   % if file exists, use it.  if it needs to be saved, specify that.
   % comma built in at the end if necessary
   if (exist(cfg.usefile, 'file'))
      fcnstr = ['m_usercoast(', 'cfg.usefile,'];
   else
      fcnstr = sprintf('m_gshhs_%c(', cfg.resolution);
      if (~isempty(cfg.savefile))
         fcnstr = [fcnstr,'''save'', cfg.savefile, '];
      end
   end      

   
   %do not prepend this string with a comma
   if (ischar(cfg.color))
      colorstr = sprintf('''%s''', cfg.color);
   else
      colorstr = sprintf(' [%f %f %f] ', ...
                         cfg.color(1), cfg.color(2), cfg.color(3));
   end
   
   
   if (strmatch(cfg.fill, 'patch'))
      fillpair = ['''patch'''  ', '  colorstr];
   else
      fillpair = ['''color'', '    colorstr];
   end      
   

   command = [fcnstr fillpair ');']
   eval(command)
end

if cfg.addglobal
   fprintf('adding crude global coastline\n')
   fcnstr = 'm_coast(';

   if (strmatch(cfg.fill, 'patch'))
      fillpair = ['''patch'''  ', '  colorstr];
   else
      fillpair = ['''color'', '    colorstr];
   end      
   

   command = [fcnstr fillpair ');']
   eval(command)

end
