How to use:
In MATLAB, call the function and input your data file (sample data file attached).
>> Create_STK_EphemerisFile('C:\Users\<username>\Desktop\Sample_LLA_Data.txt')
function [ ] = Create_STK_EphemerisFile( filepath )
fileID = fopen(filepath);
C = textscan(fileID,'%s %s %s %s');
fclose(fileID);
Time = C{1};
Lat = C{2};
Lon = C{3};
Alt = C{4};
eFilePath = [pwd '\outputEphemeris.e'];
dataPts = length(Time);
eData = cell(dataPts,4); %Define dimensions of 'eData' cell array
%Create Time, Lat, Lon, Alt columns to send to e file
for i = 1:dataPts
eData{i,1} = Time{i};
eData{i,2} = Lat{i};
eData{i,3} = Lon{i};
eData{i,4} = Alt{i};
end
%%%%---------- Create ephemeris file (*.e) ----------%%%%
eFile = fopen(eFilePath, 'wt', 'n', 'US-ASCII');
%Write ephemeris file headers
fprintf(eFile,'stk.v.10.0\n');
fprintf(eFile,'BEGIN Ephemeris\n');
fprintf(eFile,['NumberOfEphemerisPoints ' num2str(dataPts) '\n']);
fprintf(eFile,'InterpolationMethod GreatArcMSL\n');
fprintf(eFile,'InterpolationOrder 1\n');
fprintf(eFile,'CentralBody Earth\n');
fprintf(eFile,'DistanceUnit Feet\n');
fprintf(eFile,'ScenarioEpoch 9 Oct 2015 16:00:00.000\n');
fprintf(eFile,'TimeFormat EpSec\n');
fprintf(eFile,'EphemerisMSLLLATimePos\n');
%Add Time, Lat, Lon, Alt Columns to the file
formatSpec = '%s %s %s %s\n';
for row = 1:dataPts
fprintf(eFile,formatSpec,eData{row,:});
end
fprintf(eFile,'END Ephemeris\n');
%Close and confirm the creation of the new file
fclose(eFile);