function ecef = ENU2ECEF(enu,varargin)
lat = 0;
lon = 0;
ecef = 0;
% resolve inputs
if nargin == 3
if isfloat(varargin{1}) lat = varargin{1}; end
if isfloat(varargin{2}) lon = varargin{2}; end
end
% prepare input to conversion function
outPtr = libpointer('doublePtr',ones(1,6));
if isstruct(enu)
if sum(isfield(enu,{'x','y','z','xdot','ydot','zdot'}))==6
in = [enu.x enu.y enu.z enu.xdot enu.ydot enu.zdot];
inPtr = libpointer('doublePtr',in);
else
errorstr = sprintf('Unexpected input format.\nPlease provide enu.x,y,z,xdot,ydot,zdot.');
errordlg(errorstr);
return;
end
else
if length(enu)==6
inPtr = libpointer('doublePtr',enu);
else
errorstr = sprintf('Unexpected input format.\nPlease provide enu.x,y,z,xdot,ydot,zdot.');
errordlg(errorstr);
return;
end
end
% load library if not loaded
if(~libisloaded('CoorConversionDLL'))
if(~LoadCoorConversionDLL)
errordlg('Failed to load coordinate conversion library!\nConfirm proper working directory.');
return;
end
end
% call function
[ecefVect, ecefVect] = calllib('CoorConversionDLL','ENU2ECEF',inPtr,dt,outPtr);
ecef.x = ecefVect(1); ecef.y = ecefVect(2); ecef.z = ecefVect(3);
ecef.xdot = ecefVect(4); ecef.ydot = ecefVect(5); ecef.zdot = ecefVect(6);