function pspspgr1_s1(spgr,cl,seg_plot,freq,opt_str)
% function pspspgr1_s1(spgr,cl,seg_plot,freq,opt_str)
% Function to plot single section at fixed segment from
%  log10 MT spectrogram in current subplot window
%
% Inputs
%    spgr           Frequency matrix from spectrogram analysis.
%    cl             cl structure from spectrogram analysis.
%    seg_plot       Ssegment to plot
%    freq           Frequency limit for plotting (Hz).
%    opt_str        Plotting Options, use string, e.g.:   'c'
%                    c    Include point wise confidence limits

% Check numbers of arguments. 
if (nargin<4)
  error('Not enough input arguments');
end

% Check type
if (cl(1).type~=30)
  error('Not type 30 analysis')
end

% x axis is frequency
plot_pts=find(cl.freq<=freq);
x_axis=cl.freq(plot_pts);
if (length(x_axis)==0)
	error('No data to plot. Increase frequency limit')
end	

% Time axis in seconds
seg_sec=cl.seg_size/cl.samp_rate;
sec_start=seg_sec/2;
seg_sec_inc=seg_sec*cl.seg_inc_fac;
time_axis=(0:cl.seg_tot-1)'*seg_sec_inc+sec_start;

% Check valid segment number
if (seg_plot<1 | seg_plot>cl.seg_tot)
	error(['Invalid segment number. Min, Max: ',num2str([1 cl.seg_tot])])
end	

if nargin<5
	opt_str='';
end

% Options
cl_flag=0;
options=deblank(opt_str);
while (any(options))              % Parse individual options from string.
  [opt,options]=strtok(options);
  optarg=opt(2:length(opt));      % Determine option argument.
  switch (opt(1))
		case 'c'             % Include pointwise confidence limits
			cl_flag=1;
    otherwise
      error (['Illegal option -- ',opt]);  % Illegal option.
  end
end

f11=spgr(plot_pts,seg_plot);

if cl_flag % Pointwise confidence limits in grey
	f11_c95up=f11+cl.spg_c95;
	f11_c95lp=f11-cl.spg_c95;
	h=plot(x_axis,f11_c95up,x_axis,f11_c95lp);
	set(h,'color',0.75*[1 1 1]);
	hold on
end

plot(x_axis,f11,'k');
hold on

% Confidence limit scale bar.
freq_cl=0.95*max(x_axis);
plot([freq_cl freq_cl],[max(f11) max(f11)-(2*cl.spg_c95)],'k-')

xlabel('Frequency (Hz)')
title([cl(1).what, ' Log_{10} Spectrogram, Segment: ',num2str(seg_plot),'.  Sec: ',num2str(time_axis(seg_plot))])
axis([0,freq,-inf,inf]);
hold off
