

data_struct=ssmt2_ngdc_ncreader( filename )

% FORMAT
% data_struct=satreaders.ssmt2_ngdc_ncreader( filename )

% IN 	filename 	full path to smt2 netcdf-NGDC file

% OUT 	data_struct	structure with fileds for all entries in the NGDC netcdf file


% function based on
%https://atmos.washington.edu/~cjones/public/load_from_netcdf_to_structure.html (acess: 27.03.2018)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% create a cell array of variables to load
variables_to_load = {'ancil_data','channel_quality_flag','cold_counts','counts_to_tb_gain','counts_to_tb_offset','gain_control','lat','lon','tb','Temperature_misc_housekeeping','thermal_reference','warm_counts'};

% loop over the variables
for j=1:numel(variables_to_load)
    % extract the jth variable (type = string)
    var = variables_to_load{j};

    % use dynamic field name to add this to the structure
    data_struct.(var) = ncread(filename,var);

    % convert from single to double, if that matters to you (it does to me)
    if isa(data_struct.(var),'single')
        data_struct.(var) = double(data_struct.(var));
    end
end
