% Sweep DARM (differential arm length) in DRFPMI and generate plots.
%
% [xPos, sigDC, fDC] = sweepDARM(Nsweep)
% see sweepDC for information about the parameters
%
% This displays some DC signals, and some demod signals, during
% a DARM sweep.  The AS_I2 and Q2 signals are used for DARM, but
% the phase at DC is only part of the story (see respDARM).

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

  % Check number of input arguments
  if nargin < 1
    Nsweep = 100;
  elseif nargin > 1
    error('Too Many Arguments!')
  end

  % 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)];

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % DARM sweep
  pos = zeros(opt.Noptic, 1);
  pos(nEX) = 0.5e-11;
  pos(nEY) = -0.5e-11;
  
  [xPos, sigDC, fDC] = sweepDC(opt, -pos, pos, Nsweep);

  subplot('position',[0.1 0.475 0.85 0.45])
  semilogy(xPos(nEX, :)*2e12, sigDC(nDC, :))
  ylabel('Watts')
  legend(prbNames(nDC),...
         'Location','SouthWest')
  title('DARM sweep: DC signals (top) & Demods (below)',...
        'Color',[0.1 0 0.5],...
        'FontWeight','demi')
  grid on
  axis([-pos(nEX)*2e12 pos(nEX)*2e12 1e-3 1])
  set(gca,'XTickLabel',[])
  %lineAtX(0, 0.3 * [1 1 1]);
 
  subplot('position',[0.1 0.06 0.85 0.4])
  plot(xPos(nEX, :)*2e12, sigDC(nAS([1:3 8:14]), :))
  legend(prbNames(nAS([1:3 8:14])))
  axis([-pos(nEX)*2e12 pos(nEX)*2e12 -1 1])
  xlabel('dL- [pm]')
  ylabel('~Volts')
  grid on


  
  % Error routine for output arguments - - - - - - - - - - - - - - - - - -
  if nargout > 3
    error('Too Many Output Arguments. Max = 3')
  end
  
  orient tall
  print -dpdf DARMsweep-aLIGO.pdf
  
