function [status] = CreateFiducialFile(et,es,z,name)
%   [status] = CreateFiducialFile(et,es,z,name)
%   CreateFiducialFile - Create Slicer Fiducial File for GMR microdrive.
%   9/16/2020   
%
%   This function calculates the x,y,z coordinates of the electrode tips 
%   based on the intial position of the microdrive and the 
%   amount of travel for each electrode.  The points are 
%   saved to a .fcsv file that can be opened in 3D Slicer.  
%
%   Input Parameters:
%   ELECTRODE_TRAVEL is a 1 x numchannels array specifing how far each
%   electrode has moved in number of turns.  1 turn each .125mm.
%
%   ELECTRODE_STARTS is a numchannels x 3 array specifiying the x,y,z
%   starting coordinates of each electrode tip.  Get this from the GMR
%   MicrodriveSpecs excel file on the Electrode Starts sheet.
%
%   TRAVEL_DIRECTION_UNIT_VECTOR is a unit vector specifing the diection of
%   travel for all electrodes.  Get this from the GMR
%   MicrodriveSpecs excel file on the Electrode Starts sheet.
%
%   NAME is a string for the fiducial list filename.
%

%create fake travel for testing
if isempty(et)
    %et = zeros(1,size(es,1));     %starting positions
    et = 1.5*8*ones(1,size(es,1));  %specify travel
end

%convert turns to mm
et = et/8;
%calculate electrode tip
pp = es + et'*z;
%concatenate id to positions for file writing
id = 1:size(pp,1);
pp = [id' pp id' id'];
%write Slicer Fiducial File
fid = fopen([name '.fcsv'],'w');
fprintf(fid,'# Markups fiducial file version = 4.10 \n');
fprintf(fid,'# columns = id,x,y,z,ow,ox,oy,oz,Vis,Sel,Lock,Name,Description \n');
%               id  x  y  z owoxoyozV S L N    Desc
fprintf(fid,'id_%i,%f,%f,%f,0,0,0,1,1,0,1,%i,electrode%i \r\n',pp');
fid=fclose(fid);
status=1;
end



