Home > atmlab > sensors > ssmt2_read_ngdc.m

ssmt2_read_ngdc

PURPOSE ^

ssmt2_read_ngdc Read SSM-T/2 NGDC file

SYNOPSIS ^

function S = ssmt2_read_ngdc(fn, varargin)

DESCRIPTION ^

 ssmt2_read_ngdc Read SSM-T/2 NGDC file

 Reads an SSM-T/2 file from NGDC

 FORMAT

   S = ssmt2_read_ngdc(path_to_file)

 IN

   path_to_file    String representing path to file containing data.
                   Either compressed or plain.
   fields          Cella rray of strings containing fields to read.
                   Optional; by default, read all fields.
                   To explicitly read all, pass string 'all'.
                   See below for valid fields.

 OUT

   S               structure with data fields


 Fields that can be read:

 global_attributes ancil_data tb lon lat channel_quality_flag
 gain_control counts_to_tb_gain counts_to_tb_offset thermal_reference
 Temperature_misc_housekeeping warm_counts cold_counts

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

ssmt2_read_ngdc.m

SOURCE CODE ^

0001 function S = ssmt2_read_ngdc(fn, varargin)
0002 
0003 % ssmt2_read_ngdc Read SSM-T/2 NGDC file
0004 %
0005 % Reads an SSM-T/2 file from NGDC
0006 %
0007 % FORMAT
0008 %
0009 %   S = ssmt2_read_ngdc(path_to_file)
0010 %
0011 % IN
0012 %
0013 %   path_to_file    String representing path to file containing data.
0014 %                   Either compressed or plain.
0015 %   fields          Cella rray of strings containing fields to read.
0016 %                   Optional; by default, read all fields.
0017 %                   To explicitly read all, pass string 'all'.
0018 %                   See below for valid fields.
0019 %
0020 % OUT
0021 %
0022 %   S               structure with data fields
0023 %
0024 %
0025 % Fields that can be read:
0026 %
0027 % global_attributes ancil_data tb lon lat channel_quality_flag
0028 % gain_control counts_to_tb_gain counts_to_tb_offset thermal_reference
0029 % Temperature_misc_housekeeping warm_counts cold_counts
0030 
0031 % $Id: ssmt2_read_ngdc.m 8201 2013-02-14 09:10:26Z seliasson $
0032 
0033 [~, ~, ext] = fileparts(fn);
0034 fields = optargs(varargin, {'all'});
0035 
0036 %% unpack if necessary
0037 if strcmpi(ext, '.gz') 
0038     T2file = uncompress(fn, atmlab('WORK_AREA'), struct('unidentified', 'error'));
0039     c1 = onCleanup(@()delete(T2file));
0040 else
0041     T2file = fn;
0042 end
0043 
0044 %% convert from T2 to nc. Needs Python.
0045 pyscript = fullfile(fileparts(mfilename('fullpath')), ...
0046                     'ssmt2_reader_netcdf.py');
0047 
0048 try 
0049     ncfile = [tempname(atmlab('WORK_AREA')) '.nc'];
0050     c2 = onCleanup(@()delete(ncfile));
0051     cmd = [atmlab('PYTHON') ' ' pyscript ' ' T2file ' ' ncfile];
0052     [out, ret] = exec_system_cmd(cmd, true, false);
0053 catch ME
0054     error(['atmlab:' mfilename ':conversion'], ...
0055         ['I tried to convert from T2 to nc using a Python script, ' ...
0056          'but failed. You need a Python installation with a suitable ' ...
0057          'right NetCDF library. The problem was: %s'], ME.message);
0058 end
0059                 
0060 switch nargin
0061     case 1
0062         S = loadncfile(ncfile);
0063     case 2
0064         [S, S.global_attributes] = loadncvar(ncfile, fields);
0065     otherwise
0066         error(['atmlab:' mfilename], 'I can''t possibly be here!');
0067 end
0068 
0069 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005