Home > atmlab > arts > qarts_atm_field.m

qarts_atm_field

PURPOSE ^

QARTS_ATM_FIELD Extracts a basic atmospheric field from e.g. Q.T_ATMDATA

SYNOPSIS ^

function atmfield = qarts_atm_field( Q, vstring, varargin )

DESCRIPTION ^

 QARTS_ATM_FIELD   Extracts a basic atmospheric field from e.g. Q.T_ATMDATA

   Performs an interpolation of ATMDATA, for those variables having such a
   sub-field. Those variables include: T, Z, WIND_U, WIND_V and WIND_W.

   The field ATMDATA must be set. For 3D cases, P_GRID, LAT_GRID and LON_GRID
   are used as interpolation grids. For 1D and 2D, LAT_TRUE and LON_TRUE
   replace LAT_GRID and LON_GRID.

   The interpolation is made as using *atmdata_regrid*. 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.

   It is also possible to handle atmdata having day and hour dimensions. The
   optional arguments must then be set.

   The following fields must always be set:
      Q.ATMOSPHERE_DIM
      Q.P_GRID

 FORMAT   atmfield = qarts_atm_field( Q, vstring [, day, hour] )
        
 OUT   atmfield    Obtained data field.
 IN    Q           Qarts setting structure.
       vstring     The variable for which ATMDATA shall be interpolated.
                   Case of strong is ignored. Examples: 't', 'T', 'z', 
                   'wind_u' and 'WIND_w'.
 OPT   mjd         Date as MJD. A scalar.
       ltime       Local (solar) time, in hours. A scalar.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

qarts_atm_field.m

SOURCE CODE ^

