function setup_info = setup_optotrak(varargin)

if nargin > 0 & nargin < 5
    disp('Not enough inputs to setup_optotrak');
    return;
elseif nargin > 0
    nPort1 = varargin{1};
    nPort2 = varargin{2};
    nPort3 = varargin{3};
    nPort4 = 0; 
    fFrameFrequency = varargin{4};
    fCollectionTime = varargin{5};
else
    %get information about the number of markers on each port, the collection
    %frequency and the collection time.  Here we use the input dialog,
    %alternatively you could hard code these values.  Note, we use the naming
    %convention adopted in the API
    [nPort1, nPort2, nPort3, nPort4,fFrameFrequency, fCollectionTime] = setup_optotrak_dialog;
end

%setup the strober specific information (number of markers per
%port)...NOTE, this function requires a value for a 4th port, but since the
%Certus only has 3, this 4th value is always 0
OptotrakSetStroberPortTable(nPort1,nPort2,nPort3,nPort4);

%setup collection - note, these values are from Binstead code,
%which match those listed in the API.
nMarkers = nPort1 + nPort2 + nPort3;
fMarkerFrequency=2500.0;
nThreshold=30;
nMinimumGain=160;
nStreamData=0;
fDutyCycle=0.5;
fVoltage=8.0;
fPreTriggerTime=0.0;
nFlags=0;
%[nMarkers,fFrameFrequency,fMarkerFrequency,nThreshold,nMinimumGain,nStreamData,fDutyCycle,fVoltage,fPreTriggerTime,nFlags] = OptotrakSetupCollection(nMarkers,fFrameFrequency,fMarkerFrequency,nThreshold,nMinimumGain,nStreamData,fDutyCycle,fVoltage,fPreTriggerTime,nFlags);
[nMarkers,fFrameFrequency,fMarkerFrequency,nThreshold,nMinimumGain,nStreamData,fDutyCycle,fVoltage,fCollectionTime,fPreTriggerTime,nFlags] = OptotrakSetupCollection(nMarkers,fFrameFrequency,fMarkerFrequency,nThreshold,nMinimumGain,nStreamData,fDutyCycle,fVoltage,fCollectionTime,fPreTriggerTime,nFlags);
pause(1);
OptotrakActivateMarkers();
pause(2); %wait times recommended in API

setup_info.numMarkers = nMarkers;
setup_info.frameRate = fFrameFrequency;
setup_info.collectionTime = fCollectionTime;

function [numMarkPort1, numMarkPort2, numMarkPort3, numMarkPort4,collFreq, collTime] = setup_optotrak_dialog

%create the dialog box and get user input
prompt={'Markers on Port 1:',...
       'Markers on Port 2:',...
       'Markers on Port 3:',...
       'Collection Frequency (Hz):',...
       'Collection duration (s):'};
name='Optotrak Setup';
numlines=[1,35]; %this width allows for title to be seen
defaultanswer={'6','0','0','200','2'};
answer=inputdlg(prompt,name,numlines,defaultanswer);

%convert from string to number data for output variables
numMarkPort1 = str2num(answer{1});
numMarkPort2 = str2num(answer{2});
numMarkPort3 = str2num(answer{3});
numMarkPort4 = 0; %note Certus requires this be set to 0
collFreq = str2num(answer{4});
collTime = str2num(answer{5});