function mat_aod(rl_fname, daymap_fname, h2oam_fname, settings_fname, sat_fname, ic_fnames)

% This script is a matlab wrapper to run the different sub-functions that
% are used to calculate AOD

% mat_aod - V 2017 Feb 24  - JKH

addpath('matlab_aodsubs'); %add subdir to path

%% First, calculate a .atf file
interpcat_prei0(rl_fname, daymap_fname, h2oam_fname, settings_fname, sat_fname, ic_fnames);

out_dir_sf = strfind(sat_fname, '/'); %index the slash
if ~isempty(out_dir_sf);
    out_dir = sat_fname(1:out_dir_sf(end)); %name for outgoing directory (same folder as .ic file)
else
%     out_dir_sf = 0;
    out_dir = ''; %no directory
end
out_name_df = strfind(ic_fnames{1}, '.'); %index for the dots
atf_pname = [ic_fnames{1}(out_name_df(1)+1:out_name_df(end)), 'aft']; % name for output file. All Filled Transmission
atf_fname = [out_dir, atf_pname]; %full outgoing filename


%% Next calculate I0 values and make a .i0 file
calc_i0(atf_fname, ic_fnames, settings_fname); %

i0_fnames = cell(size(ic_fnames)); %pre-allocate
for i1=1:length(ic_fnames);
  out_name_df = strfind(ic_fnames{i1}, '.'); %index for the dots

  i0_fnames{i1} = [ic_fnames{i1}(1:out_name_df(end)), 'i0']; %full outgoing filename
end


%% Finally, calculate the AOD and angstrom parameter and write all values to a .raod file (final output file)
calc_raod(atf_fname, ic_fnames, i0_fnames)



