function [] = plot_packet(data, scaling, delta, trans)

% pack_square(DATA) plots a packet using square cells.

if nargin<2,                   scaling = [];     end
if nargin<3 | isempty(delta),  delta = .035;     end
if nargin<4 | isempty(trans),  trans = [0 0];    end

q = [-1 -1  1  1]*.8;
w = [-1  1  1 -1]*.8;

dimen = size(data);
ipos = [0:floor(dimen(1)/2)-1 -floor(dimen(1)/2):-1]*delta + trans(1);
jpos = [0:floor(dimen(2)/2)-1 -floor(dimen(2)/2):-1]*delta + trans(2);
pr = abs(data);
if isempty(scaling), scaling = max(max(pr)); end
pr = pr ./ scaling .* (delta/2);

%irange = 1:dimen(1);  jrange = 1:dimen(2);
sz = floor(dimen(1)/4);
irange = [1+(sz:-1:0) dimen(1)-(0:(sz-1))];
sz = floor(dimen(2)/4);
jrange = [1+(sz:-1:0) dimen(2)-(0:(sz-1))];

newplot;
set(gca, 'DataAspectRatio',[1 1 1], 'Box','on');
set(gca, 'XLim',[ipos(irange(length(irange))) ipos(irange(1))], ...
         'YLim',[jpos(jrange(length(jrange))) jpos(jrange(1))]);
for i = irange,
  for j = jrange,
    if pr(i,j)>=1e-6,
      patch(ipos(i)+pr(i,j)*q, jpos(j)+pr(i,j)*w, 'k', 'EdgeColor', 'none');
    end
  end
end

global energy_contour
if ~isempty(energy_contour) & ~ishold,
  line(energy_contour(1,:),energy_contour(2,:), 'Color', [0 0 1]);
end
