function out = read_sat(sat_fname)

% basic function written to read in .sat files into a structure
% The .sat files contain 1) an sza list, 2) airmass (for water)
% 3) various Transmissions for gases at different windows.

fid = fopen(sat_fname); %open the ic file
fgetl(fid); fgetl(fid);  %skip the first 2 lines
satfile_raw.header = textscan(fgetl(fid), '%s'); %unspecified/unknown number of columns for headers.
satfile_raw.header = satfile_raw.header{1}; 
satfile_raw.data = textscan(fid, [repmat('%f', 1, length(satfile_raw.header)), '\n']); %read in the rest of the file. All numbers.
for i1=1:length(satfile_raw.header); %split remaining data into a structure
    satfile_raw.(satfile_raw.header{i1}) = satfile_raw.data{i1};
end
fclose(fid);

win_nm = NaN*zeros(length(satfile_raw.header)-2, 1); %window wavenumbers. Skipping first 2 columns. Pre-allocating
T_name_gas = cell(length(win_nm), 2); %window name and gas
T_name_gas(:,1) = satfile_raw.header(3:end); %full names, skipping first 2 rows
for i1=1:length(win_nm); %for each T 
    srt_ind = 2; %starting sting index for wavelength
    un_ind = strfind(T_name_gas{i1,1}, '_'); %find underscore
    win_nm(i1) = str2double(T_name_gas{i1,1}(srt_ind:un_ind-1)); %saves wavelength as a number
    T_name_gas{i1,2} = T_name_gas{i1,1}(un_ind+1:end);
end

out = satfile_raw; %file output
out.win_wn = win_nm;
out.T_name_gas = T_name_gas;


