%% read EEJ Model file
% NiO change 07012023: solar flux redepdency R moved to end of file
function [m_i, R, QD_lat, params] = read_EEJM(filename)

fid = fopen(filename, 'r');

line = fgetl(fid);

% skip comment lines at beginning of file
while strcmp(line(1), '#')
    line = fgetl(fid);
end
% read model parameterisation
tmp = sscanf(line, '%d %d %d %d %d');
params.n_t = tmp(1); params.n_phi = tmp(2); params.n_s = tmp(3); params.n_l = tmp(4); params.n_QD = tmp(5);

% read QD-latitudes
line = fgetl(fid);
while strcmp(line(1), '#') % skip comment lines 
    line = fgetl(fid);
end
QD_lat = sscanf(line, '%e');

line = fgetl(fid);
while strcmp(line(1), '#') % skip comment lines 
    line = fgetl(fid);
end
% read model coefficients a/b
m_i = [];
while ~strcmp(line(1), '#')
    m_i = [m_i; sscanf(line(20:end), '%e')'];
    line = fgetl(fid);
end

% read solar flux dependencies R
line = fgetl(fid);
while strcmp(line(1), '#') % skip comment lines 
    line = fgetl(fid);
end
R = sscanf(line, '%e');

fclose(fid);

