% *********************************************************************
% Staplot: An interactive hydrographic data viewing routine for Matlab
%                          Version 3.1
%
%            Deirdre Byrne, L-DEO, 1 Dec 1995
%
%                 dbyrne@grayling.umeoce.maine.edu
% *********************************************************************
%
% Packing list: M-files (scripts and functions)
%
%      add_data.m, changelog, coast.m, coastln.mat, colorbr1.m, 
%      contfill.m, contsurf.m, dist.m, findnew.m, findold.m, gvars.m, gvarso.m, 
%      hydroplt.m, install.m, isolabel.m, isopycs.m, isstrcmp.m, loaddata.m, 
%      manifest, minmax.m, optsmerg.m, pltctrl.m, position.m, ppldot.gif, 
%      readme.1st, samp1dat.mat, samp2dat.mat, sample1.m, sample1.tpl, 
%      sample1o.m, sample2.m, sample2.tpl, sample2o.m, saveopts.m, settype.m, 
%      showtype.m, sta_plot.m, staid.m, staintro.html, stamenu.m, staplot.html, 
%      staplot.m, staplot.tpl, staplot.txt, stasave.m, stasel.m, swfreeze.m, 
%      swstate.m, topomap.m, xclabel.m, xcont.txt, xcontour.m
%
% MAT files (binary)
%
%       coastln.mat, samp1dat.mat, samp2dat.mat, sealevel.mat,
%       b0010.mat, b0025.mat, b0050.mat, b0075.mat, b0100.mat, 
%       b0150.mat, b0200.mat, b0250.mat, b0500.mat, b0750.mat
%       b1000.mat, b2000.mat b3000.mat b4000.mat, b5000.mat, b6000.mat
%
% Also included for use with topomap, but not in STAPLOT, are (binary)
%       b7000.mat, b8000.mat, b9000.mat, b10000.mat, t1000.mat, t2000.mat,
%       t3000.mat, t4000.mat, t5000.mat, t6000.mat, and t7000.mat.
%
% Total size: about 13Mb
%-----------------------------------------------------------------------
% Please see the file 'staplot.htm' or 'staplot.txt' for help and instructions.
%  Bug reports and suggestions to me at:
%
%                   dbyrne@grayling.umeoce.maine.edu
%
%                              -- Deirdre Byrne 98/04/09
%
%------------------------------------------------------------------------

% check for most recent session. 
global saveopts_file
% SAVE SESSION NAME TO CURRENT DIRECTORY
saveopts_file = 'saveopts.m';

% uncomment lines below to make sure path is correct and run the 'trial' version
%pa = path;
%dir = pwd;
%dirsep = '/';
%c = computer;
%if strcmp(c(1:2),'PC')
%  dirsep = '\';
%elseif strcmp(c(1:2),'MA')
%  dirsep = ':';
%elseif isvms
%  dirsep = '.';
%end
%if isempty(findstr(dir,pa))
%  path(path,dir)
%end
%pa = path;
%l = size(dir,2);
%if ~strcmp(dir(l),dirsep)
%  dir = [dir dirsep 'BATHYMETRY'];
%end
%if isempty(findstr(dir,pa))
%  path(path,dir)
%end

fid = fopen(saveopts_file,'r+');
if fid > -1
  tag = fgetl(fid);
  fclose(fid);
  if isstr(tag)
    tag = deblank(tag);
    tag = fliplr(deblank(fliplr(tag)));
    arg = sprintf('Load saved session ''%s''? [y] >> ',tag);
    choice = input(arg,'s');
    if isempty(choice), choice = 'y'; end
    if ~strcmp(deblank(lower(choice)),'y')
      disp('Load a different session?')
      tag = input('[type in session name, or CR to load defaults] >> ','s');
      if isempty(tag)
	tag = 'gvars';
      end
    end
  else % tag is not a string. very rare. (means line was empty)
    disp('Load a different session?')
    tag = input('[type in session name, or CR to load defaults] >> ','s');
    if isstr(tag)
      tag = deblank(tag);
      tag = fliplr(deblank(fliplr(tag)));
    elseif isempty(tag)
      tag = 'gvars';
    end
  end
else % we couldn't load saveopts
  disp('Couldn''t find a ''saveopts'' file')
  disp('Load a saved session?')
  tag = input('[type in session name, or CR to load defaults] >> ','s');
  if isstr(tag)
    if ~isempty(tag)
      tag = fliplr(deblank(fliplr(deblank(tag))));
    else
      tag = 'gvars';
    end
  else
    tag = 'gvars';
  end
end

if strcmp(tag,'gvars')
  disp('Loading default options. Please load a datafile before trying to plot.')
end

eval([tag 'o'])
arg = sprintf('options_file:%s',tag);
hydroplt(arg);
clear ans arg choice tag fid pa dir dirsep c l
