function [] = set_up_poincare_plots()
% POINCARE -- optional preparation for making Poincare' plots

eval('doit', ...
    [ 'disp(''Can''''t proceed nor redo due to deficiencies in Matlab.'');' ...
      'disp(''Please type ''''poincare'''' again.'');' ]);


function [] = doit()

if isunix
  cd ~/Thesis/matlab/poincare
else
  cd c:\users\bert\matlab\poincare
end

if 1
  disp('generating P files.');
  clear functions; clear mex;
  delete *.p
  clear functions; clear mex;
  dirent = dir('*.m');
  for idx = 1:length(dirent)
    % paranoia: don't ever make a P-file from this file
    if ~strcmp(lower(dirent(idx).name), 'poincare.m')
      %disp([ '  ' dirent(idx).name ]);
      clear functions; clear mex
      pcode(dirent(idx).name);
      clear functions; clear mex
    end  
    clear functions; clear mex;
  end
  disp(' ');
end

disp('Use exhaustive_map(''name'', E) to plot the specified potential')
disp('at energy E.  interactive_map(...) lets you explore the plots')
disp('interactively.  Known potential names are currently:');

% display all files which have both d_XXX_[fb].m and XXX.m files
dirent = dir('*.m');

for idx = 1:length(dirent)
  % extract the "base" potential name...
  base = dirent(idx).name;           % extract the name
  ext = findstr(base, '.m');
  if ~isempty(ext)
    base = base(1:(ext(1)-1));
  end
  % ...and check if both exist
  if exist(sprintf('d_%s_f', base), 'file') ...
	& exist(sprintf('d_%s_b', base), 'file'),
    % valid name: display
    disp([ '    ' base ]);

  elseif exist(sprintf('d_%s_f', base), 'file') ...
	| exist(sprintf('d_%s_b', base), 'file'),
    % error: a d_* tile is lying about its origins.
    error([ 'internal inconsistency: d_' base ' doesn''t go both ways?' ]);

  end
  % (NB: do nothing if a mismatch occurs)
end
