Home > atmlab > gformat > atmdata_regrid.m

atmdata_regrid

PURPOSE ^

ATMDATA_REGRID Change of rectangular grid for atmdata

SYNOPSIS ^

function G = atmdata_regrid( G, grids, nonstdname )

DESCRIPTION ^

 ATMDATA_REGRID   Change of rectangular grid for atmdata

    Largely an interface to *gf_regrid*, but ensures that the atmdata format
    is followed and that pressure grids are converted to log(p).

    If *grids* covers the day dimension (fourth dimension), the day(s) shall
    be given as MJD. These dates are translated to the date format used in
    *G* by the function. If *G* is an array, the same time format is assumed
    for all elements.

 FORMAT   G = atmdata_regrid( G, grids [, nonstdname] )

 OUT   G            Re-grided atmlab data.
 IN    G            Original atmlab data.
       grids        New grids. An array of vectors.
 OPT   nonstdname   Name of *G* to use in error message. Default is
                    to use the function *inputname* to determine the
                    variable name.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

atmdata_regrid.m

SOURCE CODE ^

0001 % ATMDATA_REGRID   Change of rectangular grid for atmdata
0002 %
0003 %    Largely an interface to *gf_regrid*, but ensures that the atmdata format
0004 %    is followed and that pressure grids are converted to log(p).
0005 %
0006 %    If *grids* covers the day dimension (fourth dimension), the day(s) shall
0007 %    be given as MJD. These dates are translated to the date format used in
0008 %    *G* by the function. If *G* is an array, the same time format is assumed
0009 %    for all elements.
0010 %
0011 % FORMAT   G = atmdata_regrid( G, grids [, nonstdname] )
0012 %
0013 % OUT   G            Re-grided atmlab data.
0014 % IN    G            Original atmlab data.
0015 %       grids        New grids. An array of vectors.
0016 % OPT   nonstdname   Name of *G* to use in error message. Default is
0017 %                    to use the function *inputname* to determine the
0018 %                    variable name.
0019 
0020 % 2007-10-17   Created by Patrick Eriksson.
0021 
0022 
0023 function G = atmdata_regrid( G, grids, nonstdname )
0024 
0025 strictAssert = atmlab('STRICT_ASSERT');
0026 
0027 if strictAssert
0028   rqre_nargin( 2, nargin );
0029   if nargin == 2 
0030     rqre_datatype( G, @isatmdata );
0031   else
0032     rqre_datatype( nonstdname, @ischar );
0033     rqre_datatype( G, @isatmdata, nonstdname );
0034   end
0035 end
0036 % grids checked in gf_regrid
0037 
0038 
0039 %- Take log of pressure
0040 %
0041 if ~isempty( grids )
0042   g0       = grids{1};
0043   grids{1} = -log( grids{1} );
0044 end
0045 for i = 1 : length(G)
0046   if G(i).DIM > 0
0047     G(i).GRID1 = -log( G(i).GRID1 );
0048   end
0049 end
0050 
0051 
0052 %- Handle day formats
0053 %
0054 if length(grids) >= 4
0055     
0056   if strictAssert
0057     % Trigger warning if doy or datenum (with std. pivot year) are used
0058     if min(grids{4}) < 370 ||  max(grids{4}) > 250e3
0059       warning(['atmlab:' mfilename], ...
0060           'Suspicious day data found! Dates (in *grids*) should use MJD.')
0061     end
0062   end
0063 
0064 
0065   [maxdim,i] = max( [G.DIM] );
0066   if maxdim >= 4
0067     tformat = lower( G(i).GRID4_NAME );
0068     if strcmp( tformat, 'mjd' )
0069       %
0070     elseif strcmp( tformat, 'doy' )
0071       grids{4} = mjd2doy( grids{4} );
0072     elseif strcmp( tformat, 'datenum' )
0073       [ye,mo,da,ho,mi,se] = mjd2date( grids{4} );
0074       grids{4} = datenum( ye, mo, da, ho, mi, se );
0075     else 
0076       assert( false );
0077     end 
0078   end
0079 end
0080 
0081 G = gf_regrid( G, grids );
0082 
0083 % Restore pressure grid
0084 %
0085 for i = 1 : length(G)
0086   if G(i).DIM > 0
0087     G(i).GRID1 = g0;
0088   end
0089 end

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