function [cp hp cn hn] = Plot2DSpec(xppm, yppm, spec_data, spec_axes, init_contour, cnt_factor, num_contours)
% Plot2DSpec(xppm, yppm, spec_data, spec_axes, init_contour, cnt_factor, num_contours)
% [cp hp cn hn] = Plot2DSpec(xppm, yppm, spec_data, spec_axes, init_contour, cnt_factor, num_contours)
% Plot 2D spectrum data (with axes info) as read in by read_nmrp
%    xppm indicates the range along the direct dimension to plot and
%    yppm along the indirect dimension.  Optional outputs are those from
%    the matlab function contour
% For now, only plotting of 2D spectra (stored as MATLAB/OCTAVE arrays) is
% supported -- eventually support plotting of all spectra

%% for now aspect ratio is set to "square" -- figure out how to better do this automatically
%% or via command options

bounds = ppm2inc([max(xppm) max(yppm); min(xppm) min(yppm)], spec_axes);
xsize = 1+bounds(2,1)-bounds(1,1);
ysize = 1+bounds(2,2)-bounds(1,2);
xrange = linspace(max(xppm),min(xppm),xsize);
yrange = linspace(max(yppm),min(yppm),ysize);
the_contours = exp(log(init_contour):log(cnt_factor):log(init_contour*(cnt_factor^num_contours)));

% x_width = spec_axes(26,1);
% y_width = spec_axes(26,2);

%  Below is adapted from code, Auto-generated by MATLAB on 29-Jun-2010 14:29:34

% Create figure
figure1 = figure('XVisual',...
    '0x24 (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)','Color',[1 1 1]);
colormap('bone');

% Create axes
axes('Parent',figure1,'YDir','reverse','XDir','reverse',...
    'PlotBoxAspectRatio',[1 1 1],...
    'LineWidth',1,'Layer','top');
% Uncomment the following line to preserve the X-limits of the axes
% xlim([6.5 7.5]);
% Uncomment the following line to preserve the Y-limits of the axes
% ylim([0.5 1.5]);
box('on');
hold('all');

% Create contour
[cp hp] = contour(xrange,yrange,spec_data(bounds(1,1):bounds(2,1),bounds(1,2):bounds(2,2))',the_contours,'LineWidth',1);
hold on
[cn hn] = contour(xrange,yrange,spec_data(bounds(1,1):bounds(2,1),bounds(1,2):bounds(2,2))',-the_contours,'LineWidth',1,'LineStyle',':');
xlabel('\omega_2 (ppm)')
ylabel('\omega_1 (ppm)')