function vectormaster(fctn, varargin)
%%% vector switchyard function
global XYDATA
global UVDATA
global VECFIG

switch(fctn)
   case 'setup'                % from plotmaster - orig. call
      close(gcf);
      VECFIG.webplot =  0;
      figvectorsetup;
   case 'configsetup'        % from plotmaster via gplotconfig
      close(gcf);                % or, from webmaster (Edit...) using webvspec fields
      VECFIG.webplot =  0;
      configsetup(varargin);
   case 'websetup'            % from mksecplt2, initialize "web" fields
      VECFIG.webplot = 1;
      webplotsetup
   case 'readfigvector'	     % from gplotvector (Vector fig.) - btnOK
      readfigvector;
   case 'mvecfigsetup'         % from gplotvector - btnArrow
      mvecfigsetup;
   case 'mvecfigOK'            % from mvecfig (arrows fig.) - btnOK
      mvecvbls;
   case 'xytsection'           % from gplotvector - btnXYTzoom
      xytsection;
   case 'dprange'              % from gplotvector - chkdprange
      fixtitle;
   case 'calendar'             % from gplotvector - chkcalendar
      fixtitle;
   case 'decimal'              % from gplotvector - chkdecimal
      fixtitle;
   case 'mindepth'             % from gplotvector - popupdepth1
      pd1 = findobj(gcbf,'tag','popupdepth1');
      pd2 = findobj(gcbf,'tag','popupdepth2');
      pd1val = get(pd1,'value');
      set(pd2,'value',pd1val);
      fixtitle;
   case 'maxdepth'             % from gplotvector - popupdepth2
      pd1 = findobj(gcbf,'tag','popupdepth1');
      pd2 = findobj(gcbf,'tag','popupdepth2');
      pd1val = get(pd1,'value');
      pd2val = get(pd2,'value');
      if pd2val < pd1val
         set(pd1,'value',pd2val);
         msg = sprintf('Max. must exceed Min.  \n\nSet Min. first.  ');
         noticeOK(msg);
      end
      fixtitle;
   case 'moreboundaries'           % from gplotvector - popupproj
      bbh = findobj(gcbf,'tag','popupproj');
      pjval = get(bbh,'value');
      pjstr = get(bbh,'string');
      VECFIG.projection = pjstr{pjval};
      if strcmp(VECFIG.projection, 'More...') 
         newstring = {'Stereographic';...
               'Orthographic';...
               'Azimuthal Equal-area';...
               'Azimuthal Equidistant';...
               'Gnomonic';...
               'Satellite';...
               'Albers Equal-Area Conic';...
               'Lambert Conformal Conic';...
               'Mercator';...
               'Miller Cylindrical';...
               'Equidistant Cylindrical';...
               'Oblique Mercator';...
               'Transverse Mercator';...
               'Sinusoidal';...
               'Gall-Peters';...
               'Hammer-Aitoff';...
               'Mollweide';...
               'UTM'};
         set(bbh,'string', newstring);
         VECFIG.moreproj = 1;
      else
         disp('  ');
         disp(' Projection Features');
         m_proj('get',VECFIG.projection);
         msg = sprintf('See Matlab window for parameters. \nUse [Customize Map Parameters...] if nec');
         noticeOK(msg);
      end
      return
   case 'boundaries'           % from gplotvector - btnProj (Parameters...)
      VECFIG.btntype = 'bounds';
      bbh = findobj(gcbf,'tag','popupproj');
      pjval = get(bbh,'value');
      pjstr = get(bbh,'string');
      VECFIG.projection = pjstr{pjval};
      paramfig;
      load_param_defaults;
   case 'coast'                % from gplotvector - btnCoast
      VECFIG.btntype = 'coast';
      notestr = sprintf('\nThe "coast" can be modified with\nMatlab "patch" parameters ...');
      noticeOK(notestr);
      paramfig;
      load_param_defaults;
   case 'grid'                 % from gplotvector - btnGrid
      VECFIG.btntype = 'grid';
      noticeOK('See Matlab window for parameters.  ');
      hhhide = figure;
      set(hhhide,'visible','off');
      m_proj('merc');
      disp('  ');
      disp(' Grid Features');
      m_grid('get');
      close;
      paramfig;
      load_param_defaults;
   case 'addparams'            % from paramfig - btnOK
      addparams;
   case 'savenow'              % from gplotvector - btnSave
      cnffs = findobj(gcf,'tag','txtboxsavepath');
      pname = get(cnffs,'string');
      VECFIG.savepath = pname;
      cnffs = findobj(gcf,'tag','txtboxsavefn');
      fname = get(cnffs,'string');
      if isempty(findstr(fname, 'cfg'))
         msg = sprintf('\nOnly files with "cfg" in name \ncan be recoved. ');
         noticeOK(msg)
         return
      end
      VECFIG.savefn = fname;
      fn = fullfile(pname, fname);
      save6(fn, 'VECFIG');
      vectormaster('renewloadfn')
      notice(' Finished ');
   case 'renewloadfn'      % from gplotvector - editbox for load path  
      curdir =  pwd;          % new path -> new set of potential cfg files
      rn = findobj(gcf,'tag','txtboxloadpath');
      lp = get(rn,'string');
      if exist(lp, 'dir')
         VECFIG.loadpath = lp;
      else
         noticeOK('Error in load path. ')
         return
      end
      cd(VECFIG.loadpath)
      files = what;
      str_b = files.mat;
      for i = length(str_b):-1:1
         chary = char(str_b(i));
         if isempty(findstr(chary, 'cfg'))
            str_b(i) = [];
         end
      end
      VECFIG.loadfn = str_b;
      pop = findobj(gcf,'tag','popuploadfn');
      if isempty(str_b); VECFIG.loadfn = {'None'}; end;
      cd(curdir)
      set(pop,'value',length(VECFIG.loadfn))
      set(pop,'string',VECFIG.loadfn)
   case 'loadnow'              % from gplotvector - btnLoad
      loadnow(0);    % 0=normal load, i.e layout only, data present
   case 'printfile'                % from gplotvector - toggle chkbox for print
      ckp = findobj(gcf,'tag','chkboxprint');
      if get(ckp,'value')  % may be diabling instead of activating
         pfn = findobj(gcf,'tag','txtboxprintfn');
         VECFIG.printfilefn = get(pfn,'string');
         if isempty(VECFIG.printfilefn)
            noticeOK('File name undefined')
            return
         end
      end
   case 'radiocolor'    % from mvecfig -- color type radio buttons
      n = char(varargin(1));
      ckf = findobj(gcf,'tag','chkfixedcolor');
      ckct = findobj(gcf,'tag','chktemperature');
      switch(n)
           case '1'
              set(ckct,'value',0);
              set(ckf, 'value', 1);
           case '2'
              set(ckf,'value',0);
              set(ckct, 'value', 1);
      end
   case 'radioscale'         % from mvecfig -- scale type radio buttons
      n = char(varargin(1));
      rc = findobj(gcf,'tag','radiotempcruise');
		rp = findobj(gcf,'tag','radiotempplot');
		cs = findobj(gcf,'tag','radiotempcustom');
		switch(n)
           case '1'
              set(rp,'value',0);
              set(cs,'value',0);
              set(rc,'value',1);
              VECFIG.radioscale = 1;
           case '2'
              set(rc,'value',0);
              set(cs,'value',0);
              set(rp,'value',1);
              VECFIG.radioscale = 2;
           case '3'
              set(rp,'value',0);
              set(rc,'value',0);
              set(cs,'value',1);
              VECFIG.radioscale = 3;
       end
   case 'gettempfilepath'   % from mvecfig, searching for temperature file [. . .]
      edh = findobj(gcf,'tag', 'txtboxcfile');
      currstr = get(edh, 'string');
      [uifile, uipath] = uigetfile('*','Select temperature data file', 200, 100);
      if uipath ~= 0
         fullname = fullfile(uipath, uifile);
         set(edh, 'string', fullname);
      else
         set(edh, 'enable', 'on');
         set(edh, 'string', currstr);
      end
   case 'getsuppfilepath'   % from mvecfig, searching for supplemental file [. . .]
      edh = findobj(gcf,'tag', 'txtboxsuppfile');
      currstr = get(edh, 'string');
      [uifile, uipath] = uigetfile('*','Select supplemental data file', 200, 100);
      if uipath ~= 0
         fullname = fullfile(uipath, uifile);
         set(edh, 'string', fullname);
      else
         set(edh, 'enable', 'on');
         set(edh, 'string', currstr);
      end
   case 'cancel'   % from gplotvector - btnCancel
      close
      if VECFIG.webplot == 0, gplot; end
   case 'help'
      noticeOK('Help is on the way')
   end

