% Sweep PRCL (signal recycling cavity length) in DRFPMI and generate plots.
%
% [xPos, sigDC, fDC] = sweepPRCL(Nsweep)
% see sweepDC for information about the parameters
%
% This displays some DC signals, and some demod signals, during
% a PRCL sweep.  From this sweep, one might try to find a good
% signal for PRCL.

function [xPos, sigDC, fDC] = sweepPRCL(Nsweep)

  % prepare some variables
  sweepSetup

  % adding this to sweepSetup causes matlab to crash, so do it here
  nDC = [nREFL(1) nAS(1) nPOX(1) nPOY(1) nTRX(1) nTRY(1)];

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % PRCL sweep
  pos = zeros(opt.Noptic, 1);
  pos(nPR) = 4e-8;
  
  [xPos, sigDC, fDC] = sweepDC(opt, -pos, pos, Nsweep);

  % make some plots
  fDCp = permute(fDC, [2, 3, 1]);  
  n = getFieldAt(opt, nPR, 'fr');		% PR front input field

  subplot(2, 1, 1)
  semilogy(xPos(nPR, :), abs(fDCp(:, :, n)))
  title('PRCL sweep: RF component powers in the PRC')
  legend(num2str(vFrf / 1e6))
  grid on

  subplot(2, 1, 2)
  plot(xPos(nPR, :), sigDC(nREFL(2:end), :))
  legend(prbNames(nREFL(2:end)))
  title('PRCL sweep: REFL demod signals')
  grid on
