[fid, iopt, nsegments, mass0, thrmag, xisp, time_g, time_lb, ...

function [fid, iopt, nsegments, mass0, thrmag, xisp, time_g, time_lb, ...
time_ub, throttle_g, throttle_lb, throttle_ub, alpha_g, ...
alpha_lb, alpha_ub, jd_guess] = read_ilt(filename)
% read simulation data file
% required by ilt_opt.m
% input
% filename = name of simulation data file
% output
% fid = file id
% iopt = type of trajectory optimization
% nsegments = number of trajectory time segments
% mass0 = initial mass (kilograms)
% thrmag = propulsive thrust (newtons)
% xisp = specific impulse (seconds)
% time_g = initial guess for mission duration (days)
% time_lb = lower bound for mission duration (days)
% time_ub = upper bound for mission duration (days)
% throttle_g = initial guess for throttle setting
% throttle_lb = lower bound for throttle setting
% throttle_ub = upper bound for throttle setting
% alpha_g = initial guess for steering angles (radians)
% alpha_lb = lower bound for steering angles (radians)
% alpha_ub = upper bound for steering angles (radians)
% jd_guess = julian date guess for departure
% NOTE: all angular elements are returned in radians
% Orbital Mechanics with MATLAB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dtr = pi / 180.0;
% open data file
fid = fopen(filename, 'r');
% check for file open error
if (fid == 1)
clc; home;
fprintf('\n\n error: cannot find this file!!');
pause;
return;
end
% read 52 lines of data file
for i = 1:1:52
cline = fgetl(fid);
switch i
case 10
% type of trajectory optimization
iopt = str2double(cline);
case 13
% number of trajectory time segments
nsegments = str2double(cline);
case 16
% initial mass (kilograms)
mass0 = str2double(cline);
case 19
% propulsive thrust (newtons)
thrmag = str2double(cline);
case 22
% specific impulse (seconds)
xisp = str2double(cline);
case 25
% initial guess for mission duration (days)
time_g = str2double(cline);
case 28
% lower bound for mission duration (days)
time_lb = str2double(cline);
case 31
% upper bound for mission duration (days)
time_ub = str2double(cline);
case 34
% initial guess for throttle setting
throttle_g = str2double(cline);
case 37
% lower bound for throttle setting
throttle_lb = str2double(cline);
case 40
% upper bound for throttle setting
throttle_ub = str2double(cline);
case 43
% initial guess for steering angles
alpha_g = dtr * str2double(cline);
case 46
% lower bound for steering angles
alpha_lb = dtr * str2double(cline);
case 49
% upper bound for steering angles
alpha_ub = dtr * str2double(cline);
case 52
% initial guess for departure calendar date
tl = size(cline);
ci = strfind(cline, ',');
% extract month, day and year
month = str2double(cline(1:ci(1)1));
day = str2double(cline(ci(1)+1:ci(2)1));
year = str2double(cline(ci(2)+1:tl(2)));
jd_guess = julian(month, day, year);
end
end
fclose(fid);