%%%%%%%%%%%

function figvectorsetup

global UVDATA
global XYDATA
global VECFIG
  
loaderrorflag = 0;
uvdatapath = [VECFIG.xydatapath(1:end-6), 'uv.mat'];
eval('UVDATA = load(uvdatapath);', 'loaderrorflag = 1;');
eval('XYDATA = load(VECFIG.xydatapath);', 'loaderrorflag = 1;');
if loaderrorflag
   msg = sprintf('\nError trying to load:\n%s  --\nPlease start over.\nSelect *.mat type for both xyt & uv data.  ', VECFIG.xydatapath);
   noticeOK(msg)
   uiwait   
   loaderrorflag = 0;
   if VECFIG.webplot == 0, gplot; end
   return
end
preparedata

if isfield(XYDATA,'year_base')
   VECFIG.year_base = XYDATA.year_base;
else
   VECFIG.year_base = '???';
end
VECFIG.dbname = XYDATA.dbname;

gplotvector;

df = findobj(gcf,'tag','textdata');
set(df,'string', 'uv.mat, _xy.mat');
yb = findobj(gcf,'tag','txtboxyear');
set(yb,'string',num2str(VECFIG.year_base));
oph = findobj(gcf,'tag','txtboxoutpath');
set(oph,'string',VECFIG.outpath);
cnffs = findobj(gcf,'tag','txtboxsavefn');
VECFIG.savefn = 'vec_cfg.mat';  
set(cnffs,'string', VECFIG.savefn);
dspo = findobj(gcf,'tag','txtboxsavepath');
set(dspo,'string',VECFIG.outpath);
dtpo = findobj(gcf,'tag','txtboxloadpath');
set(dtpo,'string',VECFIG.outpath);
cnffl = findobj(gcf,'tag','popuploadfn');
VECFIG.loadpath = VECFIG.outpath;
curdir =  pwd;
cd(VECFIG.loadpath)
files = what;
str_b = files.mat;
for i = length(str_b):-1:1
   chary = char(str_b(i));
   if isempty(findstr(chary, 'cfg'))
      str_b(i) = [];
   end
end
VECFIG.loadfn = str_b;
if isempty(str_b); VECFIG.loadfn = {'None'}; end;
cd(curdir)
set(cnffl,'value',length(VECFIG.loadfn))
set(cnffl,'string',VECFIG.loadfn);

pud1 = findobj(gcf,'tag','popupdepth1');
depthvars = num2cell(XYDATA.z(1:end-1));
set(pud1,'string',depthvars);
set(pud1,'max',length(depthvars));
pud2 = findobj(gcf,'tag','popupdepth2');
depthvars2 = num2cell(XYDATA.z(2:end));
set(pud2,'string',depthvars2);
set(pud2,'max',length(depthvars2));
tbt = findobj(gcf,'tag','txtboxtitle');
pp = VECFIG.xydatapath;
marks = findstr(pp,filesep);
VECFIG.cruiseID = upper(pp(marks(end-2)+1:marks(end-1)-1));
if length(VECFIG.cruiseID) == 6 & ~isletter(VECFIG.cruiseID(end)) 
   VECFIG.title = VECFIG.cruiseID;
else
   pp = what;
   marks = findstr(pp.path,filesep);
   VECFIG.cruiseID = upper(pp.path(marks(end)+1:end));
   if length(VECFIG.cruiseID) == 6 & ~isletter(VECFIG.cruiseID(end))
      VECFIG.title = VECFIG.cruiseID;
   else
      VECFIG.title = 'vector';
   end
end;
set(tbt,'string',VECFIG.title);
VECFIG.printfilefn = [VECFIG.title, '.ps'];
fpn = findobj(gcf,'tag','txtboxprintfn');
set(fpn,'string',VECFIG.printfilefn);
set(fpn,'HorizontalAlignment','center');
VECFIG.printfile = 0;
pfb = findobj(gcf,'tag','chkboxprint');
set(pfb,'value',VECFIG.printfile);
sc = findobj(gcf,'tag','txtboxscale');
vec_scalestr = get(sc,'string');
VECFIG.vec_scale = 1/str2num(vec_scalestr);

