Home > atmlab > datasets > +satreaders > mirs.m

mirs

PURPOSE ^

SATREADERS.MIRS reads MIRS data

SYNOPSIS ^

function S = mirs(file, varargin)

DESCRIPTION ^

 SATREADERS.MIRS reads MIRS data

 Read MIRS data and output the data in the format common to all
 satreaders.<dataset>.m readers in atmlab. Geodata and time data are
 always retrieved from the data file.

 For info on the common format, see <a href="matlab:help SatDataset/reader">SatDataset/reader</a>.

 IN

   file    string      Path to hdf file
   extra   cell array (optional) extra fields.

 OUT

   data    struct  With fields:
                   time    time in seconds since 00:00 UT
                   lat     latitude in degrees, one column per viewing angle
                   lon     longitude in [-180, 180] degrees, colums as for lat

 FORMAT

   S = satreaders.modis(file, varargin)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

mirs.m

SOURCE CODE ^

0001 function S = mirs(file, varargin)
0002 % SATREADERS.MIRS reads MIRS data
0003 %
0004 % Read MIRS data and output the data in the format common to all
0005 % satreaders.<dataset>.m readers in atmlab. Geodata and time data are
0006 % always retrieved from the data file.
0007 %
0008 % For info on the common format, see <a href="matlab:help SatDataset/reader">SatDataset/reader</a>.
0009 %
0010 % IN
0011 %
0012 %   file    string      Path to hdf file
0013 %   extra   cell array (optional) extra fields.
0014 %
0015 % OUT
0016 %
0017 %   data    struct  With fields:
0018 %                   time    time in seconds since 00:00 UT
0019 %                   lat     latitude in degrees, one column per viewing angle
0020 %                   lon     longitude in [-180, 180] degrees, colums as for lat
0021 %
0022 % FORMAT
0023 %
0024 %   S = satreaders.modis(file, varargin)
0025 
0026 % $Id: mirs.m 8720 2013-10-21 20:41:39Z gerrit $
0027 % Created by Salomon Eliasson
0028 
0029 try
0030     X = read_native_mirs(file);
0031 catch ME
0032     if strcmp(ME.identifier,'MATLAB:subsassignnumelmismatch') % such as if nprf if incorrect
0033         error('atmlab:invalid_data','Something is wrong with the file')
0034     else
0035         error(ME.identifier,ME.message)
0036     end
0037     
0038 end
0039     
0040 core_fields   = {'scanUTC','lat','lon'};
0041 extra_fields  = optargs(varargin, {{}});
0042 all_fields    = [core_fields(:); extra_fields(:)];
0043 % List of hand-made fields that can be composed already here to save memory and
0044 % storage space. I call them "pseudo fields" (e.g. modis_IWP that depends on 3
0045 % fields in the modis file). The loop of hdfread will check if any psudeo fields
0046 % are present. If so, it will be processed and the fields this pseudo field
0047 % requires to be created are further assumed to be frivolous and therefore
0048 % removed afterwards.
0049 pseudo_fields = {'MIRS_IWP'};
0050 
0051 for F = all_fields'
0052     if ismember(F{1},pseudo_fields)
0053         continue
0054     end
0055     S.(F{1}) = X.(F{1});
0056     if isvector(S.(F{1})),
0057         S.(F{1}) = S.(F{1})';
0058     end
0059 end
0060 
0061 S.lat   = double(S.lat);
0062 S.lon   = double(S.lon);
0063 S.time  = double(S.scanUTC);
0064 
0065 % get the verion directly from the filename
0066 D = datasets;
0067 info = D.mirs.find_info_from_granule(file);
0068 % year = YEAR2
0069 date = dayofyear_inverse(2000+str2double(info.year02), str2double(info.doy));
0070 S.epoch = round(date2unixsecs(date.year, date.month, date.day));
0071 
0072 S.version = X.algsn; %actually algorithm serial number
0073 S.path = file;
0074 
0075 S = MaskInvalidGeoTimedataWithNaN(S);
0076 
0077 S = rmfield(S,{'scanUTC'});
0078 
0079 end
0080 
0081 function S = read_native_mirs(filename)
0082 %% read_native_mirs
0083 % OUT   S   SSM/T-2 structure
0084 %   TYPE   :: DEP_type
0085 %     INTEGER                                    :: AlgSN      !MIRS Algorithm serial number (svn)
0086 %     INTEGER                                    :: iTyp       !0->DEP from Scene, 1->DEP from retrieved scene
0087 %     INTEGER                                    :: ProfIndx   !Profile Index
0088 %     !---Positioning Data
0089 %     REAL                                       :: Angle      !Angle
0090 %     REAL                                       :: RelAziAngle!Relative Azimuth Angle
0091 %     REAL                                       :: SolZenAngle!Solar Zenith Angle
0092 %     REAL                                       :: lat        !Latitude
0093 %     REAL                                       :: lon        !Longitude
0094 %     INTEGER                                    :: node       !=0->ASC, =1->DESC
0095 %     INTEGER                                    :: scanDay    !Day
0096 %     INTEGER                                    :: scanYear   !Year
0097 %     REAL                                       :: scanUTC    !UTC time
0098 %     INTEGER                                    :: iscanPos   !Scan position
0099 %     INTEGER                                    :: iscanLine  !Scan Line index
0100 %     INTEGER                                    :: nPosScan   !Number of scan positions within scanline
0101 %     INTEGER                                    :: nScanLines !Number of scan lines within orbit (msome might be missing)
0102 %     !---Atmospheric/Hydrometeors/Cloud-related information
0103 %     INTEGER                                    :: iTypAtm    !Atmospheric type ID
0104 %     CHARACTER(LEN=20)                          :: DescTypAtm !Label of the atmospheric class
0105 %     REAL                                       :: TPW        !Total precipitable Water
0106 %     REAL                                       :: Clw        !Integrated Cloud amount
0107 %     REAL                                       :: RWP        !Integrated Liquid Rain water path
0108 %     REAL                                       :: LWP        !Integrated Liquid Water Path
0109 %     REAL                                       :: SWP        !Integrated Snow water path
0110 %     REAL                                       :: IWP        !Integrated Ice water path
0111 %     REAL                                       :: GWP        !Integrated Graupel water path
0112 %     REAL                                       :: RR         !Surface rain rate
0113 %     REAL                                       :: SFR        !Snow falling rate
0114 %     REAL                                       :: CldTop     !Cloud Top Pressure
0115 %     REAL                                       :: CldBase    !Cloud Base Pressure
0116 %     REAL                                       :: CldThick   !Cloud thickness
0117 %     REAL                                       :: PrecipType !Precipitation type (frozen/liquid)
0118 %     REAL                                       :: RainFlag   !Rain flag
0119 %     !---Surface -related information
0120 %     INTEGER                                    :: iTypSfc    !Surface type ID
0121 %     CHARACTER(LEN=20)                          :: DescTypSfc !Label of the surface class
0122 %     REAL                                       :: SWE        !Snow water equivalent
0123 %     REAL                                       :: SnowGS     !Snow Effective Grain Size
0124 %     REAL                                       :: SnowCover  !Snow cover extent
0125 %     REAL                                       :: SM         !Soil Moisture
0126 %     REAL                                       :: SIC        !Sea-ice concentration
0127 %     REAL                                       :: SIC_MY     !Multi-year Sea-ice concentration
0128 %     REAL                                       :: SIC_FY     !First-year Sea-ice concentration
0129 %     REAL                                       :: WindSp     !Wind speed
0130 %     REAL                                       :: WindDir    !Wind vector
0131 %     REAL                                       :: WindU      !U-direction wind speed
0132 %     REAL                                       :: WindV      !V-direction wind speed
0133 %     !---QC info
0134 %     INTEGER,           DIMENSION(4)            :: qc         !QC vector
0135 %     !---Convergence items (when the DEP is coming from a retrieved scene )
0136 %     INTEGER                                    :: nIter      !Number of iterations
0137 %     REAL                                       :: ChiSq      !Convergence metric
0138 %
0139 %
0140 % IN    filename            Name of SSM/T-2 file
0141 % OPT
0142 
0143 % 2009-11-20   Created by Oliver Lemke and Salomon Eliasson.
0144 
0145 errId = ['atmlab:' mfilename ':error'];
0146 if ~exist(filename,'file')
0147     error(errId,'No such file:  %s',filename)
0148 end
0149 tmpdir = create_tmpfolder();
0150 cleanupObject = onCleanup(@() delete_tmpfolder(tmpdir));
0151 filename = uncompress(filename,tmpdir);
0152 if isempty(filename), error(errId,'Uncompressing failed'); end
0153 
0154 fid = fopen (filename, 'rb', 'b');
0155 cleanupObj2 = onCleanup(@() (fclose(fid)));
0156 if (fid == -1)
0157     error (errId, 'Can''t open input file %s', filename);
0158 end
0159 
0160 
0161 % READ THE BINARY DATA file
0162 
0163 % HEADER
0164 fread (fid, 1, 'int32');
0165 S.itype      = fread (fid, 1, 'int32');
0166 S.algsn      = fread (fid, 1, 'int32');
0167 fread (fid, 1, 'int32');
0168 
0169 fread (fid, 1, 'int32');
0170 S.nprf       = fread (fid, 1, 'int32');
0171 fread (fid, 1, 'int32');
0172 
0173 fread (fid, 1, 'int32');
0174 S.nPosScan   = fread (fid, 1, 'int32');
0175 fread (fid, 1, 'int32');
0176 
0177 fread (fid, 1, 'int32');
0178 S.nScanLines = fread (fid, 1, 'int32');
0179 fread (fid, 1, 'int32');
0180 
0181 % loop over profiles
0182 allfields = {'ProfIndx','iTypAtm','TPW','Clw','RWP','SWP','IWP','GWP',...
0183     'RR','SFR','CldTop','CldBase','CldThick','PrecipType','RainFlag',...
0184     'LWP','iTypSfc','SWE','SnowCover','SM','SIC','WindSp','WindDir',...
0185     'WindU','WindV','SnowGS','SIC_FY','SIC_MY','QC','lat','lon','node',...
0186     'scanUTC','scanYear','scanDay','iscanPos','iscanLine','angle',...
0187     'RelAziAngle','SolZenAngle','nIter','ChiSq'};
0188 tmp =  cell(1,2*length(allfields)); tmp(1:2:end-1)= allfields;
0189 X = struct(tmp{:});
0190 for i = 1:S.nprf
0191     % profile index
0192     fread (fid,1,'int32');
0193     X.ProfIndx(i) = fread (fid,1, 'int32');
0194     fread (fid, 1, 'int32');
0195     
0196     % ATMOSPHERIC
0197     fread (fid, 1, 'int32');
0198     X.iTypAtm(i)     = fread (fid, 1, 'int32');
0199     X.TPW(i)         = fread (fid, 1, 'single');
0200     X.Clw(i)         = fread (fid, 1, 'single');
0201     X.RWP(i)         = fread (fid, 1, 'single');
0202     X.SWP(i)         = fread (fid, 1, 'single');
0203     X.IWP(i)         = fread (fid, 1, 'single');
0204     X.GWP(i)         = fread (fid, 1, 'single');
0205     X.RR(i)          = fread (fid, 1, 'single');
0206     X.SFR(i)         = fread (fid, 1, 'single');
0207     X.CldTop(i)      = fread (fid, 1, 'single');
0208     X.CldBase(i)     = fread (fid, 1, 'single');
0209     X.CldThick(i)    = fread (fid, 1, 'single');
0210     X.PrecipType(i)  = fread (fid, 1, 'single');
0211     X.RainFlag(i)    = fread (fid, 1, 'single');
0212     X.LWP(i)         = fread (fid, 1, 'single');
0213     fread (fid, 1, 'int32');
0214     
0215     % SURFACE
0216     fread(fid,1,'int32');
0217     X.iTypSfc(i)     = fread (fid, 1, 'int32');
0218     X.SWE(i)         = fread (fid, 1, 'single');
0219     X.SnowCover(i)   = fread (fid, 1, 'single');
0220     X.SM(i)          = fread (fid, 1, 'single');
0221     X.SIC(i)         = fread (fid, 1, 'single');
0222     X.WindSp(i)      = fread (fid, 1, 'single');
0223     X.WindDir(i)     = fread (fid, 1, 'single');
0224     X.WindU(i)       = fread (fid, 1, 'single');
0225     X.WindV(i)       = fread (fid, 1, 'single');
0226     X.SnowGS(i)      = fread (fid, 1, 'single');
0227     X.SIC_FY(i)      = fread (fid, 1, 'single');
0228     X.SIC_MY(i)      = fread (fid, 1, 'single');
0229     fread(fid,1,'int32');
0230     
0231     % QUALITY FLAGS
0232     fread(fid,1,'int32');
0233     X.QC(i,1:4)   = fread (fid, 4, 'int32');
0234     fread(fid,1,'int32');
0235     
0236     % POSITION
0237     fread(fid,1,'int32');
0238     X.lat(i)         = fread (fid, 1, 'single');
0239     X.lon(i)         = fread (fid, 1, 'single');
0240     X.node(i)        = fread (fid, 1, 'int32');
0241     X.scanUTC(i)     = fread (fid, 1, 'single');
0242     X.scanYear(i)    = fread (fid, 1, 'int32');
0243     X.scanDay(i)     = fread (fid, 1, 'int32');
0244     X.iscanPos(i)    = fread (fid, 1, 'int32');
0245     X.iscanLine(i)   = fread (fid, 1, 'int32');
0246     X.angle(i)       = fread (fid, 1, 'single');
0247     X.RelAziAngle(i) = fread (fid, 1, 'single');
0248     X.SolZenAngle(i) = fread (fid, 1, 'single');
0249     fread(fid,1,'int32');
0250     
0251     if S.itype==1
0252         % RETRIEVED SCENE
0253         fread(fid,1,'int32');
0254         X.nIter(i)   = fread (fid, 1, 'int32');
0255         X.ChiSq(i)   = fread (fid, 1, 'single');
0256         fread(fid,1,'int32');
0257     else
0258         X.nIter(i)   = -1;
0259         X.ChiSq(i)   = 0;
0260     end
0261 end
0262 S = catstruct(S,X);
0263 
0264 end

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