Home > atmlab > geographical > modlev2presslev.m

modlev2presslev

PURPOSE ^

MODELEV2PRESSLEV converts model levels to pressure levels using linear interpolation

SYNOPSIS ^

function [data] = modlev2presslev(iarray,P,pgrid,nlev)

DESCRIPTION ^

 MODELEV2PRESSLEV converts model levels to pressure levels using linear interpolation

 IN
     iarrray  [%f,...]            input matrix 2D or greater
     P        [%f,...]            pressure values on model level. Must be same
                                  size as iarray. [Pa]
     pgrid                        vector containing new presure vertical
                                  coordintates. Should be within the model's 
                                  own domain [Pa]
     nlev     %f                  Number of model vertical levels

 OUT
     out = data                   Interpolated data to the new pressure grid

 NOTE
     * MUST have the input dimensions data(lev,....) 

 USAGE: out = modlev2presslev(data(lev,...),P(lev,...),pgrid)

 $Id: modlev2presslev.m 7194 2011-11-07 12:38:15Z seliasson $ 
 Created Marston Johnston

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

modlev2presslev.m

SOURCE CODE ^

0001 function [data] = modlev2presslev(iarray,P,pgrid,nlev)
0002 % MODELEV2PRESSLEV converts model levels to pressure levels using linear interpolation
0003 %
0004 % IN
0005 %     iarrray  [%f,...]            input matrix 2D or greater
0006 %     P        [%f,...]            pressure values on model level. Must be same
0007 %                                  size as iarray. [Pa]
0008 %     pgrid                        vector containing new presure vertical
0009 %                                  coordintates. Should be within the model's
0010 %                                  own domain [Pa]
0011 %     nlev     %f                  Number of model vertical levels
0012 %
0013 % OUT
0014 %     out = data                   Interpolated data to the new pressure grid
0015 %
0016 % NOTE
0017 %     * MUST have the input dimensions data(lev,....)
0018 %
0019 % USAGE: out = modlev2presslev(data(lev,...),P(lev,...),pgrid)
0020 %
0021 % $Id: modlev2presslev.m 7194 2011-11-07 12:38:15Z seliasson $
0022 % Created Marston Johnston
0023 
0024 
0025 assert(nargin == 4,['atmlab:' mfilename ':badInput'],...
0026     'incorrect number of arguments')
0027 assert(isequal(size(iarray),size(P)),['atmlab:' mfilename ':badInput'],...
0028     '''iarray'' and ''P'' must be the same size')
0029 assert(isvector(pgrid),['atmlab:' mfilename ':badInput'],...
0030     'pgrid must be a vector')
0031 assert(all(pgrid >= min(P(:)))&&all(pgrid <= max(P(:))),...
0032     ['atmlab:' mfilename ':badInput'],...
0033     'pgrid is out side the domain if the pressure matrix')
0034 assert(isequal(size(iarray,1),nlev),...
0035     ['atmlab:' mfilename ':dimError'],...
0036     'Dimension 1 must equal to number of levels');
0037 
0038 % Get the size of the input array
0039 sz = size(iarray);
0040 % Change the pressure level dimension to the new grid.
0041 sz(1) = length(pgrid);
0042 % compress the array to 2D
0043 iarray = iarray(:,:); 
0044 P = P(:,:);
0045 pAr = NaN(sz);
0046 pAr = pAr(:,:);
0047 for a = 1:size(iarray,2)
0048     ivalues = iarray(:,a);
0049     igrid   = P(:,a);
0050     ovalues = interp1(log10(igrid),ivalues,log10(pgrid));
0051     pAr(:,a) = ovalues;
0052 end
0053 data = reshape(pAr,sz);

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