% default data for/from mvecfig.m in case bypassed
VECFIG.mv_color = 'k';
VECFIG.mv_edgecolor = 'k';
VECFIG.mv_headangle = 60;
VECFIG.mv_headwidth = NaN;
VECFIG.mv_shaftwidth = 1;
VECFIG.mv_headlength = 5;
VECFIG.mv_centered = 0;
if ~isfield(VECFIG,'mv_cdatafile'), VECFIG.mv_cdatafile = []; end;
VECFIG.cdata_mm = -99;
VECFIG.circlescale = '10';
if ~isfield(VECFIG,'mv_suppdatafile'),  VECFIG.mv_suppdatafile= pwd; end;
VECFIG.mv_supplementary = 0;
VECFIG.mv_colorsupp = 'none';
VECFIG.mv_edgecolorsupp = 'red';
VECFIG.circlescalesupp = '20';
VECFIG.usecdata = 0;
VECFIG.radioscale = 2;

% other defaults
VECFIG.btntype = [];
VECFIG.projection = 'merc';
VECFIG.moreproj = 0;
VECFIG.m_coast_str = 'm_coast(''patch'',[0.6  0.5  0.0]);';
VECFIG.basintype = 1;
VECFIG.basinresolution = 3;
VECFIG.boundsflag = 0;
VECFIG.coastflag = 0;
VECFIG.gridflag = 0;
VECFIG.ii = 1:length(XYDATA.DDAY); 

determine_ranges;
fixtitle;

%%%%%%%%%%%%%%%

function configsetup(varargin)  % called with initializing cfg file (or webvspecs file)

global UVDATA
global XYDATA
global VECFIG
 
fname = char(varargin{1});  % cell to str
trouble = 0;
eval('load(fname)', 'trouble = 1')
if trouble == 1
   noticeOK('Problems loading file')
   return
end

if VECFIG.webplot == 0, [VECFIG.loadpath,  vfn] = fileparts(fname); end;  %was just overwritten

curdir =  pwd;
cd(VECFIG.loadpath)
files = what;
str_b = files.mat;
for i = length(str_b):-1:1
   chary = char(str_b(i));
   if isempty(findstr(chary, 'cfg'))
      str_b(i) = [];
   end
end
VECFIG.loadfn = str_b;   
if isempty(str_b); VECFIG.loadfn = {'None'}; end;
cd(curdir)

if VECFIG.webplot == 0
   uvdatapath = [VECFIG.xydatapath(1:end-6), 'uv.mat'];
   UVDATA = load(uvdatapath);
   XYDATA = load(VECFIG.xydatapath);
else
   UVDATA = load('v_sect_uv.mat');
   XYDATA = load('v_sect_xy.mat');
end

preparedata

gplotvector
loadnow(1)  % 1=continue loading with new data, skip prelims

%%%%%%%%%%%%%%%

function loadnow(skip)   % use cfg (or webvspec) file parameters

global UVDATA
global XYDATA
global VECFIG

if isempty(VECFIG.ii)
   msg = sprintf('Data set (lat-longs) must be \nselected before loading config.');
   noticeOK(msg);
   return
end

if ~skip   % main screen load doesn't skip; skip if initializing with config.
   % save some current data vbls before overwritten
   cID = VECFIG.cruiseID;
   wbfg = VECFIG.webplot;
   ttl = VECFIG.title;
   iinow = VECFIG.ii;
   latr = VECFIG.latrange;
   lonr = VECFIG.lonrange;
   opath = VECFIG.outpath;
   bflag = VECFIG.boundsflag;
   gflag = VECFIG.gridflag;
   mpstr = VECFIG.m_proj_str;
   gstr =   VECFIG.m_grid_str;
   
   ptx = findobj(gcf,'tag','txtboxloadpath');
   ldpath = get(ptx,'string');
   cnffl = findobj(gcf,'tag','popuploadfn');
   pv = get(cnffl,'value');
   pstr = get(cnffl,'string');
   fname1 = pstr{pv};
   fname = fullfile(ldpath, fname1);
   
   goodload = 1;
   eval('load(fname);', 'goodload = 0;');
   if ~goodload
      noticeOK('Unable to load requested file.  ');
      return
   end
      
   VECFIG.loadfn = pstr;
   VECFIG.loadpath = ldpath;
   VECFIG.cruiseID = cID;
   VECFIG.webplot = wbfg;
   VECFIG.title = ttl;
   VECFIG.ii = iinow;
   VECFIG.latrange = latr;
   VECFIG.lonrange = lonr;
   VECFIG.outpath = opath;
   VECFIG.boundsflag = bflag;
   VECFIG.gridflag = gflag;
   VECFIG.m_proj_str = mpstr;
   VECFIG.m_grid_str = gstr;
end

% re-establish new layout
cnffs = findobj(gcf,'tag','txtboxsavefn');
fname = VECFIG.savefn; 
if isempty(findstr(fname, 'cfg')), 
   set(cnffs,'string', 'webvec_cfg');
else
   set(cnffs,'string', VECFIG.savefn); 
end
dtpo = findobj(gcf,'tag','txtboxloadpath');
set(dtpo,'string',VECFIG.loadpath);
dspo = findobj(gcf,'tag','txtboxsavepath');
set(dspo,'string',VECFIG.savepath);
cnffl = findobj(gcf,'tag','popuploadfn');
set(cnffl,'value',length(VECFIG.loadfn));
set(cnffl,'string',VECFIG.loadfn);
yb = findobj(gcf,'tag','txtboxyear');
set(yb,'string',num2str(VECFIG.year_base));
oph = findobj(gcf,'tag','txtboxoutpath');
set(oph,'string',VECFIG.outpath);
tbt = findobj(gcf,'tag','txtboxtitle'); 
set(tbt,'string',VECFIG.title);
df = findobj(gcf,'tag','textdata');
set(df,'string','custom load');
pud1 = findobj(gcf,'tag','popupdepth1');
depthvars = num2cell(XYDATA.z(1:end-1));
set(pud1,'string',depthvars);
set(pud1,'max',length(depthvars));
pud2 = findobj(gcf,'tag','popupdepth2');
depthvars2 = num2cell(XYDATA.z(2:end));
set(pud2,'string',depthvars2);
set(pud2,'max',length(depthvars2));

% new scheme to reset by actual level in meters, if poss.
vlevm1 = str2num(VECFIG.veclevelmeters{1}); 
vlev1 = find(XYDATA.z == vlevm1);
if ~isempty(vlev1), VECFIG.vectorlevel(1) = vlev1; end; % can use orig value rather than str
set(pud1,'value',VECFIG.vectorlevel(1));
vlevm2 = str2num(VECFIG.veclevelmeters{2});
vlev2 = find(XYDATA.z == vlevm2);
if ~isempty(vlev2), VECFIG.vectorlevel(2) = vlev2 - 1; end; % 2nd set of depthvars is offset + 1
set(pud2,'value',VECFIG.vectorlevel(2));

