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

avhrr_cmsaf_gac

PURPOSE ^

SATREADERS.AVHRR_CMSAF_GAC Read avhhrCMSAF data in the common format

SYNOPSIS ^

function S = avhrr_cmsaf_gac(file, varargin)

DESCRIPTION ^

 SATREADERS.AVHRR_CMSAF_GAC Read avhhrCMSAF data in the common format

 This file reads data from a avhhrCMSAF file and rearranges the fields to
 the common format. 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.cmsaf_gac(file, varargin)

 See also: SatDataset/reader

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

avhrr_cmsaf_gac.m

SOURCE CODE ^

0001 function S = avhrr_cmsaf_gac(file, varargin)
0002 
0003 % SATREADERS.AVHRR_CMSAF_GAC Read avhhrCMSAF data in the common format
0004 %
0005 % This file reads data from a avhhrCMSAF file and rearranges the fields to
0006 % the common format. Geodata and time data are always retrieved from the
0007 % data file.
0008 %
0009 % For info on the common format, see <a href="matlab:help SatDataset/reader">SatDataset/reader</a>.
0010 %
0011 %
0012 % IN
0013 %
0014 %   file    string      Path to hdf file
0015 %   extra   cell array (optional) extra fields.
0016 %
0017 % OUT
0018 %
0019 %   data    struct  With fields:
0020 %                   time    time in seconds since 00:00 UT
0021 %                   lat     latitude in degrees, one column per viewing angle
0022 %                   lon     longitude in [-180, 180] degrees, colums as for lat
0023 %
0024 % FORMAT
0025 %
0026 %   S = satreaders.cmsaf_gac(file, varargin)
0027 %
0028 % See also: SatDataset/reader
0029 
0030 % $Id: avhrr_cmsaf_gac.m 8720 2013-10-21 20:41:39Z gerrit $
0031 % Created by Salomon Eliasson
0032 
0033 core_fields   = {'time','lat','lon'};
0034 extra_fields  = optargs(varargin, {{}});
0035 all_fields    = [core_fields(:); extra_fields(:)];
0036 % List of hand-made fields that can be composed already here to save memory and
0037 % storage space. I call them "pseudo fields" (e.g. modis_IWP that depends on 3
0038 % fields in the modis file). The loop of hdfread will check if any psudeo fields
0039 % are present. If so, it will be processed and the fields this pseudo field
0040 % requires to be created are further assumed to be frivolous and therefore
0041 % removed afterwards.
0042 pseudo_fields = {'AVHRR_IWP'};
0043 
0044 S.path = file; % get original file
0045 
0046 % UNCOMPRESS (if needed)
0047 tmpdir = create_tmpfolder;
0048 c = onCleanup(@() rmdir(tmpdir,'s'));
0049 file = uncompress(file,tmpdir);
0050 
0051 for F = all_fields'
0052     if ismember(F{1},pseudo_fields)
0053         continue
0054     end
0055     S.(F{1}) = loadncvar(file,F{1});
0056 end
0057 
0058 % turn time data into seconds (in hours)
0059 S.time = S.time*3600;
0060 
0061 S.lat  = double(S.lat'*0.01); % use scale (see attributes), make along x across
0062 S.lon  = double(S.lon'*0.01); % use scale (see attributes), make along x across
0063 S.time = double(S.time);
0064 
0065 % get the verion directly from the filename
0066 D = datasets;
0067 info = D.avhrr_cmsaf_gac.find_info_from_granule(file);
0068 S.epoch = round(date2unixsecs(str2double(info.year), str2double(info.month), str2double(info.day)));
0069 
0070 if any(ismember(pseudo_fields,extra_fields))
0071     for P = pseudo_fields(:)'
0072         S = dealWithPseudoFields(S,P{1},file);
0073     end
0074 end
0075 S.version = info.version;
0076 
0077 S = MaskInvalidGeoTimedataWithNaN(S);
0078 
0079 end
0080 
0081 %%%%%%%%%%%%%
0082 % SUBFUNCTION
0083 
0084 function S = dealWithPseudoFields(S,field,file)
0085 %% dealWithPseudoFields
0086 %
0087 % List of hand-made fields that can be composed already here to save memory
0088 % and storage space. Will check in the loop if this field is present. The
0089 % crux is that the fields the psuedo field relies on must be read, hence
0090 % listed before it. This is because they are ofcourse needed to build the
0091 % data field. and the fields it required are further assumed to be
0092 % frivolous and therefore removed afterwards. This part is hardcoded
0093 
0094 % READ dependent fields
0095 switch field
0096     case 'AVHRR_IWP'
0097         dependent_fields = {'cwp','cty'};
0098         rmflag = ~ismember(dependent_fields,fieldnames(S));
0099         for F = dependent_fields
0100             S.(F{1}) = loadncvar(file,F{1})'; % orientation is across x along
0101         end
0102 end
0103 
0104 % use dependent fields to BUILD the pseudo field
0105 switch field
0106     case 'AVHRR_IWP'
0107         
0108         % Keeping record of the pixels that are deemed to be cloud free
0109         clearPixel = S.cty==0;
0110         %S.cwp(clearPixel)=0;
0111         
0112         % grab values flagged as ice phase
0113         icePhase = S.cty==2;
0114              
0115         % NaN all non applicable data
0116         S.cwp(~(clearPixel | icePhase)) = NaN;
0117         
0118         % Therefore we can call this simply IWP
0119         S.AVHRR_IWP = S.cwp;
0120         
0121 end
0122 
0123 S=rmfield(S,dependent_fields(rmflag));
0124 end

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