% Add a probe of some output/departing field.
%
% Arguments:
% opt - the optickle model
% name - probe name
% snOpt - the serial number or name of the source optic
% nameOut - the number or name of the output port
% freq - demodulation/RF frequency
% phase - demodulation/RF phase offset (degrees)
%
% The input/output ports of an optic depend on the type of optic.
% See dispPortNames for more information.  See also addPortIn,
% and addLink (as the argument syntax is similar).
%
% opt = addProbeOut(opt, name, snOpt, nameOut, freq, phase);

function opt = addProbeOut(opt, name, snOpt, nameOut, freq, phase)

  % check/parse field source
  snOpt = getSerialNum(opt, snOpt);
  portFrom = getPortNum(opt, nameOut, opt.optic(snOpt).outNames);

  snLink = opt.optic(snOpt).out(portFrom);
  if snLink == 0
    error('Unavailable Field: %s not linked (sorry.  Add a sink?)', ...
          getOutputName(opt, snOpt, portFrom));
  end
  nField = opt.link(snLink).m;

  % create new probe
  opt = addProbe(opt, name, nField, freq, phase);