ckb = findobj(gcf,'tag','chkbold');
set(ckb,'value',VECFIG.bold);
cst = findobj(gcf,'tag','chkskiptitle');
set(cst,'value',VECFIG.skiptitle);
bwc = findobj(gcf,'tag','chkblkwht');
set(bwc,'value',VECFIG.blkwht);
df = findobj(gcf,'tag','textdata');
set(df,'string','custom load');
sc = findobj(gcf,'tag','txtboxscale');
if VECFIG.vec_scale == 0
   set(sc,'string','0');
else
   set(sc,'string',num2str(1/VECFIG.vec_scale));
end
pj = findobj(gcf,'tag','popupproj');
if VECFIG.moreproj == 1
    newstring = {'Stereographic';...
               'Orthographic';...
               'Azimuthal Equal-area';...
               'Azimuthal Equidistant';...
               'Gnomonic';...
               'Satellite';...
               'Albers Equal-Area Conic';...
               'Lambert Conformal Conic';...
               'Mercator';...
               'Miller Cylindrical';...
               'Equidistant Cylindrical';...
               'Oblique Mercator';...
               'Transverse Mercator';...
               'Sinusoidal';...
               'Gall-Peters';...
               'Hammer-Aitoff';...
               'Mollweide';...
               'UTM'};
   set(pj,'string',newstring);
end
set(pj,'value',VECFIG.projvalue);
dbh = findobj(gcf,'tag','popupdbase');
set(dbh,'value',VECFIG.basinresolution); % reflects database to use; old name
bst = findobj(gcf,'tag','popupbasin');
set(bst,'value',VECFIG.basintype);

di = findobj(gcf,'tag','chkboxdate');
set(di,'value',VECFIG.datestamp);
pfb = findobj(gcf,'tag','chkboxprint');
set(pfb,'value',VECFIG.printfile);
pfn = findobj(gcf,'tag','txtboxprintfn');
if VECFIG.webplot == 0
    set(pfn,'string', VECFIG.printfilefn);
else
    set(pfn,'string',[VECFIG.printfilefn, '.eps']);
end
dp = findobj(gcf,'tag','chkdprange');
ch = findobj(gcf,'tag','chkcalendar');
dh = findobj(gcf,'tag','chkdecimal');
set(dp,'value',VECFIG.titlebtnstatus(1));
set(ch,'value',VECFIG.titlebtnstatus(2));
set(dh,'value',VECFIG.titlebtnstatus(3));

XYDATA.X=XYDATA.x(VECFIG.ii);
XYDATA.Y=XYDATA.y(VECFIG.ii);
XYDATA.DDAY=XYDATA.dday(VECFIG.ii);
UVDATA.U=UVDATA.u(:,VECFIG.ii);
UVDATA.V=UVDATA.v(:,VECFIG.ii);

% determine_ranges;
fixtitle;

%%%%%%%%%%%%%%

function determine_ranges

global UVDATA
global XYDATA
global VECFIG

[lonrange, latrange] = map_range(XYDATA.X, XYDATA.Y);
VECFIG.latrange=latrange;
VECFIG.lonrange=lonrange;

if VECFIG.boundsflag == 0
   VECFIG.m_proj_str = sprintf('m_proj(''%s'',''lon'',[%s],''lat'',[%s]);',...
      VECFIG.projection,num2str(VECFIG.lonrange),num2str(VECFIG.latrange));
end
if VECFIG.gridflag == 0
   xtick = best_ticks(VECFIG.lonrange);
   ytick = best_ticks(VECFIG.latrange);
   VECFIG.m_grid_str = sprintf('m_grid(''tickdir'',''out'',''xtick'',[%s],''ytick'',[%s]);',...
      num2str(xtick),num2str(ytick));
end

%%%%%%%%%%%%%%

function xytsection
% this simply obtains the new data set from xytzoom

global UVDATA
global XYDATA
global VECFIG

if ~isempty(VECFIG.ii) & VECFIG.ii(end) <= length(XYDATA.x) 
   VECFIG.ii = gxytzoom2(XYDATA.x, XYDATA.y, XYDATA.dday, VECFIG.ii);
else
   VECFIG.ii = gxytzoom2(XYDATA.x, XYDATA.y, XYDATA.dday);
end
% now receives any earlier selections also
if isempty(VECFIG.ii), return; end;
XYDATA.X=XYDATA.x(VECFIG.ii);
XYDATA.Y=XYDATA.y(VECFIG.ii);
XYDATA.DDAY=XYDATA.dday(VECFIG.ii);
UVDATA.U=UVDATA.u(:,VECFIG.ii);
UVDATA.V=UVDATA.v(:,VECFIG.ii);

VECFIG.boundsflag = 0;
VECFIG.gridflag = 0;
determine_ranges;
fixtitle;

%%%%%%%%%%%%%%%%

function readfigvector
% To call gvector

notice('Working ...',1.0);
hhfig = figure;
% Basic data
global UVDATA
global XYDATA
global VECFIG

% Retreive latest dialog data
tbt = findobj(gcbf,'tag','txtboxtitle');
VECFIG.title = get(tbt,'string');
oph = findobj(gcbf,'tag','txtboxoutpath');
VECFIG.outpath = get(oph,'string');
oph = findobj(gcbf,'tag','txtboxsavepath');
VECFIG.savepath = get(oph,'string');
oph = findobj(gcbf,'tag','txtboxloadpath');
VECFIG.loadpath = get(oph,'string');
oph = findobj(gcbf,'tag','txtboxsavefn');
VECFIG.savefn = get(oph,'string');
oph = findobj(gcbf,'tag','popuploadfn');
VECFIG.loadfn = get(oph,'string');
ckb = findobj(gcbf,'tag','chkbold');
VECFIG.bold = get(ckb,'value');
cst = findobj(gcbf,'tag','chkskiptitle');
VECFIG.skiptitle = get(cst,'value');
bwd = findobj(gcbf,'tag','chkblkwht');
VECFIG.blkwht = get(bwd,'value');
chp = findobj(gcbf,'tag','chkboxprint');
VECFIG.printfile = get(chp,'value');
pfn = findobj(gcbf,'tag','txtboxprintfn');
VECFIG.printfilefn = get(pfn,'string');
sc = findobj(gcbf,'tag','txtboxscale');
vec_scalestr = get(sc,'string');
if ~strcmp(vec_scalestr,'0')
   VECFIG.vec_scale = 1/str2num(vec_scalestr);
else
   VECFIG.vec_scale = 0;
end
dbh = findobj(gcbf,'tag','popupdbase');
VECFIG.basinresolution = get(dbh,'value'); % reflects geog. database to use; old name
bst = findobj(gcbf,'tag','popupbasin');
VECFIG.basintype = get(bst,'value');

