Home > atmlab > files > read_openmtp_uth.m

read_openmtp_uth

PURPOSE ^

READ_OPENMTP_UTH Read Open MTP UTH data file.

SYNOPSIS ^

function S = read_openmtp_uth (filename)

DESCRIPTION ^

 READ_OPENMTP_UTH   Read Open MTP UTH data file.

    Reads an Open MTP UTH file into a structure.

 FORMAT   S = read_openmtp_uth (filename)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

read_openmtp_uth.m

SOURCE CODE ^

0001 % READ_OPENMTP_UTH   Read Open MTP UTH data file.
0002 %
0003 %    Reads an Open MTP UTH file into a structure.
0004 %
0005 % FORMAT   S = read_openmtp_uth (filename)
0006 
0007 function S = read_openmtp_uth (filename)
0008 
0009 if strcmp( filename(length(filename)-2:end), '.gz')
0010   uncompressed_filename = tempname(atmlab( 'WORK_AREA' ));
0011   cleanupObj = onCleanup(@() (delete(uncompressed_filename)));
0012   cmd = [ 'gunzip -cd ' filename ' > ' uncompressed_filename ];
0013   st = system (cmd);
0014   if st
0015     error ('atmlab:read_openmtp_uth', 'Failed to uncompress OpenMTP UTH file %s', filename);
0016   end
0017   filename = uncompressed_filename;
0018 end
0019 
0020 fid = fopen (filename, 'rb', 'b');
0021 cleanupObj2 = onCleanup(@() (fclose(fid)));
0022 
0023 if (fid == -1)
0024   error ('Can''t open input file')
0025 end
0026 
0027 %%%%%%%%%% Read Header %%%%%%%%%%
0028 %
0029 S.hdr = fread (fid, 542, 'uint8=>char')';
0030 
0031 %%%%%%%%%% Read Segment Header %%%%%%%%%%
0032 %
0033 S.slot = fread (fid, 1, 'int32');
0034 S.time = fread (fid, 1, 'int32');
0035 S.jday = fread (fid, 1, 'int32');
0036 S.year = fread (fid, 1, 'int32');
0037 S.pltfrm = fread (fid, 4, 'uint8=>char')';
0038 fread (fid, 8, 'int8');  %spares
0039 S.fname = fread (fid, 4, 'uint8=>char')';
0040 S.ptime = fread (fid, 1, 'int32');
0041 S.palg = fread (fid, 32, 'uint8=>char')';
0042 S.pvers = fread (fid, 1, 'int32');
0043 S.nseg = fread (fid, 1, 'int32');
0044 S.mqcflg = fread (fid, 1, 'uint8');
0045 fread (fid, 15, 'int8');  %spares
0046 S.qtotal = fread (fid, 1, 'int32');
0047 S.dist = fread (fid, 1, 'uint8');
0048 fread (fid, 3, 'int8');  %spares
0049 
0050 % Preallocation commented out because it's slighty faster without
0051 %
0052 % S.seglin = zeros(1, S.nseg, 'int32');
0053 % S.segcol = zeros(1, S.nseg, 'int32');
0054 % S.selpix = zeros(1, S.nseg, 'int32');
0055 % S.segpix = zeros(1, S.nseg, 'int32');
0056 % S.selat = zeros(1, S.nseg, 'single');
0057 % S.selon = zeros(1, S.nseg, 'single');
0058 % S.sheight = zeros(1, S.nseg, 'int32');
0059 % S.swidth = zeros(1, S.nseg, 'int32');
0060 %
0061 % S.cenlat = zeros(1, S.nseg, 'single');
0062 % S.cenlon = zeros(1, S.nseg, 'single');
0063 % S.uth = zeros(1, S.nseg, 'single');
0064 % S.csr = zeros(1, S.nseg, 'single');
0065 % S.locq = zeros(1, S.nseg, 'int32');
0066 % S.uthq = zeros(1, S.nseg, 'int32');
0067 % S.acqrej = zeros(1, S.nseg, 'uint8');
0068 % S.mqcrej = zeros(1, S.nseg, 'uint8');
0069 % S.mqcmod = zeros(1, S.nseg, 'uint8');
0070 
0071 %%%%%%%%%% Read Results Blocks %%%%%%%%%%
0072 %
0073 recn = 0;
0074 while (~feof (fid) && recn < S.nseg)
0075     recn = recn + 1;
0076     
0077     S.seglin(recn) = fread (fid, 1, 'int32');
0078     S.segcol(recn) = fread (fid, 1, 'int32');
0079     S.selpix(recn) = fread (fid, 1, 'int32');
0080     S.segpix(recn) = fread (fid, 1, 'int32');
0081     S.selat(recn) = fread (fid, 1, 'float32');
0082     S.selon(recn) = fread (fid, 1, 'float32');
0083     S.sheight(recn) = fread (fid, 1, 'int32');
0084     S.swidth(recn) = fread (fid, 1, 'int32');
0085     nres = fread (fid, 1, 'int32');
0086     
0087     assert (nres==1, 'atmlab:read_openmtp_uth', ...
0088         'Number of result blocks expected to be 1 in OpenMTP UTH file %s', filename);
0089     
0090     S.cenlat(recn) = fread (fid, 1, 'float32');
0091     S.cenlon(recn) = fread (fid, 1, 'float32');
0092     S.uth(recn) = fread (fid, 1, 'float32');
0093     S.csr(recn) = fread (fid, 1, 'float32');
0094     fread (fid, 4, 'int8');  %spares
0095     S.locq(recn) = fread (fid, 1, 'int32');
0096     S.uthq(recn) = fread (fid, 1, 'int32');
0097 %    fread (fid, 8, 'int8');  %spares
0098     fread (fid, 40, 'int8');  %spares
0099     S.acqrej(recn) = fread (fid, 1, 'uint8');
0100     S.mqcrej(recn) = fread (fid, 1, 'uint8');
0101     S.mqcmod(recn) = fread (fid, 1, 'uint8');
0102     fread (fid, 1, 'int8');  %spares
0103 end

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