% Sweep CARM  (common arm length) in DRFPMI and generate plots.
%
% [xPos, sigDC, fDC] = sweepCARM(Nsweep)
% see sweepDC for information about the parameters
%
% This displays some DC signals, and some demod signals, during
% a CARM sweep.  The phase of the REFL_I1 signal is set to maximize
% its response to this sweep.

%setPosOffset.m ---

%  set the position offset for an optic
  
 % opt = setPosOffset(opt, snOpt, pos)
 % snOpt - serial number or name of an optic
 % pos - zero position for this optic

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


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

  % prepare some variables
  sweepSetup

    % XARM DeToon in degrees
  dTunePhase_XARM = -.07; % XARM micro detuning (see note)
  % set position offsets for XARM
  dTune = dTunePhase_XARM * (opt.lambda / 360);
  opt = setPosOffset(opt, nEX,  dTune); %opt.lambda / 4 +
  
  % 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)];
%  nDC = [nPOX(1) nPOY(1) nTRX(1) nTRY(1)];
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % XARM sweep
  pos = zeros(opt.Noptic, 1);
  pos(nEX) = 3e-9;
  %pos(nEY) =0;% 3e-11;
  
  
  [xPos, sigDC, fDC] = sweepDC(opt, -pos, pos, Nsweep);
figure(2)
  subplot(2, 1, 1)
  semilogy(xPos(nEX, :), sigDC(nDC, :))
  legend(prbNames(nDC))
  title('XARM sweep: DC signals')
  xlabel('ETMX detuning [m]')
  grid on

  subplot(2, 1, 2)
  plot(xPos(nEX, :), sigDC(nPOX(2:end), :))
  legend(prbNames(nPOX(2:end)))
  title('XARM sweep: REFL demod signals')
  xlabel('ETMX detuning [m]')
  grid on
