Home > atmlab > gformat > gf_regrid.m

gf_regrid

PURPOSE ^

GF_REGRID Change of rectangular grid for gformat data

SYNOPSIS ^

function G = gf_regrid( G, grids, iopt )

DESCRIPTION ^

 GF_REGRID   Change of rectangular grid for gformat data

    Largely an interface to *gridinterp*. The dimension and size of new data
    are determined by the number of grids and their lengths, respectively.

   The interpolation is made as using *gridinterp* with its optional argument
   *extrap* set to true. That is, the data are assumed to be defined
   everywhere (end values valid all the way to +-INF). This is also valid for
   singleton dimensions. The grid for empty/singleton dimensions can be empty
   or a scalar.

    The function is "vectorised". That is, can be called as
      G(2:3) = gf_regrid( G(2:3), ...

 FORMAT   G = gf_regrid( G, grids, iopt )

 OUT   G      Re-grided gformat data.
 IN    G      Original gformat data.
       grids  New grids. An array of vectors.
 OPT   iopt   Interpolation option. See *regrid*.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

gf_regrid.m

SOURCE CODE ^

0001 % GF_REGRID   Change of rectangular grid for gformat data
0002 %
0003 %    Largely an interface to *gridinterp*. The dimension and size of new data
0004 %    are determined by the number of grids and their lengths, respectively.
0005 %
0006 %   The interpolation is made as using *gridinterp* with its optional argument
0007 %   *extrap* set to true. That is, the data are assumed to be defined
0008 %   everywhere (end values valid all the way to +-INF). This is also valid for
0009 %   singleton dimensions. The grid for empty/singleton dimensions can be empty
0010 %   or a scalar.
0011 %
0012 %    The function is "vectorised". That is, can be called as
0013 %      G(2:3) = gf_regrid( G(2:3), ...
0014 %
0015 % FORMAT   G = gf_regrid( G, grids, iopt )
0016 %
0017 % OUT   G      Re-grided gformat data.
0018 % IN    G      Original gformat data.
0019 %       grids  New grids. An array of vectors.
0020 % OPT   iopt   Interpolation option. See *regrid*.
0021 %
0022 
0023 % 2007-10-17   Created by Patrick Eriksson.
0024 
0025 
0026 function G = gf_regrid( G, grids, iopt )
0027 %
0028 if nargin < 3
0029   iopt = 'linear';
0030 end
0031 
0032 if atmlab('STRICT_ASSERT')
0033   %
0034   rqre_datatype( G, @isgformat );
0035   % Grids of G are checked inside *gridinterp*
0036   rqre_datatype( grids, @iscell );
0037   rqre_datatype( iopt, @ischar );
0038 end
0039 
0040 agrids = cell(length(G));
0041 for i = 1 : length( G )
0042   %
0043   for d = 1  : G(i).DIM
0044       gname        = sprintf('GRID%d',d);
0045       agrids{d}    = G(i).(gname);
0046       G(i).(gname) = grids{d};
0047   end
0048   %
0049   G(i).DATA = gridinterp( agrids, G(i).DATA, grids, iopt, true );
0050   %
0051 end

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