Home > atmlab > datasets > convert_dardar.m

convert_dardar

PURPOSE ^

convert full dardar to subselected dardar

SYNOPSIS ^

function convert_dardar(dt1, dt2)

DESCRIPTION ^

 convert full dardar to subselected dardar

 Fields are defined by dataset 'dardarsub'

 FORMAT

   convert_dardar(dt1, dt2)

 IN

   dt1     datevec, starting date
   dt2     datevec, ending date


 $Id: convert_dardar.m 8250 2013-03-01 12:34:40Z gerrit $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

convert_dardar.m

SOURCE CODE ^

0001 function convert_dardar(dt1, dt2)
0002     % convert full dardar to subselected dardar
0003     %
0004     % Fields are defined by dataset 'dardarsub'
0005     %
0006     % FORMAT
0007     %
0008     %   convert_dardar(dt1, dt2)
0009     %
0010     % IN
0011     %
0012     %   dt1     datevec, starting date
0013     %   dt2     datevec, ending date
0014     %
0015     %
0016     % $Id: convert_dardar.m 8250 2013-03-01 12:34:40Z gerrit $
0017     
0018     D = datasets;
0019     dd_full = D.dardar;
0020     dd_sub = D.dardarsub;
0021     
0022     tostore = fieldnames(dd_sub.members);
0023     [grans, paths] = dd_full.find_granules_for_period(dt1, dt2, '');
0024 
0025     builtins = {'time', 'lat', 'lon'};
0026     
0027     for i = 1:size(grans, 1);
0028         dt = grans(i, :);
0029                 
0030         [~, bs] = fileparts(paths{i});
0031         dd_sub.filename = [bs '_selection.nc.gz'];
0032         ff = fullfile(dd_sub.find_datadir_by_date(dt), dd_sub.filename);
0033         if exist(ff, 'file') && ~dd_sub.overwrite
0034             logtext(atmlab('OUT'), 'Already exists, skipping: %s\n', ff);
0035             continue
0036         end
0037         data = dd_full.read_granule(dt, '', ...
0038             setdiff(tostore, builtins), ...
0039             false, false, false); % (no duplicate removing, no force-on-error, no reloading)
0040         
0041         ncols = sum(cellfun(@(f) size(data.(f), 2), tostore));
0042         nrows = size(data.time, 1);
0043 %         data.height = repmat(data.height, [nrows 1]);
0044         % Apply factor and offset where appropriate. So far hardcoded for
0045         % temperature only, if more fields should then systematic searching
0046         % ought to be implemented
0047         data.temperature = int16(round(...
0048             (data.temperature - dd_sub.members.temperature.atts.add_offset)/(dd_sub.members.temperature.atts.scale_factor)));
0049         data.temperature(data.temperature<0) = dd_sub.members.temperature.atts.missing_value;
0050 
0051         M = zeros(nrows, ncols);
0052         nc = 1;
0053         
0054         for k = 1:length(tostore)
0055             fld = tostore{k};
0056             w = size(data.(fld), 2);
0057             rng = nc:(nc+w-1);
0058             M(:, rng) = data.(fld);
0059             cc.(fld) = rng;
0060             nc = nc + w;
0061         end
0062         
0063         dd_sub.cols = cc;
0064         
0065         info = struct();
0066         info.title = 'Reduced DARDAR data';
0067         dd_sub.store(dt(1:3), '', M, info);
0068     end
0069     
0070 end

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