0001 % QARTS_ATM_FIELD   Extracts a basic atmospheric field from e.g. Q.T_ATMDATA
0002 %
0003 %   Performs an interpolation of ATMDATA, for those variables having such a
0004 %   sub-field. Those variables include: T, Z, WIND_U, WIND_V and WIND_W.
0005 %
0006 %   The field ATMDATA must be set. For 3D cases, P_GRID, LAT_GRID and LON_GRID
0007 %   are used as interpolation grids. For 1D and 2D, LAT_TRUE and LON_TRUE
0008 %   replace LAT_GRID and LON_GRID.
0009 %
0010 %   The interpolation is made as using *atmdata_regrid*. That is, the data are
0011 %   assumed to be defined everywhere (end values valid all the way to +-INF).
0012 %   This is also valid for singleton dimensions. The grid for empty/singleton
0013 %   dimensions can be empty or a scalar.
0014 %
0015 %   It is also possible to handle atmdata having day and hour dimensions. The
0016 %   optional arguments must then be set.
0017 %
0018 %   The following fields must always be set:
0019 %      Q.ATMOSPHERE_DIM
0020 %      Q.P_GRID
0021 %
0022 % FORMAT   atmfield = qarts_atm_field( Q, vstring [, day, hour] )
0023 %
0024 % OUT   atmfield    Obtained data field.
0025 % IN    Q           Qarts setting structure.
0026 %       vstring     The variable for which ATMDATA shall be interpolated.
0027 %                   Case of strong is ignored. Examples: 't', 'T', 'z',
0028 %                   'wind_u' and 'WIND_w'.
0029 % OPT   mjd         Date as MJD. A scalar.
0030 %       ltime       Local (solar) time, in hours. A scalar.
0031 
0032 % 2010-01-09   Created by Patrick Eriksson.
0033 
0034 function atmfield = qarts_atm_field( Q, vstring, varargin )
0035 
0036 
0037 %- Some help variables
0038 %
0039 VNAME = upper( vstring );
0040 astr  = sprintf( 'Q.%c.ATMDATA', VNAME );
0041 
0042 
0043 %- Variable checks
0044 %
0045 strict_assert = atmlab( 'STRICT_ASSERT' );
0046 %
0047 if strict_assert
0048 
0049   rqre_nargin( 2, nargin );
0050   rqre_datatype( vstring, @ischar );
0051   for i = 1 : length( varargin )
0052     rqre_datatype( varargin{i}, @istensor0, ...
0053                                      'Optional arguments *mjd* and *ltime*.' ); 
0054   end
0055   
0056   if ~qarts_isset( Q.ATMOSPHERE_DIM )
0057     error( 'Q.ATMOSPHERE_DIM must be set when using this function' );
0058   end
0059   if ~qarts_isset( Q.P_GRID )
0060     error( 'Q.P_GRID must be set when using this function' );
0061   end
0062   if Q.ATMOSPHERE_DIM < 3
0063     if ~qarts_isset( Q.LAT_TRUE )
0064       error( 'For 1D and 2D, Q.LAT_TRUE must be set when using this function' );
0065     end
0066     if ~qarts_isset( Q.LON_TRUE )
0067       error( 'For 1D and 2D, Q.LON_TRUE must be set when using this function' );
0068     end
0069   else
0070     if ~qarts_isset( Q.LAT_GRID )
0071       error( 'For 3D, Q.LAT_GRID must be set when using this function' );
0072     end
0073     if ~qarts_isset( Q.LON_GRID )
0074       error( 'For 3D, Q.LON_GRID must be set when using this function' );
0075     end
0076   end
0077   
0078   if ~isfield( Q.(VNAME), 'ATMDATA' ) | ~qarts_isset( Q.(VNAME).ATMDATA )
0079     error( sprintf( '%s must be set when using this function', astr ) );
0080   end
0081 
0082 end
0083 
0084 
0085 %- Get data to interpolate
0086 %
0087 G = qarts_get_gformat( Q.(VNAME).ATMDATA );
0088 %
0089 if strict_assert
0090   rqre_datatype( G, @isatmdata, astr ); 
0091 end
0092 
0093 
0094 %- Standard "regrid" can be applied for 1D and 3D
0095 %
0096 if Q.ATMOSPHERE_DIM ~= 2
0097   %
0098   grids{1} = qarts_get( Q.P_GRID );
0099   %
0100   if Q.ATMOSPHERE_DIM == 1
0101     grids{2} = qarts_get( Q.LAT_TRUE );
0102     grids{3} = qarts_get( Q.LON_TRUE );
0103     if strict_assert  &  ( length(grids{2}) ~= 1  |  length(grids{3}) ~= 1 )
0104       error( 'For 1D, Q.LAT_TRUE and Q.LON_TRUE must have length 1.' );
0105     end
0106   else
0107     grids{2} = qarts_get( Q.LAT_GRID );
0108     grids{3} = qarts_get( Q.LON_GRID );
0109   end
0110   %
0111   for i = 1 : length( varargin )
0112     grids{3+i} = varargin{i};
0113   end
0114   %
0115   % Minimum dimension for interpolation is Q.ATMOSPHERE_DIM
0116   dim = max( [ G.DIM Q.ATMOSPHERE_DIM ] );
0117   %
0118   G = atmdata_regrid( G, {grids{1:dim}}, astr );
0119   %
0120   atmfield = G.DATA;
0121   
0122   
0123 %- For 2D we perform repeated 1D regridding
0124 %
0125 else
0126   %
0127   lat_true = qarts_get( Q.LAT_TRUE );
0128   lon_true = qarts_get( Q.LON_TRUE );
0129   %
0130   if strict_assert  &  length(lat_true) ~= length(lon_true)
0131     error( 'For 2D, Q.LAT_TRUE and Q.LON_TRUE must have the same length.' );
0132   end
0133   %
0134   grids{1} = qarts_get( Q.P_GRID );
0135   grids{2} = lat_true(1);
0136   grids{3} = lon_true(1);
0137   %
0138   for i = 1 : length( varargin )
0139     grids{3+i} = varargin{i};
0140   end
0141   %
0142   dim             = max( [ G.DIM Q.ATMOSPHERE_DIM ] );
0143   Gtemp               = atmdata_regrid( G, {grids{1:dim}}, astr );
0144   n               = length( lat_true );
0145   atmfield        = zeros( size(Gtemp.DATA,1), n );
0146   atmfield(:,1)   = Gtemp.DATA;  
0147   %
0148   for i = 2 : n
0149     grids{2}      = lat_true(i);
0150     grids{3}      = lon_true(i);
0151     Gtemp             = atmdata_regrid( G, {grids{1:dim}}, astr );
0152     atmfield(:,i) = Gtemp.DATA;  
0153   end
0154 end

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