pj = findobj(gcbf,'tag','popupproj');
pjval = get(pj,'value');
pjstr = get(pj,'string');
VECFIG.projection = pjstr{pjval};
VECFIG.projvalue = pjval;
xps = VECFIG.m_proj_str;
f=findstr(xps,',');
VECFIG.m_proj_str = sprintf('%s''%s''%s',xps(1:7),VECFIG.projection,xps(f(1):end));

pd1 = findobj(gcbf,'tag','popupdepth1');
pd2 = findobj(gcbf,'tag','popupdepth2');
pd1val = get(pd1,'value');
pd2val = get(pd2,'value');
pd1str = get(pd1,'string');
pd2str = get(pd2,'string');
VECFIG.veclevelmeters = {pd1str{pd1val}; pd2str{pd2val}};
VECFIG.vectorlevel = [pd1val pd2val];

if pd1val == pd2val  % one level only
   UVDATA.UU=UVDATA.U(VECFIG.vectorlevel(1),:)';
   UVDATA.VV=UVDATA.V(VECFIG.vectorlevel(1),:)';
else  % multiple levels - needs weighted average
   ref = min(diff(XYDATA.Z));
   for k = 1:length(XYDATA.Z)-1
      wt(k) = (XYDATA.Z(k+1)-XYDATA.Z(k))/ref;
   end
   totwt = sum(wt(pd1val:pd2val));
   UT = zeros(1,length(UVDATA.U(1,:))); 
   VT = UT; 
   for k = pd1val:pd2val
      UT(1,:) = UT(1,:) + UVDATA.U(k,:).*wt(k);
      VT(1,:) = VT(1,:) + UVDATA.V(k,:).*wt(k);
   end
   UVDATA.UU=UT(1,:)./totwt;
   UVDATA.VV=VT(1,:)./totwt;
   UVDATA.UU=UVDATA.UU';
   UVDATA.VV=UVDATA.VV';
end

%  %let's fake it a bit - replot vectors twice (since we don't have colors)
TT=-99+0*XYDATA.X;
tt = [];  % try to fill this with temperature data

if VECFIG.usecdata & ~isempty(VECFIG.mv_cdatafile)
   ttfile = VECFIG.mv_cdatafile;
   tt = read_asc(ttfile);        % col 1 = ddates; col 2 = temperatures
   ttout = zeros(size(XYDATA.dday));   % already badi NaN'ed
   trouble = 0;
   for lap = 1:length(XYDATA.dday)
      index = find(tt(:,1) >= XYDATA.dday(lap));  % == off in 4th decimal usu.
      eval('ttout(lap) = tt(index(1),2);', 'trouble = 1;')
      if trouble == 1
         marks = findstr(ttfile, filesep);
         shortname = ttfile(marks(end-2):end);
         okstr = sprintf('\nTemperature file error. \n\nEdit: %s\n\nProbably not enough dday time', shortname); 
         noticeOK(okstr)
         return
      end
   end
   if isempty(tt)
      msg = sprintf('Cdata file unsuccessfully read:\nfile must be >= 2 cols.\n');
      msg = sprintf('%s(date  data(e.g. temps).', msg);
      noticeOK(msg);
      return
   else
      TT = ttout;
   end
else
   TT = VECFIG.mv_color;
end
VECFIG.TT = TT;

vv = num2str(VECFIG.lonrange);
VECFIG.lonrange = str2num(vv); % do not delete this strange couplet

gvector;

di = findobj(gcbf,'tag','chkboxdate');
if get(di,'value'), date_it; end;
VECFIG.datestamp = get(di,'value');

if VECFIG.printfile % print & possibly webvspecs file
   [VECFIG.printfilefn, sfix] = strtok(VECFIG.printfilefn, '.');
   if isempty(sfix), sfix = '.ps'; end;
   if VECFIG.webplot == 1, sfix = '.eps'; end;
   pfname = fullfile(VECFIG.outpath, [VECFIG.printfilefn, sfix]);
   orient tall; 
   if VECFIG.blkwht & strcmp(sfix, '.ps'), print( '-dps2', '-append', pfname); end;
   if VECFIG.blkwht & strcmp(sfix, '.eps'), print( '-deps2', pfname); end;
   if strcmp(sfix, '.ps') & ~VECFIG.blkwht, print( '-dpsc2', '-append', pfname); end;
   if strcmp(sfix, '.eps') & ~VECFIG.blkwht, print( '-depsc2', pfname); end; 
   if VECFIG.webplot == 1
      % save spec file for future redo's (ONLY DONE WITH "PRINT'S")
      fname = VECFIG.title;
      gaps = findstr(fname, ' ');
      sufx = fname(gaps(3)+1:gaps(4)-2);
      fname = sprintf('webvspecs_%s', sufx);
      VECFIG.savefn = fname;
      VECFIG.DDAY = XYDATA.DDAY;
      save6(fname, 'VECFIG');
      % save mat file with xyt, uv, & zc
      fname2 = sprintf('sect%s', sufx);
      j1 = find(XYDATA.xyt(3,:)>=VECFIG.DDAY(1));
      j2 = find(XYDATA.xyt(3,:)<=VECFIG.DDAY(end));
      xyt = XYDATA.xyt(:,j1(1):j2(end));
      uvj1 = j1(1)*2 - 1;
      uvj2 = j2(end)*2;
      uv = UVDATA.uv(:,uvj1:uvj2);
      zc = XYDATA.zc;
      save6(fname2, 'xyt', 'uv', 'zc')
   end    
end % printing

%%%%%%%%%%%%%%%

function fixtitle

global XYDATA
global VECFIG

dp = findobj(gcf,'tag','chkdprange');
ch = findobj(gcf,'tag','chkcalendar');
dh = findobj(gcf,'tag','chkdecimal');
tti = findobj(gcf,'tag','txtboxtitle');

dprangeflag = get(dp,'value');
calendarflag = get(ch,'value');
decimalflag = get(dh,'value');
VECFIG.title = get(tti,'string');
VECFIG.titlebtnstatus = [dprangeflag calendarflag decimalflag];

[cruiseID, rest] = strtok(VECFIG.title,';');
part1 = cruiseID;

if dprangeflag
   pud1 = findobj(gcf,'tag','popupdepth1');
   pdval1 = get(pud1,'value');
   pud2 = findobj(gcf,'tag','popupdepth2');
   pdval2 = get(pud2,'value');
   part2 = sprintf('; %.0f-%.0f m',XYDATA.Z(pdval1),XYDATA.Z(pdval2+1));
else
   part2 = '';
