function out = read_aod_settings(settings_fname)

% function to read in aod settings
fid = fopen(settings_fname); %open the setting file
fgetl(fid); fgetl(fid); %skip the first 2 lines
set_raw.header = textscan(fgetl(fid), '%s%s%s%s'); 
set_raw.data = textscan(fid, '%s%f%f%*[^\n]'); %read in first 3 columns of the rest of the file (skipping description)
set_raw.fld_flg = cell(length(set_raw.data{1}), 2); %fieldnames and their flags
for i1=1:size(set_raw.data{1}, 1); %split row data into a structure
    set_raw.(set_raw.data{1}{i1}) = [set_raw.data{2}(i1), set_raw.data{3}(i1)]; %save lower & upper limits
    set_raw.fld_flg(i1,:) = {set_raw.data{1}{i1}, i1}; %save the fieldname and the flag number
end
fclose(fid);

fid = fopen(settings_fname); %open the setting file
fgetl(fid); fgetl(fid); %skip the first 2 lines
inqctext = textscan(fid, '%s','delimiter','\n'); %reads generic text file into a cell
inqctext = inqctext{1};
fclose(fid);
inqctext{1} = [' Flag ', ' nflgd ', inqctext{1}];
inqctext{2} = ['  1 ', '    0  ', inqctext{2}];

out = set_raw;
out.inqctext = inqctext; %prepare writing of .qc lines in output file

