Home > atmlab > sensors > atovs > atovs_read_header.m

atovs_read_header

PURPOSE ^

ATOVS_READ_HEADER Read header of ATOVS data file.

SYNOPSIS ^

function [sat_id, inst_id, level, nlines, err] = atovs_read_header( file_name )

DESCRIPTION ^

 ATOVS_READ_HEADER   Read header of ATOVS data file.

 The function reads header of ATOVS data file and determines
 satellite and instrument IDs, data level, and a number of scanlines.

 FORMAT   [sat_id, inst_id, level, nlines, err] = atovs_read_header( file_name );

 IN    file_name   Name of an ATOVS data file.

 OUT   sat_id      NOAA satellite ID e.g. 14, 15, 16, 17.
       inst_id     Instrument ID e.g. 'AMSU-B', 'AMSU-A', 'HIRS'.
       level       Data level e.g. 'l1c' or 'notl1c'
       nlines      Number of scanlines.
       err         Error flag. 0 - no error, 1 - error.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

atovs_read_header.m

SOURCE CODE ^

0001 % ATOVS_READ_HEADER   Read header of ATOVS data file.
0002 %
0003 % The function reads header of ATOVS data file and determines
0004 % satellite and instrument IDs, data level, and a number of scanlines.
0005 %
0006 % FORMAT   [sat_id, inst_id, level, nlines, err] = atovs_read_header( file_name );
0007 %
0008 % IN    file_name   Name of an ATOVS data file.
0009 %
0010 % OUT   sat_id      NOAA satellite ID e.g. 14, 15, 16, 17.
0011 %       inst_id     Instrument ID e.g. 'AMSU-B', 'AMSU-A', 'HIRS'.
0012 %       level       Data level e.g. 'l1c' or 'notl1c'
0013 %       nlines      Number of scanlines.
0014 %       err         Error flag. 0 - no error, 1 - error.
0015 
0016 % 2004-06-29   Created by Mashrab Kuvatov.
0017 
0018 
0019 function [sat_id, inst_id, level, nlines, err] = atovs_read_header( file_name )
0020 
0021 % we want to read this many words
0022 rec_len = 22;
0023 
0024 sat_id = '';
0025 inst_id = '';
0026 level = '';
0027 nlines = 0;
0028 err = 0;
0029   
0030 try
0031 
0032 % open a file
0033 % 'b' means big-endian byte ordering
0034 % It seems that big-endian was only necessary on Marvin (SAB 2007-12-11)
0035 %file_id = fopen( file_name, 'r', 'b' );
0036 file_id = fopen( file_name, 'r' );
0037 
0038 % read header
0039 [header, count] = fread( file_id, rec_len, 'int32' );
0040 
0041 % close a file
0042 fclose( file_id );
0043 
0044 if count ~= rec_len
0045   disp( 'Error. Input file is not valid.' );
0046   err = 1;
0047   return
0048 end
0049 
0050 % number of scan lines
0051 nlines = header( 19 );
0052 
0053 % disp( ['Number of scanlines = ', num2str( nlines ) ] );
0054 
0055 % satellite id (e.g. 14 for NOAA-14)
0056 sat_id = header( 7 );
0057 
0058 % disp( ['Satellite ID = ', num2str( sat_id )] );
0059 
0060 % instrument ID
0061 switch  header( 8 )
0062  case 5
0063   inst_id = 'HIRS';
0064  case 10
0065   inst_id = 'AMSU-A';
0066  case 11
0067   inst_id = 'AMSU-B';
0068  case 12
0069   inst_id = 'MHS';
0070 end
0071 
0072 % disp( ['Instrument ID = ', inst_id] );
0073 
0074 if( strcmp( inst_id, 'HIRS' ) )
0075   level_flag = header( 21 );
0076 else
0077   level_flag = header( 22 );
0078 end
0079 
0080 % Copied from Caroline's IDL routine rdatovs_head.pro. I do
0081 % not know what exactly it means, neither could I find a
0082 % documentation.
0083 
0084 if( ( level_flag <= 0 ) || ( ( level_flag & ~59) > 0 ) )
0085   level = 'l1c';
0086 else
0087   level = 'notl1c';
0088 end
0089 
0090 % disp( ['Data level = ', level] );
0091 
0092 catch
0093   disp( 'Error. Most probably, input file does not exist.' );
0094   err = 1;
0095 end
0096 
0097 return

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