end
if calendarflag
   cal1 = to_date(VECFIG.year_base, min(XYDATA.DDAY),'s');
   cal2 = to_date(VECFIG.year_base, max(XYDATA.DDAY),'s');
   cal1 = cal1(6:10); cal2 = cal2(6:10);
   part3 = sprintf('; %s-%s, %d', cal1, cal2, VECFIG.year_base);
else
   part3 = '';
end
if decimalflag
   part4 = sprintf('; %.2f - %.2f dd', min(XYDATA.DDAY), max(XYDATA.DDAY));
else
   part4 = '';
end

VECFIG.title = strcat(part1, part2, part3, part4);
set(tti,'string',VECFIG.title);

%%%%%%%%%%%%%%

function load_param_defaults  % universal setup for paramfig

global VECFIG

pss1 = findobj(gcf,'tag','ps1');
pvv1 = findobj(gcf,'tag','pv1');
pss2 = findobj(gcf,'tag','ps2');
pvv2 = findobj(gcf,'tag','pv2');
pss3 = findobj(gcf,'tag','ps3');
pvv3 = findobj(gcf,'tag','pv3');
pss4 = findobj(gcf,'tag','ps4');
pvv4 = findobj(gcf,'tag','pv4');
pss5 = findobj(gcf,'tag','ps5');
pvv5 = findobj(gcf,'tag','pv5');
vvbox = 'pvv1'; % initialize only

switch(VECFIG.btntype)
   case 'bounds'                 % from gplotvector - btnProj
      if VECFIG.boundsflag == 0  % original defaults
         set(pss1,'string','lon');
         set(pss2,'string','lat');
         set(pvv1,'string',num2str(VECFIG.lonrange));
         set(pvv2,'string',num2str(VECFIG.latrange));
         VECFIG.boundsflag = 1;
      else                       % retrieve previous set
         [element, rest] = strtok(VECFIG.m_proj_str,',');
         jj = 0;
         while ~isempty(rest)
            jj = jj + 1;
            ssbox = sprintf('pss%d',jj);
            [element, rest] = strtok(rest,',');
            set(eval(ssbox),'string',element(2:end-1));
            vvbox = sprintf('pvv%d',jj);
            [element, rest] = strtok(rest,',');
            set(eval(vvbox),'string',element(2:end-1));
         end
         set(eval(vvbox),'string',element(2:end-3)); % = -");"
      end 
   case 'coast'
      if VECFIG.coastflag == 0  % original defaults
         set(pss1,'string','patch');
         set(pvv1,'string','[0.6  0.5  0.0]');
         set(pss2,'string','facecolor');
         set(pvv2,'string','none');
         set(pss3,'string','');
         set(pvv3,'string','');
         VECFIG.coastflag = 1;
      else
         [element, rest] = strtok(VECFIG.m_coast_str,'(');
         rest = rest(2:end);
         jj = 0;
         while ~isempty(rest)
            jj = jj + 1;
            ssbox = sprintf('pss%d',jj);
            [element, rest] = strtok(rest,',');
            set(eval(ssbox),'string',element(2:end-1));
            vvbox = sprintf('pvv%d',jj);
            [element, rest] = strtok(rest,',');
            set(eval(vvbox),'string',element(2:end-1));
         end
         if jj > 0, set(eval(vvbox),'string',element(2:end-3));, end;
      end     
   case 'grid'
      if VECFIG.gridflag == 0  % original defaults
         xtick = round(VECFIG.lonrange(1)):floor(diff(VECFIG.lonrange)/4):floor(VECFIG.lonrange(2));
         ytick = round(VECFIG.latrange(1)):floor(diff(VECFIG.latrange)/4):floor(VECFIG.latrange(2));
         set(pss1,'string','tickdir');
         set(pvv1,'string','out');
         set(pss2,'string','xtick');
         set(pvv2,'string',num2str(xtick));
         set(pss3,'string','ytick');
         set(pvv3,'string',num2str(ytick));
         VECFIG.gridflag = 1;
      else
         [element, rest] = strtok(VECFIG.m_grid_str,'(');
         rest = rest(2:end);
         jj = 0;
         while ~isempty(rest)
            jj = jj + 1;
            ssbox = sprintf('pss%d',jj);
            [element, rest] = strtok(rest,',');
            set(eval(ssbox),'string',element(2:end-1));
            vvbox = sprintf('pvv%d',jj);
            [element, rest] = strtok(rest,',');
            set(eval(vvbox),'string',element(2:end-1));
         end
         set(eval(vvbox),'string',element(2:end-3));
      end            
end

%%%%%%%%%%%%%

function addparams  % universal return from paramfig

global VECFIG

jj = 0;
paramlist = [1];
while ~isempty(paramlist)
   jj = jj+1;
   if jj > 5, break;, end;
   pstr = sprintf('ps%d',jj);
   pval = sprintf('pv%d',jj);
   pps = findobj(gcbf,'tag',pstr);
   ppv = findobj(gcbf,'tag',pval);
   para{jj,1} = get(pps,'string');
   para{jj,2} = get(ppv,'string');
   paran(jj) = ~isempty(str2num(char(para{jj,2})));  % allow for numerics
   if isempty(para{jj,1}) | isempty(para{jj,2}), paramlist=[];, end;
end

if jj > 1
   
   switch(VECFIG.btntype)
      case 'bounds' 
         b_str = sprintf('m_proj(''%s'',',VECFIG.projection); % use no spaces
      case 'coast'
         b_str = sprintf('m_coast(');
      case 'grid'
         b_str = sprintf('m_grid(');
   end
   
   if paran(1) == 0
     b_str2 = sprintf('%s''%s'',''%s''',b_str,char(para{1,1}), char(para{1,2}));
   else  % numerics
      b_str2 = sprintf('%s''%s'',[%s]',b_str,char(para{1,1}), char(para{1,2}));
   end
   
   for kk = 2:jj-1
      if paran(kk) == 0
         b_str2 = sprintf('%s,''%s'',''%s''',b_str2,char(para{kk,1}),char(para{kk,2}));
      else 
         b_str2 = sprintf('%s,''%s'',[%s]',b_str2,char(para{kk,1}),char(para{kk,2}));
      end
   end
  
end

switch(VECFIG.btntype)
   case 'bounds' 
      VECFIG.m_proj_str = strcat(b_str2,');');
   case 'coast'
      if jj > 1, VECFIG.m_coast_str = strcat(b_str2,');');, end; 
   case 'grid'
      if jj > 1, VECFIG.m_grid_str = strcat(b_str2,');');, end;
end

close;

