function params = igwparams
% Reads the quantities written to 'startup_graphics' and stores them in
% a struct. Usage:
%   params = igwparams;
% The name of each quantity is matched to what IGW's src/main.c writes.
% For reference, the code from src/main.c is reproduced below. 
% 
% v0.1, Aug 2013, Michael Dunphy, mdunphy@math.uwaterloo.ca

% Excerpt from IGW's src/main.c from April 2013:
%   f1 = fopen("startup_graphics","w");
%   fprintf(f1,"%d %d %d %d\n",I,J,Il,Ir);
%   fprintf(f1,"%1.6e %1.6e\n",L,H);
%   fprintf(f1,"%1.6e %1.6e %1.6e %1.6e\n",f,g,fh,PHI);
%   fprintf(f1,"%1.6e %1.6e %1.6e\n",amp,width,shift);
%   fprintf(f1,"%1.6e %1.6e %1.6e %1.6e %d\n",*time_end,*save_interval,*prev_dt,*max_dt,*max_steps);
%   fprintf(f1,"%1.6e %1.6e\n",NN,Umax);
%   fprintf(f1,"%d %1.6e %1.6e %1.6e %1.6e\n",reg,grpar1_l,grpar1_r,grpar2,grpar3);
% #if DIFFUSIVE
%   fprintf(f1,"%1.6e %1.6e %1.6e %1.6e %1.6e\n", KU, KV, KW, KD,stress_coeff);
%   fprintf(f1,"%1.6e %1.6e %1.6e %1.6e\n", KhU, KhV, KhW, KhD);
% #endif
%   fprintf(f1,"%d\n",*cnt_str);
%   fclose(f1);


% Open for reading
finfo=dir('startup_graphics');
fid=fopen('startup_graphics','r');
% Read the parameters up to #if DIFFUSIVE
list1={'I','J','Il','Ir',...
    'L','H',...
    'f','g','fh','PHI', ...
    'amp','width','shift', ...
    'time_end','save_interval','prev_dt','max_dt','max_steps',...
    'NN','Umax',...
    'reg','grpar1_l','grpar1_r','grpar2','grpar3'};
for ii=1:length(list1)
    tmp = textscan(fid,'%f',1);
    params.(list1{ii}) = tmp{1};
end

% If DIFFUSIVE was turned on, there will be at least 100 more bytes for
% the diffusion parameters. If it was off, there will be only 4 more bytes
% for cnt_str. So remaining file length will determine if DIFFUSIVE was on.
if finfo.bytes - ftell(fid) > 100
    list2={'KU','KV','KW','KD','stress_coeff',...
        'KhU','KhV','KhW','KhD','cnt_str'};
else
    list2={'cnt_str'};
end
for ii=1:length(list2)
    tmp = textscan(fid,'%f',1);
    params.(list2{ii}) = tmp{1};
end

% Close file cleanly
fclose(fid);

return