function install
p = sprintf('\n'); disp(p);
disp('Please type in the fully defined pathname and directory')
disp('in which you have put STAPLOT.')
p = sprintf('\n'); disp(p);
dir = input('[CR to abort] >> ','s');
if ~isempty(dir)
  ismac = 0;
  dirsep = '/';
  c = computer;
  if strcmp(c(1:2),'PC')
    dirsep = '\';
  elseif strcmp(c(1:2),'MA')
    dirsep = ':';
  elseif isvms
    p = sprintf('\n'); disp(p);
    disp('''Install'' is not available for VAX/VMS systems.  Please edit')
    disp('the STAPLOT file ''staplot.m'', and add a path specification')
    disp('to the file name contained in the variable saveopts_file.')
    disp('                                                          ')
    disp('Please also edit STAPLOT files ''sample1.m'', and ''sample2.m'' and')
    disp('add a fully qualified path into the strings beginning with ''file = ''.')
    disp('which you will find near the top of each of these scripts.')
    p = sprintf('\n'); disp(p);
    return
%    dirsep = '.';
  end
  dir = fliplr(deblank(fliplr(deblank(dir))));
  arg = sprintf('path(path,''%s'')',dir);
  p = sprintf('\n'); disp(p);
  eval(arg)
  subdir = [dir dirsep 'BATHYMETRY'];
  arg2 = sprintf('path(path,''%s'')',subdir);
  eval(arg2)
  ll = length(dir);
  multi = input(['Will there be more than one person using this ', ...
	  'copy of STAPLOT ? (y/n) [n] >> '],'s');
  if isempty(multi)
    multi = 0;
  else
    if strcmp(deblank(lower(multi)),'y')
      multi = 1;
    else
      multi = 0;
    end
  end
  if ~strcmp(dir(ll),dirsep);
    dir = [dir dirsep];
  end
  fnames = str2mat('sample1.tpl','sample2.tpl','staplot.tpl');
  newnames = str2mat('sample1.m','sample2.m','staplot.m');
  tags = str2mat('samp1dat','samp2dat','saveopts.m');
  check = [];
  for i = 1:3
    fname = [dir deblank(fnames(i,:))];
    newname = [dir deblank(newnames(i,:))];
    fid1 = fopen(fname,'r');
    if fid1 == (-1)
      p = sprintf('\n'); disp(p);
      disp('Not able to complete install. Please check the path and')
      disp('directory specifications and try again. Possibly you are')
      disp('missing some files.  Your STAPLOT directory should contain')
      disp('these files:')
      p = sprintf('\n'); disp(p);
      disp(str2mat(str2mat('add_data.m','b0000.mat','b1000.mat','b2000.mat', ...
	  'b3000.mat', 'b4000.mat', 'b5000.mat', 'b6000.mat'), ...
	  str2mat('changelog','coast.m','coastline.mat','colorbr1.m','contfill.m', ...
	  'contsurf.m', 'findnew.m', 'findold.m', 'gvars.m', 'gvarso.m'), ...
	  str2mat('hydroplt.m','install.m','isolabel.m','isopycs.m','isstrcmp.m', ...
	  'loaddata.m', 'manifest', 'minmax.m', 'optsmerg.m', 'pltctrl.m'), ...
	  str2mat('readme.1st','samp1dat.mat','samp2dat.mat','sampdata.mat',...
	  'sample1.m', ...
	  'sample1.tpl', 'sample1o.m', 'sample2.m', 'sample2.tpl', 'sample2o.m'), ...
	  str2mat('saveopts.m','settype.m', 'showtype.m', 'sta_plot.m', 'staid.m', ...
	  'stamenu.m', 'staplot.m', 'staplot.tpl', 'staplot.html', 'staplot.txt'), ...
	  str2mat('stasave.m', 'stasel.m', 'swfreeze.m', 'swstate.m', 'topomap.m', ...
	  'wishlist', 'xclabel.m', 'xcont.txt', 'xcontour.m')))
      p = sprintf('\n'); disp(p);
      return
    else
      fseek(fid1,0,'eof');
      eof = ftell(fid1);
      fseek(fid1,0,'bof');
      fid2 = fopen(newname,'w');
      if fid2 > -1
	line = fgetl(fid1);
	f = 1;
	while ftell(fid1) < eof
	  if strcmp(line,'% TEMPLATE FOR INSTALLED VERSION')
	    if (multi & i == 3)
	      line = '% SAVE SESSION NAME TO CURRENT DIRECTORY';
	    else
	      line = '% THIS SHOULD BE A FULLY DEFINED PATHNAME AFTER INSTALLATION';
	    end
	  end
	  p = findstr(line,deblank(tags(i,:)));
	  if ~isempty(p)
	    if multi & (i == 3)
	      % don't change to an absolute saveopts.m in multi-user mode
	    else
	      if ~strcmp(line(1),'%')  % ignore the packing list
		line = [line(1:p-1) dir line(p:length(line))];
	      end
	    end
	    f = 0;
	  end
	  fprintf(fid2,'%s\n',line);
	  line = fgetl(fid1);
        end
        fprintf(fid2,'%s\n',line); % print last line
        check = [f check];
        p = fclose(fid1);
        check = [p check];
        p = fclose(fid2);
        check = [p check];
      else
	disp('Output file unable to be opened.  Please check your directory')
	disp('specification and also the write permisson in that directory.')
	disp('Specifically, you must have write permission for these files:')
	disp('sample1.m, sample2.m and staplot.m')
	fclose(fid1);
	break
	return
      end
    end
  end
    
  if all(~check)
    p = sprintf('\n'); disp(p);
    disp('Installation successful.  Please add the lines:' )
    disp(arg)
    disp(arg2)
    disp('to your startup.m file.')
    disp('Otherwise you may have to execute them each time you want use STAPLOT.')
    disp('To reinnstall at any point, simply repeat the steps you took to get to')
    disp('this point.  No ''uninstall'' should be necessary.')
    p = sprintf('\n'); disp(p);
  else
    disp('Installation not complete')
  end
else
  p = sprintf('\n'); disp(p);
  disp('No installation has been done.  To use STAPLOT without proper installation,')
  disp('Please ''cd'' to the STAPLOT directory before attemping to start or use it.')
  p = sprintf('\n'); disp(p);
end
clear dir ll fid1 fid2 fname newname eof p line ans ppp1 ppp2 arg c dirsep
clear check fnames newnames f i tags