% special case: lat lon mods in projection
flagged = 0;
ndex = 1;
while ~isempty(char(para(ndex, 1)))
   check = char(para(ndex,1));
   if  lower(check(1:3)) == 'lon', 
      VECFIG.lonrange = str2num(char(para{ndex,2})); 
      flagged = 1;
   end;
   if  lower(check(1:3)) == 'lat', 
      VECFIG.latrange = str2num(char(para{ndex,2})); 
      flagged = 1;
   end;
   ndex = ndex + 1;
end

if flagged
   xtick = round(VECFIG.lonrange(1)):floor(diff(VECFIG.lonrange)/4):floor(VECFIG.lonrange(2));
   ytick = round(VECFIG.latrange(1)):floor(diff(VECFIG.latrange)/4):floor(VECFIG.latrange(2));
   VECFIG.m_grid_str = sprintf('m_grid(''tickdir'',''out'',''xtick'',[%s],''ytick'',[%s]);',...
      num2str(xtick),num2str(ytick));
end

%%%%%%%%%%%%%

function mvecfigsetup   % This is the setup for the 'Customized arrow' dialog window

global XYDATA
global VECFIG

sc = findobj(gcf,'tag','txtboxscale');  % need this from main window beforehand
vec_scalestr = get(sc,'string');

mvecfig;     % dialog window

col = findobj(gcf,'tag','txtboxcolor');
set(col,'string', VECFIG.mv_color);
ec = findobj(gcf,'tag','txtboxedgecolor');
set(ec,'string', VECFIG.mv_edgecolor);
ha = findobj(gcf,'tag','txtboxheadangle');
set(ha,'string', num2str(VECFIG.mv_headangle));
hw = findobj(gcf,'tag','txtboxheadwidth');
set(hw,'string', num2str(VECFIG.mv_headwidth));
sw = findobj(gcf,'tag','txtboxshaftwidth');
set(sw,'string', num2str(VECFIG.mv_shaftwidth));
hl = findobj(gcf,'tag','txtboxheadlength');
set(hl,'string', num2str(VECFIG.mv_headlength));
tbc =  findobj(gcf,'tag','txtboxcfile');
set(tbc,'string', VECFIG.mv_cdatafile);
set(tbc,'horizontalalignment','right');
ct = findobj(gcf,'tag','chkcentered');
set(ct,'value', VECFIG.mv_centered);

if strcmp(vec_scalestr, '0'), set(ct,'value',1); end; 

tt = findobj(gcf,'tag','chktemperature');
fc= findobj(gcf,'tag','chkfixedcolor');
if  VECFIG.usecdata  
   set(tt,'value', 1);
   set(fc,'value',0);
else
   set(fc,'value', 1);
   set(tt,'value', 0);  
end
rc = findobj(gcf,'tag','radiotempcruise');
rp = findobj(gcf,'tag','radiotempplot');
cs = findobj(gcf,'tag','radiotempcustom');
if VECFIG.radioscale == 1
   set(cs,'value', 0);
   set(rp,'value', 0);
   set(rc,'value', 1);
elseif VECFIG.radioscale == 2
   set(cs,'value', 0);
   set(rp,'value', 1);
   set(rc,'value', 0);  
else
   set(cs,'value', 1);
   set(rp,'value', 0);
   set(rc,'value', 0);
end
cdf = findobj(gcf,'tag','txtboxcdatamm');
if VECFIG.cdata_mm == -99
   set(cdf,'string', 'auto');  
else  
   set(cdf,'string', num2str(VECFIG.cdata_mm));
end

if isempty(VECFIG.mv_cdatafile)
   % try to setup default color file
   marks = findstr(VECFIG.xydatapath, filesep);
   newpath = VECFIG.xydatapath(1:marks(end-1));
   ttfile = fullfile(newpath,'edit', 'corrtemp.dat');
   if exist(ttfile)  % try for this file first
      set(tbc,'string',ttfile);
   else              % try this second
      marks = findstr(VECFIG.dbname, filesep);
      prefix = VECFIG.dbname(marks(end)+1:end);
      ttfile = fullfile(newpath,'edit', [prefix,'.tem']);
      if VECFIG.webplot == 1, ttfile = fullfile(newpath,'edit', [prefix(1:end-7),'.tem']); end;
      if exist(ttfile)  
         set(tbc,'string',ttfile);
      end
   end
end
if ~exist(ttfile)  % one more try
   newpath = pwd;
   prefix = VECFIG.dbname(end-4:end);
   ttfile = fullfile(newpath,'edit', [prefix,'.tem']);
   if exist(ttfile)  
      set(tbc,'string',ttfile);
   else
      ttfile = fullfile(VECFIG.dbname(1:marks(end-1)), 'edit', [prefix,'.tem']);
      if exist(ttfile), set(tbc,'string',ttfile); end
   end
end

   
crd = findobj(gcf,'tag','txtboxcirclescale');
set(crd,'string', VECFIG.circlescale);
tbc =  findobj(gcf,'tag','txtboxsuppfile');
set(tbc,'string', VECFIG.mv_suppdatafile);
ckk = findobj(gcf,'tag','chksupplementary');
set(ckk,'value', VECFIG.mv_supplementary);
eclr = findobj(gcf,'tag','txtboxedgecolorsupp');
set(eclr,'string', VECFIG.mv_edgecolorsupp);
clr = findobj(gcf,'tag','txtboxcolorsupp');
set(clr,'string', VECFIG.mv_colorsupp);
crds = findobj(gcf,'tag','txtboxcirclescalesupp');
set(crds,'string', VECFIG.circlescalesupp);

%%%%%%%%%%%%%

function mvecvbls
% this retrieves the variables from mvecfig.m ---
% these are loaded into VECFIG which does not expose them since
% they are hidden within this structure.
global VECFIG

col = findobj(gcf,'tag','txtboxcolor');
colr = get(col,'string');
VECFIG.mv_color = colr;
ha = findobj(gcf,'tag','txtboxheadangle');
han = get(ha,'string');
VECFIG.mv_headangle = str2num(han);
hw = findobj(gcf,'tag','txtboxheadwidth');
hwd = get(hw,'string');
VECFIG.mv_headwidth = str2num(hwd);
sw = findobj(gcf,'tag','txtboxshaftwidth');
swd = get(sw,'string');
VECFIG.mv_shaftwidth = str2num(swd);
ec = findobj(gcf,'tag','txtboxedgecolor');
ecr = get(ec,'string');
VECFIG.mv_edgecolor = ecr;
hl = findobj(gcf,'tag','txtboxheadlength');
hlg = get(hl,'string');
VECFIG.mv_headlength = str2num(hlg);
ct = findobj(gcf,'tag','chkcentered');
VECFIG.mv_centered = get(ct,'value');
tt = findobj(gcf,'tag','chktemperature'); 
VECFIG.usecdata = get(tt,'value');

