Home > atmlab > sensors > atovs > atovs_read_data.m

atovs_read_data

PURPOSE ^

ATOVS_READ_DATA Read ATOVS level 1c data

SYNOPSIS ^

function [data, err] = atovs_read_data( file_name )

DESCRIPTION ^

 ATOVS_READ_DATA   Read ATOVS level 1c data

 This function reads ATOVS level 1c data.

 FORMAT   data = atovs_read_data( file_name );

 IN    file_name   File name.
 OUT   data        Data structure with the following fields:
           time    Vector of scanline time stamps in UTC [msec].
           elev    Vector of satellite elevations [km]
           satlat  Vector of satellite latitude* [degrees]
           satlon  Vector of satellite longinude* [degrees]
           lon     2D matrix (fov,scanline) of longitudes in [degrees].
           lat     2D matrix (fov,scanline) of latitudes in [degrees].
           lza     2D matrix (fov,scanline) of local zenith angle in
                   [degrees].
           laa     2D matrix (fov,scanline) of local azimuth angle in
                   [degrees].
           sza     2D matrix (fov,scanline) of solar zenith angle in
                   [degrees].
           saa     2D matrix (fov,scanline) of solar azimuth angle in
                   [degrees].
           tb      3D matrix (fov,channel,scanline) of brightness
                   temperatures in [K].
           
       err         Error flag. 0 - no error, 1 - error.

 * Satellite latitude and longitude is approximated by assuming the
 average position between the two footprints closest to nadir.  L1C data
 does not contain the position explicitly.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

atovs_read_data.m

SOURCE CODE ^

0001 % ATOVS_READ_DATA   Read ATOVS level 1c data
0002 %
0003 % This function reads ATOVS level 1c data.
0004 %
0005 % FORMAT   data = atovs_read_data( file_name );
0006 %
0007 % IN    file_name   File name.
0008 % OUT   data        Data structure with the following fields:
0009 %           time    Vector of scanline time stamps in UTC [msec].
0010 %           elev    Vector of satellite elevations [km]
0011 %           satlat  Vector of satellite latitude* [degrees]
0012 %           satlon  Vector of satellite longinude* [degrees]
0013 %           lon     2D matrix (fov,scanline) of longitudes in [degrees].
0014 %           lat     2D matrix (fov,scanline) of latitudes in [degrees].
0015 %           lza     2D matrix (fov,scanline) of local zenith angle in
0016 %                   [degrees].
0017 %           laa     2D matrix (fov,scanline) of local azimuth angle in
0018 %                   [degrees].
0019 %           sza     2D matrix (fov,scanline) of solar zenith angle in
0020 %                   [degrees].
0021 %           saa     2D matrix (fov,scanline) of solar azimuth angle in
0022 %                   [degrees].
0023 %           tb      3D matrix (fov,channel,scanline) of brightness
0024 %                   temperatures in [K].
0025 %
0026 %       err         Error flag. 0 - no error, 1 - error.
0027 %
0028 % * Satellite latitude and longitude is approximated by assuming the
0029 % average position between the two footprints closest to nadir.  L1C data
0030 % does not contain the position explicitly.
0031 
0032 % 2004-06-29   Created by Mashrab Kuvatov.
0033 % 2010-11-11   Adapted by Gerrit Holl (also return angles)
0034 
0035 function [data, err] = atovs_read_data( file_name )
0036 
0037 
0038 % determine satellite and instrument IDs, data level,
0039 % and number of scan lines
0040 [sat_id, inst_id, level, nlines, err] = atovs_read_header( file_name ); %#ok<ASGLU>
0041 
0042 if err ~= 0
0043   % error
0044   disp( 'Error. Unable to read input file.' );
0045   data = [];
0046   err = 1;
0047   return
0048 end
0049 
0050 % make sure it is level 1c data
0051 if ~strcmp( level, 'l1c')
0052   % error
0053   disp('atmlab:atovs_read_data', 'Error. Input file must be of level 1c.' );
0054   data = [];
0055   err = 1;
0056   return
0057 end
0058 
0059 % depending on instrument, define data record format
0060 switch inst_id
0061  case {'AMSU-B', 'MHS'}
0062   [rec_format, rec_len, nchan, nfovs] = atovs_define_amsubl1c;
0063  case 'AMSU-A'
0064   [rec_format, rec_len, nchan, nfovs] = atovs_define_amsual1c;
0065  case 'HIRS'
0066   [rec_format, rec_len, nchan, nfovs] = atovs_define_hirsl1c;
0067  otherwise
0068   error('atmlab:atovs_read_data','No known instrument: %s', inst_id)
0069 end
0070 
0071 % open a file
0072 % 'b' means big-endian byte ordering
0073 % It seems that big-endian was only necessary on Marvin (SAB 2007-12-11)
0074 %file_id = fopen( file_name, 'r', 'b' );
0075 file_id = fopen( file_name, 'r' );
0076 
0077 % skip the header
0078 fseek( file_id, rec_len * 4, -1 );
0079 
0080 % read all records
0081 [record, count] = fread( file_id, rec_len * nlines, 'int32' );
0082 
0083 % close a file
0084 fclose( file_id );
0085 
0086 % number of scan lines read
0087 nlines_read = count / rec_len;
0088 
0089 % if amount of data read is less than asked
0090 if count < rec_len * nlines
0091   % if some scan lines are missing, we still can go on
0092   if iswhole( nlines_read )
0093     disp( 'Warning. Some scanlines are missing.' );
0094   % if number of scan lines is not integer, part of a record is missing
0095   else
0096     disp( 'Error. Input file is corrupt.' );
0097     data = [];
0098     err = 1;
0099     return
0100   end
0101 end
0102 
0103 % Reshape read data. Result: rec_len rows and nlines_read columns
0104 record = reshape( record, rec_len, nlines_read );
0105 
0106 % read into the structure according to the record format
0107 data.lon = record( rec_format.lon, : ) * .0001;
0108 data.lat = record(  rec_format.lat, : ) * .0001;
0109 data.time = record( rec_format.time, : );
0110 data.lza = record(rec_format.lza, :) * .01;
0111 data.laa = record(rec_format.laa, :) * .01;
0112 data.sza = record(rec_format.sza, :) * .01;
0113 data.saa = record(rec_format.saa, :) * .01;
0114 if isfield(rec_format, 'elev')
0115     data.elev = record(rec_format.elev, :) * .1;
0116 end
0117 data.tb = reshape( record( rec_format.tb', : ) * .01, nfovs, nchan, nlines_read );
0118 
0119 % approximate satellite position
0120 ind = floor(size(data.lat, 1)/2);
0121 [data.satlat, data.satlon] = geographic_mean(data.lat(ind:ind+1, :).', data.lon(ind:ind+1, :).');
0122 
0123 end

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