if VECFIG.usecdata, 
   tbc =  findobj(gcf,'tag','txtboxcfile');
   VECFIG.mv_cdatafile = get(tbc,'string');
   cdf = findobj(gcf,'tag','txtboxcdatamm');
   cdmm = get(cdf,'string');
   if ~exist(VECFIG.mv_cdatafile,'file')
      noticeOK('Color file not found.  ');
      return
   end
   if findstr(cdmm,'auto') | isempty(cdmm) | length(str2num(cdmm)) ~= 2 
      VECFIG.cdata_mm = -99;
      cs = findobj(gcf,'tag','radiotempcustom');
      if get(cs,'value')
         msg = sprintf('\nYou must supply min & max \nTemperature values.');
         noticeOK(msg);
         return
      end
   else
      VECFIG.cdata_mm = str2num(cdmm);
   end
end;
crd = findobj(gcf,'tag','txtboxcirclescale');
VECFIG.circlescale = get(crd,'string');

sup = findobj(gcf,'tag','chksupplementary');
VECFIG.mv_supplementary = get(sup,'value');
col = findobj(gcf,'tag','txtboxcolorsupp');
VECFIG.mv_colorsupp = get(col,'string');
ec = findobj(gcf,'tag','txtboxedgecolorsupp');
VECFIG.mv_edgecolorsupp = get(ec,'string');
crd = findobj(gcf,'tag','txtboxcirclescalesupp');
VECFIG.circlescalesupp = get(crd,'string');
tbc =  findobj(gcf,'tag','txtboxsuppfile');
VECFIG.mv_suppdatafile = get(tbc,'string');
if VECFIG.mv_supplementary
      if ~exist(VECFIG.mv_suppdatafile,'file')
      noticeOK('Supplementary file not found.  ');
      return
   end
end

close;

%%%%%%%%%%%%%

function webplotsetup   % called from mksecplt2

global UVDATA
global XYDATA
global VECFIG
global ALLFIG
  
VECFIG.year_base = XYDATA.year_base;
VECFIG.dbpath = ALLFIG.dbpath;

gplotvector;

df = findobj(gcf,'tag','textdata');
set(df,'string','from web section'); 
yb = findobj(gcf,'tag','txtboxyear');
set(yb,'string',num2str(VECFIG.year_base));
opph = findobj(gcf,'tag','txtboxoutpath');
set(opph,'string',VECFIG.outpath);
dspo = findobj(gcf,'tag','txtboxsavepath');
set(dspo,'string',VECFIG.outpath);
cnffs = findobj(gcf,'tag','txtboxsavefn');
set(cnffs,'string', 'webvec_cfg');
dtpo = findobj(gcf,'tag','txtboxloadpath');
set(dtpo,'string',VECFIG.outpath);
set(dtpo,'HorizontalAlignment', 'right');
cnffl = findobj(gcf,'tag','popuploadfn');
curdir =  pwd;
cd(VECFIG.loadpath)
files = what;
str_b = files.mat;
for i = length(str_b):-1:1
   chary = char(str_b(i));
   if isempty(findstr(chary, 'cfg'))
      str_b(i) = [];
   end
end
VECFIG.loadfn = str_b;
if isempty(str_b); VECFIG.loadfn = {'None'}; end;
cd(curdir)
set(cnffl,'value',length(VECFIG.loadfn));
set(cnffl,'string',VECFIG.loadfn);
pud1 = findobj(gcf,'tag','popupdepth1');
depthvars = num2cell(XYDATA.z(1:end-1));
set(pud1,'string',depthvars);
set(pud1,'max',length(depthvars));
pud2 = findobj(gcf,'tag','popupdepth2');
depthvars2 = num2cell(XYDATA.z(2:end));
set(pud2,'string',depthvars2);
set(pud2,'max',length(depthvars2));
tbt = findobj(gcf,'tag','txtboxtitle');
set(tbt,'string',VECFIG.title);
pnm = findobj(gcf,'tag','txtboxprintfn');
set(pnm,'string',[VECFIG.printfilefn, '.eps'] );
set(pnm,'HorizontalAlignment','center');
cbp = findobj(gcf,'tag','chkboxprint');
set(cbp,'value', 1); 
pp = pwd;
marks = findstr(pp, filesep);
VECFIG.cruiseID = upper(pp(marks(end)+1:end));

sc = findobj(gcf,'tag','txtboxscale');
set(sc, 'string', '3');
VECFIG.vec_scale = 1/3; %=1/str2num(vec_scalestr);
VECFIG.printchoice = 0;
di = findobj(gcf,'tag','chkboxdate');
set(di,'value',0);

% default data for/from mvecfig.m in case bypassed
VECFIG.mv_color = 'k';
VECFIG.mv_edgecolor = 'k';
VECFIG.mv_headangle = 60;
VECFIG.mv_headwidth = NaN;
VECFIG.mv_shaftwidth = 1;
VECFIG.mv_headlength = 5;
VECFIG.mv_centered = 0;
VECFIG.usecdata = 1; 
VECFIG.mv_cdatafile = [];
VECFIG.cdata_mm = -99;
VECFIG.circlescale = 10;
VECFIG.mv_suppdatafile = [];
VECFIG.mv_supplementary = 0;
VECFIG.mv_colorsupp = 'none';
VECFIG.mv_edgecolorsupp = 'red';
VECFIG.circlescalesupp = '20';
VECFIG.usecdata = 1;
VECFIG.radioscale = 2;

% other defaults
VECFIG.btntype = [];
VECFIG.projection = 'merc';
VECFIG.moreproj = 0;
VECFIG.m_coast_str = 'm_coast(''patch'',[0.6  0.5  0.0]);';
VECFIG.basintype = 1;
VECFIG.basinresolution = 1;
brs = findobj(gcf,'tag','popupdbase');
set(brs,'value',VECFIG.basinresolution);
VECFIG.boundsflag = 0;
VECFIG.coastflag = 0;
VECFIG.gridflag = 0;

dp = findobj(gcf,'tag','chkdprange');
set(dp,'value',1);
ch = findobj(gcf,'tag','chkcalendar');
set(ch,'value',1);
% try to set up temp. colored arrows
marks = findstr(VECFIG.dbpath, filesep);
newpath = VECFIG.dbpath(1:marks(end-1));
prefix = VECFIG.dbpath(marks(end)+1:marks(end)+5);
ttfile = fullfile(newpath,'edit', [prefix,'.tem']);
if exist(ttfile)  
   VECFIG.mv_cdatafile = ttfile;
end

determine_ranges;
fixtitle;

%%%%%%%%%%%%%    EOF